Implementation:Langgenius Dify Use Education
| Knowledge Sources | |
|---|---|
| Domains | Frontend, API_Service |
| Last Updated | 2026-02-12 07:00 GMT |
Overview
React Query hooks for education verification workflows including student verification, education application submission, institution autocomplete search, and education status checking.
Description
use-education.ts provides React Query hooks for the Dify education verification feature, which allows students to verify their educational status for special benefits. The module exports five hooks: useEducationVerify is a useMutation hook that initiates the education verification process by calling GET /account/education/verify with silent: true to suppress error toasts, returning a verification token; useEducationAdd is a useMutation hook that submits the education application with EducationAddParams (institution details, student proof) via POST /account/education and accepts an optional onSuccess callback; useEducationAutocomplete is a useMutation hook that searches for educational institutions with pagination support, accepting keywords, page (default 0), and limit (default 40) parameters and returning results with has_next pagination info; useEducationStatus is a useQuery hook that fetches the current education status (is_student, allow_refresh, expire_at) with staleTime: 0 to ensure fresh data and retry: false to avoid retrying failed requests; and useInvalidateEducationStatus provides a cache invalidation function for the education status query using the useInvalid utility. All hooks use the "education" namespace for query keys.
Usage
Use these hooks in the education verification page and related components. The typical workflow is: verify eligibility with useEducationVerify, search for an institution with useEducationAutocomplete, submit the application with useEducationAdd, and check status with useEducationStatus.
Code Reference
Source Location
- Repository: Langgenius_Dify
- File: web/service/use-education.ts
- Lines: 1-68
Signature
export const useEducationVerify = () => UseMutationResult<{ token: string }>
export const useEducationAdd = (options: {
onSuccess?: () => void
}) => UseMutationResult<{ message: string }, unknown, EducationAddParams>
export const useEducationAutocomplete = () => UseMutationResult<
{ data: string[], has_next: boolean, curr_page: number },
unknown,
SearchParams
>
export const useEducationStatus = (disable?: boolean) => UseQueryResult<{
is_student: boolean
allow_refresh: boolean
expire_at: number | null
}>
export const useInvalidateEducationStatus = () => () => void
Import
import {
useEducationVerify,
useEducationAdd,
useEducationAutocomplete,
useEducationStatus,
useInvalidateEducationStatus,
} from '@/service/use-education'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| disable | boolean | No | When true, disables the useEducationStatus query |
| onSuccess | () => void | No | Callback invoked after successful education application submission |
| params.keywords | string | No | Search keywords for institution autocomplete |
| params.page | number | No | Page number for autocomplete pagination (default 0) |
| params.limit | number | No | Results per page for autocomplete (default 40) |
| EducationAddParams | EducationAddParams | Yes (mutation) | Education application form data |
Outputs
| Name | Type | Description |
|---|---|---|
| token | string | Verification token from useEducationVerify |
| message | string | Success message from education application submission |
| data | string[] | Array of institution names from autocomplete search |
| has_next | boolean | Whether more autocomplete results are available |
| is_student | boolean | Whether the user is verified as a student |
| allow_refresh | boolean | Whether the user can refresh their education status |
| expire_at | number or null | Unix timestamp when the education status expires |
Usage Examples
Education Verification Flow
import { useEducationVerify, useEducationAdd } from '@/service/use-education'
function EducationApplyPage() {
const verify = useEducationVerify()
const add = useEducationAdd({ onSuccess: () => alert('Application submitted!') })
const handleApply = async () => {
const { token } = await verify.mutateAsync()
await add.mutateAsync({
token,
institution: 'MIT',
// ... other fields
})
}
return <button onClick={handleApply}>Apply</button>
}
Institution Autocomplete
import { useEducationAutocomplete } from '@/service/use-education'
function InstitutionSearch() {
const autocomplete = useEducationAutocomplete()
const handleSearch = async (keyword: string) => {
const result = await autocomplete.mutateAsync({
keywords: keyword,
page: 0,
limit: 20,
})
console.log('Institutions:', result.data)
}
return <input onChange={(e) => handleSearch(e.target.value)} />
}
Check Education Status
import { useEducationStatus } from '@/service/use-education'
function EducationBadge() {
const { data } = useEducationStatus()
if (data?.is_student) {
return <span>Student verified</span>
}
return null
}
Related Pages
- Principle:Langgenius_Dify_React_Query_Pattern
- Langgenius_Dify_Service_Base - HTTP wrappers used by query/mutation functions