- eslint.config.mjs 규칙 강화 및 정리 - 전역 unused import/변수 제거 (312개 파일) - next.config.ts, middleware, proxy route 개선 - CopyableCell molecule 추가 - 회계/결재/HR/생산/건설/품질/영업 등 전 도메인 lint 정리 - IntegratedListTemplateV2, DataTable, MobileCard 등 공통 컴포넌트 개선 - execute-server-action 에러 핸들링 보강
149 lines
4.4 KiB
TypeScript
149 lines
4.4 KiB
TypeScript
'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 (
|
|
<>
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent className="sm:max-w-[400px]">
|
|
<DialogHeader>
|
|
<DialogTitle>회사 추가</DialogTitle>
|
|
</DialogHeader>
|
|
|
|
<div className="space-y-4 py-4">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="businessNumber">사업자등록번호</Label>
|
|
<Input
|
|
id="businessNumber"
|
|
value={businessNumber}
|
|
onChange={(e) => handleBusinessNumberChange(e.target.value)}
|
|
placeholder="숫자 10자리 입력"
|
|
maxLength={10}
|
|
/>
|
|
<p className="text-xs text-muted-foreground">
|
|
숫자만 가능, 10자리
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex justify-end gap-2">
|
|
<Button
|
|
variant="outline"
|
|
onClick={handleCancel}
|
|
disabled={isLoading}
|
|
>
|
|
취소
|
|
</Button>
|
|
<Button
|
|
onClick={handleNext}
|
|
disabled={isLoading || businessNumber.length !== 10}
|
|
>
|
|
{isLoading ? '조회 중...' : '다음'}
|
|
</Button>
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
|
|
{/* Alert 다이얼로그 */}
|
|
<AlertDialog open={alertOpen} onOpenChange={setAlertOpen}>
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>알림</AlertDialogTitle>
|
|
<AlertDialogDescription>{alertMessage}</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogAction>확인</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</>
|
|
);
|
|
} |