Skip to content

Commit

Permalink
chore: remove unnecessary id from EditContactInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Oct 16, 2024
1 parent 7df384e commit d93cd4a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { useCustomFieldsMetadata } from '../directory/hooks/useCustomFieldsMetad
import { useContactRoute } from '../hooks/useContactRoute';

type ContactNewEditProps = {
id: string;
contactData?: Serialized<ILivechatContact> | null;
onClose: () => void;
onCancel: () => void;
Expand Down Expand Up @@ -63,7 +62,7 @@ const getInitialValues = (data: ContactNewEditProps['contactData']): ContactForm
};
};

const EditContactInfo = ({ id, contactData, onClose, onCancel }: ContactNewEditProps): ReactElement => {
const EditContactInfo = ({ contactData, onClose, onCancel }: ContactNewEditProps): ReactElement => {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -122,15 +121,15 @@ const EditContactInfo = ({ id, contactData, onClose, onCancel }: ContactNewEditP
}

const { contact } = await getContact({ email: emailValue });
return (!contact || contact._id === id) && !isDuplicated ? true : t('Email_already_exists');
return (!contact || contact._id === contactData?._id) && !isDuplicated ? true : t('Email_already_exists');
};

const validatePhone = async (phoneValue: string) => {
const currentPhones = phones.map(({ phoneNumber }) => phoneNumber);
const isDuplicated = currentPhones.filter((phone) => phone === phoneValue).length > 1;

const { contact } = await getContact({ phone: phoneValue });
return (!contact || contact._id === id) && !isDuplicated ? true : t('Phone_already_exists');
return (!contact || contact._id === contactData?._id) && !isDuplicated ? true : t('Phone_already_exists');
};

const validateName = (v: string): string | boolean => (!v.trim() ? t('Required_field', { field: t('Name') }) : true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const EditContactInfoWithData = ({ id, onClose, onCancel }: EditContactInfoWithD
return <Box mbs={16}>{t('Contact_not_found')}</Box>;
}

return <EditContactInfo id={id} contactData={data.contact} onClose={onClose} onCancel={onCancel} />;
return <EditContactInfo contactData={data.contact} onClose={onClose} onCancel={onCancel} />;
};

export default EditContactInfoWithData;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ContactContextualBar = () => {
};

if (context === 'new') {
return <EditContactInfo id={contactId} onClose={handleClose} onCancel={handleClose} />;
return <EditContactInfo onClose={handleClose} onCancel={handleClose} />;
}

if (context === 'edit') {
Expand Down

0 comments on commit d93cd4a

Please sign in to comment.