setup1
This commit is contained in:
38
apps/Frontend/src/hooks/use-extractPdfData.ts
Normal file
38
apps/Frontend/src/hooks/use-extractPdfData.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { apiRequest, queryClient } from "@/lib/queryClient";
|
||||
|
||||
export interface ExtractedData {
|
||||
name: string;
|
||||
memberId: string;
|
||||
dob: string;
|
||||
}
|
||||
|
||||
export default function useExtractPdfData() {
|
||||
const { toast } = useToast();
|
||||
|
||||
return useMutation<ExtractedData, Error, File>({
|
||||
mutationFn: async (pdfFile: File) => {
|
||||
const formData = new FormData();
|
||||
formData.append("pdf", pdfFile);
|
||||
|
||||
const res = await apiRequest("POST", "/api/pdfExtraction/", formData);
|
||||
if (!res.ok) throw new Error("Failed to extract PDF");
|
||||
return res.json();
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast({
|
||||
title: "Success",
|
||||
description: "PDF data extracted!",
|
||||
variant: "default",
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
toast({
|
||||
title: "Error",
|
||||
description: `Failed to extract PDF: ${error.message}`,
|
||||
variant: "destructive",
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user