refactor(WEB): 공통코드 클라이언트 훅 전환 및 품목 탭 동적 생성

- common-codes.ts에서 'use server' 제거, 타입/유틸리티만 유지
- useCommonCodes 훅 생성 (클라이언트 /api/proxy/ 패턴, 5분 캐시)
- ItemListClient 탭/통계카드를 common_codes 기반 동적 생성으로 전환
- OrderSalesDetailEdit 서버액션 → useCommonCodes 훅 전환
- order-management actions.ts 서버액션 내 공통코드 직접 조회로 변경
This commit is contained in:
2026-01-30 20:13:46 +09:00
parent d0634bb2e7
commit fc8d29e513
6 changed files with 215 additions and 189 deletions

View File

@@ -1,11 +1,10 @@
'use server';
import { apiClient } from './index';
// ========================================
// 공통 코드 타입
// 공통 코드 타입 및 유틸리티
// ========================================
/**
* 공통 코드 타입
*/
export interface CommonCode {
id: number;
code: string;
@@ -15,147 +14,28 @@ export interface CommonCode {
attributes: Record<string, unknown> | null;
}
// ========================================
// 공통 코드 조회 함수
// ========================================
/**
* 특정 그룹의 공통 코드 목록 조회
* GET /api/v1/settings/common/{group}
* 공통 코드 옵션 (Select/ComboBox용)
*/
export async function getCommonCodes(group: string): Promise<{
success: boolean;
data?: CommonCode[];
error?: string;
}> {
try {
const response = await apiClient.get<CommonCode[]>(`/settings/common/${group}`);
return { success: true, data: response };
} catch (error) {
console.error(`공통코드 조회 오류 (${group}):`, error);
return { success: false, error: '공통코드를 불러오는데 실패했습니다.' };
}
export interface CommonCodeOption {
value: string;
label: string;
}
/**
* 공통 코드 옵션 형태로 변환
* Select/ComboBox 등에서 사용
* CommonCode[] → 옵션 배열로 변환
*/
export async function getCommonCodeOptions(group: string): Promise<{
success: boolean;
data?: { value: string; label: string }[];
error?: string;
}> {
const result = await getCommonCodes(group);
if (!result.success || !result.data) {
return { success: false, error: result.error };
}
const options = result.data.map((code) => ({
export function toCommonCodeOptions(codes: CommonCode[]): CommonCodeOption[] {
return codes.map((code) => ({
value: code.code,
label: code.name,
}));
return { success: true, data: options };
}
// ========================================
// 자주 사용하는 코드 그룹 함수
// ========================================
/**
* 수주 상태 코드 조회
*/
export async function getOrderStatusCodes() {
return getCommonCodes('order_status');
}
/**
* 수주 상태 옵션 조회
* CommonCode[]에서 code로 name 조회
*/
export async function getOrderStatusOptions() {
return getCommonCodeOptions('order_status');
}
/**
* 수주 유형 코드 조회
*/
export async function getOrderTypeCodes() {
return getCommonCodes('order_type');
}
/**
* 수주 유형 옵션 조회
*/
export async function getOrderTypeOptions() {
return getCommonCodeOptions('order_type');
}
/**
* 거래처 유형 코드 조회
*/
export async function getClientTypeCodes() {
return getCommonCodes('client_type');
}
/**
* 거래처 유형 옵션 조회
*/
export async function getClientTypeOptions() {
return getCommonCodeOptions('client_type');
}
/**
* 품목 유형 코드 조회
*/
export async function getItemTypeCodes() {
return getCommonCodes('item_type');
}
/**
* 품목 유형 옵션 조회
*/
export async function getItemTypeOptions() {
return getCommonCodeOptions('item_type');
}
/**
* 배송방식 코드 조회
*/
export async function getDeliveryMethodCodes() {
return getCommonCodes('delivery_method');
}
/**
* 배송방식 옵션 조회
*/
export async function getDeliveryMethodOptions() {
return getCommonCodeOptions('delivery_method');
}
/**
* 운임비용 코드 조회
*/
export async function getShippingCostCodes() {
return getCommonCodes('shipping_cost');
}
/**
* 운임비용 옵션 조회
*/
export async function getShippingCostOptions() {
return getCommonCodeOptions('shipping_cost');
}
/**
* 코드값으로 라벨 조회 (code → name 매핑)
*/
export async function getCodeLabel(group: string, code: string): Promise<string> {
const result = await getCommonCodes(group);
if (result.success && result.data) {
const found = result.data.find((item) => item.code === code);
return found?.name || code;
}
return code;
export function getCodeLabel(codes: CommonCode[], code: string): string {
const found = codes.find((item) => item.code === code);
return found?.name || code;
}

View File

@@ -5,19 +5,12 @@ export { ApiClient, withTokenRefresh } from './client';
export { serverFetch } from './fetch-wrapper';
export { AUTH_CONFIG } from './auth/auth-config';
// 공통 코드 유틸리티
// 공통 코드 타입 및 유틸리티
export {
getCommonCodes,
getCommonCodeOptions,
getOrderStatusCodes,
getOrderStatusOptions,
getOrderTypeCodes,
getOrderTypeOptions,
getClientTypeCodes,
getClientTypeOptions,
getItemTypeCodes,
getItemTypeOptions,
toCommonCodeOptions,
getCodeLabel,
type CommonCode,
type CommonCodeOption,
} from './common-codes';
// Server-side API 클라이언트