[as] feat: 행정지원 업무 신청 시 시도/구군 선택 로직 추가

This commit is contained in:
2026-07-31 13:50:07 +09:00
parent e0956e05a6
commit 2acbeb83d0
26 changed files with 460 additions and 177 deletions
+4 -1
View File
@@ -33,6 +33,10 @@ export { BusinessScaleFormSection } from "./ui/business-scale-form-section";
export { ChecklistFormSection } from "./ui/checklist-form-section";
export { ContactInfoFormSection } from "./ui/contact-info-form-section";
export { FnrsSharFormSection } from "./ui/fnrs-shar-form-section";
export {
PbadmsTaskApplyDialog,
type PbadmsTaskApplySelection,
} from "./ui/pbadms-task-apply-dialog";
export { PrivacyConsentSection } from "./ui/privacy-consent-section";
export { SectionCollapsible } from "./ui/section-collapsible";
export {
@@ -42,4 +46,3 @@ export {
} from "./ui/splmnt-dmnd-dialog";
export { type SplmntDmndFormItem, SplmntDmndFormSection } from "./ui/splmnt-dmnd-form-section";
export { SupplementDemandSection } from "./ui/supplement-demand-section";
export { TaskSePickerDialog } from "./ui/task-se-picker-dialog";
@@ -0,0 +1,210 @@
"use client";
import { useEffect, useState } from "react";
import { useUserStore } from "@/shared/lib";
import { Field, FieldGroup, FieldLabel, FieldSet } from "@/shared/ui/field";
import {
type CmCdAdstDstrComboResponseDto,
useFindUserGugunCombo,
useFindUserSidoCombo,
} from "@/entities/adstdstr";
import { useCodeList } from "@/entities/code";
import {
Button,
Checkbox,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
Skeleton,
Table,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@common/components";
interface PbadmsTaskApplySelection {
admdstCd: string;
sido: string;
gugun: string;
selectedCodes: string[];
}
interface PbadmsTaskApplyDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: (selection: PbadmsTaskApplySelection) => void;
title: string;
codeUpCd?: string;
}
const EMPTY_ADST_LIST: CmCdAdstDstrComboResponseDto[] = [];
function PbadmsTaskApplyDialog({
open,
onOpenChange,
onConfirm,
title,
codeUpCd,
}: PbadmsTaskApplyDialogProps) {
const userInfo = useUserStore((state) => state.userInfo);
const [sidoComCd, setSidoComCd] = useState("");
const [sggComCd, setSggComCd] = useState("");
const [selectedCodes, setSelectedCodes] = useState<string[]>([]);
const sidoFilterUserInfo =
userInfo?.dtlInstCd === "ROLE_USER04" || userInfo?.dtlInstCd === "ROLE_USER05"
? userInfo
: undefined;
const { data: sidoData, isPending: isSidoPending } = useFindUserSidoCombo(sidoFilterUserInfo);
const { data: gugunData, isPending: isGugunPending } = useFindUserGugunCombo(sidoComCd);
const { data: taskOptions, isPending: isTaskSePending } = useCodeList(codeUpCd);
const sidoOptions = sidoData ?? EMPTY_ADST_LIST;
const gugunOptions = gugunData ?? EMPTY_ADST_LIST;
const isPending = isSidoPending || isTaskSePending;
const canConfirm = Boolean(sidoComCd && selectedCodes.length > 0);
useEffect(() => {
if (!open) return;
setSidoComCd("");
setSggComCd("");
setSelectedCodes([]);
}, [open]);
function handleCheckedChange(code: string, checked: boolean) {
setSelectedCodes((prev) => {
if (!checked) return prev.filter((value) => value !== code);
if (code.includes("RE")) return [code];
return [...prev.filter((value) => !value.includes("RE")), code];
});
}
function handleConfirm() {
if (!canConfirm) return;
const sidoOption = sidoOptions.find((option) => option.adstDstrCd === sidoComCd);
const gugunOption = gugunOptions.find((option) => option.adstDstrCd === sggComCd);
onConfirm({
admdstCd: sggComCd || sidoComCd,
sido: sidoOption?.adstDstrNm ?? "",
gugun: gugunOption?.adstDstrNm ?? "",
selectedCodes,
});
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-[60rem]" aria-describedby={undefined}>
<DialogHeader>
<DialogTitle>{title}</DialogTitle>
</DialogHeader>
{isPending ? (
<Skeleton className="h-[16rem] w-full" />
) : (
<Table variant="secondary">
<colgroup>
<col width="15%" />
<col width="35%" />
<col width="15%" />
<col width="35%" />
</colgroup>
<TableHeader>
<TableRow>
<TableHead data-required>시도</TableHead>
<TableCell>
<Select
value={sidoComCd || undefined}
onValueChange={(value) => {
setSidoComCd(value);
setSggComCd("");
}}
>
<SelectTrigger className="w-full">
<SelectValue placeholder="선택" />
</SelectTrigger>
<SelectContent>
{sidoOptions.map((option) => (
<SelectItem key={option.adstDstrCd} value={option.adstDstrCd}>
{option.adstDstrNm}
</SelectItem>
))}
</SelectContent>
</Select>
</TableCell>
<TableHead>시군구</TableHead>
<TableCell>
<Select
value={sggComCd || undefined}
onValueChange={setSggComCd}
disabled={!sidoComCd || isGugunPending}
>
<SelectTrigger className="w-full">
<SelectValue placeholder="선택" />
</SelectTrigger>
<SelectContent>
{gugunOptions.map((option) => (
<SelectItem key={option.adstDstrCd} value={option.adstDstrCd}>
{option.adstDstrNm}
</SelectItem>
))}
</SelectContent>
</Select>
</TableCell>
</TableRow>
<TableRow>
<TableHead data-required>업무구분</TableHead>
<TableCell colSpan={3}>
<FieldSet className="px-2">
<FieldGroup data-slot="checkbox-group" className="flex-row flex-wrap">
{taskOptions?.map((option) => (
<Field key={option.lwpoCd} orientation="horizontal" className="w-auto">
<Checkbox
id={`pbadms-task-apply-${option.lwpoCd}`}
checked={selectedCodes.includes(option.lwpoCd)}
onCheckedChange={(checked) =>
handleCheckedChange(option.lwpoCd, checked === true)
}
/>
<FieldLabel
htmlFor={`pbadms-task-apply-${option.lwpoCd}`}
className="font-normal"
>
{option.lwpoCdNm}
</FieldLabel>
</Field>
))}
</FieldGroup>
</FieldSet>
</TableCell>
</TableRow>
</TableHeader>
</Table>
)}
<DialogFooter>
<Button type="button" color="white" onClick={() => onOpenChange(false)}>
취소
</Button>
<Button type="button" onClick={handleConfirm} disabled={isPending || !canConfirm}>
확인
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
export { PbadmsTaskApplyDialog };
export type { PbadmsTaskApplySelection };
@@ -1,117 +0,0 @@
"use client";
import { useEffect, useState } from "react";
import { Field, FieldGroup, FieldLabel, FieldSet } from "@/shared/ui/field";
import { useCodeList } from "@/entities/code";
import {
Button,
Checkbox,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
Skeleton,
Table,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@common/components";
interface TaskSePickerDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: (selectedCodes: string[]) => void;
title: string;
codeUpCd?: string;
}
function TaskSePickerDialog({
open,
onOpenChange,
onConfirm,
title,
codeUpCd,
}: TaskSePickerDialogProps) {
const [selectedCodes, setSelectedCodes] = useState<string[]>([]);
const { data: taskOptions, isPending } = useCodeList(codeUpCd);
useEffect(() => {
if (!open) return;
setSelectedCodes([]);
}, [open]);
function handleCheckedChange(code: string, checked: boolean) {
setSelectedCodes((prev) => {
if (!checked) return prev.filter((value) => value !== code);
if (code.includes("RE")) return [code];
return [...prev.filter((value) => !value.includes("RE")), code];
});
}
function handleConfirm() {
onConfirm(selectedCodes);
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-[60rem]" aria-describedby={undefined}>
<DialogHeader>
<DialogTitle>{title}</DialogTitle>
</DialogHeader>
{isPending ? (
<Skeleton className="h-[16rem] w-full" />
) : (
<Table variant="secondary">
<TableHeader>
<TableRow>
<TableHead>업무구분</TableHead>
<TableCell>
<FieldSet className="px-2">
<FieldGroup data-slot="checkbox-group" className="flex-row flex-wrap">
{taskOptions?.map((option) => (
<Field key={option.lwpoCd} orientation="horizontal" className="w-auto">
<Checkbox
id={`task-se-picker-${option.lwpoCd}`}
checked={selectedCodes.includes(option.lwpoCd)}
onCheckedChange={(checked) =>
handleCheckedChange(option.lwpoCd, checked === true)
}
/>
<FieldLabel
htmlFor={`task-se-picker-${option.lwpoCd}`}
className="font-normal"
>
{option.lwpoCdNm}
</FieldLabel>
</Field>
))}
</FieldGroup>
</FieldSet>
</TableCell>
</TableRow>
</TableHeader>
</Table>
)}
<DialogFooter>
<Button type="button" color="white" onClick={() => onOpenChange(false)}>
취소
</Button>
<Button
type="button"
onClick={handleConfirm}
disabled={isPending || selectedCodes.length === 0}
>
확인
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
export { TaskSePickerDialog };