@mussnad/frappe-react-query
Version:
A React Query SDK for Frappe
31 lines (30 loc) • 1.2 kB
TypeScript
import { FileArgs, FrappeError, FrappeFileUploadResponse } from '../types';
interface UseFrappeFileUploadReturnType<T = FrappeFileUploadResponse> {
/** Function to upload the file */
upload: (file: File, args: FileArgs, apiPath?: string) => Promise<T>;
/** Upload Progress in % - rounded off */
progress: number;
/** Will be true when the file is being uploaded */
loading: boolean;
/** Error object returned from API call */
error: FrappeError | null;
/** Will be true if file upload is successful. Else false */
isCompleted: boolean;
/** Function to reset the state of the hook */
reset: () => void;
}
/**
* Hook to upload files to the server
*
* @returns an object with the following properties: loading, error, isCompleted , result, and call and reset functions
*
* @example
*
* const { upload, progress, loading, error, isCompleted, reset } = useFrappeFileUpload()
*
* const onSubmit = async () => {
* const message = await upload(myFile, { doctype: "User", docname: "test@example.com", fieldname: "profile_pic", is_private: 1 })
* }
*/
export declare const useFrappeFileUpload: () => UseFrappeFileUploadReturnType;
export {};