Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/hooks/useScrollToError.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function smoothScrollTo(targetScrollTop, duration) {
requestAnimationFrame(animationStep);
}

const useScrollToError = (formik) => {
const useScrollToError = (formik, relative = false) => {
const { errors, isValid, isSubmitting } = formik;
const errorArray = Object.keys(errors);
const errorCount = errorArray.length;
Expand Down Expand Up @@ -56,7 +56,11 @@ const useScrollToError = (formik) => {
const duration = 500; // 500ms scroll duration
const scrollToY = target.top - offset;

smoothScrollTo(scrollToY, duration);
if (relative) {
target?.element.scrollIntoView({ behavior: "smooth", block: "center" });
} else {
smoothScrollTo(scrollToY, duration);
}
}, [isSubmitting]);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ const ProcessRequestForm = ({ request, userGroups, summit, onSubmit }) => {
.when("sponsor_type", {
is: SPONSOR_USER_ASSIGNMENT_TYPE.EXISTING,
then: (schema) =>
schema.required(T.translate("validation.required")).shape({
id: yup.number().required(),
name: yup.string().required()
}),
schema
.test(
"sponsor-required",
T.translate("validation.required"),
(value) => value && value.id && value.name
)
.required(T.translate("validation.required")),
otherwise: (schema) => schema.notRequired()
}),
company: yup
Expand All @@ -67,13 +70,13 @@ const ProcessRequestForm = ({ request, userGroups, summit, onSubmit }) => {
.when("sponsor_type", {
is: SPONSOR_USER_ASSIGNMENT_TYPE.NEW,
then: (schema) =>
schema.required(T.translate("validation.required")).shape({
id: yup
.number()
.min(0, T.translate("validation.required"))
.required(),
name: yup.string().required()
}),
schema
.test(
"company-required",
T.translate("validation.required"),
(value) => value && value.id && value.name
)
.required(T.translate("validation.required")),
otherwise: (schema) => schema.notRequired()
}),
tiers: yup
Expand All @@ -98,7 +101,7 @@ const ProcessRequestForm = ({ request, userGroups, summit, onSubmit }) => {
});

// SCROLL TO ERROR
useScrollToError(formik);
useScrollToError(formik, true);

return (
<FormikProvider value={formik}>
Expand Down