Compare commits
5 Commits
feat/refre
...
date-forma
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48eeb40940 | ||
|
|
8ba5b8ac83 | ||
|
|
d9161985ad | ||
|
|
7afe8cfa18 | ||
|
|
9139f3a3b4 |
@@ -11,6 +11,7 @@ import { FieldWithSignature } from '@documenso/prisma/types/field-with-signature
|
||||
import { trpc } from '@documenso/trpc/react';
|
||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||
|
||||
import { useRequiredSigningContext } from './provider';
|
||||
import { SigningFieldContainer } from './signing-field-container';
|
||||
|
||||
export type DateFieldProps = {
|
||||
@@ -25,6 +26,8 @@ export const DateField = ({ field, recipient }: DateFieldProps) => {
|
||||
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const { dateFormat } = useRequiredSigningContext();
|
||||
|
||||
const { mutateAsync: signFieldWithToken, isLoading: isSignFieldWithTokenLoading } =
|
||||
trpc.field.signFieldWithToken.useMutation();
|
||||
|
||||
@@ -40,7 +43,7 @@ export const DateField = ({ field, recipient }: DateFieldProps) => {
|
||||
await signFieldWithToken({
|
||||
token: recipient.token,
|
||||
fieldId: field.id,
|
||||
value: '',
|
||||
value: dateFormat,
|
||||
});
|
||||
|
||||
startTransition(() => router.refresh());
|
||||
|
||||
@@ -16,8 +16,17 @@ import { Button } from '@documenso/ui/primitives/button';
|
||||
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
||||
import { Input } from '@documenso/ui/primitives/input';
|
||||
import { Label } from '@documenso/ui/primitives/label';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@documenso/ui/primitives/select';
|
||||
import { SignaturePad } from '@documenso/ui/primitives/signature-pad';
|
||||
|
||||
import { DATE_FORMATS } from '~/helpers/constants';
|
||||
|
||||
import { useRequiredSigningContext } from './provider';
|
||||
import { SignDialog } from './sign-dialog';
|
||||
|
||||
@@ -31,9 +40,13 @@ export const SigningForm = ({ document, recipient, fields }: SigningFormProps) =
|
||||
const router = useRouter();
|
||||
const { data: session } = useSession();
|
||||
|
||||
const { fullName, signature, setFullName, setSignature } = useRequiredSigningContext();
|
||||
const { fullName, signature, setFullName, setSignature, dateFormat, setDateFormat } =
|
||||
useRequiredSigningContext();
|
||||
|
||||
const [validateUninsertedFields, setValidateUninsertedFields] = useState(false);
|
||||
|
||||
const hasDateField = fields.find((field) => field.type === 'DATE');
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
formState: { isSubmitting },
|
||||
@@ -104,6 +117,30 @@ export const SigningForm = ({ document, recipient, fields }: SigningFormProps) =
|
||||
/>
|
||||
</div>
|
||||
|
||||
{hasDateField && (
|
||||
<div>
|
||||
<Label htmlFor="date-format">Date Format</Label>
|
||||
|
||||
<Select
|
||||
onValueChange={(value) => {
|
||||
setDateFormat(value);
|
||||
}}
|
||||
defaultValue={dateFormat}
|
||||
>
|
||||
<SelectTrigger className="bg-background mt-2">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{DATE_FORMATS.map((format) => (
|
||||
<SelectItem key={format.key} value={format.value}>
|
||||
{format.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<Label htmlFor="Signature">Signature</Label>
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ export type SigningContextValue = {
|
||||
setEmail: (_value: string) => void;
|
||||
signature: string | null;
|
||||
setSignature: (_value: string | null) => void;
|
||||
dateFormat: string;
|
||||
setDateFormat: (_value: string) => void;
|
||||
};
|
||||
|
||||
const SigningContext = createContext<SigningContextValue | null>(null);
|
||||
@@ -31,6 +33,7 @@ export interface SigningProviderProps {
|
||||
fullName?: string | null;
|
||||
email?: string | null;
|
||||
signature?: string | null;
|
||||
dateFormat?: string | null;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
@@ -38,11 +41,13 @@ export const SigningProvider = ({
|
||||
fullName: initialFullName,
|
||||
email: initialEmail,
|
||||
signature: initialSignature,
|
||||
dateFormat: initialDateFormat,
|
||||
children,
|
||||
}: SigningProviderProps) => {
|
||||
const [fullName, setFullName] = useState(initialFullName || '');
|
||||
const [email, setEmail] = useState(initialEmail || '');
|
||||
const [signature, setSignature] = useState(initialSignature || null);
|
||||
const [dateFormat, setDateFormat] = useState(initialDateFormat || 'yyyy-MM-dd hh:mm a');
|
||||
|
||||
return (
|
||||
<SigningContext.Provider
|
||||
@@ -53,6 +58,8 @@ export const SigningProvider = ({
|
||||
setEmail,
|
||||
signature,
|
||||
setSignature,
|
||||
dateFormat,
|
||||
setDateFormat,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
17
apps/web/src/helpers/constants.ts
Normal file
17
apps/web/src/helpers/constants.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export const DATE_FORMATS = [
|
||||
{
|
||||
key: 'YYYYMMDD',
|
||||
label: 'YYYY-MM-DD',
|
||||
value: 'yyyy-MM-dd hh:mm a',
|
||||
},
|
||||
{
|
||||
key: 'DDMMYYYY',
|
||||
label: 'DD/MM/YYYY',
|
||||
value: 'dd/MM/yyyy hh:mm a',
|
||||
},
|
||||
{
|
||||
key: 'MMDDYYYY',
|
||||
label: 'MM/DD/YYYY',
|
||||
value: 'MM/dd/yyyy hh:mm a',
|
||||
},
|
||||
];
|
||||
@@ -58,7 +58,7 @@ export const signFieldWithToken = async ({
|
||||
const typedSignature = isSignatureField && !isBase64 ? value : undefined;
|
||||
|
||||
if (field.type === FieldType.DATE) {
|
||||
customText = DateTime.now().toFormat('yyyy-MM-dd hh:mm a');
|
||||
customText = DateTime.now().toFormat(value);
|
||||
}
|
||||
|
||||
await prisma.field.update({
|
||||
|
||||
Reference in New Issue
Block a user