import { zodResolver } from '@hookform/resolvers/zod'; import { msg } from '@lingui/core/macro'; import { useLingui } from '@lingui/react'; import { Trans } from '@lingui/react/macro'; import type { Team, TeamGlobalSettings } from '@prisma/client'; import { DocumentVisibility } from '@prisma/client'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; import { useSession } from '@documenso/lib/client-only/providers/session'; import { SUPPORTED_LANGUAGES, SUPPORTED_LANGUAGE_CODES, isValidLanguageCode, } from '@documenso/lib/constants/i18n'; import { trpc } from '@documenso/trpc/react'; import { Alert } from '@documenso/ui/primitives/alert'; import { Button } from '@documenso/ui/primitives/button'; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, } from '@documenso/ui/primitives/form/form'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@documenso/ui/primitives/select'; import { Switch } from '@documenso/ui/primitives/switch'; import { useToast } from '@documenso/ui/primitives/use-toast'; const ZTeamDocumentPreferencesFormSchema = z.object({ documentVisibility: z.nativeEnum(DocumentVisibility), documentLanguage: z.enum(SUPPORTED_LANGUAGE_CODES), includeSenderDetails: z.boolean(), typedSignatureEnabled: z.boolean(), includeSigningCertificate: z.boolean(), }); type TTeamDocumentPreferencesFormSchema = z.infer; export type TeamDocumentPreferencesFormProps = { team: Team; settings?: TeamGlobalSettings | null; }; export const TeamDocumentPreferencesForm = ({ team, settings, }: TeamDocumentPreferencesFormProps) => { const { _ } = useLingui(); const { toast } = useToast(); const { user } = useSession(); const placeholderEmail = user.email ?? 'user@example.com'; const { mutateAsync: updateTeamDocumentPreferences } = trpc.team.updateTeamDocumentSettings.useMutation(); const form = useForm({ defaultValues: { documentVisibility: settings?.documentVisibility ?? 'EVERYONE', documentLanguage: isValidLanguageCode(settings?.documentLanguage) ? settings?.documentLanguage : 'en', includeSenderDetails: settings?.includeSenderDetails ?? false, typedSignatureEnabled: settings?.typedSignatureEnabled ?? true, includeSigningCertificate: settings?.includeSigningCertificate ?? true, }, resolver: zodResolver(ZTeamDocumentPreferencesFormSchema), }); const includeSenderDetails = form.watch('includeSenderDetails'); const onSubmit = async (data: TTeamDocumentPreferencesFormSchema) => { try { const { documentVisibility, documentLanguage, includeSenderDetails, includeSigningCertificate, typedSignatureEnabled, } = data; await updateTeamDocumentPreferences({ teamId: team.id, settings: { documentVisibility, documentLanguage, includeSenderDetails, typedSignatureEnabled, includeSigningCertificate, }, }); toast({ title: _(msg`Document preferences updated`), description: _(msg`Your document preferences have been updated`), }); } catch (err) { toast({ title: _(msg`Something went wrong!`), description: _( msg`We were unable to update your document preferences at this time, please try again later`, ), }); } }; return (
( Default Document Visibility Controls the default visibility of an uploaded document. )} /> ( Default Document Language Controls the default language of an uploaded document. This will be used as the language in email communications with the recipients. )} /> ( Send on Behalf of Team
Preview
{includeSenderDetails ? ( "{placeholderEmail}" on behalf of "{team.name}" has invited you to sign "example document". ) : ( "{team.name}" has invited you to sign "example document". )}
Controls the formatting of the message that will be sent when inviting a recipient to sign a document. If a custom message has been provided while configuring the document, it will be used instead.
)} /> ( Enable Typed Signature
Controls whether the recipients can sign the documents using a typed signature. Enable or disable the typed signature globally.
)} /> ( Include the Signing Certificate in the Document
Controls whether the signing certificate will be included in the document when it is downloaded. The signing certificate can still be downloaded from the logs page separately.
)} />
); };