mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
fix: multiple text fields sharing the same text value
This commit is contained in:
@ -9,8 +9,6 @@ export type SigningContextValue = {
|
||||
setEmail: (_value: string) => void;
|
||||
signature: string | null;
|
||||
setSignature: (_value: string | null) => void;
|
||||
customText: string;
|
||||
setCustomText: (_value: string) => void;
|
||||
};
|
||||
|
||||
const SigningContext = createContext<SigningContextValue | null>(null);
|
||||
@ -33,7 +31,6 @@ export interface SigningProviderProps {
|
||||
fullName?: string | null;
|
||||
email?: string | null;
|
||||
signature?: string | null;
|
||||
customText?: string | null;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
@ -41,13 +38,11 @@ export const SigningProvider = ({
|
||||
fullName: initialFullName,
|
||||
email: initialEmail,
|
||||
signature: initialSignature,
|
||||
customText: initialCustomText,
|
||||
children,
|
||||
}: SigningProviderProps) => {
|
||||
const [fullName, setFullName] = useState(initialFullName || '');
|
||||
const [email, setEmail] = useState(initialEmail || '');
|
||||
const [signature, setSignature] = useState(initialSignature || null);
|
||||
const [customText, setCustomText] = useState(initialCustomText || '');
|
||||
|
||||
return (
|
||||
<SigningContext.Provider
|
||||
@ -58,8 +53,6 @@ export const SigningProvider = ({
|
||||
setEmail,
|
||||
signature,
|
||||
setSignature,
|
||||
customText,
|
||||
setCustomText,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@ -15,7 +15,6 @@ import { Label } from '@documenso/ui/primitives/label';
|
||||
import { Textarea } from '@documenso/ui/primitives/textarea';
|
||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||
|
||||
import { useRequiredSigningContext } from './provider';
|
||||
import { SigningFieldContainer } from './signing-field-container';
|
||||
|
||||
export type TextFieldProps = {
|
||||
@ -27,8 +26,6 @@ export const TextField = ({ field, recipient }: TextFieldProps) => {
|
||||
const router = useRouter();
|
||||
|
||||
const { toast } = useToast();
|
||||
const { customText: providedCustomText, setCustomText: setProvidedCustomText } =
|
||||
useRequiredSigningContext();
|
||||
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
@ -52,31 +49,25 @@ export const TextField = ({ field, recipient }: TextFieldProps) => {
|
||||
}
|
||||
}, [showCustomTextModal, isLocalSignatureSet]);
|
||||
|
||||
const onSign = async (source: 'local' | 'provider' = 'provider') => {
|
||||
const onSign = async () => {
|
||||
try {
|
||||
if (!providedCustomText && !localText) {
|
||||
if (!localText) {
|
||||
setIsLocalSignatureSet(false);
|
||||
setShowCustomTextModal(true);
|
||||
return;
|
||||
}
|
||||
|
||||
const value = source === 'local' && localText ? localText : providedCustomText ?? '';
|
||||
|
||||
if (!value) {
|
||||
if (!localText) {
|
||||
return;
|
||||
}
|
||||
|
||||
await signFieldWithToken({
|
||||
token: recipient.token,
|
||||
fieldId: field.id,
|
||||
value,
|
||||
value: localText,
|
||||
isBase64: true,
|
||||
});
|
||||
|
||||
if (source === 'local' && !providedCustomText) {
|
||||
setProvidedCustomText(localText);
|
||||
}
|
||||
|
||||
setLocalCustomText('');
|
||||
|
||||
startTransition(() => router.refresh());
|
||||
@ -93,9 +84,6 @@ export const TextField = ({ field, recipient }: TextFieldProps) => {
|
||||
|
||||
const onRemove = async () => {
|
||||
try {
|
||||
// Necessary to reset the custom text if the user removes the signature
|
||||
setProvidedCustomText('');
|
||||
|
||||
await removeSignedFieldWithToken({
|
||||
token: recipient.token,
|
||||
fieldId: field.id,
|
||||
@ -164,7 +152,7 @@ export const TextField = ({ field, recipient }: TextFieldProps) => {
|
||||
onClick={() => {
|
||||
setShowCustomTextModal(false);
|
||||
setIsLocalSignatureSet(true);
|
||||
void onSign('local');
|
||||
void onSign();
|
||||
}}
|
||||
>
|
||||
Save Text
|
||||
|
||||
Reference in New Issue
Block a user