fix sorting and add delete dialog
This commit is contained in:
@ -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 = () => {
|
||||
</div>
|
||||
<AddDialog />
|
||||
<EditDialog />
|
||||
<DeleteDialog />
|
||||
</Container>
|
||||
</ManageSucosContextProvider>
|
||||
);
|
||||
|
||||
@ -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<ContextProps>(initialProps);
|
||||
const API_URL = apiConfig.service_master_data;
|
||||
|
||||
const ManageSucosContextProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const [sucos, setSucos] = useState<SucosProps[]>([]);
|
||||
const [showSearchDialog, setShowSearchDialog] = useState(false);
|
||||
const [showEditDialog, setShowEditDialog] = useState(false);
|
||||
const [showAddDialog, setShowAddDialog] = useState(false);
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||
const [selectedSucos, setSelectedSucos] = useState<string | null>(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);
|
||||
}, [])
|
||||
};
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user