dify/web/service/use-education.ts

53 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-03-13 15:52:43 +08:00
import { get, post } from './base'
import {
useMutation,
2025-03-14 15:13:56 +08:00
useQuery,
2025-03-13 15:52:43 +08:00
} from '@tanstack/react-query'
import type { EducationAddParams } from '@/app/education-apply/components/types'
const NAME_SPACE = 'education'
2025-03-14 15:13:56 +08:00
export const useEducationVerify = () => {
return useQuery({
queryKey: [NAME_SPACE, 'education-verify'],
queryFn: () => {
return get<{ token: string }>('/account/education/verify')
},
retry: false,
})
}
2025-03-13 15:52:43 +08:00
export const useEducationAdd = ({
onSuccess,
}: {
onSuccess?: () => void
}) => {
return useMutation({
mutationKey: [NAME_SPACE, 'education-add'],
mutationFn: (params: EducationAddParams) => {
2025-03-14 15:13:56 +08:00
return post<{ message: string }>('/account/education', {
2025-03-13 15:52:43 +08:00
body: params,
})
},
onSuccess,
})
}
type SearchParams = {
keywords?: string
page?: number
limit?: number
}
export const useEducationAutocomplete = () => {
return useMutation({
mutationFn: (searchParams: SearchParams) => {
const {
keywords = '',
page = 1,
limit = 20,
} = searchParams
return get<{ data: string[]; has_next: boolean; curr_page: number }>(`/account/education/autocomplete?keywords=${keywords}&page=${page}&limit=${limit}`)
},
})
}