chore: refactor removal logic

This commit is contained in:
Adithya Krishna
2024-04-29 17:30:01 +05:30
committed by GitHub
parent e82e402540
commit 917c83fc5f

View File

@ -116,6 +116,7 @@ export const AddSignersFormPartial = ({
const onFormSubmit = form.handleSubmit(onSubmit); const onFormSubmit = form.handleSubmit(onSubmit);
const { const {
append: appendSigner, append: appendSigner,
fields: signers, fields: signers,
@ -124,7 +125,7 @@ export const AddSignersFormPartial = ({
control, control,
name: 'signers', name: 'signers',
}); });
const hasBeenSentToRecipientId = (id?: number) => { const hasBeenSentToRecipientId = (id?: number) => {
if (!id) { if (!id) {
return false; return false;
@ -165,7 +166,10 @@ export const AddSignersFormPartial = ({
}; };
const onAddSelfSigner = () => { const onAddSelfSigner = () => {
if(signers.length !== 0) onRemoveSigner(0); const lastSignerIndex = signers.length - 1;
if(!signers[lastSignerIndex].name || !signers[lastSignerIndex].email){
onRemoveSigner(lastSignerIndex)
}
appendSigner({ appendSigner({
formId: nanoid(12), formId: nanoid(12),
name: user?.name ?? '', name: user?.name ?? '',