Feat: Admin 여부 확인할 수 있는 훅
This commit is contained in:
parent
989a466048
commit
5bb65a9c4f
17
frontend/src/hooks/useIsAdminOrManager.ts
Normal file
17
frontend/src/hooks/useIsAdminOrManager.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { useMemo } from 'react';
|
||||
import useAuthStore from '@/stores/useAuthStore';
|
||||
import useProjectMembersQuery from '@/queries/projects/useProjectMembersQuery';
|
||||
|
||||
export default function useIsAdminOrManager(projectId: number) {
|
||||
const profile = useAuthStore((state) => state.profile);
|
||||
const memberId = profile?.id || 0;
|
||||
|
||||
const { data: projectMembers = [] } = useProjectMembersQuery(projectId, memberId);
|
||||
|
||||
const isAdminOrManager = useMemo(() => {
|
||||
const currentMember = projectMembers.find((member) => member.memberId === memberId);
|
||||
return currentMember?.privilegeType === 'ADMIN' || currentMember?.privilegeType === 'MANAGER';
|
||||
}, [projectMembers, memberId]);
|
||||
|
||||
return isAdminOrManager;
|
||||
}
|
Loading…
Reference in New Issue
Block a user