MCPcopy Create free account
hub / github.com/mlco2/codecarbon / CreateProjectModal

Function CreateProjectModal

webapp/src/components/createProjectModal.tsx:30–135  ·  view source on GitHub ↗
({
    organizationId,
    isOpen,
    onClose,
    onProjectCreated,
})

Source from the content-addressed store, hash-verified

28}
29
30const CreateProjectModal: React.FC<ModalProps> = ({
31 organizationId,
32 isOpen,
33 onClose,
34 onProjectCreated,
35}) => {
36 const [formData, setFormData] = useState<CreateProjectInput>({
37 name: "",
38 description: "",
39 });
40 const [isLoading, setIsLoading] = useState(false);
41
42 const handleSave = async () => {
43 toast.promise(
44 async () => {
45 setIsLoading(true);
46 try {
47 const newProject = await createProject(
48 organizationId,
49 formData,
50 );
51 await onProjectCreated(); // Call the callback to refresh the project list
52 handleClose(); // Automatically close the modal after successful creation
53 return newProject; // Return for the success message
54 } catch (error) {
55 console.error("Failed to create project:", error);
56 throw error; // Rethrow for the error message
57 } finally {
58 setIsLoading(false);
59 }
60 },
61 {
62 loading: "Creating project...",
63 success: "Project created successfully!",
64 error: "Failed to create project",
65 },
66 );
67 };
68
69 const handleClose = () => {
70 // Reset state when closing
71 setFormData({ name: "", description: "" });
72 onClose();
73 };
74
75 return (
76 <Dialog open={isOpen} onOpenChange={handleClose}>
77 <DialogContent className="sm:max-w-[425px]">
78 <DialogHeader>
79 <DialogTitle>Create new project</DialogTitle>
80 <DialogDescription>
81 Fill in the details to create your project
82 </DialogDescription>
83 </DialogHeader>
84 <Separator className="my-4" />
85 <div className="grid gap-4 py-4">
86 <div className="space-y-2">
87 <Label htmlFor="project-name">Project Name</Label>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…