85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import React, { useState, useMemo, useEffect } from "react";
|
|
import { SelectBox } from '@common/business_components/ui'
|
|
import { Label } from '@common/components';
|
|
import useStore from '../../store/useStore';
|
|
|
|
interface Option {
|
|
id: number;
|
|
name: string;
|
|
}
|
|
|
|
interface SidoSigunguSelectBoxProps {
|
|
sido: number;
|
|
sigungu: number;
|
|
onSidoChange: (id: number) => void;
|
|
setCtpvName?: (name: string) => void;
|
|
onSigunguChange: (id: number) => void;
|
|
setSggName?: (name: string) => void;
|
|
className?: string;
|
|
}
|
|
|
|
export function SidoSigunguSelectBox({
|
|
sido,
|
|
sigungu,
|
|
onSidoChange,
|
|
setCtpvName,
|
|
onSigunguChange,
|
|
setSggName,
|
|
className = "",
|
|
}: SidoSigunguSelectBoxProps) {
|
|
|
|
const { ctpv, sgg} = useStore();
|
|
|
|
useEffect(() => {
|
|
(async () => {
|
|
onSidoChange(0);
|
|
onSigunguChange(0);
|
|
if (setCtpvName && setSggName) {
|
|
setCtpvName("");
|
|
setSggName("");
|
|
}
|
|
})();
|
|
}, []);
|
|
|
|
|
|
return (
|
|
<div className={`flex items-center justify-center ${className} mr-8`}>
|
|
<Label className="text-xl text-gray-600 font-medium whitespace-nowrap mr-2">시도</Label>
|
|
<SelectBox
|
|
className="w-60 mr-8"
|
|
selectClass="rounded-lg bg-white"
|
|
label=""
|
|
selectArray={
|
|
[{ val: 0, text: '전체' },
|
|
...ctpv.map(opt => ({ val: opt.id, text: opt.name }))
|
|
]
|
|
}
|
|
value={sido}
|
|
onSelectValue={val => {
|
|
onSidoChange(Number(val));
|
|
if (setCtpvName) setCtpvName(ctpv.find(opt => Number(opt.id) === Number(val))?.name || "");
|
|
}}
|
|
selectContentClass="z-[101]"
|
|
/>
|
|
<Label className="text-xl text-gray-600 font-medium whitespace-nowrap mr-2">시군구</Label>
|
|
<SelectBox
|
|
className="w-48"
|
|
selectClass="w-48 rounded-lg bg-white truncate"
|
|
label=""
|
|
selectArray={
|
|
[{ val: 0, text: '전체' },
|
|
...sgg
|
|
.filter(opt => String(opt.id).slice(0, 2) === String(sido))
|
|
.map(opt => ({ val: opt.id, text: opt.name }))
|
|
]
|
|
}
|
|
value={sigungu}
|
|
onSelectValue={val => {
|
|
onSigunguChange(Number(val))
|
|
if (setSggName) setSggName(sgg.find(opt => Number(opt.id) === Number(val))?.name || "");
|
|
}}
|
|
selectContentClass="z-[101]"
|
|
/>
|
|
</div>
|
|
);
|
|
} |