feat: profile-viewer: handleOk with loading state

This commit is contained in:
keiko233 2023-10-21 16:47:39 +08:00
parent f57c49ce3a
commit 2c2c174874

View File

@ -40,6 +40,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
const { t } = useTranslation(); const { t } = useTranslation();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [openType, setOpenType] = useState<"new" | "edit">("new"); const [openType, setOpenType] = useState<"new" | "edit">("new");
const [loading, setLoading] = useState(false);
// file input // file input
const fileDataRef = useRef<string | null>(null); const fileDataRef = useRef<string | null>(null);
@ -87,6 +88,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
const handleOk = useLockFn( const handleOk = useLockFn(
formIns.handleSubmit(async (form) => { formIns.handleSubmit(async (form) => {
setLoading(true);
try { try {
if (!form.type) throw new Error("`Type` should not be null"); if (!form.type) throw new Error("`Type` should not be null");
if (form.type === "remote" && !form.url) { if (form.type === "remote" && !form.url) {
@ -111,11 +113,13 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
await patchProfile(form.uid, item); await patchProfile(form.uid, item);
} }
setOpen(false); setOpen(false);
setLoading(false);
setTimeout(() => formIns.reset(), 500); setTimeout(() => formIns.reset(), 500);
fileDataRef.current = null; fileDataRef.current = null;
props.onChange(); props.onChange();
} catch (err: any) { } catch (err: any) {
Notice.error(err.message || err.toString()); Notice.error(err.message || err.toString());
setLoading(false);
} }
}) })
); );
@ -149,6 +153,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
onClose={handleClose} onClose={handleClose}
onCancel={handleClose} onCancel={handleClose}
onOk={handleOk} onOk={handleOk}
loading={loading}
> >
<Controller <Controller
name="type" name="type"