mirror of
https://github.com/documenso/documenso.git
synced 2025-11-21 12:11:29 +10:00
chore: refactor
This commit is contained in:
@ -15,22 +15,22 @@ import {
|
||||
DialogTitle,
|
||||
} from '@documenso/ui/primitives/dialog';
|
||||
|
||||
type DocumentAiStep = 'PROMPT' | 'PROCESSING';
|
||||
type RecipientDetectionStep = 'PROMPT' | 'PROCESSING';
|
||||
|
||||
export type DocumentAiPromptDialogProps = {
|
||||
export type RecipientDetectionPromptDialogProps = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onAccept: () => Promise<void> | void;
|
||||
onSkip: () => void;
|
||||
};
|
||||
|
||||
export const DocumentAiPromptDialog = ({
|
||||
export const RecipientDetectionPromptDialog = ({
|
||||
open,
|
||||
onOpenChange,
|
||||
onAccept,
|
||||
onSkip,
|
||||
}: DocumentAiPromptDialogProps) => {
|
||||
const [currentStep, setCurrentStep] = useState<DocumentAiStep>('PROMPT');
|
||||
}: RecipientDetectionPromptDialogProps) => {
|
||||
const [currentStep, setCurrentStep] = useState<RecipientDetectionStep>('PROMPT');
|
||||
|
||||
// Reset to first step when dialog closes
|
||||
useEffect(() => {
|
||||
@ -39,7 +39,7 @@ export const DocumentAiPromptDialog = ({
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
const handleUseAi = () => {
|
||||
const handleStartDetection = () => {
|
||||
setCurrentStep('PROCESSING');
|
||||
|
||||
Promise.resolve(onAccept()).catch(() => {
|
||||
@ -61,12 +61,12 @@ export const DocumentAiPromptDialog = ({
|
||||
<>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<Trans>Use AI to prepare your document?</Trans>
|
||||
<Trans>Auto-detect recipients?</Trans>
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
<Trans>
|
||||
Would you like to use AI to automatically add recipients to your document?
|
||||
This can save you time in setting up your document.
|
||||
Would you like to automatically detect recipients in your document? This can
|
||||
save you time in setting up your document.
|
||||
</Trans>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
@ -75,8 +75,8 @@ export const DocumentAiPromptDialog = ({
|
||||
<Button type="button" variant="secondary" onClick={handleSkip}>
|
||||
<Trans>Skip for now</Trans>
|
||||
</Button>
|
||||
<Button type="button" onClick={handleUseAi}>
|
||||
<Trans>Use AI</Trans>
|
||||
<Button type="button" onClick={handleStartDetection}>
|
||||
<Trans>Detect recipients</Trans>
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</>
|
||||
@ -90,8 +90,7 @@ export const DocumentAiPromptDialog = ({
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-center">
|
||||
<Trans>
|
||||
Our AI is scanning your document to detect recipient names, emails, and
|
||||
signing order.
|
||||
Scanning your document to detect recipient names, emails, and signing order.
|
||||
</Trans>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
@ -34,9 +34,9 @@ import {
|
||||
} from '@documenso/ui/primitives/form/form';
|
||||
import { FormErrorMessage } from '@documenso/ui/primitives/form/form-error-message';
|
||||
|
||||
import type { RecipientForCreation } from '~/utils/analyze-ai-recipients';
|
||||
import type { RecipientForCreation } from '~/utils/detect-document-recipients';
|
||||
|
||||
const ZDocumentAiRecipientSchema = z.object({
|
||||
const ZSuggestedRecipientSchema = z.object({
|
||||
formId: z.string().min(1),
|
||||
name: z
|
||||
.string()
|
||||
@ -50,15 +50,15 @@ const ZDocumentAiRecipientSchema = z.object({
|
||||
role: z.nativeEnum(RecipientRole),
|
||||
});
|
||||
|
||||
const ZDocumentAiRecipientsForm = z.object({
|
||||
const ZSuggestedRecipientsFormSchema = z.object({
|
||||
recipients: z
|
||||
.array(ZDocumentAiRecipientSchema)
|
||||
.array(ZSuggestedRecipientSchema)
|
||||
.min(1, { message: msg`Please add at least one recipient`.id }),
|
||||
});
|
||||
|
||||
type TDocumentAiRecipientsForm = z.infer<typeof ZDocumentAiRecipientsForm>;
|
||||
type TSuggestedRecipientsFormSchema = z.infer<typeof ZSuggestedRecipientsFormSchema>;
|
||||
|
||||
export type DocumentAiRecipientsDialogProps = {
|
||||
export type SuggestedRecipientsDialogProps = {
|
||||
open: boolean;
|
||||
recipients: RecipientForCreation[] | null;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
@ -66,13 +66,13 @@ export type DocumentAiRecipientsDialogProps = {
|
||||
onSubmit: (recipients: RecipientForCreation[]) => Promise<void> | void;
|
||||
};
|
||||
|
||||
export const DocumentAiRecipientsDialog = ({
|
||||
export const SuggestedRecipientsDialog = ({
|
||||
open,
|
||||
recipients,
|
||||
onOpenChange,
|
||||
onCancel,
|
||||
onSubmit,
|
||||
}: DocumentAiRecipientsDialogProps) => {
|
||||
}: SuggestedRecipientsDialogProps) => {
|
||||
const { t } = useLingui();
|
||||
|
||||
const [recipientSearchQuery, setRecipientSearchQuery] = useState('');
|
||||
@ -117,8 +117,8 @@ export const DocumentAiRecipientsDialog = ({
|
||||
];
|
||||
}, [recipients]);
|
||||
|
||||
const form = useForm<TDocumentAiRecipientsForm>({
|
||||
resolver: zodResolver(ZDocumentAiRecipientsForm),
|
||||
const form = useForm<TSuggestedRecipientsFormSchema>({
|
||||
resolver: zodResolver(ZSuggestedRecipientsFormSchema),
|
||||
defaultValues: {
|
||||
recipients: defaultRecipients,
|
||||
},
|
||||
Reference in New Issue
Block a user