From 743788135f71be0b06315b59a4ebb8109afe8fc0 Mon Sep 17 00:00:00 2001 From: GyDi Date: Mon, 7 Mar 2022 01:30:32 +0800 Subject: [PATCH] fix: profile field check --- src/components/profile/profile-edit.tsx | 5 +++++ src/components/profile/profile-new.tsx | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/profile/profile-edit.tsx b/src/components/profile/profile-edit.tsx index ae5856d..72693d8 100644 --- a/src/components/profile/profile-edit.tsx +++ b/src/components/profile/profile-edit.tsx @@ -34,6 +34,11 @@ const ProfileEdit = (props: Props) => { try { const { uid } = itemData; const { name, desc, url } = form; + + if (itemData.type === "remote" && !url) { + throw new Error("Remote URL should not be null"); + } + await patchProfile(uid, { uid, name, desc, url }); mutate("getProfiles"); onClose(); diff --git a/src/components/profile/profile-new.tsx b/src/components/profile/profile-new.tsx index 439f121..f58e770 100644 --- a/src/components/profile/profile-new.tsx +++ b/src/components/profile/profile-new.tsx @@ -40,7 +40,13 @@ const ProfileNew = (props: Props) => { } try { - await createProfile({ ...form }); + const name = form.name || `${form.type} file`; + + if (form.type === "remote" && !form.url) { + throw new Error("Remote URL should not be null"); + } + + await createProfile({ ...form, name }); setForm({ name: "", desc: "", type: "remote", url: "" }); mutate("getProfiles"); onClose();