From e82e4025400660e860c9eb090b8942ad015b0777 Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Mon, 29 Apr 2024 17:10:56 +0530 Subject: [PATCH 1/8] feat: remove the existing empty signer if its the only one --- .../primitives/document-flow/add-signers.tsx | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/packages/ui/primitives/document-flow/add-signers.tsx b/packages/ui/primitives/document-flow/add-signers.tsx index 2f9f2f234..b83e5064c 100644 --- a/packages/ui/primitives/document-flow/add-signers.tsx +++ b/packages/ui/primitives/document-flow/add-signers.tsx @@ -138,16 +138,6 @@ export const AddSignersFormPartial = ({ ); }; - const onAddSelfSigner = () => { - appendSigner({ - formId: nanoid(12), - name: user?.name ?? '', - email: user?.email ?? '', - role: RecipientRole.SIGNER, - actionAuth: undefined, - }); - }; - const onAddSigner = () => { appendSigner({ formId: nanoid(12), @@ -174,6 +164,17 @@ export const AddSignersFormPartial = ({ removeSigner(index); }; + const onAddSelfSigner = () => { + if(signers.length !== 0) onRemoveSigner(0); + appendSigner({ + formId: nanoid(12), + name: user?.name ?? '', + email: user?.email ?? '', + role: RecipientRole.SIGNER, + actionAuth: undefined, + }); + }; + const onKeyDown = (event: React.KeyboardEvent) => { if (event.key === 'Enter' && event.target instanceof HTMLInputElement) { onAddSigner(); @@ -302,10 +303,10 @@ export const AddSignersFormPartial = ({ global action signing authentication method configured in the "General Settings" step - {/*
  • +
  • Require account - The recipient must be signed in -
  • */} +
  • Require passkey - The recipient must have an account and passkey configured via their settings @@ -326,13 +327,11 @@ export const AddSignersFormPartial = ({ {/* Note: -1 is remapped in the Zod schema to the required value. */} Inherit authentication method - {Object.values(RecipientActionAuth) - .filter((auth) => auth !== RecipientActionAuth.ACCOUNT) - .map((authType) => ( - - {DOCUMENT_AUTH_TYPES[authType].value} - - ))} + {Object.values(RecipientActionAuth).map((authType) => ( + + {DOCUMENT_AUTH_TYPES[authType].value} + + ))} From 917c83fc5f68a8c861a6bf3ee2449e3cd15a7593 Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Mon, 29 Apr 2024 17:30:01 +0530 Subject: [PATCH 2/8] chore: refactor removal logic --- packages/ui/primitives/document-flow/add-signers.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/ui/primitives/document-flow/add-signers.tsx b/packages/ui/primitives/document-flow/add-signers.tsx index b83e5064c..b62d4c433 100644 --- a/packages/ui/primitives/document-flow/add-signers.tsx +++ b/packages/ui/primitives/document-flow/add-signers.tsx @@ -116,6 +116,7 @@ export const AddSignersFormPartial = ({ const onFormSubmit = form.handleSubmit(onSubmit); + const { append: appendSigner, fields: signers, @@ -124,7 +125,7 @@ export const AddSignersFormPartial = ({ control, name: 'signers', }); - + const hasBeenSentToRecipientId = (id?: number) => { if (!id) { return false; @@ -165,7 +166,10 @@ export const AddSignersFormPartial = ({ }; const onAddSelfSigner = () => { - if(signers.length !== 0) onRemoveSigner(0); + const lastSignerIndex = signers.length - 1; + if(!signers[lastSignerIndex].name || !signers[lastSignerIndex].email){ + onRemoveSigner(lastSignerIndex) + } appendSigner({ formId: nanoid(12), name: user?.name ?? '', From 6b5750c7bf8e8af051872bd49068381b11b8b3de Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Mon, 29 Apr 2024 17:48:00 +0530 Subject: [PATCH 3/8] chore: revert previous changes --- .../primitives/document-flow/add-signers.tsx | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/ui/primitives/document-flow/add-signers.tsx b/packages/ui/primitives/document-flow/add-signers.tsx index b62d4c433..2f9f2f234 100644 --- a/packages/ui/primitives/document-flow/add-signers.tsx +++ b/packages/ui/primitives/document-flow/add-signers.tsx @@ -116,7 +116,6 @@ export const AddSignersFormPartial = ({ const onFormSubmit = form.handleSubmit(onSubmit); - const { append: appendSigner, fields: signers, @@ -125,7 +124,7 @@ export const AddSignersFormPartial = ({ control, name: 'signers', }); - + const hasBeenSentToRecipientId = (id?: number) => { if (!id) { return false; @@ -139,6 +138,16 @@ export const AddSignersFormPartial = ({ ); }; + const onAddSelfSigner = () => { + appendSigner({ + formId: nanoid(12), + name: user?.name ?? '', + email: user?.email ?? '', + role: RecipientRole.SIGNER, + actionAuth: undefined, + }); + }; + const onAddSigner = () => { appendSigner({ formId: nanoid(12), @@ -165,20 +174,6 @@ export const AddSignersFormPartial = ({ removeSigner(index); }; - const onAddSelfSigner = () => { - const lastSignerIndex = signers.length - 1; - if(!signers[lastSignerIndex].name || !signers[lastSignerIndex].email){ - onRemoveSigner(lastSignerIndex) - } - appendSigner({ - formId: nanoid(12), - name: user?.name ?? '', - email: user?.email ?? '', - role: RecipientRole.SIGNER, - actionAuth: undefined, - }); - }; - const onKeyDown = (event: React.KeyboardEvent) => { if (event.key === 'Enter' && event.target instanceof HTMLInputElement) { onAddSigner(); @@ -307,10 +302,10 @@ export const AddSignersFormPartial = ({ global action signing authentication method configured in the "General Settings" step
  • -
  • + {/*
  • Require account - The recipient must be signed in -
  • + */}
  • Require passkey - The recipient must have an account and passkey configured via their settings @@ -331,11 +326,13 @@ export const AddSignersFormPartial = ({ {/* Note: -1 is remapped in the Zod schema to the required value. */} Inherit authentication method - {Object.values(RecipientActionAuth).map((authType) => ( - - {DOCUMENT_AUTH_TYPES[authType].value} - - ))} + {Object.values(RecipientActionAuth) + .filter((auth) => auth !== RecipientActionAuth.ACCOUNT) + .map((authType) => ( + + {DOCUMENT_AUTH_TYPES[authType].value} + + ))} From bde0f5893fa0f5a1b0f338cb978cbddb85c6b4eb Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Mon, 29 Apr 2024 17:49:50 +0530 Subject: [PATCH 4/8] feat: update add self signer logic --- .../primitives/document-flow/add-signers.tsx | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/ui/primitives/document-flow/add-signers.tsx b/packages/ui/primitives/document-flow/add-signers.tsx index 2f9f2f234..3227cdeb6 100644 --- a/packages/ui/primitives/document-flow/add-signers.tsx +++ b/packages/ui/primitives/document-flow/add-signers.tsx @@ -138,16 +138,6 @@ export const AddSignersFormPartial = ({ ); }; - const onAddSelfSigner = () => { - appendSigner({ - formId: nanoid(12), - name: user?.name ?? '', - email: user?.email ?? '', - role: RecipientRole.SIGNER, - actionAuth: undefined, - }); - }; - const onAddSigner = () => { appendSigner({ formId: nanoid(12), @@ -174,6 +164,20 @@ export const AddSignersFormPartial = ({ removeSigner(index); }; + const onAddSelfSigner = () => { + const lastSignerIndex = signers.length - 1; + if(!signers[lastSignerIndex].name || !signers[lastSignerIndex].email){ + onRemoveSigner(lastSignerIndex) + } + appendSigner({ + formId: nanoid(12), + name: user?.name ?? '', + email: user?.email ?? '', + role: RecipientRole.SIGNER, + actionAuth: undefined, + }); + }; + const onKeyDown = (event: React.KeyboardEvent) => { if (event.key === 'Enter' && event.target instanceof HTMLInputElement) { onAddSigner(); From db9e605031ed5a57e5c86f28d5845860fbf15707 Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Tue, 30 Apr 2024 01:32:58 +0530 Subject: [PATCH 5/8] chore: fix lint issues Signed-off-by: Adithya Krishna --- packages/ui/primitives/document-flow/add-signers.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ui/primitives/document-flow/add-signers.tsx b/packages/ui/primitives/document-flow/add-signers.tsx index 3227cdeb6..2b3a9592d 100644 --- a/packages/ui/primitives/document-flow/add-signers.tsx +++ b/packages/ui/primitives/document-flow/add-signers.tsx @@ -166,8 +166,8 @@ export const AddSignersFormPartial = ({ const onAddSelfSigner = () => { const lastSignerIndex = signers.length - 1; - if(!signers[lastSignerIndex].name || !signers[lastSignerIndex].email){ - onRemoveSigner(lastSignerIndex) + if (!signers[lastSignerIndex].name || !signers[lastSignerIndex].email) { + onRemoveSigner(lastSignerIndex); } appendSigner({ formId: nanoid(12), From 6df525b670f0b6e571b22ab83fa2cc1110890da1 Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Tue, 30 Apr 2024 12:05:42 +0530 Subject: [PATCH 6/8] feat: updated signer logic Signed-off-by: Adithya Krishna --- .../primitives/document-flow/add-signers.tsx | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/ui/primitives/document-flow/add-signers.tsx b/packages/ui/primitives/document-flow/add-signers.tsx index 2b3a9592d..2203b7e6d 100644 --- a/packages/ui/primitives/document-flow/add-signers.tsx +++ b/packages/ui/primitives/document-flow/add-signers.tsx @@ -110,6 +110,8 @@ export const AddSignersFormPartial = ({ const [showAdvancedSettings, setShowAdvancedSettings] = useState(alwaysShowAdvancedSettings); const { + setValue, + getValues, formState: { errors, isSubmitting }, control, } = form; @@ -164,18 +166,29 @@ export const AddSignersFormPartial = ({ removeSigner(index); }; + const emptySignerIndex = signers.findIndex( + (signer) => + !getValues(`signers.${signers.indexOf(signer)}.name`) || + !getValues(`signers.${signers.indexOf(signer)}.email`), + ); + const onAddSelfSigner = () => { const lastSignerIndex = signers.length - 1; - if (!signers[lastSignerIndex].name || !signers[lastSignerIndex].email) { + if (!signers[lastSignerIndex].name && !signers[lastSignerIndex].email) { onRemoveSigner(lastSignerIndex); } - appendSigner({ - formId: nanoid(12), - name: user?.name ?? '', - email: user?.email ?? '', - role: RecipientRole.SIGNER, - actionAuth: undefined, - }); + if (emptySignerIndex !== -1) { + setValue(`signers.${emptySignerIndex}.name`, user?.name ?? ''); + setValue(`signers.${emptySignerIndex}.email`, user?.email ?? ''); + } else { + appendSigner({ + formId: nanoid(12), + name: user?.name ?? '', + email: user?.email ?? '', + role: RecipientRole.SIGNER, + actionAuth: undefined, + }); + } }; const onKeyDown = (event: React.KeyboardEvent) => { From 98672560ca0db215e3816bc383061edc287e5feb Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Wed, 8 May 2024 17:02:01 +0530 Subject: [PATCH 7/8] chore: update self signer logic Signed-off-by: Adithya Krishna --- packages/ui/primitives/document-flow/add-signers.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ui/primitives/document-flow/add-signers.tsx b/packages/ui/primitives/document-flow/add-signers.tsx index 682a3fe7a..cfee325e1 100644 --- a/packages/ui/primitives/document-flow/add-signers.tsx +++ b/packages/ui/primitives/document-flow/add-signers.tsx @@ -169,7 +169,7 @@ export const AddSignersFormPartial = ({ const onAddSelfSigner = () => { const lastSignerIndex = signers.length - 1; - if (!signers[lastSignerIndex].name && !signers[lastSignerIndex].email) { + if (signers[lastSignerIndex].email || signers[lastSignerIndex].name) { onRemoveSigner(lastSignerIndex); } if (emptySignerIndex !== -1) { @@ -268,7 +268,7 @@ export const AddSignersFormPartial = ({ disabled={ isSubmitting || hasBeenSentToRecipientId(signer.nativeId) || - signers[index].email === user?.email + signers[index].name === user?.name } onKeyDown={onKeyDown} /> From c21e30d689ce3181c931eaa21680499478ad8f28 Mon Sep 17 00:00:00 2001 From: Lucas Smith Date: Tue, 28 May 2024 02:45:57 +0000 Subject: [PATCH 8/8] chore: tidy code --- .../primitives/document-flow/add-signers.tsx | 37 ++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/packages/ui/primitives/document-flow/add-signers.tsx b/packages/ui/primitives/document-flow/add-signers.tsx index cfee325e1..3ec73f599 100644 --- a/packages/ui/primitives/document-flow/add-signers.tsx +++ b/packages/ui/primitives/document-flow/add-signers.tsx @@ -106,11 +106,13 @@ export const AddSignersFormPartial = ({ const { setValue, - getValues, formState: { errors, isSubmitting }, control, + watch, } = form; + const watchedSigners = watch('signers'); + const onFormSubmit = form.handleSubmit(onSubmit); const { @@ -122,6 +124,11 @@ export const AddSignersFormPartial = ({ name: 'signers', }); + const emptySignerIndex = watchedSigners.findIndex((signer) => !signer.name && !signer.email); + const isUserAlreadyARecipient = watchedSigners.some( + (signer) => signer.email.toLowerCase() === user?.email?.toLowerCase(), + ); + const hasBeenSentToRecipientId = (id?: number) => { if (!id) { return false; @@ -161,17 +168,7 @@ export const AddSignersFormPartial = ({ removeSigner(index); }; - const emptySignerIndex = signers.findIndex( - (signer) => - !getValues(`signers.${signers.indexOf(signer)}.name`) || - !getValues(`signers.${signers.indexOf(signer)}.email`), - ); - const onAddSelfSigner = () => { - const lastSignerIndex = signers.length - 1; - if (signers[lastSignerIndex].email || signers[lastSignerIndex].name) { - onRemoveSigner(lastSignerIndex); - } if (emptySignerIndex !== -1) { setValue(`signers.${emptySignerIndex}.name`, user?.name ?? ''); setValue(`signers.${emptySignerIndex}.email`, user?.email ?? ''); @@ -235,11 +232,7 @@ export const AddSignersFormPartial = ({ type="email" placeholder="Email" {...field} - disabled={ - isSubmitting || - hasBeenSentToRecipientId(signer.nativeId) || - signers[index].email === user?.email - } + disabled={isSubmitting || hasBeenSentToRecipientId(signer.nativeId)} onKeyDown={onKeyDown} /> @@ -265,11 +258,7 @@ export const AddSignersFormPartial = ({ @@ -352,14 +341,12 @@ export const AddSignersFormPartial = ({ Add Signer +