mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
chore: tidy code
This commit is contained in:
@ -106,11 +106,13 @@ export const AddSignersFormPartial = ({
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
setValue,
|
setValue,
|
||||||
getValues,
|
|
||||||
formState: { errors, isSubmitting },
|
formState: { errors, isSubmitting },
|
||||||
control,
|
control,
|
||||||
|
watch,
|
||||||
} = form;
|
} = form;
|
||||||
|
|
||||||
|
const watchedSigners = watch('signers');
|
||||||
|
|
||||||
const onFormSubmit = form.handleSubmit(onSubmit);
|
const onFormSubmit = form.handleSubmit(onSubmit);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -122,6 +124,11 @@ export const AddSignersFormPartial = ({
|
|||||||
name: 'signers',
|
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) => {
|
const hasBeenSentToRecipientId = (id?: number) => {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return false;
|
return false;
|
||||||
@ -161,17 +168,7 @@ export const AddSignersFormPartial = ({
|
|||||||
removeSigner(index);
|
removeSigner(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
const emptySignerIndex = signers.findIndex(
|
|
||||||
(signer) =>
|
|
||||||
!getValues(`signers.${signers.indexOf(signer)}.name`) ||
|
|
||||||
!getValues(`signers.${signers.indexOf(signer)}.email`),
|
|
||||||
);
|
|
||||||
|
|
||||||
const onAddSelfSigner = () => {
|
const onAddSelfSigner = () => {
|
||||||
const lastSignerIndex = signers.length - 1;
|
|
||||||
if (signers[lastSignerIndex].email || signers[lastSignerIndex].name) {
|
|
||||||
onRemoveSigner(lastSignerIndex);
|
|
||||||
}
|
|
||||||
if (emptySignerIndex !== -1) {
|
if (emptySignerIndex !== -1) {
|
||||||
setValue(`signers.${emptySignerIndex}.name`, user?.name ?? '');
|
setValue(`signers.${emptySignerIndex}.name`, user?.name ?? '');
|
||||||
setValue(`signers.${emptySignerIndex}.email`, user?.email ?? '');
|
setValue(`signers.${emptySignerIndex}.email`, user?.email ?? '');
|
||||||
@ -235,11 +232,7 @@ export const AddSignersFormPartial = ({
|
|||||||
type="email"
|
type="email"
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
{...field}
|
{...field}
|
||||||
disabled={
|
disabled={isSubmitting || hasBeenSentToRecipientId(signer.nativeId)}
|
||||||
isSubmitting ||
|
|
||||||
hasBeenSentToRecipientId(signer.nativeId) ||
|
|
||||||
signers[index].email === user?.email
|
|
||||||
}
|
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@ -265,11 +258,7 @@ export const AddSignersFormPartial = ({
|
|||||||
<Input
|
<Input
|
||||||
placeholder="Name"
|
placeholder="Name"
|
||||||
{...field}
|
{...field}
|
||||||
disabled={
|
disabled={isSubmitting || hasBeenSentToRecipientId(signer.nativeId)}
|
||||||
isSubmitting ||
|
|
||||||
hasBeenSentToRecipientId(signer.nativeId) ||
|
|
||||||
signers[index].name === user?.name
|
|
||||||
}
|
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@ -352,14 +341,12 @@ export const AddSignersFormPartial = ({
|
|||||||
<Plus className="-ml-1 mr-2 h-5 w-5" />
|
<Plus className="-ml-1 mr-2 h-5 w-5" />
|
||||||
Add Signer
|
Add Signer
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
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 || isUserAlreadyARecipient}
|
||||||
isSubmitting ||
|
|
||||||
form.getValues('signers').some((signer) => signer.email === user?.email)
|
|
||||||
}
|
|
||||||
onClick={() => onAddSelfSigner()}
|
onClick={() => onAddSelfSigner()}
|
||||||
>
|
>
|
||||||
<Plus className="-ml-1 mr-2 h-5 w-5" />
|
<Plus className="-ml-1 mr-2 h-5 w-5" />
|
||||||
|
|||||||
Reference in New Issue
Block a user