Bin
2025-12-17 bc6aa38242b0a7dea4b18bc90e2d78740436a58b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { APIUser } from "@humansignal/core/types/user";
import { getApiInstance } from "../lib/api-provider/api-instance";
import { atomWithMutation, atomWithQuery, queryClientAtom } from "jotai-tanstack-query";
 
export const currentUserAtom = atomWithQuery(() => ({
  queryKey: ["current-user"],
  async queryFn() {
    const api = getApiInstance();
    return await api.invoke<APIUser>("me");
  },
}));
 
export const currentUserUpdateAtom = atomWithMutation((get) => ({
  mutationKey: ["update-current-user"],
  async mutationFn({ pk, user }: { pk: number; user: Partial<APIUser> }) {
    const api = getApiInstance();
    return await api.invoke<APIUser>("updateUser", { pk }, { body: user });
  },
 
  onSettled() {
    const queryClient = get(queryClientAtom);
    queryClient.invalidateQueries({ queryKey: ["current-user"] });
  },
}));