cleaning code

This commit is contained in:
wayanrivan
2025-03-25 13:23:47 +07:00
parent f7d0c77692
commit f11ace54c4
7 changed files with 45 additions and 704 deletions

View File

@ -15,16 +15,6 @@ interface TransactionProps {
}
interface ContextProps {
municipios: TransactionProps[];
showSearchDialog: boolean;
handleSearchDialog: (show: boolean) => void;
showEditDialog: boolean;
handleEditDialog: (show: boolean, selected_user: string | null) => void;
showAddDialog: boolean;
handleAddDialog: (show: boolean) => void;
showDeleteDialog: boolean;
handleDeleteDialog: (show: boolean, selected_user: string | null) => void;
selectedMunicipios: string | null;
getTransactionLists: (
limit: number,
page: number,
@ -36,16 +26,6 @@ interface ContextProps {
}
const initialProps: ContextProps = {
municipios: [],
showSearchDialog: false,
handleSearchDialog: (show: boolean) => { },
showEditDialog: false,
handleEditDialog: (show: boolean, selected_user: string | null) => { },
showAddDialog: false,
handleAddDialog: (show: boolean) => { },
showDeleteDialog: false,
handleDeleteDialog: (show: boolean, selected_user: string | null) => { },
selectedMunicipios: null,
getTransactionLists: async () => ({ data: [], totalCount: 0 })
};
@ -53,33 +33,9 @@ const ManageTransactionContext = createContext<ContextProps>(initialProps);
const API_URL = apiConfig.transaction;
const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
const [showSearchDialog, setShowSearchDialog] = useState(false);
const [showEditDialog, setShowEditDialog] = useState(false);
const [showAddDialog, setShowAddDialog] = useState(false);
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
const [selectedMunicipios, setSelectedMunicipios] = useState<string | null>(null);
const [municipios, setTransaction] = useState<TransactionProps[]>([]);
const [transaction, setTransaction] = useState<TransactionProps[]>([]);
const { GetData } = useCallApi();
const navigate = useNavigate();
const handleSearchDialog = useCallback((show: boolean) => {
setShowSearchDialog(show);
}, []);
const handleAddDialog = useCallback((show: boolean) => {
setShowAddDialog(show);
}, []);
const handleEditDialog = useCallback((show: boolean, selected_municipios: string | null) => {
setSelectedMunicipios(show ? selected_municipios : null);
setShowEditDialog(show);
}, []);
const handleDeleteDialog = useCallback((show: boolean, selected_municipios: string | null) => {
setSelectedMunicipios(show ? selected_municipios : null);
setShowDeleteDialog(show);
}, []);
const handleNavigate = (path: string) => {
const url = navigate(`${API_URL}/transaction/history/${path}`);
};
@ -136,6 +92,28 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
headerClassName: 'w-[250px]',
},
},
{
accessorFn: (row) => {
let status;
if (row.status === 'C') {
status = 'COMPLETE';
} else if(row.status === 'F') {
status = 'FAILED';
} else if(row.status === 'O') {
status = 'ON PROCESS';
} else {
status = 'PENDING';
}
return status;
},
accessorKey: 'status',
header: ({ column }) => <DataGridColumnHeader title="Status" column={column} />,
enableSorting: false,
enableHiding: false,
meta: {
headerClassName: 'w-[250px]',
},
},
{
accessorKey: 'description',
header: ({ column }) => <DataGridColumnHeader title="Description" column={column} />,
@ -175,8 +153,7 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
}
}
],
[handleEditDialog, handleDeleteDialog]
);
[]);
const getTransactionLists = async (page: number, limit: number, sorting: any, filter: any) => {
try {
@ -222,16 +199,6 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
return (
<ManageTransactionContext.Provider
value={{
municipios,
showSearchDialog,
handleSearchDialog,
showAddDialog,
handleAddDialog,
showDeleteDialog,
handleDeleteDialog,
showEditDialog,
handleEditDialog,
selectedMunicipios,
getTransactionLists
}}
>