use-education.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { get, post } from './base'
  2. import {
  3. useMutation,
  4. useQuery,
  5. } from '@tanstack/react-query'
  6. import { useInvalid } from './use-base'
  7. import type { EducationAddParams } from '@/app/education-apply/types'
  8. const NAME_SPACE = 'education'
  9. export const useEducationVerify = () => {
  10. return useMutation({
  11. mutationKey: [NAME_SPACE, 'education-verify'],
  12. mutationFn: () => {
  13. return get<{ token: string }>('/account/education/verify', {}, { silent: true })
  14. },
  15. })
  16. }
  17. export const useEducationAdd = ({
  18. onSuccess,
  19. }: {
  20. onSuccess?: () => void
  21. }) => {
  22. return useMutation({
  23. mutationKey: [NAME_SPACE, 'education-add'],
  24. mutationFn: (params: EducationAddParams) => {
  25. return post<{ message: string }>('/account/education', {
  26. body: params,
  27. })
  28. },
  29. onSuccess,
  30. })
  31. }
  32. type SearchParams = {
  33. keywords?: string
  34. page?: number
  35. limit?: number
  36. }
  37. export const useEducationAutocomplete = () => {
  38. return useMutation({
  39. mutationFn: (searchParams: SearchParams) => {
  40. const {
  41. keywords = '',
  42. page = 0,
  43. limit = 40,
  44. } = searchParams
  45. return get<{ data: string[]; has_next: boolean; curr_page: number }>(`/account/education/autocomplete?keywords=${keywords}&page=${page}&limit=${limit}`)
  46. },
  47. })
  48. }
  49. export const useEducationStatus = (disable?: boolean) => {
  50. return useQuery({
  51. enabled: !disable,
  52. queryKey: [NAME_SPACE, 'education-status'],
  53. queryFn: () => {
  54. return get<{ result: boolean }>('/account/education')
  55. },
  56. retry: false,
  57. })
  58. }
  59. export const useInvalidateEducationStatus = () => {
  60. return useInvalid([NAME_SPACE, 'education-status'])
  61. }