Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
akanshaaa19 committed Nov 6, 2024
1 parent b9ded55 commit 0752f0a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 66 deletions.
6 changes: 6 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
2 changes: 1 addition & 1 deletion src/components/UI/Form/PhoneInput/PhoneInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down
10 changes: 5 additions & 5 deletions src/containers/Organization/Onboarding/FormLayout/FormLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
>
Expand All @@ -248,10 +248,10 @@ export const FormLayout = ({
<DialogBox
handleOk={() => setCustomError(null)}
handleCancel={() => setCustomError(null)}

Check warning on line 250 in src/containers/Organization/Onboarding/FormLayout/FormLayout.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/FormLayout/FormLayout.tsx#L249-L250

Added lines #L249 - L250 were not covered by tests
title={'Something went wrong!'}
buttonOk={'Ok'}
title="Something went wrong!"
buttonOk="Ok"
skipCancel
colorOk={'warning'}
colorOk="warning"
>
<div className={styles.Modal}>
<p>{customError}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

.Errors {
font-size: 12px;
margin: 0px;
margin: 0;
margin-left: 14px;
line-height: 18px;
font-weight: 400;
Expand Down
13 changes: 3 additions & 10 deletions src/containers/Organization/Onboarding/Steps/Address/Address.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { OutlinedInput, Typography } from '@mui/material';
import { formatString } from 'common/utils';
import styles from './Address.module.css';

interface RegisteredAddressProps {
inputLabel: string;
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,
Expand Down Expand Up @@ -48,7 +41,7 @@ export const RegisteredAddress = ({
.slice(0, 2)
.map((key) => (
<div className={styles.FullRow} key={key}>
<p className={styles.Label}>{x(key)}</p>
<p className={styles.Label}>{formatString(key)}</p>
<OutlinedInput
disabled={disabled}
className={styles.InputBox}
Expand All @@ -65,7 +58,7 @@ export const RegisteredAddress = ({
.slice(2)
.map((key) => (
<div className={styles.Row} key={key}>
<p className={styles.Label}>{x(key)}</p>
<p className={styles.Label}>{formatString(key)}</p>
<OutlinedInput
disabled={disabled}
className={styles.InputBox}
Expand Down
30 changes: 17 additions & 13 deletions src/containers/Organization/Onboarding/Steps/OrgDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export interface FormStepProps {
saveData: Function;
}

const isSameAddress = (address1: any, address2: any) => {
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<string>('');
Expand Down Expand Up @@ -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);

Check warning on line 204 in src/containers/Organization/Onboarding/Steps/OrgDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/OrgDetails.tsx#L204

Added line #L204 was not covered by tests
}
setErrors(data.messages);

Check warning on line 206 in src/containers/Organization/Onboarding/Steps/OrgDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/OrgDetails.tsx#L206

Added line #L206 was not covered by tests
}
setErrors(data.messages);
}
});
})
.catch(() => {
setLoading(false);

Check warning on line 210 in src/containers/Organization/Onboarding/Steps/OrgDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/OrgDetails.tsx#L210

Added line #L210 was not covered by tests
});
};

const handleAutoUpdateAddress = (identifier: string, formik: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
};

Expand Down Expand Up @@ -148,9 +147,8 @@ export const PaymentDetails = ({ handleStepChange, saveData }: FormStepProps) =>
setLoading(false);

Check warning on line 147 in src/containers/Organization/Onboarding/Steps/PaymentDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/PaymentDetails.tsx#L146-L147

Added lines #L146 - L147 were not covered by tests
}
})
.catch((errors) => {
.catch(() => {
setLoading(false);

Check warning on line 151 in src/containers/Organization/Onboarding/Steps/PaymentDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/PaymentDetails.tsx#L151

Added line #L151 was not covered by tests
setNotification('Something went wrong', 'error');
});
};

Expand Down
51 changes: 28 additions & 23 deletions src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 170 in src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx#L170

Added line #L170 was not covered by tests
}
setErrors(data.messages);
saveData(data.messages, 'errors');
return false;

Check warning on line 174 in src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx#L172-L174

Added lines #L172 - L174 were not covered by tests
}
setErrors(data.messages);
saveData(data.messages, 'errors');
return false;
}
});
})
.catch((errors) => {
setLoading(false);

Check warning on line 178 in src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/PlatformDetails.tsx#L178

Added line #L178 was not covered by tests
});
};

const setStates = (states: any) => {
Expand Down
29 changes: 20 additions & 9 deletions src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const SigningAuthority = ({
const [signingAuthorityName, setSigningAuthorityName] = useState<string>('');
const [signingAuthorityDesignation, setSigningAuthorityDesignation] = useState<string>('');
const [signingAuthorityEmail, setSigningAuthorityEmail] = useState<string>('');
const [customError, setCustomError] = useState(null);

const [permissions, setPermissions] = useState({
terms_agreed: false,
Expand Down Expand Up @@ -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);

Check warning on line 191 in src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx#L191

Added line #L191 was not covered by tests
}
setErrors(data.messages);

Check warning on line 193 in src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx#L193

Added line #L193 was not covered by tests
}
})
.catch(() => {
setLoading(false);

Check warning on line 197 in src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Organization/Onboarding/Steps/SigningAuthority.tsx#L197

Added line #L197 was not covered by tests
});
};

return (
Expand All @@ -205,6 +214,8 @@ export const SigningAuthority = ({
loading={loading}
submitData={handleSubmit}
buttonState={{ text: 'Submit' }}
setCustomError={setCustomError}
customError={customError}
/>
);
};

0 comments on commit 0752f0a

Please sign in to comment.