worlabel/frontend/src/hooks/useIsAdminOrManager.ts
2024-09-20 17:17:50 +09:00

18 lines
706 B
TypeScript

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