From 6c8ed88ab544730257f8109b49dbd9c5255d14a3 Mon Sep 17 00:00:00 2001 From: Santiago Palenque Date: Fri, 20 Feb 2026 18:18:24 -0300 Subject: [PATCH] fix: sponsor and company validation and scrollToError on popups --- src/hooks/useScrollToError.js | 8 ++++-- .../components/process-request-form.js | 27 ++++++++++--------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/hooks/useScrollToError.js b/src/hooks/useScrollToError.js index 2d0cabeec..7579e47a8 100644 --- a/src/hooks/useScrollToError.js +++ b/src/hooks/useScrollToError.js @@ -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; @@ -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]); }; diff --git a/src/pages/sponsors/sponsor-users-list-page/components/process-request-form.js b/src/pages/sponsors/sponsor-users-list-page/components/process-request-form.js index 434f96fc5..d3276cd47 100644 --- a/src/pages/sponsors/sponsor-users-list-page/components/process-request-form.js +++ b/src/pages/sponsors/sponsor-users-list-page/components/process-request-form.js @@ -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 @@ -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 @@ -98,7 +101,7 @@ const ProcessRequestForm = ({ request, userGroups, summit, onSubmit }) => { }); // SCROLL TO ERROR - useScrollToError(formik); + useScrollToError(formik, true); return (