From eaabe01b4d9d091d6afa53f7b7b267445df61cd4 Mon Sep 17 00:00:00 2001 From: Philip Cheung Date: Tue, 8 Oct 2024 11:07:54 +0800 Subject: [PATCH] add loading --- .../src/components/AboutUs/AddAboutUs.tsx | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/frontend/src/components/AboutUs/AddAboutUs.tsx b/frontend/src/components/AboutUs/AddAboutUs.tsx index 700bb19..94db65e 100644 --- a/frontend/src/components/AboutUs/AddAboutUs.tsx +++ b/frontend/src/components/AboutUs/AddAboutUs.tsx @@ -91,23 +91,6 @@ const AddAboutUs = ({ isOpen, onClose }: AddAboutUsProps) => { const [editorState, setEditorState] = useState(EditorState.createEmpty()); const [content, setContent] = useState(''); - // const validateFiles = (value: File) => { - // if (typeof value === 'string') return true; - - - // const fsMb = value.size / (1024 * 1024) - // const MAX_FILE_SIZE = 10 - // if (fsMb > MAX_FILE_SIZE) { - // return 'Max file size 10mb' - // } - - // return true - // } - - - // type FormValues = { - // file_: FileList - // } const mutation = useMutation({ @@ -128,15 +111,24 @@ const AddAboutUs = ({ isOpen, onClose }: AddAboutUsProps) => { }) const onSubmit: SubmitHandler = (data) => { - if (data.image instanceof FileList && data.image.length > 0) { - data.image = data.image[0] + + + if (isSubmitting) return + + try { + + if (data.image instanceof FileList && data.image.length > 0) { + data.image = data.image[0] + } + mutation.mutate(data) + console.log(data) + + } + catch (error) { + console.error("Error:", error); } - mutation.mutate(data) - console.log(data) } - - return ( <>