-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
117 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/frontend/src/apis/queries/user/useGetUserTheme.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { UserThemeSchema, type GetUserTheme } from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getUserTheme = () => | ||
get<GetUserTheme>({ | ||
schema: UserThemeSchema, | ||
url: '/api/user/theme', | ||
}); | ||
|
||
export const useGetUserTheme = () => { | ||
return useQuery({ | ||
queryKey: ['userTheme'], | ||
queryFn: getUserTheme, | ||
staleTime: 1000 * 60 * 5, | ||
}); | ||
}; |
26 changes: 26 additions & 0 deletions
26
packages/frontend/src/apis/queries/user/usePatchUserTheme.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { | ||
type PatchUserTheme, | ||
type PatchUserThemeRequest, | ||
UserThemeSchema, | ||
} from './schema'; | ||
import { patch } from '@/apis/utils/patch'; | ||
|
||
const patchUserTheme = ({ theme }: PatchUserThemeRequest) => | ||
patch<PatchUserTheme>({ | ||
params: { theme }, | ||
schema: UserThemeSchema, | ||
url: '/api/user/theme', | ||
}); | ||
|
||
export const usePatchUserTheme = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ['patchTheme'], | ||
mutationFn: ({ theme }: PatchUserThemeRequest) => patchUserTheme({ theme }), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ['userTheme'] }); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { AxiosRequestConfig } from 'axios'; | ||
import { z } from 'zod'; | ||
import { instance } from '../config'; | ||
import { formatZodError } from './formatZodError'; | ||
|
||
interface PatchParams { | ||
params?: AxiosRequestConfig['params']; | ||
schema: z.ZodType; | ||
url: string; | ||
} | ||
|
||
export const patch = async <T>({ | ||
params, | ||
schema, | ||
url, | ||
}: PatchParams): Promise<T> => { | ||
const { data } = await instance.patch(url, params); | ||
const result = schema.safeParse(data); | ||
|
||
if (!result.success) { | ||
throw new Error(formatZodError(result.error)); | ||
} | ||
|
||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters