fix: make sure the user can't add its details more than once

This commit is contained in:
Catalin Pit
2024-04-11 13:25:54 +03:00
parent 318a77c936
commit ef1d4ed0fa

View File

@ -49,6 +49,8 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
recipients.length > 1 ? recipients.length + 1 : 2,
);
const userIsSelfRecipient = () => signers.some((signer) => signer.email === user?.email);
const { currentStep, totalSteps, previousStep } = useStep();
const {
@ -115,9 +117,11 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
};
const onRemoveSigner = (index: number) => {
const isSelfSigner = signers[index].formId === selfSignerFormId;
removeSigner(index);
if (signers[index].formId === selfSignerFormId) {
if (isSelfSigner) {
setSelfSignerFormId(undefined);
}
};
@ -238,7 +242,7 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
<Button
type="button"
className="dark:bg-muted dark:hover:bg-muted/80 bg-black/5 hover:bg-black/10"
disabled={isSubmitting || !!selfSignerFormId}
disabled={isSubmitting || !!selfSignerFormId || userIsSelfRecipient()}
onClick={() => onAddPlaceholderSelfRecipient()}
>
<Plus className="-ml-1 mr-2 h-5 w-5" />