61 lines
2.1 KiB
TypeScript
61 lines
2.1 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { Button, Dialog, DialogContent, DialogHeader, DialogTitle } from "@common/components";
|
|
|
|
import SidoSggFacilityNameSearchForm from "./SidoSggFacilityNameSearchForm";
|
|
import type { SearchFormValues } from "../type/SearchForm.type";
|
|
|
|
type GridTopActionButtonProps = {
|
|
text: string;
|
|
onClick?: (helpers: { openDialog: (title?: string) => void; closeDialog: () => void }) => void;
|
|
/** 상위 화면 검색 통계연도 — 시설 조회 다이얼로그에 전달 */
|
|
statsYr?: string;
|
|
/** 상위 화면 최근 검색조건 */
|
|
initialSearchValues?: Pick<SearchFormValues, "sido" | "gugun" | "bsnmCd"> | null;
|
|
/** 다이얼로그 저장 성공 후 부모 갱신 */
|
|
onSaveSuccess?: () => Promise<void> | void;
|
|
};
|
|
|
|
const GridTopActionButton = ({ text, onClick, statsYr, initialSearchValues, onSaveSuccess }: GridTopActionButtonProps) => {
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const [title, setTitle] = useState(text);
|
|
|
|
const openDialog = (nextTitle?: string) => {
|
|
setTitle(nextTitle ?? text);
|
|
setIsOpen(true);
|
|
};
|
|
|
|
const closeDialog = () => setIsOpen(false);
|
|
|
|
const handleClick = () => {
|
|
if (onClick) {
|
|
onClick({ openDialog, closeDialog });
|
|
return;
|
|
}
|
|
openDialog(text);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Button className="h-[3.2rem] px-6" color="white" type="button" onClick={handleClick}>
|
|
<span>{text}</span>
|
|
</Button>
|
|
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
|
<DialogContent aria-describedby={undefined} className="max-w-[100rem]">
|
|
<DialogHeader>
|
|
<DialogTitle>{title}</DialogTitle>
|
|
</DialogHeader>
|
|
<SidoSggFacilityNameSearchForm
|
|
statsYr={statsYr}
|
|
initialSearchValues={initialSearchValues}
|
|
onSaveSuccess={onSaveSuccess}
|
|
/>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default GridTopActionButton;
|