36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { api } from "@nice/client";
|
|
import { useAuth } from "@web/src/providers/auth-provider";
|
|
import { Department, TrainContent, UserProfile } from "@nice/common";
|
|
import { createContext, ReactNode, useContext, useEffect, useState } from "react";
|
|
|
|
interface DailyContextProviderProps{
|
|
staffs:UserProfile[],
|
|
staffsLoading:boolean,
|
|
}
|
|
|
|
interface DailyContextProps{
|
|
children:ReactNode
|
|
}
|
|
|
|
const DailyContextProvider = createContext<DailyContextProviderProps>(null)
|
|
|
|
export default function DailyContext({children}:DailyContextProps){
|
|
const {user,isAuthenticated} = useAuth()
|
|
// 获取当前员工的单位下的所有staff的记录
|
|
const {data:staffs,isLoading:staffsLoading} = isAuthenticated?api.staff.findByDept.useQuery({
|
|
deptId:user.deptId
|
|
}):{data:null,isLoading:false}
|
|
|
|
return <DailyContextProvider.Provider value={{
|
|
staffs:staffs as any as UserProfile[],
|
|
staffsLoading,
|
|
}}>
|
|
{children}
|
|
</DailyContextProvider.Provider>
|
|
}
|
|
|
|
export function useDaily(){
|
|
const daily = useContext(DailyContextProvider)
|
|
if(!daily) {throw new Error("useParams must be used within a ParamsProvider");}
|
|
return daily
|
|
} |