mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 16:51:38 +10:00
fix: refactor
This commit is contained in:
@ -63,7 +63,6 @@ export const AddSignersFormPartial = ({
|
||||
const { remaining } = useLimits();
|
||||
const { data: session } = useSession();
|
||||
const user = session?.user;
|
||||
const [selfSignerFormId, setSelfSignerFormId] = useState<string | undefined>(undefined);
|
||||
|
||||
const initialId = useId();
|
||||
|
||||
@ -149,8 +148,6 @@ export const AddSignersFormPartial = ({
|
||||
role: RecipientRole.SIGNER,
|
||||
actionAuth: undefined,
|
||||
});
|
||||
|
||||
setSelfSignerFormId(newSelfSignerId);
|
||||
};
|
||||
|
||||
const onAddSigner = () => {
|
||||
@ -176,10 +173,6 @@ export const AddSignersFormPartial = ({
|
||||
return;
|
||||
}
|
||||
|
||||
if (signer.formId === selfSignerFormId) {
|
||||
setSelfSignerFormId(undefined);
|
||||
}
|
||||
|
||||
removeSigner(index);
|
||||
};
|
||||
|
||||
@ -235,7 +228,6 @@ export const AddSignersFormPartial = ({
|
||||
disabled={
|
||||
isSubmitting ||
|
||||
hasBeenSentToRecipientId(signer.nativeId) ||
|
||||
signer.formId === selfSignerFormId ||
|
||||
signers[index].email === user?.email
|
||||
}
|
||||
onKeyDown={onKeyDown}
|
||||
@ -268,7 +260,6 @@ export const AddSignersFormPartial = ({
|
||||
disabled={
|
||||
isSubmitting ||
|
||||
hasBeenSentToRecipientId(signer.nativeId) ||
|
||||
signer.formId === selfSignerFormId ||
|
||||
signers[index].email === user?.email
|
||||
}
|
||||
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"
|
||||
disabled={
|
||||
isSubmitting ||
|
||||
signers.length >= remaining.recipients ||
|
||||
!!selfSignerFormId ||
|
||||
signers.some((signer) => signer.email === user?.email)
|
||||
form.getValues('signers').some((signer) => signer.email === user?.email)
|
||||
}
|
||||
onClick={() => onAddSelfSigner()}
|
||||
>
|
||||
@ -458,8 +447,9 @@ export const AddSignersFormPartial = ({
|
||||
Add myself
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{!alwaysShowAdvancedSettings && isDocumentEnterprise && (
|
||||
<div className="mt-6">
|
||||
<div className="mt-4 flex flex-row items-center">
|
||||
<Checkbox
|
||||
id="showAdvancedRecipientSettings"
|
||||
className="h-5 w-5"
|
||||
|
||||
@ -44,18 +44,16 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
||||
const initialId = useId();
|
||||
const { data: session } = useSession();
|
||||
const user = session?.user;
|
||||
const [selfSignerFormId, setSelfSignerFormId] = useState<string | undefined>(undefined);
|
||||
const [placeholderRecipientCount, setPlaceholderRecipientCount] = useState(() =>
|
||||
recipients.length > 1 ? recipients.length + 1 : 2,
|
||||
);
|
||||
|
||||
const userIsSelfRecipient = () => signers.some((signer) => signer.email === user?.email);
|
||||
|
||||
const { currentStep, totalSteps, previousStep } = useStep();
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
getValues,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm<TAddTemplatePlacholderRecipientsFormSchema>({
|
||||
resolver: zodResolver(ZAddTemplatePlacholderRecipientsFormSchema),
|
||||
@ -100,9 +98,6 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
||||
email: user?.email ?? '',
|
||||
role: RecipientRole.SIGNER,
|
||||
});
|
||||
|
||||
setSelfSignerFormId(newSelfSignerId);
|
||||
setPlaceholderRecipientCount((count) => count + 1);
|
||||
};
|
||||
|
||||
const onAddPlaceholderRecipient = () => {
|
||||
@ -117,13 +112,7 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
||||
};
|
||||
|
||||
const onRemoveSigner = (index: number) => {
|
||||
const isSelfSigner = signers[index].formId === selfSignerFormId;
|
||||
|
||||
removeSigner(index);
|
||||
|
||||
if (isSelfSigner) {
|
||||
setSelfSignerFormId(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@ -242,7 +231,9 @@ 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 || userIsSelfRecipient()}
|
||||
disabled={
|
||||
isSubmitting || getValues('signers').some((signer) => signer.email === user?.email)
|
||||
}
|
||||
onClick={() => onAddPlaceholderSelfRecipient()}
|
||||
>
|
||||
<Plus className="-ml-1 mr-2 h-5 w-5" />
|
||||
|
||||
Reference in New Issue
Block a user