MCPcopy
hub / github.com/supermemoryai/supermemory / useProjectMutations

Function useProjectMutations

apps/web/hooks/use-project-mutations.ts:16–289  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14}
15
16export function useProjectMutations() {
17 const queryClient = useQueryClient()
18 const { selectedProjects, setSelectedProjects, setSelectedProject } =
19 useProject()
20
21 const createProjectMutation = useMutation({
22 mutationFn: async (input: string | { name: string; emoji?: string }) => {
23 const { name, emoji } =
24 typeof input === "string" ? { name: input, emoji: undefined } : input
25
26 const response = await $fetch("@post/projects", {
27 body: { name, emoji },
28 })
29
30 if (response.error) {
31 throw new Error(response.error?.message || "Failed to create project")
32 }
33
34 return response.data
35 },
36 onSuccess: (data) => {
37 toast.success("Project created successfully!")
38 queryClient.invalidateQueries({ queryKey: ["projects"] })
39 queryClient.invalidateQueries({ queryKey: ["container-tags"] })
40
41 if (data?.containerTag) {
42 setSelectedProjects([data.containerTag])
43 }
44 },
45 onError: (error) => {
46 toast.error("Failed to create project", {
47 description: error instanceof Error ? error.message : "Unknown error",
48 })
49 },
50 })
51
52 const deleteProjectMutation = useMutation({
53 mutationFn: async ({
54 projectId,
55 containerTag,
56 action,
57 targetProjectId,
58 }: {
59 projectId: string
60 containerTag: string
61 action: "move" | "delete"
62 targetProjectId?: string
63 }) => {
64 const response =
65 action === "delete"
66 ? await $fetch(`@delete/container-tags/${containerTag}`)
67 : await $fetch(`@delete/projects/${projectId}`, {
68 body: { action, targetProjectId },
69 })
70
71 if (response.error) {
72 throw new Error(response.error?.message || "Failed to delete project")
73 }

Callers 3

AddSpaceModalFunction · 0.90
SpaceSelectorFunction · 0.90
SelectSpacesModalFunction · 0.90

Calls 3

useProjectFunction · 0.90
hasMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…