Files
frontend/apps/dm_new/app/(with-layout)/apply/dmdco/page.tsx
T
2026-02-19 14:54:30 +09:00

351 lines
10 KiB
TypeScript

// app/apply/dmdco/page.tsx
"use client";
import { useMemo, useState } from "react";
import SubPageHeader from "@/components/SubPageHeader";
type Option = { value: string; label: string };
type SidoValue = "" | "seoul" | "busan" | "daegu" | "incheon" | "gyeonggi";
const SIDO: { value: SidoValue; label: string }[] = [
{ value: "", label: "선택" },
{ value: "seoul", label: "서울특별시" },
{ value: "busan", label: "부산광역시" },
{ value: "daegu", label: "대구광역시" },
{ value: "incheon", label: "인천광역시" },
{ value: "gyeonggi", label: "경기도" },
];
const SIGUNGU_MAP: Record<SidoValue, Option[]> = {
"": [{ value: "", label: "선택" }],
seoul: [
{ value: "", label: "선택" },
{ value: "gangnam", label: "강남구" },
{ value: "yeongdeungpo", label: "영등포구" },
{ value: "mapo", label: "마포구" },
],
busan: [
{ value: "", label: "선택" },
{ value: "haeundae", label: "해운대구" },
{ value: "suyeong", label: "수영구" },
],
daegu: [
{ value: "", label: "선택" },
{ value: "suseong", label: "수성구" },
{ value: "dalseo", label: "달서구" },
],
incheon: [
{ value: "", label: "선택" },
{ value: "namdong", label: "남동구" },
{ value: "yeonsu", label: "연수구" },
],
gyeonggi: [
{ value: "", label: "선택" },
{ value: "bundang", label: "성남시 분당구" },
{ value: "suji", label: "용인시 수지구" },
{ value: "ilsandong", label: "고양시 일산동구" },
],
};
/* ---------------------------
* register/page.tsx 스타일과 맞춘 공통 UI (FormRow/Divider)
* -------------------------- */
function Divider() {
return <div className="h-px w-full bg-neutral-200" />;
}
function FormRow({
label,
required,
children,
}: {
label: React.ReactNode;
required?: boolean;
children: React.ReactNode;
}) {
return (
<div className="grid grid-cols-12">
{/* 라벨(좌측) */}
<div className="col-span-12 lg:col-span-2 flex items-center justify-center text-center bg-emerald-50/70 px-6 py-6">
<div className="flex items-center gap-1 text-lg font-semibold text-neutral-800">
<span>{label}</span>
{required ? <span className="text-red-500">*</span> : null}
</div>
</div>
{/* 입력(우측) */}
<div className="col-span-12 lg:col-span-10 px-6 py-6">
{children}
</div>
</div>
);
}
function TextInput({
value,
onChange,
placeholder,
type = "text",
disabled,
className = "",
}: {
value: string;
onChange: (v: string) => void;
placeholder?: string;
type?: string;
disabled?: boolean;
className?: string;
}) {
return (
<input
type={type}
value={value}
disabled={disabled}
onChange={(e) => onChange(e.target.value)}
placeholder={placeholder}
className={[
"h-11 w-full rounded border border-neutral-300 bg-white px-3 text-sm text-neutral-800",
"placeholder:text-neutral-400 focus:border-neutral-400 focus:outline-none",
disabled ? "bg-neutral-100 text-neutral-400" : "",
className,
].join(" ")}
/>
);
}
function SelectBox<T extends string>({
value,
onChange,
options,
className = "",
}: {
value: T;
onChange: (v: T) => void;
options: { value: T; label: string }[];
className?: string;
}) {
return (
<select
value={value}
onChange={(e) => onChange(e.target.value as T)}
className={[
"h-11 w-[220px] rounded border border-neutral-300 bg-white px-3 text-sm text-neutral-800",
"focus:border-neutral-400 focus:outline-none",
className,
].join(" ")}
>
{options.map((o) => (
<option key={o.value} value={o.value}>
{o.label}
</option>
))}
</select>
);
}
export default function DemandPlaceRegisterPage() {
const [sido, setSido] = useState<SidoValue>("");
const [sigungu, setSigungu] = useState<string>("");
const [company, setCompany] = useState("");
const [bizNo, setBizNo] = useState("");
const [workerNo, setWorkerNo] = useState("");
const [noWorkerNo, setNoWorkerNo] = useState(false);
const [zip, setZip] = useState("");
const [addr1, setAddr1] = useState("");
const [addr2, setAddr2] = useState("");
const [tel, setTel] = useState("");
const [pw, setPw] = useState("");
const [pw2, setPw2] = useState("");
// ✅ undefined 불가(Record<SidoValue,...> + sido가 SidoValue)
const sigunguOptions = useMemo<Option[]>(() => SIGUNGU_MAP[sido], [sido]);
const onSubmit = () => {
if (!sido || !sigungu) return alert("시도/시군구를 선택해 주세요.");
if (!company) return alert("회사명을 입력해 주세요.");
if (!bizNo) return alert("사업자등록번호를 입력해 주세요.");
if (!noWorkerNo && !workerNo)
return alert("종사자등록번호를 입력하거나 '해당없음'을 선택해 주세요.");
if (!addr1) return alert("사업자주소를 입력해 주세요.");
if (!tel) return alert("전화번호를 입력해 주세요.");
if (!pw) return alert("비밀번호를 입력해 주세요.");
if (pw !== pw2) return alert("비밀번호가 일치하지 않습니다.");
alert("수요처 등록(샘플) 완료!");
};
return (
<main className="bg-white">
<SubPageHeader
title="수요처등록"
crumbs={[
{ label: "Home", href: "/reuse" },
{ label: "수요신청", href: "/reuse/apply" },
{ label: "수요처등록" },
]}
/>
{/* register/page.tsx와 동일한 테이블 룩앤필 */}
<div className="border border-neutral-200 bg-white">
<FormRow label="시도" required>
<SelectBox<SidoValue>
value={sido}
onChange={(v) => {
setSido(v);
setSigungu(""); // 시도 변경 시 초기화
}}
options={SIDO}
/>
</FormRow>
<Divider />
<FormRow label="시군구" required>
<select
value={sigungu}
onChange={(e) => setSigungu(e.target.value)}
className="h-11 w-[220px] rounded border border-neutral-300 bg-white px-3 text-sm text-neutral-800 focus:border-neutral-400 focus:outline-none"
>
{sigunguOptions.map((o) => (
<option key={o.value} value={o.value}>
{o.label}
</option>
))}
</select>
</FormRow>
<Divider />
<FormRow label="회사명" required>
<div className="max-w-[420px]">
<TextInput
value={company}
onChange={setCompany}
placeholder="회사명을 입력해주세요."
/>
</div>
</FormRow>
<Divider />
<FormRow label="사업자등록번호" required>
<div className="max-w-[420px]">
<TextInput
value={bizNo}
onChange={setBizNo}
placeholder="사업자 등록번호를 입력해주세요."
/>
</div>
</FormRow>
<Divider />
<FormRow label="종사자등록번호">
<div className="flex flex-wrap items-center gap-4">
<div className="w-[420px] max-w-full">
<TextInput
value={workerNo}
onChange={setWorkerNo}
placeholder="종사자등록번호를 입력해주세요."
disabled={noWorkerNo}
/>
</div>
<label className="flex items-center gap-2 text-sm text-neutral-700">
<input
type="checkbox"
checked={noWorkerNo}
onChange={(e) => {
setNoWorkerNo(e.target.checked);
if (e.target.checked) setWorkerNo("");
}}
className="h-4 w-4 rounded border-neutral-300"
/>
해당없음
</label>
</div>
</FormRow>
<Divider />
<FormRow label="사업자주소" required>
<div className="max-w-[420px] space-y-2">
<div className="flex gap-2">
<div className="w-[180px]">
<TextInput value={zip} onChange={setZip} placeholder="우편번호" />
</div>
<button
type="button"
onClick={() => alert("우편번호 검색(샘플)")}
className="h-11 rounded bg-[#888] px-4 text-base text-white hover:bg-neutral-700"
>
우편번호 검색
</button>
</div>
<TextInput value={addr1} onChange={setAddr1} placeholder="주소" />
<TextInput
value={addr2}
onChange={setAddr2}
placeholder="상세 주소를 입력하세요."
/>
</div>
</FormRow>
<Divider />
<FormRow label="전화번호" required>
<div className="max-w-[420px]">
<TextInput
value={tel}
onChange={setTel}
placeholder="전화번호를 입력하세요."
/>
</div>
</FormRow>
<Divider />
<FormRow label="비밀번호" required>
<div className="max-w-[420px]">
<TextInput
value={pw}
onChange={setPw}
placeholder="비밀번호를 입력하세요."
type="password"
/>
</div>
</FormRow>
<Divider />
<FormRow label="비밀번호 확인" required>
<div className="max-w-[420px]">
<TextInput
value={pw2}
onChange={setPw2}
placeholder="비밀번호를 한번 더 입력하세요."
type="password"
/>
</div>
</FormRow>
</div>
{/* register/page.tsx와 동일하게 하단 중앙 버튼 */}
<div className="flex justify-center py-12">
<button
type="button"
onClick={onSubmit}
className="h-11 rounded-md bg-[#0B4EA2] px-10 text-lg text-white hover:opacity-90"
>
수요처 등록
</button>
</div>
</main>
);
}