From fdb7da4d453e3ea1dc1bd1aeacd25082299533fe Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Sun, 23 Jul 2023 22:10:40 +0530 Subject: [PATCH] chore: show proper error messages on profile form submit (#1611) --- .../[workspaceSlug]/me/profile/index.tsx | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/app/pages/[workspaceSlug]/me/profile/index.tsx b/apps/app/pages/[workspaceSlug]/me/profile/index.tsx index 85834d546..3fb73c40d 100644 --- a/apps/app/pages/[workspaceSlug]/me/profile/index.tsx +++ b/apps/app/pages/[workspaceSlug]/me/profile/index.tsx @@ -29,11 +29,10 @@ const defaultValues: Partial = { first_name: "", last_name: "", email: "", - role: "", + role: "Product / Project Manager", }; const Profile: NextPage = () => { - const [isEditing, setIsEditing] = useState(false); const [isRemoving, setIsRemoving] = useState(false); const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false); @@ -55,6 +54,16 @@ const Profile: NextPage = () => { }, [myProfile, reset]); const onSubmit = async (formData: IUser) => { + if (formData.first_name === "" || formData.last_name === "") { + setToastAlert({ + type: "error", + title: "Error!", + message: "First and last names are required.", + }); + + return; + } + const payload: Partial = { first_name: formData.first_name, last_name: formData.last_name, @@ -67,9 +76,9 @@ const Profile: NextPage = () => { .then((res) => { mutateUser((prevData) => { if (!prevData) return prevData; + return { ...prevData, ...res }; }, false); - setIsEditing(false); setToastAlert({ type: "success", title: "Success!", @@ -146,7 +155,7 @@ const Profile: NextPage = () => { -
+

Profile Picture

@@ -207,9 +216,6 @@ const Profile: NextPage = () => { error={errors.first_name} placeholder="Enter your first name" autoComplete="off" - validations={{ - required: "This field is required.", - }} /> { value={value} onChange={onChange} label={value ? value.toString() : "Select your role"} + buttonClassName={errors.role ? "border-red-500 bg-red-500/10" : ""} width="w-full" input position="right" @@ -267,14 +274,15 @@ const Profile: NextPage = () => { )} /> + {errors.role && Please select a role}
- + {isSubmitting ? "Updating..." : "Update profile"}
-
+ ) : (