diff --git a/src/components/data-grid/DataGridContext.tsx b/src/components/data-grid/DataGridContext.tsx index 9e95494..4b54947 100644 --- a/src/components/data-grid/DataGridContext.tsx +++ b/src/components/data-grid/DataGridContext.tsx @@ -181,6 +181,7 @@ export const DataGridProvider = (props: TDataGridProps + {loading &&
} {props.children ? props.children : } ); diff --git a/src/components/data-grid/DataGridLoader.tsx b/src/components/data-grid/DataGridLoader.tsx index 03c08ca..77e71fb 100644 --- a/src/components/data-grid/DataGridLoader.tsx +++ b/src/components/data-grid/DataGridLoader.tsx @@ -5,10 +5,10 @@ export const DataGridLoader = () => { const { props } = useDataGrid(); return ( -
+
{ - const parentRef = useRef(null); const { showAddDialog, handleAddDialog, parents } = useManageMenusContext(); const { reload } = useDataGrid(); const { PostData } = useCallApi(); + const [open, setOpen] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -51,8 +57,11 @@ const AddDialog = () => { return; } + console.log('Data dikirim ke API:', formField); const response = await PostData(`${API_URL}/menus/create`, formField); + console.log('Response from API:', response); + if (response?.status) { handleAddDialog(false); resetForm(); @@ -67,7 +76,10 @@ const AddDialog = () => { }; const resetForm = () => { - setFormField(initialState); + setFormField({ + ...initialState, + status: formField.status // Pertahankan nilai status terpilih + }); setAlert({ show: false, message: '' }); }; @@ -78,7 +90,7 @@ const AddDialog = () => { Menu - Create - +
{alert.show && ( @@ -133,24 +145,21 @@ const AddDialog = () => {
- - setFormField({ ...formField, id_parent: e.target.value })} - inputProps={{ - name: 'id_parent', - id: 'uncontrolled-native', - }} - > - - { - parents ? parents.map((el: any) => ( - - )) : '' - } - - +
@@ -190,21 +199,18 @@ const AddDialog = () => { - - setFormField({ ...formField, status: e.target.value })} - inputProps={{ - name: 'status', - id: 'uncontrolled-native', - }} - > - - - - - +
diff --git a/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx b/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx index 4f4818c..b5250eb 100644 --- a/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx +++ b/src/pages/menu/manage-menu/blocks/DeleteDialog.tsx @@ -4,7 +4,14 @@ import { Alert, useDataGrid } from '@/components'; import { useCallApi } from '@/hooks'; import { ChangeEvent, useCallback, useState } from 'react'; import { toast } from 'sonner'; -import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; import { EnforceSwitch } from '@/components/switch'; import { Button } from '@/components/ui/button'; @@ -13,14 +20,13 @@ const DeleteDialog = () => { const { showDeleteDialog, handleDeleteDialog, selectedMenu }: any = useManageMenusContext(); const { reload } = useDataGrid(); const { DeleteData } = useCallApi(); - const [enforce, setEnforce] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' }); const doDeleteMenu = async () => { - const response = await DeleteData(`${API_URL}/menus/delete/${selectedMenu.id}/${enforce}`, { + const response = await DeleteData(`${API_URL}/menus/delete/${selectedMenu.id}/false`, { id: selectedMenu.id }); @@ -44,15 +50,6 @@ const DeleteDialog = () => {

Are you sure?

you will delete this data! -
- - ) => { - setEnforce(e.target.checked); - }} - /> -
{alert.show && ( diff --git a/src/pages/menu/manage-menu/blocks/EditDialog.tsx b/src/pages/menu/manage-menu/blocks/EditDialog.tsx index 78a5ea2..6a40e87 100644 --- a/src/pages/menu/manage-menu/blocks/EditDialog.tsx +++ b/src/pages/menu/manage-menu/blocks/EditDialog.tsx @@ -12,15 +12,25 @@ import { DialogHeader, DialogTitle } from '@/components/ui/dialog'; -import { FormControl,NativeSelect } from "@mui/material"; +import { FormControl, NativeSelect } from '@mui/material'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select'; + const API_URL = apiConfig.service_dashboard; const EditDialog = () => { - const { showEditDialog, handleEditDialog, selectedMenu, setSelectedMenu, parents }: any = useManageMenusContext(); + const { showEditDialog, handleEditDialog, selectedMenu, setSelectedMenu, parents }: any = + useManageMenusContext(); const { reload } = useDataGrid(); const { PutData } = useCallApi(); + const [open, setOpen] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -38,11 +48,12 @@ const EditDialog = () => { const handleUpdate = async (e: React.FormEvent) => { e.preventDefault(); - + if ( selectedMenu.module === '' || selectedMenu.name === '' || selectedMenu.link === '' || + selectedMenu.id_parent === '' || selectedMenu.order_number === 0 || selectedMenu.status === '' ) { @@ -51,8 +62,8 @@ const EditDialog = () => { } const updateMenu = selectedMenu; - if (updateMenu.id_parent === null) updateMenu.id_parent = ""; - delete updateMenu.parentName + if (updateMenu.id_parent === null) updateMenu.id_parent = ''; + delete updateMenu.parentName; const response = await PutData(`${API_URL}/menus/update/${selectedMenu.id}`, selectedMenu); if (response?.status) { handleEditDialog(false, null); @@ -67,7 +78,7 @@ const EditDialog = () => { }; const resetForm = () => { - setSelectedMenu(initialState) + setSelectedMenu(initialState); setAlert({ show: false, message: '' }); }; @@ -78,7 +89,7 @@ const EditDialog = () => { Menu - Update - +
{alert.show && ( @@ -132,24 +143,27 @@ const EditDialog = () => {
- - - setSelectedMenu({ ...selectedMenu, id_parent: e.target.value })} - inputProps={{ - name: 'id_parent', - id: 'uncontrolled-native', - }} - > - { - parents ? parents.map((el: any) => ( - - )) : '' - } - - + +
@@ -165,7 +179,10 @@ const EditDialog = () => { value={selectedMenu.order_number === 0 ? '' : selectedMenu.order_number} onChange={(e) => { const value = parseInt(e.target.value, 10); - setSelectedMenu({ ...selectedMenu, order_number: isNaN(value) ? 0 : value }); + setSelectedMenu({ + ...selectedMenu, + order_number: isNaN(value) ? 0 : value + }); }} />
@@ -184,6 +201,26 @@ const EditDialog = () => {
+
+ + +
+
+ + {/*
-
+
*/}
diff --git a/src/pages/menu/manage-menu/hooks/ManageMenusContext.tsx b/src/pages/menu/manage-menu/hooks/ManageMenusContext.tsx index 2d76541..3ff2f54 100644 --- a/src/pages/menu/manage-menu/hooks/ManageMenusContext.tsx +++ b/src/pages/menu/manage-menu/hooks/ManageMenusContext.tsx @@ -133,12 +133,27 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode }) meta: { headerClassName: 'w-[250px]' } }, { - accessorFn: (row) => row.status, - id: 'status', + accessorKey: 'status', header: ({ column }) => , enableSorting: false, enableHiding: false, - meta: { headerClassName: 'w-[100px]', cellClassName: 'text-center' } + cell: ({ row }) => { + const isActive = row.original.status === 'Y'; + + return ( + + {isActive ? 'Active' : 'Inactive'} + + ); + }, + meta: { + headerClassName: 'w-[100px]', + cellClassName: 'text-center' + } }, { id: 'actions', @@ -211,7 +226,7 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode }) link: child.link, id_parent: child.id_parent, status: child.status, - order_number: child.order_number + order_number: parent.order_number }; }); @@ -242,7 +257,7 @@ const ManageMenusContextProvider = ({ children }: { children: React.ReactNode }) const total_count = transformedData.length; const paginatedData = transformedData.slice(page * limit, (page + 1) * limit); - console.log(response.data); + console.log('data', paginatedData); // setMenus(transformedData); return { data: paginatedData, totalCount: total_count }; } catch (error) { diff --git a/src/pages/settings/user/manage-user/hooks/ManageUserContext.tsx b/src/pages/settings/user/manage-user/hooks/ManageUserContext.tsx index efae604..231cbc6 100644 --- a/src/pages/settings/user/manage-user/hooks/ManageUserContext.tsx +++ b/src/pages/settings/user/manage-user/hooks/ManageUserContext.tsx @@ -8,6 +8,8 @@ import { ListToolBar } from '../blocks'; import { useCallApi } from '@/hooks'; interface ContextProps { + showSearchDialog: boolean; + handleSearchDialog: (show: boolean) => void; showEditDialog: boolean; handleEditDialog: (show: boolean, selected_user: string | null) => void; showAddDialog: boolean; @@ -35,6 +37,8 @@ interface RoleListProps { } const initialProps: ContextProps = { + showSearchDialog: false, + handleSearchDialog: (show: boolean) => {}, showEditDialog: false, handleEditDialog: () => {}, showAddDialog: false, @@ -52,6 +56,7 @@ const API_URL = apiConfig.service_dashboard; const ManageUserContextProvider = ({ children }: { children: React.ReactNode }) => { /* state */ const [showEditDialog, setShowEditDialog] = useState(false); + const [showSearchDialog, setShowSearchDialog] = useState(false); const [showAddDialog, setShowAddDialog] = useState(false); const [showDeleteDialog, setShowDeleteDialog] = useState(false); const [selectedUser, setSelectedUser] = useState(null); @@ -59,6 +64,10 @@ const ManageUserContextProvider = ({ children }: { children: React.ReactNode }) const { GetData } = useCallApi(); /* action */ + const handleSearchDialog = useCallback((show: boolean) => { + setShowSearchDialog(show); + }, []); + const handleEditDialog = useCallback((show: boolean, selected_user: string | null) => { setSelectedUser(show ? selected_user : null); setShowEditDialog(show); @@ -219,6 +228,8 @@ const ManageUserContextProvider = ({ children }: { children: React.ReactNode }) return (