2025-12-11 20:42:27 +00:00
|
|
|
import { atom } from "jotai";
|
2025-12-17 00:09:43 -08:00
|
|
|
import { atomWithQuery } from "jotai-tanstack-query";
|
2026-07-06 15:12:40 +05:30
|
|
|
import type { GetWorkspacesRequest } from "@/contracts/types/workspace.types";
|
|
|
|
|
import { workspacesApiService } from "@/lib/apis/workspaces-api.service";
|
2025-12-11 20:42:27 +00:00
|
|
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
|
|
|
|
|
2026-07-05 23:17:13 -07:00
|
|
|
export const activeWorkspaceIdAtom = atom<string | null>(null);
|
2025-12-11 21:19:29 +00:00
|
|
|
|
2026-07-06 15:12:40 +05:30
|
|
|
export const workspacesQueryParamsAtom = atom<GetWorkspacesRequest["queryParams"]>({
|
2025-12-11 20:50:04 +00:00
|
|
|
skip: 0,
|
|
|
|
|
limit: 10,
|
|
|
|
|
owned_only: false,
|
2025-12-11 20:42:27 +00:00
|
|
|
});
|
|
|
|
|
|
2026-07-06 15:12:40 +05:30
|
|
|
export const workspacesAtom = atomWithQuery((get) => {
|
|
|
|
|
const queryParams = get(workspacesQueryParamsAtom);
|
2025-12-11 20:42:27 +00:00
|
|
|
|
|
|
|
|
return {
|
2026-07-06 15:12:40 +05:30
|
|
|
queryKey: cacheKeys.workspaces.withQueryParams(queryParams),
|
2025-12-11 21:00:17 +00:00
|
|
|
staleTime: 5 * 60 * 1000,
|
2025-12-11 20:42:27 +00:00
|
|
|
queryFn: async () => {
|
2026-07-06 15:12:40 +05:30
|
|
|
return workspacesApiService.getWorkspaces({
|
2025-12-11 20:42:27 +00:00
|
|
|
queryParams,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
});
|