mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-20 11:22:55 -05:00
add error message when action with same name already exists
This commit is contained in:
@@ -55,10 +55,16 @@ export default function AddNoCodeEventModal({
|
||||
type: "noCode",
|
||||
} as Event;
|
||||
|
||||
await createEventClass(environmentId, updatedData);
|
||||
mutateEventClasses();
|
||||
reset();
|
||||
setOpen(false);
|
||||
try {
|
||||
await createEventClass(environmentId, updatedData);
|
||||
mutateEventClasses();
|
||||
reset();
|
||||
setOpen(false);
|
||||
toast.success("Action added successfully.");
|
||||
} catch (e) {
|
||||
toast.error(e.message);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
const [testUrl, setTestUrl] = useState("");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Link from "next/link";
|
||||
|
||||
export default function LegalFooter() {
|
||||
if (!process.env.NEXT_PUBLIC_IMPRINT_URL && !process.env.NEXT_PUBLIC_PRIVACY_URL) return null;
|
||||
return (
|
||||
<div className="top-0 z-10 w-full border-b bg-white">
|
||||
<div className="mx-auto max-w-lg p-3 text-center text-sm text-slate-400">
|
||||
|
||||
@@ -41,6 +41,13 @@ export const createEventClass = async (environmentId, eventClass: Event) => {
|
||||
body: JSON.stringify(eventClass),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status === 409) {
|
||||
throw Error("Action with this name already exists");
|
||||
}
|
||||
throw Error(`Unable to create Action: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,20 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
|
||||
res.status(400).json({ message: "You are not allowed to create new automatic events" });
|
||||
}
|
||||
|
||||
// check if eventClass already exists
|
||||
const existingEventClass = await prisma.eventClass.findFirst({
|
||||
where: {
|
||||
name: eventClass.name,
|
||||
environment: {
|
||||
id: environmentId,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (existingEventClass) {
|
||||
return res.status(409).json({ message: "EventClass already exists" });
|
||||
}
|
||||
|
||||
// create eventClass in db
|
||||
const result = await prisma.eventClass.create({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user