From 16b2e5a16d61ce00900e9ebe9daf1dd4162d4792 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Fri, 14 Mar 2025 11:22:38 +0700 Subject: [PATCH] add select dropdown on search --- .../master/postoadms/blocks/SearchDialog.tsx | 147 +++++++++--------- 1 file changed, 74 insertions(+), 73 deletions(-) diff --git a/src/pages/master/postoadms/blocks/SearchDialog.tsx b/src/pages/master/postoadms/blocks/SearchDialog.tsx index 1277ccb..2218e3e 100644 --- a/src/pages/master/postoadms/blocks/SearchDialog.tsx +++ b/src/pages/master/postoadms/blocks/SearchDialog.tsx @@ -11,14 +11,16 @@ import { Alert, KeenIcon } from '@/components'; import { Button } from '@/components/ui/button'; import { apiConfig } from '@/config/api.config'; import axios from 'axios'; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue -} from '@/components/ui/select'; import { useManagePostoAdmsContext } from '../hooks/useManagePostoAdmsContext'; +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList +} from '@/components/ui/command'; +import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; interface SucosProps { id: number; @@ -29,6 +31,7 @@ const API_URL = apiConfig.service_master_data; const SearchDialog = () => { const parentRef = useRef(null); + const [open, setOpen] = useState(false); const { showSearchDialog, handleSearchDialog, postoAdms } = useManagePostoAdmsContext(); const [alert, setAlert] = useState({ show: false, @@ -60,6 +63,7 @@ const SearchDialog = () => { if (response.data.status) { setSucos(response.data.data); + console.log(sucos); setIsFound(true); console.log('Found postoadms: ', response.data.data); } else { @@ -79,25 +83,22 @@ const SearchDialog = () => { setIsFound(false); setSucos([]); }; - // console.log(municipios); + return ( - handleSearchDialog(open)}> + - - + +
-

- Search Sucos -

-
+

Search Sucos

{ handleSearchDialog(false); - resetForm(); + handleReset(); }} > @@ -105,68 +106,68 @@ const SearchDialog = () => {
-
- {alert.show && ( - - {alert.message} - - )} -
-
-
- + + {alert.show && {alert.message}} - -
+
+ - {isFound && sucos.length > 0 && ( -
-

Sucos:

-
-
- - {sucos.map((suco) => suco.name).join(', ')} - -
-
- )} + + + + + + + + + No PostoAdms found. + + {postoAdms.map((postoAdm) => ( + { + setFormField({ + id: postoAdm.posto_adms_id, + name: postoAdm.posto_adms_name + }); + setOpen(false); + }} + > + {postoAdm.posto_adms_name} + + ))} + + + + + +
-
- - + {isFound && sucos.length > 0 && ( +
+

Sucos:

+
+ + {sucos.map((suco) => suco.name).join(', ')} +
- -
+ )} + +
+ + +
+