diff --git a/src/common/utils.ts b/src/common/utils.ts index b3331c807..fa8d349a9 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -300,3 +300,9 @@ export const updateContactCache = (client: any, id: any) => { return null; }; + +export const formatString = (str: string) => + str + .replace(/_/g, ' ') + .replace(/([a-z])([0-9])/gi, '$1 $2') + .replace(/\b\w/g, (char) => char.toUpperCase()); diff --git a/src/components/UI/Form/PhoneInput/PhoneInput.tsx b/src/components/UI/Form/PhoneInput/PhoneInput.tsx index 42c53a913..6ce4eef0e 100644 --- a/src/components/UI/Form/PhoneInput/PhoneInput.tsx +++ b/src/components/UI/Form/PhoneInput/PhoneInput.tsx @@ -18,7 +18,7 @@ export interface InputProps { form: { touched: any; errors: any; setFieldValue: any }; inputLabel?: string | null; disabled?: boolean; - changeHandler?: any; + changeHandler?: (event: string, data: {}, formFieldItems: string) => void; } export const PhoneInput = ({ diff --git a/src/containers/Organization/Onboarding/FormLayout/FormLayout.tsx b/src/containers/Organization/Onboarding/FormLayout/FormLayout.tsx index 58042ddf4..f3dca372b 100644 --- a/src/containers/Organization/Onboarding/FormLayout/FormLayout.tsx +++ b/src/containers/Organization/Onboarding/FormLayout/FormLayout.tsx @@ -229,8 +229,8 @@ export const FormLayout = ({ handleOk={() => { saveHandler(formik.values, formik.setErrors); }} - title={'Confirmation'} - buttonOk={'Confirm'} + title="Confirmation" + buttonOk="Confirm" buttonCancel="Cancel" buttonOkLoading={loading} > @@ -248,10 +248,10 @@ export const FormLayout = ({ setCustomError(null)} handleCancel={() => setCustomError(null)} - title={'Something went wrong!'} - buttonOk={'Ok'} + title="Something went wrong!" + buttonOk="Ok" skipCancel - colorOk={'warning'} + colorOk="warning" >

{customError}

diff --git a/src/containers/Organization/Onboarding/Steps/Address/Address.module.css b/src/containers/Organization/Onboarding/Steps/Address/Address.module.css index 29f777b82..2887bfdc3 100644 --- a/src/containers/Organization/Onboarding/Steps/Address/Address.module.css +++ b/src/containers/Organization/Onboarding/Steps/Address/Address.module.css @@ -37,7 +37,7 @@ .Errors { font-size: 12px; - margin: 0px; + margin: 0; margin-left: 14px; line-height: 18px; font-weight: 400; diff --git a/src/containers/Organization/Onboarding/Steps/Address/Address.tsx b/src/containers/Organization/Onboarding/Steps/Address/Address.tsx index 96e9929f3..60d994631 100644 --- a/src/containers/Organization/Onboarding/Steps/Address/Address.tsx +++ b/src/containers/Organization/Onboarding/Steps/Address/Address.tsx @@ -1,4 +1,5 @@ import { OutlinedInput, Typography } from '@mui/material'; +import { formatString } from 'common/utils'; import styles from './Address.module.css'; interface RegisteredAddressProps { @@ -6,18 +7,10 @@ interface RegisteredAddressProps { inputLabelSubtext: any; address: any; disabled: boolean; - setAddress: any; form: { touched: any; errors: any; setFieldValue: any }; field: { name: string; value: any }; } -function x(str: string) { - return str - .replace(/_/g, ' ') // Replace underscores with spaces - .replace(/([a-z])([0-9])/gi, '$1 $2') // Insert space before digits - .replace(/\b\w/g, (char) => char.toUpperCase()); // Capitalize each word -} - export const RegisteredAddress = ({ inputLabel, address, @@ -48,7 +41,7 @@ export const RegisteredAddress = ({ .slice(0, 2) .map((key) => (
-

{x(key)}

+

{formatString(key)}

(
-

{x(key)}

+

{formatString(key)}

{ - return Object.keys(address1).every((key) => address1[key] === address2[key]); -}; +const isSameAddress = (address1: any, address2: any) => + Object.keys(address1).every((key) => address1[key] === address2[key]); export const OrgDetails = ({ handleStepChange, saveData }: FormStepProps) => { const [gstin, setGstNumber] = useState(''); @@ -194,17 +193,22 @@ export const OrgDetails = ({ handleStepChange, saveData }: FormStepProps) => { const handleSubmit = async (payload: any, setErrors: any) => { setLoading(true); - await axios.post(ONBOARD_URL_UPDATE, payload).then(({ data }) => { - setLoading(false); - if (data.is_valid) { - handleStepChange(); - } else { - if (data.messages.global) { - setCustomError(data.messages.global); + await axios + .post(ONBOARD_URL_UPDATE, payload) + .then(({ data }) => { + setLoading(false); + if (data.is_valid) { + handleStepChange(); + } else { + if (data.messages.global) { + setCustomError(data.messages.global); + } + setErrors(data.messages); } - setErrors(data.messages); - } - }); + }) + .catch(() => { + setLoading(false); + }); }; const handleAutoUpdateAddress = (identifier: string, formik: any) => { diff --git a/src/containers/Organization/Onboarding/Steps/PaymentDetails.tsx b/src/containers/Organization/Onboarding/Steps/PaymentDetails.tsx index 3ca2a0625..02a1feb42 100644 --- a/src/containers/Organization/Onboarding/Steps/PaymentDetails.tsx +++ b/src/containers/Organization/Onboarding/Steps/PaymentDetails.tsx @@ -10,7 +10,6 @@ import { PhoneInput } from 'components/UI/Form/PhoneInput/PhoneInput'; import { FormLayout } from '../FormLayout/FormLayout'; import { PaymentOptions } from '../PaymentType/PaymentOptions'; import { FormStepProps } from './OrgDetails'; -import { setNotification } from 'common/notification'; export const PaymentDetails = ({ handleStepChange, saveData }: FormStepProps) => { const { t } = useTranslation(); @@ -45,7 +44,7 @@ export const PaymentDetails = ({ handleStepChange, saveData }: FormStepProps) => }; const handlePhoneNumberChange = (_: any, data: any, formFieldItems: any) => { - const formattedValue = formFieldItems.split(data.dialCode).join(data.dialCode + '-'); + const formattedValue = formFieldItems.split(data.dialCode).join(`${data.dialCode}-`); setFormattedPhone(formattedValue); }; @@ -148,9 +147,8 @@ export const PaymentDetails = ({ handleStepChange, saveData }: FormStepProps) => setLoading(false); } }) - .catch((errors) => { + .catch(() => { setLoading(false); - setNotification('Something went wrong', 'error'); }); }; diff --git a/src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx b/src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx index 07a271cfc..a7d4e7186 100644 --- a/src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx +++ b/src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx @@ -148,30 +148,35 @@ export const PlatformDetails = ({ handleStepChange, saveData }: FormStepProps) = const handleSubmit = async (payload: any, setErrors: Function) => { if (isDisabled) handleStepChange(); setLoading(true); - await axios.post(ONBOARD_URL_SETUP, payload).then(({ data }) => { - setLoading(false); - if (data.is_valid) { - saveData( - { - registration_id: data.registration_id, - org_id: data.organization?.id, - submitted: true, - }, - 'registration_details' - ); - - handleStepChange(); - - return true; - } else { - if (data.messages.global) { - setCustomError(data.messages.global); + await axios + .post(ONBOARD_URL_SETUP, payload) + .then(({ data }) => { + setLoading(false); + if (data.is_valid) { + saveData( + { + registration_id: data.registration_id, + org_id: data.organization?.id, + submitted: true, + }, + 'registration_details' + ); + + handleStepChange(); + + return true; + } else { + if (data.messages.global) { + setCustomError(data.messages.global); + } + setErrors(data.messages); + saveData(data.messages, 'errors'); + return false; } - setErrors(data.messages); - saveData(data.messages, 'errors'); - return false; - } - }); + }) + .catch((errors) => { + setLoading(false); + }); }; const setStates = (states: any) => { diff --git a/src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx b/src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx index 75871121c..40eb1ab5a 100644 --- a/src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx +++ b/src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx @@ -27,6 +27,7 @@ export const SigningAuthority = ({ const [signingAuthorityName, setSigningAuthorityName] = useState(''); const [signingAuthorityDesignation, setSigningAuthorityDesignation] = useState(''); const [signingAuthorityEmail, setSigningAuthorityEmail] = useState(''); + const [customError, setCustomError] = useState(null); const [permissions, setPermissions] = useState({ terms_agreed: false, @@ -178,15 +179,23 @@ export const SigningAuthority = ({ const handleSubmit = async (payload: any, setErrors: any) => { setLoading(true); - await axios.post(ONBOARD_URL_UPDATE, payload).then(({ data }) => { - setLoading(false); - if (data.is_valid) { - handleStepChange(); - localStorage.removeItem('registrationData'); - } else { - setErrors(data.messages); - } - }); + await axios + .post(ONBOARD_URL_UPDATE, payload) + .then(({ data }) => { + setLoading(false); + if (data.is_valid) { + handleStepChange(); + localStorage.removeItem('registrationData'); + } else { + if (data.messages.global) { + setCustomError(data.messages.global); + } + setErrors(data.messages); + } + }) + .catch(() => { + setLoading(false); + }); }; return ( @@ -205,6 +214,8 @@ export const SigningAuthority = ({ loading={loading} submitData={handleSubmit} buttonState={{ text: 'Submit' }} + setCustomError={setCustomError} + customError={customError} /> ); };