You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
967 B
36 lines
967 B
/**
|
|
* 候选人详情 hook:拉取候选人详情 + 邀请面试。
|
|
*/
|
|
import { useCallback, useState } from 'react';
|
|
import { fetchCandidateDetail, inviteCandidate } from '../api';
|
|
import type { CandidateDetail } from '../types';
|
|
import { useAsyncData } from './useAsyncData';
|
|
|
|
export function useCandidateDetail(candidateId: string) {
|
|
const fetcher = useCallback(() => fetchCandidateDetail(candidateId), [candidateId]);
|
|
const { data, loading, error, refresh } = useAsyncData<CandidateDetail>(fetcher);
|
|
|
|
const [inviting, setInviting] = useState(false);
|
|
const [invited, setInvited] = useState(false);
|
|
|
|
const invite = useCallback(async () => {
|
|
setInviting(true);
|
|
try {
|
|
await inviteCandidate(candidateId);
|
|
setInvited(true);
|
|
return true;
|
|
} finally {
|
|
setInviting(false);
|
|
}
|
|
}, [candidateId]);
|
|
|
|
return {
|
|
candidate: data ?? null,
|
|
loading,
|
|
error,
|
|
refresh,
|
|
invite,
|
|
inviting,
|
|
invited,
|
|
};
|
|
}
|
|
|