자재관리: - 입고관리 재고조정 다이얼로그 신규 추가, 상세/목록 기능 확장 - 재고현황 컴포넌트 리팩토링 출고관리: - 출하관리 생성/수정/목록/상세 개선 - 차량배차관리 상세/수정/목록 기능 보강 생산관리: - 작업지시서 WIP 생산 모달 신규 추가 - 벤딩WIP/슬랫조인트바 검사 콘텐츠 신규 추가 - 작업자화면 기능 대폭 확장 (카드/목록 개선) - 검사성적서 모달 개선 품질관리: - 실적보고서 관리 페이지 신규 추가 - 검사관리 문서/타입/목데이터 개선 단가관리: - 단가배포 페이지 및 컴포넌트 신규 추가 - 단가표 관리 페이지 및 컴포넌트 신규 추가 공통: - 권한 시스템 추가 개선 (PermissionContext, usePermission, PermissionGuard) - 메뉴 폴링 훅 개선, 레이아웃 수정 - 모바일 줌/패닝 CSS 수정 - locale 유틸 추가 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
'use client';
|
|
|
|
import { usePathname } from 'next/navigation';
|
|
import { usePermissionContext } from '@/contexts/PermissionContext';
|
|
import { findMatchingUrl } from '@/lib/permissions/utils';
|
|
import { ALL_ALLOWED } from '@/lib/permissions/types';
|
|
import type { UsePermissionReturn } from '@/lib/permissions/types';
|
|
|
|
/**
|
|
* URL 자동매칭 권한 훅
|
|
*
|
|
* 인자 없이 호출하면 현재 URL 기반 자동 매칭.
|
|
* 특수 케이스에서 URL 직접 지정 가능.
|
|
*
|
|
* @example
|
|
* // 자동 매칭 (대부분의 경우)
|
|
* const { canView, canCreate, canUpdate, canDelete } = usePermission();
|
|
*
|
|
* // URL 직접 지정 (다른 메뉴 권한 체크 시)
|
|
* const { canApprove } = usePermission('/approval/inbox');
|
|
*/
|
|
export function usePermission(overrideUrl?: string): UsePermissionReturn {
|
|
const pathname = usePathname();
|
|
const { permissionMap, isLoading } = usePermissionContext();
|
|
|
|
const targetPath = overrideUrl || pathname;
|
|
|
|
if (isLoading || !permissionMap) {
|
|
return { ...ALL_ALLOWED, isLoading };
|
|
}
|
|
|
|
const matchedUrl = findMatchingUrl(targetPath, permissionMap);
|
|
|
|
if (!matchedUrl) {
|
|
return ALL_ALLOWED;
|
|
}
|
|
|
|
const perms = permissionMap[matchedUrl] || {};
|
|
|
|
return {
|
|
canView: perms.view ?? true,
|
|
canCreate: perms.create ?? true,
|
|
canUpdate: perms.update ?? true,
|
|
canDelete: perms.delete ?? true,
|
|
canApprove: perms.approve ?? true,
|
|
canExport: perms.export ?? true,
|
|
isLoading: false,
|
|
matchedUrl,
|
|
};
|
|
}
|