mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
fix: duplicate templates (#1434)
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
import { omit } from 'remeda';
|
||||||
|
|
||||||
import { nanoid } from '@documenso/lib/universal/id';
|
import { nanoid } from '@documenso/lib/universal/id';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import type { Prisma } from '@documenso/prisma/client';
|
import type { Prisma } from '@documenso/prisma/client';
|
||||||
@ -38,6 +40,7 @@ export const duplicateTemplate = async ({
|
|||||||
Recipient: true,
|
Recipient: true,
|
||||||
Field: true,
|
Field: true,
|
||||||
templateDocumentData: true,
|
templateDocumentData: true,
|
||||||
|
templateMeta: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -53,6 +56,14 @@ export const duplicateTemplate = async ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let templateMeta: Prisma.TemplateCreateArgs['data']['templateMeta'] | undefined = undefined;
|
||||||
|
|
||||||
|
if (template.templateMeta) {
|
||||||
|
templateMeta = {
|
||||||
|
create: omit(template.templateMeta, ['id', 'templateId']),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const duplicatedTemplate = await prisma.template.create({
|
const duplicatedTemplate = await prisma.template.create({
|
||||||
data: {
|
data: {
|
||||||
userId,
|
userId,
|
||||||
@ -66,8 +77,8 @@ export const duplicateTemplate = async ({
|
|||||||
token: nanoid(),
|
token: nanoid(),
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
templateMeta,
|
||||||
},
|
},
|
||||||
|
|
||||||
include: {
|
include: {
|
||||||
Recipient: true,
|
Recipient: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import { useEffect } from 'react';
|
|||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { Trans } from '@lingui/macro';
|
import { Trans } from '@lingui/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { InfoIcon } from 'lucide-react';
|
import { InfoIcon } from 'lucide-react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
|
|
||||||
@ -74,8 +73,6 @@ export const AddTemplateSettingsFormPartial = ({
|
|||||||
template,
|
template,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
}: AddTemplateSettingsFormProps) => {
|
}: AddTemplateSettingsFormProps) => {
|
||||||
const { _ } = useLingui();
|
|
||||||
|
|
||||||
const { documentAuthOption } = extractDocumentAuthMethods({
|
const { documentAuthOption } = extractDocumentAuthMethods({
|
||||||
documentAuth: template.authOptions,
|
documentAuth: template.authOptions,
|
||||||
});
|
});
|
||||||
@ -102,7 +99,7 @@ export const AddTemplateSettingsFormPartial = ({
|
|||||||
// We almost always want to set the timezone to the user's local timezone to avoid confusion
|
// We almost always want to set the timezone to the user's local timezone to avoid confusion
|
||||||
// when the document is signed.
|
// when the document is signed.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!form.formState.touchedFields.meta?.timezone) {
|
if (!form.formState.touchedFields.meta?.timezone && !template.templateMeta?.timezone) {
|
||||||
form.setValue('meta.timezone', Intl.DateTimeFormat().resolvedOptions().timeZone);
|
form.setValue('meta.timezone', Intl.DateTimeFormat().resolvedOptions().timeZone);
|
||||||
}
|
}
|
||||||
}, [form, form.setValue, form.formState.touchedFields.meta?.timezone]);
|
}, [form, form.setValue, form.formState.touchedFields.meta?.timezone]);
|
||||||
|
|||||||
Reference in New Issue
Block a user