mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 02:10:12 -06:00
fix: show specific error when duplicate tag name is entered
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import "server-only";
|
||||
import { validateInputs } from "@/lib/utils/validate";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { ZId, ZString } from "@formbricks/types/common";
|
||||
import { TTag } from "@formbricks/types/tags";
|
||||
@@ -34,8 +35,18 @@ export const updateTagName = async (id: string, name: string): Promise<TTag> =>
|
||||
});
|
||||
|
||||
return tag;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} catch (error: any) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
return {
|
||||
data: null,
|
||||
error: { message: "already exists" },
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
data: null,
|
||||
error: { message: error.message || "Something went wrong" },
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ export const ProjectLookSettingsPage = async (props: { params: Promise<{ environ
|
||||
}
|
||||
|
||||
const canRemoveBranding = await getWhiteLabelPermission(organization.billing.plan);
|
||||
|
||||
return (
|
||||
<PageContentWrapper>
|
||||
<PageHeader pageTitle={t("common.project_configuration")}>
|
||||
|
||||
@@ -72,22 +72,23 @@ export const SingleTag: React.FC<SingleTagProps> = ({
|
||||
defaultValue={tagName}
|
||||
onBlur={(e) => {
|
||||
updateTagNameAction({ tagId, name: e.target.value.trim() }).then((updateTagNameResponse) => {
|
||||
if (updateTagNameResponse?.data) {
|
||||
const response = updateTagNameResponse?.data;
|
||||
|
||||
if (response?.id) {
|
||||
setUpdateTagError(false);
|
||||
toast.success(t("environments.project.tags.tag_updated"));
|
||||
} else {
|
||||
const errorMessage = getFormattedErrorMessage(updateTagNameResponse);
|
||||
const errorMessage = response?.error?.message ?? "";
|
||||
if (
|
||||
errorMessage?.includes(
|
||||
t("environments.project.tags.unique_constraint_failed_on_the_fields")
|
||||
)
|
||||
errorMessage.toLowerCase().includes("already exists") ||
|
||||
errorMessage.toLowerCase().includes("unique constraint failed")
|
||||
) {
|
||||
toast.error(t("environments.project.tags.tag_already_exists"), {
|
||||
duration: 2000,
|
||||
icon: <AlertCircleIcon className="h-5 w-5 text-orange-500" />,
|
||||
});
|
||||
} else {
|
||||
toast.error(errorMessage ?? t("common.something_went_wrong_please_try_again"), {
|
||||
toast.error(t("common.something_went_wrong_please_try_again"), {
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user