mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 10:19:51 -06:00
fix: add toast and error handler for multiple team/product creation with existing team/product name (#996)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import { PlusCircleIcon } from "@heroicons/react/24/outline";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
interface AddProductModalProps {
|
||||
environmentId: string;
|
||||
@@ -20,11 +21,19 @@ export default function AddProductModal({ environmentId, open, setOpen }: AddPro
|
||||
const { register, handleSubmit } = useForm();
|
||||
|
||||
const submitProduct = async (data: { name: string }) => {
|
||||
setLoading(true);
|
||||
const newEnv = await createProductAction(environmentId, data.name);
|
||||
router.push(`/environments/${newEnv.id}/`);
|
||||
setOpen(false);
|
||||
setLoading(false);
|
||||
try {
|
||||
setLoading(true);
|
||||
const newEnv = await createProductAction(environmentId, data.name);
|
||||
|
||||
toast.success("Product created successfully!");
|
||||
router.push(`/environments/${newEnv.id}/`);
|
||||
setOpen(false);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error(`Error: Unable to save product information`);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -35,7 +35,8 @@ const EditProductName: React.FC<EditProductNameProps> = ({ product, environmentI
|
||||
|
||||
router.refresh();
|
||||
} catch (err) {
|
||||
toast.error(`Error: ${err.message}`);
|
||||
console.error(err);
|
||||
toast.error(`Error: Unable to save product information`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -18,13 +18,19 @@ export default function CreateTeamModal({ open, setOpen }: CreateTeamModalProps)
|
||||
const { register, handleSubmit } = useForm();
|
||||
|
||||
const submitTeam = async (data) => {
|
||||
setLoading(true);
|
||||
const newTeam = await createTeamAction(data.name);
|
||||
try {
|
||||
setLoading(true);
|
||||
const newTeam = await createTeamAction(data.name);
|
||||
|
||||
toast.success("Team created successfully!");
|
||||
router.push(`/teams/${newTeam.id}`);
|
||||
setOpen(false);
|
||||
setLoading(false);
|
||||
toast.success("Team created successfully!");
|
||||
router.push(`/teams/${newTeam.id}`);
|
||||
setOpen(false);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error(`Unable to create team`);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[teamId,name]` on the table `Product` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Product_teamId_name_key" ON "Product"("teamId", "name");
|
||||
@@ -373,6 +373,8 @@ model Product {
|
||||
placement WidgetPlacement @default(bottomRight)
|
||||
clickOutsideClose Boolean @default(true)
|
||||
darkOverlay Boolean @default(false)
|
||||
|
||||
@@unique([teamId, name])
|
||||
}
|
||||
|
||||
enum Plan {
|
||||
|
||||
@@ -194,6 +194,7 @@ export const createProduct = async (
|
||||
if (!productInput.name) {
|
||||
throw new ValidationError("Product Name is required");
|
||||
}
|
||||
|
||||
const { environments, ...data } = productInput;
|
||||
|
||||
let product = await prisma.product.create({
|
||||
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -469,6 +469,7 @@ importers:
|
||||
eslint-config-turbo:
|
||||
specifier: latest
|
||||
version: 1.10.15(eslint@8.51.0)
|
||||
|
||||
eslint-plugin-react:
|
||||
specifier: 7.33.2
|
||||
version: 7.33.2(eslint@8.51.0)
|
||||
@@ -11630,6 +11631,7 @@ packages:
|
||||
stackframe: 1.3.4
|
||||
dev: false
|
||||
|
||||
|
||||
/es-abstract@1.22.2:
|
||||
resolution: {integrity: sha512-YoxfFcDmhjOgWPWsV13+2RNjq1F6UQnfs+8TftwNqtzlmFzEXvlUwdrNrYeaizfjQzRMxkZ6ElWMOJIFKdVqwA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -12158,6 +12160,7 @@ packages:
|
||||
semver: 6.3.1
|
||||
string.prototype.matchall: 4.0.10
|
||||
|
||||
|
||||
/eslint-plugin-turbo@1.10.15(eslint@8.51.0):
|
||||
resolution: {integrity: sha512-Tv4QSKV/U56qGcTqS/UgOvb9HcKFmWOQcVh3HEaj7of94lfaENgfrtK48E2CckQf7amhKs1i+imhCsNCKjkQyA==}
|
||||
peerDependencies:
|
||||
|
||||
Reference in New Issue
Block a user