import { Form, FormControl, FormDescription, FormField } from '@documenso/ui/primitives/form/form'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@documenso/ui/primitives/select'; import { zodResolver } from '@hookform/resolvers/zod'; import { Trans } from '@lingui/react/macro'; import type { TeamGlobalSettings } from '@prisma/client'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; import { FormStickySaveBar } from './form-sticky-save-bar'; import { InheritableField } from './inheritable-field'; const ZCertificatePreferencesFormSchema = z.object({ includeSigningCertificate: z.boolean().nullable(), includeAuditLog: z.boolean().nullable(), }); export type TCertificatePreferencesFormSchema = z.infer; type SettingsSubset = Pick; export type CertificatePreferencesFormProps = { settings: SettingsSubset; canInherit: boolean; onFormSubmit: (data: TCertificatePreferencesFormSchema) => Promise; }; export const CertificatePreferencesForm = ({ settings, canInherit, onFormSubmit }: CertificatePreferencesFormProps) => { const form = useForm({ defaultValues: { includeSigningCertificate: settings.includeSigningCertificate, includeAuditLog: settings.includeAuditLog, }, resolver: zodResolver(ZCertificatePreferencesFormSchema), }); const handleFormSubmit = form.handleSubmit(async (data) => { try { await onFormSubmit(data); } catch { // The page handler surfaces its own error toast. Keep the form dirty so // the save bar stays visible and the user can retry. return; } form.reset(data); }); return (
( Include the Signing Certificate in the Document} testId="include-signing-certificate" > 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. )} /> ( Include the Audit Logs in the Document} testId="include-audit-log" > Controls whether the audit logs will be included in the document when it is downloaded. The audit logs can still be downloaded from the logs page separately. )} /> form.reset()} />
); };