"use client"; import React, { useState, useEffect, useCallback } from "react"; /* ------------------------------------------------------------------ */ /* Types */ /* ------------------------------------------------------------------ */ interface AcceptProcessModalProps { open: boolean; onClose: () => void; onConfirm: (qty: number) => void; maxQty: number; processName: string; seqNo: string; loading?: boolean; } /* ------------------------------------------------------------------ */ /* Numpad Keys */ /* ------------------------------------------------------------------ */ const KEYS = [ { label: "7", action: "7" }, { label: "8", action: "8" }, { label: "9", action: "9" }, { label: "\u2190", action: "backspace" }, { label: "4", action: "4" }, { label: "5", action: "5" }, { label: "6", action: "6" }, { label: "C", action: "clear" }, { label: "1", action: "1" }, { label: "2", action: "2" }, { label: "3", action: "3" }, { label: "MAX", action: "max" }, ]; /* ------------------------------------------------------------------ */ /* Component */ /* ------------------------------------------------------------------ */ export function AcceptProcessModal({ open, onClose, onConfirm, maxQty, processName, seqNo, loading = false, }: AcceptProcessModalProps) { const [qty, setQty] = useState("0"); useEffect(() => { if (open) { setQty("0"); } }, [open]); const qtyNum = parseInt(qty, 10) || 0; const isOverMax = qtyNum > maxQty; const handleKey = useCallback( (key: string) => { setQty((prev) => { switch (key) { case "backspace": return prev.length <= 1 ? "0" : prev.slice(0, -1); case "clear": return "0"; case "max": return String(maxQty); default: { const next = prev === "0" ? key : prev + key; const num = parseInt(next, 10); if (isNaN(num)) return prev; return next; } } }); }, [maxQty] ); const handleConfirm = () => { const finalQty = Math.min(qtyNum, maxQty); if (finalQty <= 0) return; onConfirm(finalQty); }; if (!open) return null; return (
{seqNo}공정: {processName}
접수 수량 입력
접수할 수량(EA)을 입력하세요
{/* Display */} {isOverMax && (접수가능량({maxQty.toLocaleString()})을 초과합니다
)} {/* Numpad */}