From 6bac012474081c9c9b8ff5e7aef39ff8d9a62ce2 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 11 Dec 2025 21:12:00 +0000 Subject: [PATCH] feat: add createSearchSpaceMutationAtom --- .../search-space-mutation.atoms.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 surfsense_web/atoms/search-spaces/search-space-mutation.atoms.ts diff --git a/surfsense_web/atoms/search-spaces/search-space-mutation.atoms.ts b/surfsense_web/atoms/search-spaces/search-space-mutation.atoms.ts new file mode 100644 index 000000000..c9cc37a85 --- /dev/null +++ b/surfsense_web/atoms/search-spaces/search-space-mutation.atoms.ts @@ -0,0 +1,24 @@ +import { atomWithMutation } from "jotai-tanstack-query"; +import { toast } from "sonner"; +import type { + CreateSearchSpaceRequest, +} from "@/contracts/types/search-space.types"; +import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service"; +import { cacheKeys } from "@/lib/query-client/cache-keys"; +import { queryClient } from "@/lib/query-client/client"; + +export const createSearchSpaceMutationAtom = atomWithMutation(() => { + return { + mutationKey: ["create-search-space"], + mutationFn: async (request: CreateSearchSpaceRequest) => { + return searchSpacesApiService.createSearchSpace(request); + }, + + onSuccess: () => { + toast.success("Search space created successfully"); + queryClient.invalidateQueries({ + queryKey: cacheKeys.searchSpaces.all, + }); + }, + }; +});