From c0990e4b4d3fa9682779031c334e08f932464c12 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Thu, 6 Mar 2025 14:20:49 +0700 Subject: [PATCH] fix sorting and add delete dialog --- src/pages/master/sucos/SucosMaster.tsx | 2 + src/pages/master/sucos/hooks/ManageSucos.tsx | 66 ------------------- .../master/sucos/hooks/ManageSucosContext.tsx | 2 +- 3 files changed, 3 insertions(+), 67 deletions(-) delete mode 100644 src/pages/master/sucos/hooks/ManageSucos.tsx diff --git a/src/pages/master/sucos/SucosMaster.tsx b/src/pages/master/sucos/SucosMaster.tsx index 62911a4..9accaf9 100644 --- a/src/pages/master/sucos/SucosMaster.tsx +++ b/src/pages/master/sucos/SucosMaster.tsx @@ -2,6 +2,7 @@ import { Container, DataGridInner } from '@/components'; import { ManageSucosContextProvider } from './hooks/ManageSucosContext'; import AddDialog from './blocks/AddDialog'; import EditDialog from './blocks/EditDialog'; +import DeleteDialog from './blocks/DeleteDialog'; const SucosMaster = () => { return ( @@ -13,6 +14,7 @@ const SucosMaster = () => { + ); diff --git a/src/pages/master/sucos/hooks/ManageSucos.tsx b/src/pages/master/sucos/hooks/ManageSucos.tsx deleted file mode 100644 index cf878fa..0000000 --- a/src/pages/master/sucos/hooks/ManageSucos.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import { apiConfig } from '@/config/api.config'; -import React, { createContext, useCallback, useState } from 'react'; - -interface SucosProps { - id: number; - name: string; -} - -interface ContextProps { - sucos: SucosProps[]; - showSearchDialog: boolean; - handleSearchDialog: (show: boolean) => void; - showEditDialog: boolean; - handleEditDialog: (show: boolean, selected_sucos: string | null) => void; - showAddDialog: boolean; - handleAddDialog: (show: boolean) => void; - showDeleteDialog: boolean; - handleDeleteDialog: (show: boolean, selected_sucos: string | null) => void; - selectedSucos: string | null; - getSucosLists: ( - limit: number, - page: number, - with_deleted: boolean, - order_field: any, - order_direction: any - ) => Promise<{ data: SucosProps[]; totalCount: number } | undefined>; -} - -const initialProps: ContextProps = { - sucos: [], - showSearchDialog: false, - handleSearchDialog: () => {}, - showEditDialog: false, - handleEditDialog: () => {}, - showAddDialog: false, - handleAddDialog: () => {}, - showDeleteDialog: false, - handleDeleteDialog: () => {}, - selectedSucos: null, - getSucosLists: async () => undefined -}; - -const ManageSucosContext = createContext(initialProps); -const API_URL = apiConfig.service_master_data; - -const ManageSucosContextProvider = ({ children }: { children: React.ReactNode }) => { - const [sucos, setSucos] = useState([]); - const [showSearchDialog, setShowSearchDialog] = useState(false); - const [showEditDialog, setShowEditDialog] = useState(false); - const [showAddDialog, setShowAddDialog] = useState(false); - const [showDeleteDialog, setShowDeleteDialog] = useState(false); - const [selectedSucos, setSelectedSucos] = useState(null); - - const handleSearchDialog = useCallback((show: boolean) => { - setShowSearchDialog(show); - }, []); - - const handleAddDialog = useCallback((show: boolean) => { - setShowAddDialog(show); - }, []); - - const hanldeEditDialog = useCallback((show: boolean, selected_sucos: string | null) => { - setSelectedSucos(show ? selected_sucos : null); - setShowEditDialog(show); - }, []) -}; diff --git a/src/pages/master/sucos/hooks/ManageSucosContext.tsx b/src/pages/master/sucos/hooks/ManageSucosContext.tsx index 4e8628b..5151803 100644 --- a/src/pages/master/sucos/hooks/ManageSucosContext.tsx +++ b/src/pages/master/sucos/hooks/ManageSucosContext.tsx @@ -142,7 +142,7 @@ const ManageSucosContextProvider = ({ children }: { children: React.ReactNode }) const getSucosLists = async (page: number, limit: number, sorting: any, filter: any) => { try { - sorting: sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; + sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; const response = await GetData(`${API_URL}/sucos/list`, { limit,