dify/web/service/use-education.ts
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

62 lines
1.7 KiB
TypeScript

import type { EducationAddParams } from '@/app/education-apply/types'
import { useMutation, useQuery } from '@tanstack/react-query'
import { get, post } from './base'
import { useInvalid } from './use-base'
const NAME_SPACE = 'education'
export const useEducationVerify = () => {
return useMutation({
mutationKey: [NAME_SPACE, 'education-verify'],
mutationFn: () => {
return get<{ token: string }>('/account/education/verify', {}, { silent: true })
},
})
}
export const useEducationAdd = ({ onSuccess }: { onSuccess?: () => void }) => {
return useMutation({
mutationKey: [NAME_SPACE, 'education-add'],
mutationFn: (params: EducationAddParams) => {
return post<{ message: string }>('/account/education', {
body: params,
})
},
onSuccess,
})
}
type SearchParams = {
keywords?: string
page?: number
limit?: number
}
export const useEducationAutocomplete = () => {
return useMutation({
mutationFn: (searchParams: SearchParams) => {
const { keywords = '', page = 0, limit = 40 } = searchParams
return get<{ data: string[]; has_next: boolean; curr_page: number }>(
`/account/education/autocomplete?keywords=${keywords}&page=${page}&limit=${limit}`,
)
},
})
}
export const useEducationStatus = (disable?: boolean) => {
return useQuery({
enabled: !disable,
queryKey: [NAME_SPACE, 'education-status'],
queryFn: () => {
return get<{ is_student: boolean; allow_refresh: boolean; expire_at: number | null }>(
'/account/education',
)
},
retry: false,
staleTime: 0, // Data expires immediately, ensuring fresh data on refetch
})
}
export const useInvalidateEducationStatus = () => {
return useInvalid([NAME_SPACE, 'education-status'])
}