'use client'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { AlertDialog, AlertDialogAction, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog'; import { extractDigits } from '@/lib/formatters'; interface AddCompanyDialogProps { open: boolean; onOpenChange: (open: boolean) => void; } export function AddCompanyDialog({ open, onOpenChange }: AddCompanyDialogProps) { const [businessNumber, setBusinessNumber] = useState(''); const [isLoading, setIsLoading] = useState(false); // Alert 상태 const [alertOpen, setAlertOpen] = useState(false); const [alertMessage, setAlertMessage] = useState(''); // 숫자만 입력 가능 (10자리 제한) const handleBusinessNumberChange = (value: string) => { const numbersOnly = extractDigits(value); if (numbersOnly.length <= 10) { setBusinessNumber(numbersOnly); } }; const handleCancel = () => { setBusinessNumber(''); onOpenChange(false); }; const handleNext = async () => { if (businessNumber.length !== 10) { setAlertMessage('사업자등록번호는 10자리를 입력해주세요.'); setAlertOpen(true); return; } setIsLoading(true); try { // TODO: 바로빌 API 연동 // 1) 사업자등록번호 조회 // 2) 휴폐업 상태 확인 // 3) 기존 등록 여부 확인 // Mock 로직 - 실제로는 API 응답에 따라 처리 await new Promise(resolve => setTimeout(resolve, 1000)); // 케이스별 처리 const mockCase = Math.floor(Math.random() * 3); if (mockCase === 0) { // 휴폐업 상태 setAlertMessage('휴폐업 상태인 사업자입니다.'); } else if (mockCase === 1) { // 이미 등록된 번호 setAlertMessage('등록된 사업자등록번호 입니다.'); } else { // 신규 등록 가능 - 매니저에게 알림 setAlertMessage('매니저에게 회사 추가 신청 알림을 발송했습니다. 연락을 기다려주세요.'); setBusinessNumber(''); onOpenChange(false); } setAlertOpen(true); } catch (_error) { setAlertMessage('사업자등록번호 조회 중 오류가 발생했습니다.'); setAlertOpen(true); } finally { setIsLoading(false); } }; return ( <> 회사 추가
handleBusinessNumberChange(e.target.value)} placeholder="숫자 10자리 입력" maxLength={10} />

숫자만 가능, 10자리

{/* Alert 다이얼로그 */} 알림 {alertMessage} 확인 ); }