diff --git a/src/app/dashboard/companies/brief-form.tsx b/src/app/dashboard/companies/brief-form.tsx index 8edc6fe..2c121e2 100644 --- a/src/app/dashboard/companies/brief-form.tsx +++ b/src/app/dashboard/companies/brief-form.tsx @@ -19,17 +19,37 @@ interface BriefFormProps { onClose: () => void; } +interface DraftResponse { + title: string; + summary: string; + costUsd: number; +} + export function BriefForm({ tenantId, organizationId, organizationName, onClose }: BriefFormProps) { const queryClient = useQueryClient(); const { register, handleSubmit, + setValue, formState: { errors, isSubmitting }, } = useForm({ resolver: zodResolver(briefSchema), defaultValues: { title: `Research brief — ${organizationName}` }, }); + const generateDraft = useMutation({ + mutationFn: () => + apiFetch('/v1/research-briefs/draft', { + method: 'POST', + tenantId, + body: { organizationId }, + }), + onSuccess: (draft) => { + setValue('title', draft.title, { shouldValidate: true }); + setValue('summary', draft.summary, { shouldValidate: true }); + }, + }); + const createBrief = useMutation({ mutationFn: (values: BriefForm) => apiFetch('/v1/research-briefs', { @@ -58,14 +78,32 @@ export function BriefForm({ tenantId, organizationId, organizationName, onClose {errors.title &&

{errors.title.message}

}
- -