Skip to content

Commit 2d2300a

Browse files
committed
fix: fixed project create error
1 parent 6e86146 commit 2d2300a

4 files changed

Lines changed: 87 additions & 82 deletions

File tree

apps/api/src/routes/project/route.ts

Lines changed: 69 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,75 @@ router.get("/", async (req: RequestWithSession, res: Response) => {
136136
}
137137
});
138138

139+
router.post("/", async (req: RequestWithSession, res: Response) => {
140+
const session = req.session;
141+
if (!session) {
142+
return res.status(401).json({ error: "unauthenticated" });
143+
}
144+
145+
const userId = session.user.id;
146+
147+
try {
148+
const body = createProjectSchema.parse(req.body);
149+
150+
const project = await db.$transaction(async (tx) => {
151+
const proj = await tx.project.create({
152+
data: {
153+
name: body.name,
154+
description: body.description ?? null,
155+
ownerId: userId,
156+
},
157+
});
158+
159+
await tx.projectMember.create({
160+
data: {
161+
userId,
162+
projectId: proj.id,
163+
role: "OWNER",
164+
},
165+
});
166+
167+
const defaultEnvs = ["development", "staging", "production"];
168+
await Promise.all(
169+
defaultEnvs.map((name) =>
170+
tx.environment.create({
171+
data: {
172+
name,
173+
apiKey: crypto.randomUUID(),
174+
projectId: proj.id,
175+
},
176+
})
177+
)
178+
);
179+
180+
await tx.activityLog.create({
181+
data: {
182+
projectId: proj.id,
183+
userId,
184+
actionType: "PROJECT_CREATED",
185+
description: `Project created: "${proj.name}".`,
186+
details: body,
187+
},
188+
});
189+
190+
return proj;
191+
});
192+
193+
res.status(201).json({
194+
id: project.id,
195+
name: project.name,
196+
subtitle: project.description || "No description",
197+
flags: 0,
198+
environments: 3,
199+
lastUpdated: "Just now",
200+
isFavorite: false,
201+
});
202+
} catch (error) {
203+
console.error("Failed to create project:", error);
204+
res.status(500).json({ error: "Failed to create project" });
205+
}
206+
});
207+
139208
router.post("/feedback", async (req: RequestWithSession, res: Response) => {
140209
const session = req.session;
141210

@@ -223,79 +292,6 @@ router.get(
223292
}
224293
);
225294

226-
router.post(
227-
"/",
228-
verifyRole.MEMBER,
229-
async (req: RequestWithSession, res: Response) => {
230-
const session = req.session;
231-
if (!session) {
232-
return res.json({ error: "unauthenticated", status: 401 });
233-
}
234-
235-
const userId = session.user.id;
236-
237-
try {
238-
const body = createProjectSchema.parse(req.body);
239-
240-
const project = await db.$transaction(async (tx) => {
241-
const proj = await tx.project.create({
242-
data: {
243-
name: body.name,
244-
description: body.description ?? null,
245-
ownerId: userId,
246-
},
247-
});
248-
249-
await tx.projectMember.create({
250-
data: {
251-
userId,
252-
projectId: proj.id,
253-
role: "OWNER",
254-
},
255-
});
256-
257-
const defaultEnvs = ["development", "staging", "production"];
258-
await Promise.all(
259-
defaultEnvs.map((name) =>
260-
tx.environment.create({
261-
data: {
262-
name,
263-
apiKey: crypto.randomUUID(),
264-
projectId: proj.id,
265-
},
266-
})
267-
)
268-
);
269-
270-
await tx.activityLog.create({
271-
data: {
272-
projectId: proj.id,
273-
userId,
274-
actionType: "PROJECT_CREATED",
275-
description: `Project created: "${proj.name}".`,
276-
details: body,
277-
},
278-
});
279-
280-
return proj;
281-
});
282-
283-
res.status(201).json({
284-
id: project.id,
285-
name: project.name,
286-
subtitle: project.description || "No description",
287-
flags: 0,
288-
environments: 3,
289-
lastUpdated: "Just now",
290-
isFavorite: false,
291-
});
292-
} catch (error) {
293-
console.error("Failed to create project:", error);
294-
res.status(500).json({ error: "Failed to create project" });
295-
}
296-
}
297-
);
298-
299295
router.patch(
300296
"/:projectId/star",
301297
verifyRole.VIEWER,

apps/web/components/dashboard/project-list.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ export const ProjectList = () => {
131131
starMutation.mutate(id);
132132
};
133133

134-
const handleCreateProject = (name: string, description: string) => {
135-
createMutation.mutate({ name, description });
134+
const handleCreateProject = async (name: string, description: string) => {
135+
try {
136+
await createMutation.mutateAsync({ name, description });
137+
return true;
138+
} catch (_error) {
139+
return false;
140+
}
136141
};
137142

138143
if (isListLoading) {

apps/web/components/environment/setup-snippets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const SNIPPETS = {
88
99
const options = {
1010
apiKey: "${apiKey}",
11-
apiBaseUrl: "http://localhost:5000",
11+
apiBaseUrl: "https://api.flagix.com",
1212
initialContext: {
1313
userId: "user_123",
1414
platform: "web",
@@ -48,7 +48,7 @@ export default function MyComponent() {
4848
*/
4949
await Flagix.initialize({
5050
apiKey: "${apiKey}",
51-
apiBaseUrl: "http://localhost:5000",
51+
apiBaseUrl: "https://api.flagix.com",
5252
initialContext: {
5353
userId: "server_user_01",
5454
internal: true

apps/web/components/project/project-create-modal.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useState } from "react";
1515
type CreateProjectModalProps = {
1616
open: boolean;
1717
onOpenChange: (open: boolean) => void;
18-
onCreate: (name: string, description: string) => void;
18+
onCreate: (name: string, description: string) => Promise<boolean>;
1919
isSubmitting: boolean;
2020
};
2121

@@ -28,12 +28,16 @@ export const CreateProjectModal = ({
2828
const [name, setName] = useState("");
2929
const [description, setDescription] = useState("");
3030

31-
const handleSubmit = (e: React.FormEvent) => {
31+
const handleSubmit = async (e: React.FormEvent) => {
3232
e.preventDefault();
3333
if (name.trim()) {
34-
onCreate(name, description);
35-
setName("");
36-
setDescription("");
34+
const success = await onCreate(name, description);
35+
36+
if (success) {
37+
setName("");
38+
setDescription("");
39+
onOpenChange(false);
40+
}
3741
}
3842
};
3943

0 commit comments

Comments
 (0)