fix: project identifier check in project settings (#649)

This commit is contained in:
Aaryan Khandelwal 2023-03-31 16:04:17 +05:30 committed by GitHub
parent 480e2c4d7f
commit e3005b7776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,24 +78,9 @@ const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGu
}); });
}, [projectDetails, reset]); }, [projectDetails, reset]);
const onSubmit = async (formData: IProject) => { const updateProject = async (payload: Partial<IProject>) => {
if (!workspaceSlug || !projectDetails) return; if (!workspaceSlug || !projectDetails) return;
const payload: Partial<IProject> = {
name: formData.name,
network: formData.network,
identifier: formData.identifier,
description: formData.description,
default_assignee: formData.default_assignee,
project_lead: formData.project_lead,
icon: formData.icon,
};
await projectService
.checkProjectIdentifierAvailability(workspaceSlug as string, payload.identifier ?? "")
.then(async (res) => {
if (res.exists) setError("identifier", { message: "Identifier already exists" });
else
await projectService await projectService
.updateProject(workspaceSlug as string, projectDetails.id, payload) .updateProject(workspaceSlug as string, projectDetails.id, payload)
.then((res) => { .then((res) => {
@ -128,7 +103,29 @@ const GeneralSettings: NextPage<UserAuth> = ({ isMember, isOwner, isViewer, isGu
message: "Project could not be updated. Please try again.", message: "Project could not be updated. Please try again.",
}); });
}); });
};
const onSubmit = async (formData: IProject) => {
if (!workspaceSlug || !projectDetails) return;
const payload: Partial<IProject> = {
name: formData.name,
network: formData.network,
identifier: formData.identifier,
description: formData.description,
default_assignee: formData.default_assignee,
project_lead: formData.project_lead,
icon: formData.icon,
};
if (projectDetails.identifier !== formData.identifier)
await projectService
.checkProjectIdentifierAvailability(workspaceSlug as string, payload.identifier ?? "")
.then(async (res) => {
if (res.exists) setError("identifier", { message: "Identifier already exists" });
else await updateProject(payload);
}); });
else await updateProject(payload);
}; };
return ( return (