Feat: Admin 여부 확인할 수 있는 훅

This commit is contained in:
정현조 2024-09-20 17:17:50 +09:00
parent 989a466048
commit 5bb65a9c4f

View 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;
}