diff options
Diffstat (limited to 'components/common/selectors/place-of-shipping')
3 files changed, 94 insertions, 0 deletions
diff --git a/components/common/selectors/place-of-shipping/index.ts b/components/common/selectors/place-of-shipping/index.ts new file mode 100644 index 00000000..8d157b4d --- /dev/null +++ b/components/common/selectors/place-of-shipping/index.ts @@ -0,0 +1,2 @@ +export { PlaceOfShippingSelector } from './place-of-shipping-selector' +export type { PlaceOfShippingSelectorProps } from './place-of-shipping-selector' diff --git a/components/common/selectors/place-of-shipping/place-of-shipping-selector.tsx b/components/common/selectors/place-of-shipping/place-of-shipping-selector.tsx new file mode 100644 index 00000000..8230e265 --- /dev/null +++ b/components/common/selectors/place-of-shipping/place-of-shipping-selector.tsx @@ -0,0 +1,75 @@ + + + +'use client' + +/** + * 선적지/하역지 선택기 + * + * placeOfShipping 테이블 기준으로 선적지/하역지에 쓰이는 장소코드 및 장소명 선택 + */ + +import { Select, SelectItem, SelectContent } from "@/components/ui/select" +import { SelectTrigger } from "@/components/ui/select" +import { SelectValue } from "@/components/ui/select" +import { useState, useEffect } from "react" +import { getPlaceOfShippingForSelection } from "./place-of-shipping-service" + +interface PlaceOfShippingData { + code: string + description: string +} + +interface PlaceOfShippingSelectorProps { + value?: string + onValueChange?: (value: string) => void + placeholder?: string + disabled?: boolean + className?: string +} + +export function PlaceOfShippingSelector({ + value = "", + onValueChange, + placeholder = "선적지/하역지 선택", + disabled = false, + className +}: PlaceOfShippingSelectorProps) { + const [placeOfShippingData, setPlaceOfShippingData] = useState<PlaceOfShippingData[]>([]) + const [isLoading, setIsLoading] = useState(true) + + useEffect(() => { + const loadData = async () => { + try { + const data = await getPlaceOfShippingForSelection() + setPlaceOfShippingData(data) + } catch (error) { + console.error('선적지/하역지 데이터 로드 실패:', error) + setPlaceOfShippingData([]) + } finally { + setIsLoading(false) + } + } + + loadData() + }, []) + + return ( + <Select + value={value} + onValueChange={onValueChange} + disabled={disabled || isLoading} + > + <SelectTrigger className={className}> + <SelectValue placeholder={isLoading ? "로딩 중..." : placeholder} /> + </SelectTrigger> + <SelectContent> + {placeOfShippingData.map((item) => ( + <SelectItem key={item.code} value={item.code}> + {item.code} {item.description} + </SelectItem> + ))} + </SelectContent> + </Select> + ) +}
\ No newline at end of file diff --git a/components/common/selectors/place-of-shipping/place-of-shipping-service.tsx b/components/common/selectors/place-of-shipping/place-of-shipping-service.tsx new file mode 100644 index 00000000..22026739 --- /dev/null +++ b/components/common/selectors/place-of-shipping/place-of-shipping-service.tsx @@ -0,0 +1,17 @@ +'use server' + +import db from "@/db/db" +import { placeOfShipping } from "@/db/schema" +import { eq } from "drizzle-orm" + + +/** + * @returns 활성화된 모든 선적지/하역지 코드 및 장소명 + */ +export async function getPlaceOfShippingForSelection(): Promise<{ code: string; description: string }[]> { + const data = await db.select().from(placeOfShipping).where(eq(placeOfShipping.isActive, true)).orderBy(placeOfShipping.code) + return data.map((item) => ({ + code: item.code, + description: item.description + })) +}
\ No newline at end of file |
