forked from github/plane
fix: project identifier check in project settings (#649)
This commit is contained in:
parent
480e2c4d7f
commit
e3005b7776
@ -68,16 +68,6 @@ const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGu
|
|||||||
defaultValues,
|
defaultValues,
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkIdentifier = (value: string) => {
|
|
||||||
if (!workspaceSlug) return;
|
|
||||||
|
|
||||||
projectService
|
|
||||||
.checkProjectIdentifierAvailability(workspaceSlug as string, value)
|
|
||||||
.then((response) => {
|
|
||||||
if (response.exists) setError("identifier", { message: "Identifier already exists" });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (projectDetails)
|
if (projectDetails)
|
||||||
reset({
|
reset({
|
||||||
@ -88,6 +78,33 @@ const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGu
|
|||||||
});
|
});
|
||||||
}, [projectDetails, reset]);
|
}, [projectDetails, reset]);
|
||||||
|
|
||||||
|
const updateProject = async (payload: Partial<IProject>) => {
|
||||||
|
if (!workspaceSlug || !projectDetails) return;
|
||||||
|
|
||||||
|
await projectService
|
||||||
|
.updateProject(workspaceSlug as string, projectDetails.id, payload)
|
||||||
|
.then((res) => {
|
||||||
|
mutate<IProject>(
|
||||||
|
PROJECT_DETAILS(projectDetails.id),
|
||||||
|
(prevData) => ({ ...prevData, ...res }),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
mutate(PROJECTS_LIST(workspaceSlug as string));
|
||||||
|
setToastAlert({
|
||||||
|
type: "success",
|
||||||
|
title: "Success!",
|
||||||
|
message: "Project updated successfully",
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setToastAlert({
|
||||||
|
type: "error",
|
||||||
|
title: "Error!",
|
||||||
|
message: "Project could not be updated. Please try again.",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const onSubmit = async (formData: IProject) => {
|
const onSubmit = async (formData: IProject) => {
|
||||||
if (!workspaceSlug || !projectDetails) return;
|
if (!workspaceSlug || !projectDetails) return;
|
||||||
|
|
||||||
@ -101,34 +118,14 @@ const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGu
|
|||||||
icon: formData.icon,
|
icon: formData.icon,
|
||||||
};
|
};
|
||||||
|
|
||||||
await projectService
|
if (projectDetails.identifier !== formData.identifier)
|
||||||
.checkProjectIdentifierAvailability(workspaceSlug as string, payload.identifier ?? "")
|
await projectService
|
||||||
.then(async (res) => {
|
.checkProjectIdentifierAvailability(workspaceSlug as string, payload.identifier ?? "")
|
||||||
if (res.exists) setError("identifier", { message: "Identifier already exists" });
|
.then(async (res) => {
|
||||||
else
|
if (res.exists) setError("identifier", { message: "Identifier already exists" });
|
||||||
await projectService
|
else await updateProject(payload);
|
||||||
.updateProject(workspaceSlug as string, projectDetails.id, payload)
|
});
|
||||||
.then((res) => {
|
else await updateProject(payload);
|
||||||
mutate<IProject>(
|
|
||||||
PROJECT_DETAILS(projectDetails.id),
|
|
||||||
(prevData) => ({ ...prevData, ...res }),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
mutate(PROJECTS_LIST(workspaceSlug as string));
|
|
||||||
setToastAlert({
|
|
||||||
type: "success",
|
|
||||||
title: "Success!",
|
|
||||||
message: "Project updated successfully",
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setToastAlert({
|
|
||||||
type: "error",
|
|
||||||
title: "Error!",
|
|
||||||
message: "Project could not be updated. Please try again.",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user