-
Notifications
You must be signed in to change notification settings - Fork 60
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
132 additions
and
176 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,67 @@ | ||
import { useMutation, useQuery } from 'react-query'; | ||
import { useMutation, useQuery } from '@tanstack/react-query'; | ||
|
||
import { User } from 'types'; | ||
|
||
import { apiService } from 'services'; | ||
|
||
import queryClient from 'query-client'; | ||
|
||
export function useSignIn<T>() { | ||
const signIn = (data: T) => apiService.post('/account/sign-in', data); | ||
|
||
return useMutation<User, unknown, T>(signIn, { | ||
onSuccess: (data) => { | ||
queryClient.setQueryData(['account'], data); | ||
}, | ||
}); | ||
} | ||
|
||
export function useSignOut() { | ||
const signOut = () => apiService.post('/account/sign-out'); | ||
|
||
return useMutation(signOut, { | ||
onSuccess: () => { | ||
queryClient.setQueryData(['account'], null); | ||
}, | ||
}); | ||
} | ||
|
||
export function useSignUp<T>() { | ||
const signUp = (data: T) => apiService.post('/account/sign-up', data); | ||
|
||
export const useSignIn = <T>() => useMutation<User, unknown, T>({ | ||
mutationFn: (data: T) => apiService.post('/account/sign-in', data), | ||
onSuccess: (data) => { | ||
queryClient.setQueryData(['account'], data); | ||
}, | ||
}); | ||
|
||
export const useSignOut = () => useMutation({ | ||
mutationFn: () => apiService.post('/account/sign-out'), | ||
onSuccess: () => { | ||
queryClient.setQueryData(['account'], null); | ||
}, | ||
}); | ||
|
||
export const useSignUp = <T>() => { | ||
interface SignUpResponse { | ||
signupToken: string; | ||
} | ||
|
||
return useMutation<SignUpResponse, unknown, T>(signUp); | ||
} | ||
|
||
export function useForgotPassword<T>() { | ||
const forgotPassword = (data: T) => apiService.post('/account/forgot-password', data); | ||
|
||
return useMutation<{}, unknown, T>(forgotPassword); | ||
} | ||
|
||
export function useResetPassword<T>() { | ||
const resetPassword = (data: T) => apiService.put('/account/reset-password', data); | ||
|
||
return useMutation<{}, unknown, T>(resetPassword); | ||
} | ||
|
||
export function useResendEmail<T>() { | ||
const resendEmail = (data: T) => apiService.post('/account/resend-email', data); | ||
|
||
return useMutation<{}, unknown, T>(resendEmail); | ||
} | ||
|
||
export function useGet(options? : {}) { | ||
const get = () => apiService.get('/account'); | ||
|
||
return useQuery<User>(['account'], get, options); | ||
} | ||
|
||
export function useUpdate<T>() { | ||
const update = (data: T) => apiService.put('/account', data); | ||
|
||
return useMutation<User, unknown, T>(update); | ||
} | ||
|
||
export function useUploadAvatar<T>() { | ||
const uploadAvatar = (data: T) => apiService.post('/account/avatar', data); | ||
|
||
return useMutation<User, unknown, T>(uploadAvatar, { | ||
onSuccess: (data) => { | ||
queryClient.setQueryData(['account'], data); | ||
}, | ||
}); | ||
} | ||
|
||
export function useRemoveAvatar() { | ||
const removeAvatar = () => apiService.delete('/account/avatar'); | ||
|
||
return useMutation<User>(removeAvatar, { | ||
onSuccess: (data) => { | ||
queryClient.setQueryData(['account'], data); | ||
}, | ||
return useMutation<SignUpResponse, unknown, T>({ | ||
mutationFn: (data: T) => apiService.post('/account/sign-up', data), | ||
}); | ||
} | ||
}; | ||
|
||
export const useForgotPassword = <T>() => useMutation<{}, unknown, T>({ | ||
mutationFn: (data: T) => apiService.post('/account/forgot-password', data), | ||
}); | ||
|
||
export const useResetPassword = <T>() => useMutation<{}, unknown, T>({ | ||
mutationFn: (data: T) => apiService.put('/account/reset-password', data), | ||
}); | ||
|
||
export const useResendEmail = <T>() => useMutation<{}, unknown, T>({ | ||
mutationFn: (data: T) => apiService.post('/account/resend-email', data), | ||
}); | ||
|
||
export const useGet = (options? : {}) => useQuery<User>({ | ||
queryKey: ['account'], | ||
queryFn: () => apiService.get('/account'), | ||
...options, | ||
}); | ||
|
||
export const useUpdate = <T>() => useMutation<User, unknown, T>({ | ||
mutationFn: (data: T) => apiService.put('/account', data), | ||
}); | ||
|
||
export const useUploadAvatar = <T>() => useMutation<User, unknown, T>({ | ||
mutationFn: (data: T) => apiService.post('/account/avatar', data), | ||
onSuccess: (data) => { | ||
queryClient.setQueryData(['account'], data); | ||
}, | ||
}); | ||
|
||
export const useRemoveAvatar = () => useMutation<User>({ | ||
mutationFn: () => apiService.delete('/account/avatar'), | ||
onSuccess: (data) => { | ||
queryClient.setQueryData(['account'], 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import { useQuery } from 'react-query'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { User } from 'types'; | ||
|
||
import { apiService } from 'services'; | ||
|
||
export function useList<T>(params: T) { | ||
const list = () => apiService.get('/users', params); | ||
|
||
interface UserListResponse { | ||
count: number; | ||
items: User[]; | ||
totalPages: number; | ||
} | ||
|
||
return useQuery<UserListResponse>(['users', params], list); | ||
return useQuery<UserListResponse>({ | ||
queryKey: ['users', params], | ||
queryFn: () => apiService.get('/users', params), | ||
}); | ||
} |
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
Oops, something went wrong.