feat(WEB): DateRangeSelector 프리셋 순서 변경 및 RuleModal 품목유형 동적 조회

- DateRangeSelector: 프리셋 순서를 오늘→어제→당월→전월→전전월→당해년도로 변경
- RuleModal: 품목유형 옵션을 하드코딩에서 common_codes API 동적 조회로 변경
- RuleModal: 추가 모드 기본값을 개별 품목(individual)으로 변경
This commit is contained in:
2026-02-04 23:06:59 +09:00
parent f1c4ab62bf
commit 84363475b0
2 changed files with 21 additions and 17 deletions

View File

@@ -26,7 +26,7 @@ const PRESET_LABELS: Record<DatePreset, string> = {
/**
* 기본 프리셋 순서
*/
const DEFAULT_PRESETS: DatePreset[] = ['thisYear', 'twoMonthsAgo', 'lastMonth', 'thisMonth', 'yesterday', 'today'];
const DEFAULT_PRESETS: DatePreset[] = ['today', 'yesterday', 'thisMonth', 'lastMonth', 'twoMonthsAgo', 'thisYear' ];
interface DateRangeSelectorProps {
/** 시작 날짜 (yyyy-MM-dd 형식) */

View File

@@ -1,7 +1,7 @@
'use client';
import { useState, useEffect, useCallback } from 'react';
import { getItemList, type ItemOption } from './actions';
import { getItemList, getItemTypeOptions, type ItemOption } from './actions';
import {
Dialog,
DialogContent,
@@ -40,14 +40,8 @@ import type {
} from '@/types/process';
import { RULE_TYPE_OPTIONS, MATCHING_TYPE_OPTIONS } from '@/types/process';
// 품목 유형 옵션
const ITEM_TYPE_OPTIONS = [
{ value: 'all', label: '전체' },
{ value: '제품', label: '제품' },
{ value: '반제품', label: '반제품' },
{ value: '원자재', label: '원자재' },
{ value: '부자재', label: '부자재' },
];
// 품목 유형 기본 옵션 (전체)
const DEFAULT_ITEM_TYPE_OPTION = { value: 'all', label: '전체' };
interface RuleModalProps {
open: boolean;
@@ -81,6 +75,9 @@ export function RuleModal({ open, onOpenChange, onAdd, editRule }: RuleModalProp
const [itemList, setItemList] = useState<ItemOption[]>([]);
const [isItemsLoading, setIsItemsLoading] = useState(false);
// 품목 유형 옵션 (common_codes에서 동적 조회)
const [itemTypeOptions, setItemTypeOptions] = useState<Array<{ value: string; label: string }>>([DEFAULT_ITEM_TYPE_OPTION]);
// 품목 목록 로드 (debounced)
const loadItems = useCallback(async (q?: string, itemType?: string) => {
setIsItemsLoading(true);
@@ -131,11 +128,18 @@ export function RuleModal({ open, onOpenChange, onAdd, editRule }: RuleModalProp
loadItems(searchKeyword, selectedItemType);
}, [selectedItemType]);
// 모달 열릴 때 품목 목록 초기화 (초기 로드 안함)
// 모달 열릴 때 품목 목록 초기화 + 품목유형 옵션 로드
useEffect(() => {
if (open && registrationType === 'individual') {
setItemList([]);
setSearchKeyword('');
if (open) {
// 품목유형 옵션 로드 (common_codes에서 동적 조회)
getItemTypeOptions().then((options) => {
setItemTypeOptions([DEFAULT_ITEM_TYPE_OPTION, ...options]);
});
if (registrationType === 'individual') {
setItemList([]);
setSearchKeyword('');
}
}
}, [open, registrationType]);
@@ -186,8 +190,8 @@ export function RuleModal({ open, onOpenChange, onAdd, editRule }: RuleModalProp
setSelectedItemIds(new Set());
}
} else {
// 추가 모드: 초기화
setRegistrationType('pattern');
// 추가 모드: 초기화 (개별 품목을 디폴트로)
setRegistrationType('individual');
setDescription('');
setRuleType('품목코드');
setMatchingType('startsWith');
@@ -399,7 +403,7 @@ export function RuleModal({ open, onOpenChange, onAdd, editRule }: RuleModalProp
<SelectValue />
</SelectTrigger>
<SelectContent>
{ITEM_TYPE_OPTIONS.map((opt) => (
{itemTypeOptions.map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>