diff --git a/web/gds-user-ui/src/components/CertificateReview/index.tsx b/web/gds-user-ui/src/components/CertificateReview/index.tsx index 9eeb5113e..5bcd58d82 100644 --- a/web/gds-user-ui/src/components/CertificateReview/index.tsx +++ b/web/gds-user-ui/src/components/CertificateReview/index.tsx @@ -18,6 +18,7 @@ import { getRefreshToken } from 'utils/auth0.helper'; import { STEPPER_NETWORK } from 'utils/constants'; import { getUserCurrentOrganizationService } from 'modules/auth/login/auth.service'; import { setUserOrganization } from 'modules/auth/login/user.slice'; +import { upperCaseFirstLetter } from 'utils/utils'; const ReviewsSummary = lazy(() => import('./ReviewsSummary')); const CertificateReview = () => { const toast = useToast(); @@ -64,11 +65,11 @@ const CertificateReview = () => { setIsMainNetSubmitting(false); setIsTestNetSubmitting(false); - if (!err?.response?.data?.success) { + if (!err?.data?.success) { toast({ position: 'top-right', title: t`Error Submitting Certificate`, - description: t`${err?.response?.data?.error}`, + description: t`${upperCaseFirstLetter(err?.data?.error)}`, status: 'error', duration: 5000, isClosable: true diff --git a/web/gds-user-ui/src/components/Contacts/ContactsForm.tsx b/web/gds-user-ui/src/components/Contacts/ContactsForm.tsx index 79f34933c..18231242d 100644 --- a/web/gds-user-ui/src/components/Contacts/ContactsForm.tsx +++ b/web/gds-user-ui/src/components/Contacts/ContactsForm.tsx @@ -15,6 +15,7 @@ import FormLayout from 'layouts/FormLayout'; import { StepsIndexes } from 'constants/steps'; import { isProdEnv } from 'application/config'; import { DevTool } from '@hookform/devtools'; +import { useFetchCertificateStep } from 'hooks/useFetchCertificateStep'; interface ContactsFormProps { data?: any; isLoading?: boolean; @@ -25,13 +26,16 @@ const ContactsForm: React.FC = ({ data, shouldResetForm, onRe const { isOpen, onClose, onOpen } = useDisclosure(); const [shouldShowResetFormModal, setShouldShowResetFormModal] = useState(false); const { previousStep, nextStep, currentState, updateIsDirty } = useCertificateStepper(); + const { certificateStep } = useFetchCertificateStep({ + key: StepEnum.CONTACTS + }); const { updateCertificateStep, updatedCertificateStep, wasCertificateStepUpdated, isUpdatingCertificateStep, - reset: resetMutation + reset } = useUpdateCertificateStep(); const previousStepRef = useRef(false); const nextStepRef = useRef(false); @@ -53,7 +57,7 @@ const ContactsForm: React.FC = ({ data, shouldResetForm, onRe }, [isDirty, updateIsDirty]); if (wasCertificateStepUpdated && nextStepRef.current) { - resetMutation(); + reset(); // reset the form with the new values resetForm(updatedCertificateStep?.form, { keepValues: false @@ -63,18 +67,19 @@ const ContactsForm: React.FC = ({ data, shouldResetForm, onRe } if (wasCertificateStepUpdated && previousStepRef.current && !isUpdatingCertificateStep) { - resetMutation(); + reset(); // reset the form with the new values resetForm(updatedCertificateStep?.form, { keepValues: false }); - // console.log('[] prev updatedCertificateStep', updatedCertificateStep); previousStepRef.current = false; previousStep(updatedCertificateStep); } const handlePreviousStepClick = () => { - if (isDirty) { + if (!isDirty) { + previousStep(certificateStep); + } else { const payload = { step: StepEnum.CONTACTS, form: { @@ -85,7 +90,6 @@ const ContactsForm: React.FC = ({ data, shouldResetForm, onRe updateCertificateStep(payload); previousStepRef.current = true; } - previousStep(data); }; useEffect(() => { @@ -102,13 +106,7 @@ const ContactsForm: React.FC = ({ data, shouldResetForm, onRe const handleNextStepClick = () => { if (!isDirty) { - nextStep({ - step: StepEnum.CONTACTS, - form: { - ...methods.getValues(), - state: currentState() - } as any - }); + nextStep(certificateStep); } else { const payload = { step: StepEnum.CONTACTS, diff --git a/web/gds-user-ui/src/components/ErrorComponent/RequiredElementMissing.tsx b/web/gds-user-ui/src/components/ErrorComponent/RequiredElementMissing.tsx index 65c97f5d0..b5cc533f4 100644 --- a/web/gds-user-ui/src/components/ErrorComponent/RequiredElementMissing.tsx +++ b/web/gds-user-ui/src/components/ErrorComponent/RequiredElementMissing.tsx @@ -14,9 +14,7 @@ interface RequiredElementMissingProps { errorFields?: any[]; } -const RequiredElementMissing = ({ elementKey, errorFields }: RequiredElementMissingProps) => { - console.log('k', elementKey); - +const RequiredElementMissing = ({ errorFields }: RequiredElementMissingProps) => { return ( {errorFields?.map((errorField: any, index) => { - console.log('errorField', errorField); return ( diff --git a/web/gds-user-ui/src/components/LegalPerson/LegalForm.tsx b/web/gds-user-ui/src/components/LegalPerson/LegalForm.tsx index 2ac94d6b4..9a9c1eeef 100644 --- a/web/gds-user-ui/src/components/LegalPerson/LegalForm.tsx +++ b/web/gds-user-ui/src/components/LegalPerson/LegalForm.tsx @@ -8,7 +8,7 @@ import Address from 'components/Addresses'; import { FormProvider, useForm } from 'react-hook-form'; import StepButtons from 'components/StepsButtons'; import useCertificateStepper from 'hooks/useCertificateStepper'; -import { legalPersonValidationSchemam } from 'modules/dashboard/certificate/lib/legalPersonValidationSchema'; +import { legalPersonValidationSchema } from 'modules/dashboard/certificate/lib/legalPersonValidationSchema'; import { yupResolver } from '@hookform/resolvers/yup'; import { StepEnum } from 'types/enums'; @@ -17,6 +17,7 @@ import { useUpdateCertificateStep } from 'hooks/useUpdateCertificateStep'; import { StepsIndexes } from 'constants/steps'; import { isProdEnv } from 'application/config'; import { DevTool } from '@hookform/devtools'; +import { useFetchCertificateStep } from 'hooks/useFetchCertificateStep'; interface LegalFormProps { data?: any; isLoading?: boolean; @@ -29,16 +30,19 @@ const LegalForm: React.FC = ({ data, shouldResetForm, onResetFor const { isOpen, onClose, onOpen } = useDisclosure(); const [shouldShowResetFormModal, setShouldShowResetFormModal] = useState(false); const { previousStep, nextStep, currentState, updateIsDirty } = useCertificateStepper(); + const { certificateStep } = useFetchCertificateStep({ + key: StepEnum.LEGAL + }); const { updateCertificateStep, updatedCertificateStep, - reset: resetMutation, + reset, wasCertificateStepUpdated, isUpdatingCertificateStep } = useUpdateCertificateStep(); const previousStepRef = useRef(false); const nextStepRef = useRef(false); - const resolver = yupResolver(legalPersonValidationSchemam); + const resolver = yupResolver(legalPersonValidationSchema); const methods = useForm({ defaultValues: data, resolver, @@ -56,7 +60,7 @@ const LegalForm: React.FC = ({ data, shouldResetForm, onResetFor }; if (wasCertificateStepUpdated && nextStepRef.current) { - resetMutation(); + reset(); // reset the form with the new values resetForm(updatedCertificateStep?.form, { keepValues: false @@ -66,25 +70,18 @@ const LegalForm: React.FC = ({ data, shouldResetForm, onResetFor } if (wasCertificateStepUpdated && previousStepRef.current && !isUpdatingCertificateStep) { - resetMutation(); + reset(); // reset the form with the new values - resetForm(updatedCertificateStep?.form, { + resetForm(updatedCertificateStep?.form, { keepValues: false }); - // console.log('[] prev updatedCertificateStep', updatedCertificateStep); previousStepRef.current = false; previousStep(updatedCertificateStep); } const handleNextStepClick = () => { if (!isDirty) { - nextStep({ - step: StepEnum.LEGAL, - form: { - ...methods.getValues(), - state: currentState() - } as any - }); + nextStep(certificateStep); } else { const payload = { step: StepEnum.LEGAL, @@ -96,12 +93,13 @@ const LegalForm: React.FC = ({ data, shouldResetForm, onResetFor updateCertificateStep(payload); nextStepRef.current = true; - // nextStep(updatedCertificateStep); } }; const handlePreviousStepClick = () => { - if (isDirty) { + if (!isDirty) { + previousStep(certificateStep); + } else { const payload = { step: StepEnum.LEGAL, form: { @@ -109,14 +107,9 @@ const LegalForm: React.FC = ({ data, shouldResetForm, onResetFor state: currentState() } as any }; - // console.log('[] isDirty payload', payload); - updateCertificateStep(payload); previousStepRef.current = true; - // previousStep(updatedCertificateStep); } - - previousStep(data); }; const handleResetForm = () => { diff --git a/web/gds-user-ui/src/components/LegalPerson/index.tsx b/web/gds-user-ui/src/components/LegalPerson/index.tsx index a93f7a308..9a90429eb 100644 --- a/web/gds-user-ui/src/components/LegalPerson/index.tsx +++ b/web/gds-user-ui/src/components/LegalPerson/index.tsx @@ -21,7 +21,6 @@ const LegalPerson: React.FC = () => { useFetchCertificateStep({ key: StepEnum.LEGAL }); - const { isStepDeleted, updateDeleteStepState } = useCertificateStepper(); const isLegalStepDeleted = isStepDeleted(StepEnum.LEGAL); diff --git a/web/gds-user-ui/src/components/OtherJuridictions/OtherJuridictions.stories.tsx b/web/gds-user-ui/src/components/OtherJurisdictions/OtherJurisdictions.stories.tsx similarity index 53% rename from web/gds-user-ui/src/components/OtherJuridictions/OtherJuridictions.stories.tsx rename to web/gds-user-ui/src/components/OtherJurisdictions/OtherJurisdictions.stories.tsx index 1d2348037..39f4a115c 100644 --- a/web/gds-user-ui/src/components/OtherJuridictions/OtherJuridictions.stories.tsx +++ b/web/gds-user-ui/src/components/OtherJurisdictions/OtherJurisdictions.stories.tsx @@ -1,18 +1,18 @@ import { Meta, Story } from '@storybook/react'; import { withRHF } from 'hoc/withRHF'; -import OtherJuridictions from '.'; +import OtherJurisdictions from '.'; -type OtherJuridictionsProps = { +type OtherJurisdictionsProps = { name: string; }; export default { - title: 'components/OtherJuridictions', - component: OtherJuridictions, + title: 'components/OtherJurisdictions', + component: OtherJurisdictions, decorators: [withRHF(false)] } as Meta; -const Template: Story = (args) => ; +const Template: Story = (args) => ; export const Standard = Template.bind({}); Standard.args = { diff --git a/web/gds-user-ui/src/components/OtherJuridictions/index.tsx b/web/gds-user-ui/src/components/OtherJurisdictions/index.tsx similarity index 92% rename from web/gds-user-ui/src/components/OtherJuridictions/index.tsx rename to web/gds-user-ui/src/components/OtherJurisdictions/index.tsx index 57297b7a5..562da58e7 100644 --- a/web/gds-user-ui/src/components/OtherJuridictions/index.tsx +++ b/web/gds-user-ui/src/components/OtherJurisdictions/index.tsx @@ -6,14 +6,14 @@ import { getCountriesOptions } from 'constants/countries'; import { Controller, useFieldArray, useFormContext } from 'react-hook-form'; import { t } from '@lingui/macro'; import { Trans } from '@lingui/react'; -const OtherJuridictions: React.FC<{ name: string }> = ({ name }) => { +const OtherJurisdictions: React.FC<{ name: string }> = ({ name }) => { const { control, register } = useFormContext(); const { fields, append, remove } = useFieldArray({ name, control }); - const handleAddJuridictionClick = () => { + const handleAddJurisdictionClick = () => { append({ country: '', regulator_name: '' @@ -61,7 +61,7 @@ const OtherJuridictions: React.FC<{ name: string }> = ({ name }) => { ))}