fix sorting and add delete dialog

This commit is contained in:
Wikzyy
2025-03-06 14:20:49 +07:00
parent 0df7800155
commit c0990e4b4d
3 changed files with 3 additions and 67 deletions

View File

@ -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);
}, [])
};

View File

@ -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,