forked from github/plane
chore: show proper error messages on profile form submit (#1611)
This commit is contained in:
parent
ff6690afd2
commit
fdb7da4d45
@ -29,11 +29,10 @@ const defaultValues: Partial<IUser> = {
|
|||||||
first_name: "",
|
first_name: "",
|
||||||
last_name: "",
|
last_name: "",
|
||||||
email: "",
|
email: "",
|
||||||
role: "",
|
role: "Product / Project Manager",
|
||||||
};
|
};
|
||||||
|
|
||||||
const Profile: NextPage = () => {
|
const Profile: NextPage = () => {
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
|
||||||
const [isRemoving, setIsRemoving] = useState(false);
|
const [isRemoving, setIsRemoving] = useState(false);
|
||||||
const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false);
|
const [isImageUploadModalOpen, setIsImageUploadModalOpen] = useState(false);
|
||||||
|
|
||||||
@ -55,6 +54,16 @@ const Profile: NextPage = () => {
|
|||||||
}, [myProfile, reset]);
|
}, [myProfile, reset]);
|
||||||
|
|
||||||
const onSubmit = async (formData: IUser) => {
|
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<IUser> = {
|
const payload: Partial<IUser> = {
|
||||||
first_name: formData.first_name,
|
first_name: formData.first_name,
|
||||||
last_name: formData.last_name,
|
last_name: formData.last_name,
|
||||||
@ -67,9 +76,9 @@ const Profile: NextPage = () => {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
mutateUser((prevData) => {
|
mutateUser((prevData) => {
|
||||||
if (!prevData) return prevData;
|
if (!prevData) return prevData;
|
||||||
|
|
||||||
return { ...prevData, ...res };
|
return { ...prevData, ...res };
|
||||||
}, false);
|
}, false);
|
||||||
setIsEditing(false);
|
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "success",
|
type: "success",
|
||||||
title: "Success!",
|
title: "Success!",
|
||||||
@ -146,7 +155,7 @@ const Profile: NextPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
<SettingsNavbar profilePage />
|
<SettingsNavbar profilePage />
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-8 sm:space-y-12">
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-8 sm:space-y-12">
|
||||||
<div className="grid grid-cols-12 gap-4 sm:gap-16">
|
<div className="grid grid-cols-12 gap-4 sm:gap-16">
|
||||||
<div className="col-span-12 sm:col-span-6">
|
<div className="col-span-12 sm:col-span-6">
|
||||||
<h4 className="text-lg font-semibold text-custom-text-100">Profile Picture</h4>
|
<h4 className="text-lg font-semibold text-custom-text-100">Profile Picture</h4>
|
||||||
@ -207,9 +216,6 @@ const Profile: NextPage = () => {
|
|||||||
error={errors.first_name}
|
error={errors.first_name}
|
||||||
placeholder="Enter your first name"
|
placeholder="Enter your first name"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
validations={{
|
|
||||||
required: "This field is required.",
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
name="last_name"
|
name="last_name"
|
||||||
@ -255,6 +261,7 @@ const Profile: NextPage = () => {
|
|||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
label={value ? value.toString() : "Select your role"}
|
label={value ? value.toString() : "Select your role"}
|
||||||
|
buttonClassName={errors.role ? "border-red-500 bg-red-500/10" : ""}
|
||||||
width="w-full"
|
width="w-full"
|
||||||
input
|
input
|
||||||
position="right"
|
position="right"
|
||||||
@ -267,14 +274,15 @@ const Profile: NextPage = () => {
|
|||||||
</CustomSelect>
|
</CustomSelect>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
{errors.role && <span className="text-xs text-red-500">Please select a role</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="sm:text-right">
|
<div className="sm:text-right">
|
||||||
<SecondaryButton onClick={handleSubmit(onSubmit)} loading={isSubmitting}>
|
<SecondaryButton type="submit" loading={isSubmitting}>
|
||||||
{isSubmitting ? "Updating..." : "Update profile"}
|
{isSubmitting ? "Updating..." : "Update profile"}
|
||||||
</SecondaryButton>
|
</SecondaryButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid h-full w-full place-items-center px-4 sm:px-0">
|
<div className="grid h-full w-full place-items-center px-4 sm:px-0">
|
||||||
|
Loading…
Reference in New Issue
Block a user