fix: refactor

This commit is contained in:
David Nguyen
2024-04-15 20:29:42 +07:00
parent b1474de2da
commit 2d569292ce
2 changed files with 7 additions and 26 deletions

View File

@ -63,7 +63,6 @@ export const AddSignersFormPartial = ({
const { remaining } = useLimits(); const { remaining } = useLimits();
const { data: session } = useSession(); const { data: session } = useSession();
const user = session?.user; const user = session?.user;
const [selfSignerFormId, setSelfSignerFormId] = useState<string | undefined>(undefined);
const initialId = useId(); const initialId = useId();
@ -149,8 +148,6 @@ export const AddSignersFormPartial = ({
role: RecipientRole.SIGNER, role: RecipientRole.SIGNER,
actionAuth: undefined, actionAuth: undefined,
}); });
setSelfSignerFormId(newSelfSignerId);
}; };
const onAddSigner = () => { const onAddSigner = () => {
@ -176,10 +173,6 @@ export const AddSignersFormPartial = ({
return; return;
} }
if (signer.formId === selfSignerFormId) {
setSelfSignerFormId(undefined);
}
removeSigner(index); removeSigner(index);
}; };
@ -235,7 +228,6 @@ export const AddSignersFormPartial = ({
disabled={ disabled={
isSubmitting || isSubmitting ||
hasBeenSentToRecipientId(signer.nativeId) || hasBeenSentToRecipientId(signer.nativeId) ||
signer.formId === selfSignerFormId ||
signers[index].email === user?.email signers[index].email === user?.email
} }
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
@ -268,7 +260,6 @@ export const AddSignersFormPartial = ({
disabled={ disabled={
isSubmitting || isSubmitting ||
hasBeenSentToRecipientId(signer.nativeId) || hasBeenSentToRecipientId(signer.nativeId) ||
signer.formId === selfSignerFormId ||
signers[index].email === user?.email signers[index].email === user?.email
} }
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
@ -448,9 +439,7 @@ export const AddSignersFormPartial = ({
className="dark:bg-muted dark:hover:bg-muted/80 bg-black/5 hover:bg-black/10" className="dark:bg-muted dark:hover:bg-muted/80 bg-black/5 hover:bg-black/10"
disabled={ disabled={
isSubmitting || isSubmitting ||
signers.length >= remaining.recipients || form.getValues('signers').some((signer) => signer.email === user?.email)
!!selfSignerFormId ||
signers.some((signer) => signer.email === user?.email)
} }
onClick={() => onAddSelfSigner()} onClick={() => onAddSelfSigner()}
> >
@ -458,8 +447,9 @@ export const AddSignersFormPartial = ({
Add myself Add myself
</Button> </Button>
</div> </div>
{!alwaysShowAdvancedSettings && isDocumentEnterprise && ( {!alwaysShowAdvancedSettings && isDocumentEnterprise && (
<div className="mt-6"> <div className="mt-4 flex flex-row items-center">
<Checkbox <Checkbox
id="showAdvancedRecipientSettings" id="showAdvancedRecipientSettings"
className="h-5 w-5" className="h-5 w-5"

View File

@ -44,18 +44,16 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
const initialId = useId(); const initialId = useId();
const { data: session } = useSession(); const { data: session } = useSession();
const user = session?.user; const user = session?.user;
const [selfSignerFormId, setSelfSignerFormId] = useState<string | undefined>(undefined);
const [placeholderRecipientCount, setPlaceholderRecipientCount] = useState(() => const [placeholderRecipientCount, setPlaceholderRecipientCount] = useState(() =>
recipients.length > 1 ? recipients.length + 1 : 2, recipients.length > 1 ? recipients.length + 1 : 2,
); );
const userIsSelfRecipient = () => signers.some((signer) => signer.email === user?.email);
const { currentStep, totalSteps, previousStep } = useStep(); const { currentStep, totalSteps, previousStep } = useStep();
const { const {
control, control,
handleSubmit, handleSubmit,
getValues,
formState: { errors, isSubmitting }, formState: { errors, isSubmitting },
} = useForm<TAddTemplatePlacholderRecipientsFormSchema>({ } = useForm<TAddTemplatePlacholderRecipientsFormSchema>({
resolver: zodResolver(ZAddTemplatePlacholderRecipientsFormSchema), resolver: zodResolver(ZAddTemplatePlacholderRecipientsFormSchema),
@ -100,9 +98,6 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
email: user?.email ?? '', email: user?.email ?? '',
role: RecipientRole.SIGNER, role: RecipientRole.SIGNER,
}); });
setSelfSignerFormId(newSelfSignerId);
setPlaceholderRecipientCount((count) => count + 1);
}; };
const onAddPlaceholderRecipient = () => { const onAddPlaceholderRecipient = () => {
@ -117,13 +112,7 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
}; };
const onRemoveSigner = (index: number) => { const onRemoveSigner = (index: number) => {
const isSelfSigner = signers[index].formId === selfSignerFormId;
removeSigner(index); removeSigner(index);
if (isSelfSigner) {
setSelfSignerFormId(undefined);
}
}; };
return ( return (
@ -242,7 +231,9 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
<Button <Button
type="button" type="button"
className="dark:bg-muted dark:hover:bg-muted/80 bg-black/5 hover:bg-black/10" className="dark:bg-muted dark:hover:bg-muted/80 bg-black/5 hover:bg-black/10"
disabled={isSubmitting || !!selfSignerFormId || userIsSelfRecipient()} disabled={
isSubmitting || getValues('signers').some((signer) => signer.email === user?.email)
}
onClick={() => onAddPlaceholderSelfRecipient()} onClick={() => onAddPlaceholderSelfRecipient()}
> >
<Plus className="-ml-1 mr-2 h-5 w-5" /> <Plus className="-ml-1 mr-2 h-5 w-5" />