This commit is contained in:
wayanrivan
2025-03-24 15:51:05 +07:00
parent cc4f40af5b
commit edd9be28e9
16 changed files with 1233 additions and 271 deletions

View File

@ -4,4 +4,7 @@ GENERATE_SOURCEMAP=false
# VITE_APP_API_URL=
VITE_APP_API_URL=http://127.0.0.1:4003/apitest
VITE_APP_API_URL=https://tpay.shiblysolution.id/api
# VITE_APP_URL_TRANSACTION=https://tpay.shiblysolution.id/test/x/api
# VITE_APP_API_URL=http://127.0.0.1:4003/apitesting
VITE_ENV=development

272
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -106,5 +106,9 @@
"typescript": "^5.6.3",
"typescript-eslint": "^8.14.0",
"vite": "^5.4.11"
}
},
"description": "## Quick Setup",
"main": "postcss.config.js",
"author": "",
"license": "ISC"
}

View File

@ -4,6 +4,7 @@ interface apiConfigProps {
service_master_data: string;
service_transaction: string;
service_wallet: string;
transaction: string
}
const API_URL = import.meta.env.VITE_APP_API_URL;
@ -14,7 +15,8 @@ const apiConfig: apiConfigProps = {
// service_master_data: `${API_URL}/m`
service_master_data: `${API_URL}/t`,
service_transaction: `${API_URL}/tt`,
service_wallet: `${API_URL}/w`
service_wallet: `${API_URL}/w`,
transaction: `${API_URL}/x`
};
export { apiConfig };

View File

@ -1,11 +0,0 @@
const MenuCategory = () => {
return (
<div>
<div className="container mx-auto p-5">
<h1 className="text-xl font-medium leading-none text-gray-900">Menu Category</h1>
</div>
</div>
);
};
export default MenuCategory;

View File

@ -0,0 +1,39 @@
import { Container, DataGridInner } from '@/components';
import { TransactionProvider } from './hooks/TransactionContext';
import AddDialog from './blocks/AddDialog';
import SearchDialog from './blocks/SearchDialog';
import EditDialog from './blocks/EditDialog';
import DeleteDialog from './blocks/DeleteDialog';
import { Breadcrumbs, Link } from '@mui/material';
const Transaction = () => {
return (
<TransactionProvider>
<Container className="mb-7">
<h1 className="text-xl font-medium leading-none text-gray-900 mb-5">TRANSACTION</h1>
<Breadcrumbs sx={{ mb: 2 }}>
<Link underline="none" color="inherit" href="/">
<span className="text-sm hover:underline">Dashboard</span>
</Link>
<Link underline="none" color="inherit">
<span className="text-sm">Master Data</span>
</Link>
<Link underline="none" color="inherit">
<span className="text-sm">Transaction</span>
</Link>
</Breadcrumbs>
<div className="grid gap-5 lg:gap-7.5">
<DataGridInner />
</div>
<AddDialog />
<EditDialog />
<DeleteDialog />
<SearchDialog />
</Container>
</TransactionProvider>
);
};
export default Transaction;

View File

@ -0,0 +1,172 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useTransactionContext } from '../hooks/useTransactionContext';
import {
Dialog,
DialogBody,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle
} from '@/components/ui/dialog';
import { Alert, KeenIcon, useDataGrid } from '@/components';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import axios from 'axios';
import { apiConfig } from '@/config/api.config';
import { toast } from 'sonner';
import { getAuth, useAuthContext } from '@/auth';
import { useCallApi } from '@/hooks';
import { doSaveLogActivity } from '@/actions/GlobalActions';
const API_URL = apiConfig.service_master_data;
const AddDialog = () => {
const parentRef = useRef<any | null>(null);
const { reload } = useDataGrid();
const { PostData } = useCallApi();
const parsedUser = getAuth()?.user;
const { showAddDialog, handleAddDialog, selectedMunicipios } = useTransactionContext();
const [alert, setAlert] = useState({
show: false,
message: ''
});
const initialState = {
name: '',
created_by: '',
created_at: ''
};
const [formField, setFormField] = useState(initialState);
const created_time = new Date();
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
const resetForm = () => {
setFormField(initialState);
setAlert({ show: false, message: '' });
};
const doCreateMunicipio = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const response = await PostData(`${API_URL}/municipios/create`, formField);
if (response?.status) {
handleAddDialog(false);
resetForm();
reload();
toast.success('Municipio created successfully!');
// const createActivity = {
// module: 'Manage Municipio',
// description: `Create Municipio => ${selectedMunicipios}`,
// action: 'C'
// };
// doSaveLogActivity(createActivity);
} else {
toast.error('Failed to create municipio.');
setAlert({ show: true, message: 'Failed to create municipio. Please try again.' });
}
},
[formField]
);
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name.trim() === '') {
setAlert({ show: true, message: 'Please fill name field.' });
return;
}
doCreateMunicipio(e);
console.log(parsedUser.email);
console.log(formField);
setAlert({ show: false, message: '' });
};
const handleReset = () => {
resetForm();
setAlert({ show: false, message: '' });
};
useEffect(() => {
if (showAddDialog) {
setFormField({
name: formField.name,
created_by: parsedUser?.username,
created_at: formattedTime
});
}
}, [formattedTime]);
useEffect(() => {
if (showAddDialog === false) {
resetForm();
}
}, [showAddDialog]);
return (
<Dialog open={showAddDialog} onOpenChange={(open) => handleAddDialog(open)}>
<DialogContent className="container-fixed max-w-96 flex flex-col p-5 overflow-hidden [&>button]:hidden">
<DialogTitle></DialogTitle>
<DialogDescription></DialogDescription>
<DialogHeader className="p-2 border-0">
<div className="flex items-center justify-between flex-wrap grow">
<div className="flex flex-col justify-center">
<h1 className="text-xl font-semibold leading-none text-gray-900">Add Municipios</h1>
<div className="flex items-center gap-2 text-sm font-normal text-gray-700"></div>
</div>
<div
className="cursor-pointer hover:opacity-100 opacity-50"
onClick={() => {
handleAddDialog(false);
resetForm();
}}
>
<KeenIcon icon="cross" className="text-1.5xl" />
</div>
</div>
</DialogHeader>
<DialogBody className="scrollable-y px-0 pb-0" ref={parentRef}>
<div className="flex flex-col px-0">
{alert.show && (
<Alert variant="danger" className="mb-5">
{alert.message}
</Alert>
)}
<form action="" onSubmit={handleSubmit}>
<div className="card-body grid-cols-6 gap-5 p-0">
<div className="grid grid-cols-8 gap-2 w-full items-center">
<label className="form-label flex items-center gap-1 col-span-2">
Name<span className="text-red-500">*</span>
</label>
<Input
className="input col-span-6"
type="text"
autoComplete="off"
value={formField.name}
onChange={({ target }) =>
setFormField((prev) => ({ ...prev, name: target.value }))
}
/>
</div>
<div className="flex justify-end pt-2.5 gap-5 col-span-6">
<Button variant={'outline'} type="reset" onClick={handleReset}>
Reset
</Button>
<Button variant={'default'} type="submit">
Create
</Button>
</div>
</div>
</form>
</div>
</DialogBody>
</DialogContent>
</Dialog>
);
};
export default AddDialog;

View File

@ -0,0 +1,87 @@
import { Alert, useDataGrid } from '@/components';
import { useTransactionContext } from '../hooks/useTransactionContext';
import { ChangeEvent, useCallback, useState } from 'react';
import axios from 'axios';
import { apiConfig } from '@/config/api.config';
import { useCallApi } from '@/hooks';
import { toast } from 'sonner';
import { Dialog, DialogContent, DialogFooter, DialogHeader } from '@/components/ui/dialog';
import { EnforceSwitch } from '@/components/switch';
import { Button } from '@/components/ui/button';
import { doSaveLogActivity } from '@/actions/GlobalActions';
const API_URL = apiConfig.service_master_data;
const DeleteDialog = () => {
const { showDeleteDialog, handleDeleteDialog, selectedMunicipios, municipios } =
useTransactionContext();
const { reload } = useDataGrid();
const { DeleteData } = useCallApi();
const [enforce, setEnforce] = useState(false);
const [alert, setAlert] = useState({
show: false,
message: ''
});
const doDeleteMunicipio = useCallback(async () => {
const response = await DeleteData(
`${API_URL}/municipios/delete/${selectedMunicipios}/${enforce}`,
{
id: selectedMunicipios
}
);
if (response?.status) {
setAlert((prev) => ({ ...prev, show: false, message: '' }));
handleDeleteDialog(false, null);
toast.success('Success Delete Municipio');
reload();
// const createActivity = {
// module: 'Manage Municipio',
// description: `Delete Municipio => ${selectedMunicipios}`,
// action: 'D'
// };
// doSaveLogActivity(createActivity);
} else {
setAlert((prev) => ({ ...prev, show: true, message: response?.message }));
}
}, [selectedMunicipios, enforce]);
return (
<Dialog open={showDeleteDialog} onOpenChange={(open) => handleDeleteDialog(open, null)}>
<DialogContent className="container-fixed max-w-md flex flex-col p-5 overflow-hidden [&>button]:hidden">
<DialogHeader className="p-0 border-0 block">
<Alert variant="warning">
<h3 className="text-lg">Are you sure?</h3>
<span className="text-sm">you will delete this data!</span>
<div className="mt-2 flex items-center gap-x-2">
<label className="form-label max-w-56">Hard Delete</label>
<EnforceSwitch
enforce={enforce}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
setEnforce(e.target.checked);
}}
/>
</div>
</Alert>
{alert.show && (
<Alert variant="danger">
<h3>{alert.message}</h3>
</Alert>
)}
</DialogHeader>
<DialogFooter className="flex justify-end items-center gap-4 mt-3">
<Button variant={'outline'} onClick={() => handleDeleteDialog(false, null)}>
Cancel
</Button>
<Button variant={'destructive'} onClick={() => doDeleteMunicipio()}>
Delete
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
};
export default DeleteDialog;

View File

@ -0,0 +1,173 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useTransactionContext } from '../hooks/useTransactionContext';
import { Alert, useDataGrid } from '@/components';
import axios from 'axios';
import { apiConfig } from '@/config/api.config';
import { toast } from 'sonner';
import {
Dialog,
DialogBody,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle
} from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { getAuth, useAuthContext } from '@/auth';
import { useCallApi } from '@/hooks';
import { doSaveLogActivity } from '@/actions/GlobalActions';
const API_URL = apiConfig.service_master_data;
const EditDialog = () => {
const parentRef = useRef<any | null>(null);
const { showEditDialog, handleEditDialog, selectedMunicipios, municipios } =
useTransactionContext();
const { reload } = useDataGrid();
const { PutData, GetData } = useCallApi();
const parsedUser = getAuth()?.user;
const [alert, setAlert] = useState({
show: false,
message: ''
});
const initialState = {
name: '',
updated_by: '',
updated_at: ''
};
const [formField, setFormField] = useState(initialState);
const created_time = new Date();
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
const resetForm = () => {
setFormField(initialState);
setAlert({ show: false, message: '' });
};
const doUpdateMunicipios = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const response = await PutData(
`${API_URL}/municipios/update/${selectedMunicipios}`,
formField
);
if (response?.status) {
handleEditDialog(false, null);
resetForm();
toast.success('Success update municipio');
reload();
// const createActivity = {
// module: 'Manage Municipio',
// description: `Edit Municipio => ${selectedMunicipios}`,
// action: 'U'
// };
// doSaveLogActivity(createActivity);
} else {
toast.error('Failed update user');
setAlert({ show: true, message: 'Failed to update municipio. Please try again.' });
}
},
[selectedMunicipios, formField]
);
const doFetchData = useCallback(async (id: string) => {
const response = await GetData(`${API_URL}/municipios/getdata/${id}`, { id });
if (response?.status) {
setFormField((prev) => ({
...prev,
name: response.data.name
}));
} else {
setFormField((prev) => ({
...prev,
name: ''
}));
}
}, []);
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name.trim() === '') {
setAlert({ show: true, message: 'Please fill name field.' });
return;
}
doUpdateMunicipios(e);
console.log(formField);
setAlert({ show: false, message: '' });
};
useEffect(() => {
if (selectedMunicipios) {
doFetchData(selectedMunicipios);
}
}, [selectedMunicipios]);
useEffect(() => {
if (showEditDialog === false) {
resetForm();
}
}, [showEditDialog]);
useEffect(() => {
if (selectedMunicipios) {
setFormField({
name: formField.name,
updated_by: parsedUser.email,
updated_at: formattedTime
});
}
}, [formattedTime]);
// console.log(selectedMunicipios);
return (
<Dialog open={showEditDialog} onOpenChange={(open) => handleEditDialog(open, null)}>
<DialogContent className="container-fixed max-w-[768px] flex flex-col p-5 overflow-hidden">
<DialogHeader>
<DialogTitle>Municipios - Update</DialogTitle>
<DialogDescription></DialogDescription>
</DialogHeader>
<DialogBody>
<div className="flex flex-col">
{alert.show && (
<Alert variant="danger">
<h3>{alert.message}</h3>
</Alert>
)}
<form onSubmit={handleUpdate}>
<div className="card-body grid gap-5">
<div className="w-full">
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label className="form-label flex items-center gap-1 max-w-56">
Name<span className="text-red-500">*</span>
</label>
<Input
className="input"
type="text"
value={formField.name}
onChange={(e) => setFormField({ ...formField, name: e.target.value })}
/>
</div>
</div>
<div className="flex justify-end">
<Button className="btn btn-primary">Save Changes</Button>
</div>
</div>
</form>
</div>
</DialogBody>
</DialogContent>
</Dialog>
);
};
export default EditDialog;

View File

@ -0,0 +1,90 @@
import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
import { useTransactionContext } from '../hooks/useTransactionContext';
import { Button } from '@/components/ui/button';
import { useCallback, useState, useEffect } from 'react';
import { toast } from 'sonner';
const ListToolbar = () => {
const { table, reload } = useDataGrid();
const { handleAddDialog, handleSearchDialog } = useTransactionContext();
// Set the initial state for trxDate
const [trxDate, settrxDate] = useState({ from: '', to: '' });
// Function to format date to YYYY-MM-DD
const formatDate = (date: Date): string => {
return date.toISOString().split('T')[0];
};
// useEffect to set the default date values
useEffect(() => {
const today = new Date();
const nextWeek = new Date(today);
nextWeek.setDate(today.getDate() + 7);
settrxDate({
from: formatDate(today), // Set 'from' to today
to: formatDate(nextWeek), // Set 'to' to 7 days later
});
}, []);
const handleFilterData = useCallback(() => {
try {
table.getColumn('transaction_date')?.setFilterValue(trxDate);
} catch (error) {
toast.error('Error applying filter');
console.error('Error applying filter:', error);
}
}, [trxDate, table]);
useEffect(() => {
if (trxDate.from && trxDate.to) {
handleFilterData();
}
}, [trxDate]);
return (
<div className="card-header flex-wrap gap-2 border-b-0 px-5">
<div className="flex flex-wrap gap-2 lg:gap-5 w-full">
<div className="flex justify-between w-full items-center">
<div className="flex w-[50%] gap-3 items-center">
<label className="input input-sm w-1/3">
From
<input
type="date"
placeholder="From"
value={trxDate.from}
onChange={(event) =>
settrxDate({ ...trxDate, from: event.target.value })
}
name="from"
/>
</label>
<label className="input input-sm w-1/3">
To
<input
type="date"
placeholder="To"
value={trxDate.to}
onChange={(event) =>
settrxDate({ ...trxDate, to: event.target.value })
}
name="to"
/>
</label>
</div>
<div className="flex gap-3 items-center">
<DefaultTooltip title={'Refresh'} placement={'top'}>
<Button variant="outline" className="h-7.5" onClick={() => reload()}>
<KeenIcon icon="arrows-circle" />
</Button>
</DefaultTooltip>
</div>
</div>
</div>
</div>
);
};
export default ListToolbar;

View File

@ -0,0 +1,178 @@
import { useRef, useState } from 'react';
import {
Dialog,
DialogBody,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle
} from '@/components/ui/dialog';
import { Alert, KeenIcon } from '@/components';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { useTransactionContext } from '../hooks/useTransactionContext';
import { apiConfig } from '@/config/api.config';
import axios from 'axios';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue
} from '@/components/ui/select';
interface trxDate {
from: string;
to: string;
}
const API_URL = apiConfig.service_master_data;
const SearchDialog = () => {
const parentRef = useRef<any | null>(null);
const { showSearchDialog, handleSearchDialog, municipios } = useTransactionContext();
const [alert, setAlert] = useState({
show: false,
message: ''
});
const initialState = {
from: '',
to: ''
};
const [formField, setFormField] = useState(initialState);
const resetForm = () => {
setFormField(initialState);
};
const [trxDate, settrxDate] = useState<trxDate[]>([]);
const [isFound, setIsFound] = useState(false);
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const from = String(formField.from);
const to = String(formField.to);
// if (formField.id === 0) {
// setAlert({ show: true, message: 'Please fill name field.' });
// return;
// }
try {
// const response = await axios.get(`${API_URL}/municipios/postoadms/${id}`);
// if (response.data.status) {
// setPostoadms(response.data.data);
// setIsFound(true);
// // console.log('Found postoadms: ', response.data.data);
// } else {
// setPostoadms([]);
// setIsFound(false);
// setAlert({ show: true, message: 'No postoadms found.' });
// }
} catch (error) {
console.error('Error fetching postoadms', error);
setAlert({ show: true, message: 'Failed to fetch postoadms. Please try again.' });
}
setAlert({ show: false, message: '' });
};
const handleReset = () => {
setFormField(initialState);
setIsFound(false);
settrxDate([]);
};
// console.log(municipios);
return (
<Dialog open={showSearchDialog} onOpenChange={(open) => handleSearchDialog(open)}>
<DialogContent className="container-fixed max-w-[700px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
<DialogTitle></DialogTitle>
<DialogDescription></DialogDescription>
<DialogHeader className="p-2 border-0">
<div className="flex items-center justify-between flex-wrap grow">
<div className="flex flex-col justify-center">
<h1 className="text-xl font-semibold leading-none text-gray-900">
Search Postoadms
</h1>
<div className="flex items-center gap-2 text-sm font-normal text-gray-700"></div>
</div>
<div
className="cursor-pointer hover:opacity-100 opacity-50"
onClick={() => {
handleSearchDialog(false);
resetForm();
}}
>
<KeenIcon icon="cross" className="text-1.5xl" />
</div>
</div>
</DialogHeader>
<DialogBody className="scrollable-y px-0 pb-0" ref={parentRef}>
<div className="flex flex-col px-0">
{alert.show && (
<Alert variant="danger" className="mb-5">
{alert.message}
</Alert>
)}
<form action="" onSubmit={handleSubmit}>
<div className="card-body grid-cols-6 gap-5 p-0">
<div className="grid grid-cols-8 gap-2 w-full items-center">
<label className="form-label flex items-center gap-1 col-span-2">
Municipio Name<span className="text-red-500">*</span>
</label>
{/* <Select
value={formField.id.toString()}
onValueChange={(target) => {
const selectedMunicipio = municipios.find((m) => m.id.toString() === target);
if (selectedMunicipio) {
setFormField({
...formField,
id: selectedMunicipio.id,
name: selectedMunicipio.name
});
}
}}
> */}
{/* <SelectTrigger className="col-span-6">
<SelectValue placeholder="Select Municipios" />
</SelectTrigger>
<SelectContent>
{municipios.map((municipio) => (
<SelectItem key={municipio.id} value={municipio.id.toString()}>
{municipio.name}
</SelectItem>
))}
</SelectContent>
</Select> */}
</div>
{/* {isFound && postoadms.length > 0 && (
<div className="mt-4 border-t pt-4">
<h2 className="text-md font-semibold">Postu Administravo: </h2>
<br />
<div className="flex flex-col">
<span className="text-sm form-hint">
{postoadms.map((posto) => posto.name).join(', ')}
</span>
</div>
</div>
)} */}
<div className="flex justify-end pt-2.5 gap-5 col-span-6">
<Button variant={'outline'} type="reset" onClick={handleReset}>
Reset
</Button>
<Button variant={'default'} type="submit">
Search
</Button>
</div>
</div>
</form>
</div>
</DialogBody>
</DialogContent>
</Dialog>
);
};
export default SearchDialog;

View File

@ -0,0 +1,258 @@
import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components';
import { Toaster } from '@/components/ui/sonner';
import { apiConfig } from '@/config/api.config';
import { ColumnDef } from '@tanstack/react-table';
import axios from 'axios';
import React, { createContext, useCallback, useEffect, useMemo, useState } from 'react';
import { useCallApi } from '@/hooks';
import ListToolbar from '../blocks/ListToolbar';
import { Button } from '@/components/ui/button';
import { useNavigate } from 'react-router';
interface TransactionProps {
id: number;
name: string;
}
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,
with_deleted: boolean,
order_field: any,
order_direction: any,
filter: any
) => Promise<{ data: TransactionProps[]; totalCount: number } | undefined>;
}
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 })
};
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 { 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}`);
};
const columns = useMemo<ColumnDef<any>[]>(
() => [
{
accessorKey: 'transaction_date',
header: ({ column }) => <DataGridColumnHeader title="Transaction Date" column={column} />,
enableSorting: false,
enableHiding: false,
meta: {
headerClassName: 'w-[250px]'
}
},
{
accessorKey: 'origin_customer.fullname',
header: ({ column }) => <DataGridColumnHeader title="Full Name" column={column} />,
enableSorting: false,
enableHiding: false,
meta: {
headerClassName: 'w-[250px]'
}
},
{
accessorFn: (row) =>
new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(row.purchase.amount),
id: 'amount',
header: ({ column }) => <DataGridColumnHeader title="Amount" column={column} />,
enableSorting: false,
enableHiding: false,
meta: {
headerClassName: 'w-[250px]',
},
},
{
accessorFn: (row) => {
let fee;
if (row.kind === 'P') {
fee = row.purchase.fee_amount;
} else {
fee = row.transfer.fee_amount;
}
return fee.toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
});
},
accessorKey: 'fee',
header: ({ column }) => <DataGridColumnHeader title="Fee" column={column} />,
enableSorting: false,
enableHiding: false,
meta: {
headerClassName: 'w-[250px]',
},
},
{
accessorKey: 'description',
header: ({ column }) => <DataGridColumnHeader title="Description" column={column} />,
enableSorting: false,
enableHiding: false,
meta: {
headerClassName: 'w-[250px]'
}
},
{
accessorKey: 'type.name',
header: ({ column }) => <DataGridColumnHeader title="Name" column={column} />,
enableSorting: false,
enableHiding: false,
meta: {
headerClassName: 'w-[250px]'
}
},
{
id: 'actions',
header: ({ column }) => <DataGridColumnHeader title="Actions" column={column} />,
enableSorting: false,
enableHiding: false,
cell: (data) => {
const row = data.row.original.id;
return (
<>
<button className="btn btn-sm btn-icon btn-clear btn-light">
<KeenIcon icon="eye" />
</button>
</>
);
},
meta: {
headerClassName: 'w-[100px]',
cellClassName: 'text-center'
}
}
],
[handleEditDialog, handleDeleteDialog]
);
const getTransactionLists = async (page: number, limit: number, sorting: any, filter: any) => {
try {
let startdate;
let enddate;
let formattedFilter;
if (filter == undefined || filter.length==0) {
const today = new Date();
const nextWeek = new Date();
nextWeek.setDate(today.getDate() + 7);
startdate = today.toISOString().split('T')[0];
enddate = nextWeek.toISOString().split('T')[0];
}else if (filter != undefined || filter.length!=0) {
startdate = filter[0].value.from;
enddate = filter[0].value.to;
}
formattedFilter = {
"Transactions.transaction_date": {
from: startdate+" 00:00:00",
to: enddate+" 23:59:59"
}
};
const response = await GetData(`${API_URL}/transaction/history`, {
limit,
page: page + 1,
with_deleted: false,
order_field: "Transactions.created_at",
order_direction: 'DESC',
filter: JSON.stringify(formattedFilter)
});
setTransaction(response?.data.list);
return { data: response?.data.list, totalCount: response?.data.total_count };
} catch (error) {
console.error('Error fetching transaction', error);
}
};
return (
<ManageTransactionContext.Provider
value={{
municipios,
showSearchDialog,
handleSearchDialog,
showAddDialog,
handleAddDialog,
showDeleteDialog,
handleDeleteDialog,
showEditDialog,
handleEditDialog,
selectedMunicipios,
getTransactionLists
}}
>
<Toaster expand visibleToasts={9} duration={3000} />
<DataGridProvider
columns={columns}
pagination={{ size: 10 }}
toolbar={<ListToolbar />}
layout={{ card: true }}
sorting={[{ id: 'id', desc: false }]}
serverSide={true}
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
getTransactionLists(pageIndex, pageSize, sorting, columnFilters)
}
>
{children}
</DataGridProvider>
</ManageTransactionContext.Provider>
);
};
export { TransactionProvider, ManageTransactionContext };
export type { TransactionProps };

View File

@ -0,0 +1,12 @@
import { useContext } from 'react';
import { ManageTransactionContext } from './TransactionContext';
const useTransactionContext = () => {
const context = useContext(ManageTransactionContext);
if (!context) throw new Error('useTransactionContext must be used within AuthProvider');
return context;
};
export { useTransactionContext };

View File

@ -1,12 +1,39 @@
import { Container, DataGridInner } from '@/components';
import { TransactionProvider } from './hooks/TransactionContext';
import AddDialog from './blocks/AddDialog';
import SearchDialog from './blocks/SearchDialog';
import EditDialog from './blocks/EditDialog';
import DeleteDialog from './blocks/DeleteDialog';
import { Breadcrumbs, Link } from '@mui/material';
const Transaction = () => {
return (
<div>
<div className="container mx-auto p-5">
<h1 className="text-xl font-medium leading-none text-gray-900">Transaction</h1>
return (
<TransactionProvider>
<Container className="mb-7">
<h1 className="text-xl font-medium leading-none text-gray-900 mb-5">TRANSACTION</h1>
<Breadcrumbs sx={{ mb: 2 }}>
<Link underline="none" color="inherit" href="/">
<span className="text-sm hover:underline">Dashboard</span>
</Link>
<Link underline="none" color="inherit">
<span className="text-sm">Master Data</span>
</Link>
<Link underline="none" color="inherit">
<span className="text-sm">Transaction</span>
</Link>
</Breadcrumbs>
<div className="grid gap-5 lg:gap-7.5">
<DataGridInner />
</div>
</div>
);
};
export default Transaction;
<AddDialog />
<EditDialog />
<DeleteDialog />
<SearchDialog />
</Container>
</TransactionProvider>
);
};
export default Transaction;

View File

@ -19,7 +19,7 @@ import AccessType from '@/pages/access/access-type/AccessType';
import MemberCredential from '@/pages/access/member-credentials/MemberCredentials';
import ManageCurrency from '@/pages/account/manage-currency/ManageCurrency';
import ManageNotification from '@/pages/notification/ManageNotification';
import MenuCategory from '@/pages/menu/menu-category/MenuCategory';
import Transaction from '@/pages/transaction/Transaction';
import ManageMenu from '@/pages/menu/manage-menu/ManageMenu';
import Welcome from '@/pages/menu/welcome/Welcome';
import Inbox from '@/pages/message/Inbox';
@ -76,7 +76,7 @@ const AppRoutingSetup = (): ReactElement => {
<Route path="/notification/notification-management" element={<ManageNotification />} />
<Route path="/menu/menu-category" element={<MenuCategory />} />
<Route path="/transaction" element={<Transaction />} />
<Route path="/menu/menu-management" element={<ManageMenu />} />
<Route path="/menu/welcome" element={<Welcome />} />
<Route path="/transaction" element={<Transaction />} />

148
yarn.lock
View File

@ -524,14 +524,14 @@
source-map "^0.5.7"
stylis "4.2.0"
"@emotion/cache@^11.13.0", "@emotion/cache@^11.13.1":
version "11.13.1"
resolved "https://registry.npmjs.org/@emotion/cache/-/cache-11.13.1.tgz"
integrity sha512-iqouYkuEblRcXmylXIwwOodiEK5Ifl7JcX7o6V4jI3iW4mLXX3dmt5xwBtIkJiQEXFAI+pC8X0i67yiPkH9Ucw==
"@emotion/cache@^11.13.0", "@emotion/cache@^11.13.1", "@emotion/cache@^11.13.5":
version "11.14.0"
resolved "https://registry.npmjs.org/@emotion/cache/-/cache-11.14.0.tgz"
integrity sha512-L/B1lc/TViYk4DcpGxtAVbx0ZyiKM5ktoIyafGkH6zg/tj+mA+NE//aPYKG0k8kCHSHVJrpLpcAlOBEXQ3SavA==
dependencies:
"@emotion/memoize" "^0.9.0"
"@emotion/sheet" "^1.4.0"
"@emotion/utils" "^1.4.0"
"@emotion/utils" "^1.4.2"
"@emotion/weak-memoize" "^0.4.0"
stylis "4.2.0"
@ -578,15 +578,15 @@
"@emotion/weak-memoize" "^0.4.0"
hoist-non-react-statics "^3.3.1"
"@emotion/serialize@^1.2.0", "@emotion/serialize@^1.3.0", "@emotion/serialize@^1.3.1", "@emotion/serialize@^1.3.2":
version "1.3.2"
resolved "https://registry.npmjs.org/@emotion/serialize/-/serialize-1.3.2.tgz"
integrity sha512-grVnMvVPK9yUVE6rkKfAJlYZgo0cu3l9iMC77V7DW6E1DUIrU68pSEXRmFZFOFB1QFo57TncmOcvcbMDWsL4yA==
"@emotion/serialize@^1.2.0", "@emotion/serialize@^1.3.0", "@emotion/serialize@^1.3.1", "@emotion/serialize@^1.3.3":
version "1.3.3"
resolved "https://registry.npmjs.org/@emotion/serialize/-/serialize-1.3.3.tgz"
integrity sha512-EISGqt7sSNWHGI76hC7x1CksiXPahbxEOrC5RjmFRJTqLyEK9/9hZvBbiYn70dw4wuwMKiEMCUlR6ZXTSWQqxA==
dependencies:
"@emotion/hash" "^0.9.2"
"@emotion/memoize" "^0.9.0"
"@emotion/unitless" "^0.10.0"
"@emotion/utils" "^1.4.1"
"@emotion/utils" "^1.4.2"
csstype "^3.0.2"
"@emotion/sheet@^1.4.0":
@ -621,10 +621,10 @@
resolved "https://registry.npmjs.org/@emotion/use-insertion-effect-with-fallbacks/-/use-insertion-effect-with-fallbacks-1.1.0.tgz"
integrity sha512-+wBOcIV5snwGgI2ya3u99D7/FJquOIniQT1IKyDsBmEgwvpxMNeS65Oib7OnE2d2aY+3BU4OiH+0Wchf8yk3Hw==
"@emotion/utils@^1.4.0", "@emotion/utils@^1.4.1":
version "1.4.1"
resolved "https://registry.npmjs.org/@emotion/utils/-/utils-1.4.1.tgz"
integrity sha512-BymCXzCG3r72VKJxaYVwOXATqXIZ85cuvg0YOUDxMGNrKc1DJRZk8MgV5wyXRyEayIMd4FuXJIUgTBXvDNW5cA==
"@emotion/utils@^1.4.0", "@emotion/utils@^1.4.2":
version "1.4.2"
resolved "https://registry.npmjs.org/@emotion/utils/-/utils-1.4.2.tgz"
integrity sha512-3vLclRofFziIa3J2wDh9jjbkUz9qk5Vi3IZ/FSTKViB0k+ef0fPV7dYrUIugbgupYDx7v9ud/SjrtEP8Y4xLoA==
"@emotion/weak-memoize@^0.4.0":
version "0.4.0"
@ -979,68 +979,75 @@
clsx "^2.1.0"
prop-types "^15.8.1"
"@mui/core-downloads-tracker@^6.1.6":
version "6.1.6"
resolved "https://registry.npmjs.org/@mui/core-downloads-tracker/-/core-downloads-tracker-6.1.6.tgz"
integrity sha512-nz1SlR9TdBYYPz4qKoNasMPRiGb4PaIHFkzLzhju0YVYS5QSuFF2+n7CsiHMIDcHv3piPu/xDWI53ruhOqvZwQ==
"@mui/core-downloads-tracker@^6.4.8":
version "6.4.8"
resolved "https://registry.npmjs.org/@mui/core-downloads-tracker/-/core-downloads-tracker-6.4.8.tgz"
integrity sha512-vjP4+A1ybyCRhDZC7r5EPWu/gLseFZxaGyPdDl94vzVvk6Yj6gahdaqcjbhkaCrJjdZj90m3VioltWPAnWF/zw==
"@mui/material@^6.1.6":
version "6.1.6"
resolved "https://registry.npmjs.org/@mui/material/-/material-6.1.6.tgz"
integrity sha512-1yvejiQ/601l5AK3uIdUlAVElyCxoqKnl7QA+2oFB/2qYPWfRwDgavW/MoywS5Y2gZEslcJKhe0s2F3IthgFgw==
"@mui/icons-material@^6.4.6":
version "6.4.6"
resolved "https://registry.npmjs.org/@mui/icons-material/-/icons-material-6.4.6.tgz"
integrity sha512-rGJBvIQQbQAlyKYljHQ8wAQS/K2/uYwvemcpygnAmCizmCI4zSF9HQPuiG8Ql4YLZ6V/uKjA3WHIYmF/8sV+pQ==
dependencies:
"@babel/runtime" "^7.26.0"
"@mui/core-downloads-tracker" "^6.1.6"
"@mui/system" "^6.1.6"
"@mui/types" "^7.2.19"
"@mui/utils" "^6.1.6"
"@mui/material@^6.1.6", "@mui/material@^6.4.6":
version "6.4.8"
resolved "https://registry.npmjs.org/@mui/material/-/material-6.4.8.tgz"
integrity sha512-5S9UTjKZZBd9GfbcYh/nYfD9cv6OXmj5Y7NgKYfk7JcSoshp8/pW5zP4wecRiroBSZX8wcrywSgogpVNO+5W0Q==
dependencies:
"@babel/runtime" "^7.26.0"
"@mui/core-downloads-tracker" "^6.4.8"
"@mui/system" "^6.4.8"
"@mui/types" "~7.2.24"
"@mui/utils" "^6.4.8"
"@popperjs/core" "^2.11.8"
"@types/react-transition-group" "^4.4.11"
"@types/react-transition-group" "^4.4.12"
clsx "^2.1.1"
csstype "^3.1.3"
prop-types "^15.8.1"
react-is "^18.3.1"
react-is "^19.0.0"
react-transition-group "^4.4.5"
"@mui/private-theming@^6.1.6":
version "6.1.6"
resolved "https://registry.npmjs.org/@mui/private-theming/-/private-theming-6.1.6.tgz"
integrity sha512-ioAiFckaD/fJSnTrUMWgjl9HYBWt7ixCh7zZw7gDZ+Tae7NuprNV6QJK95EidDT7K0GetR2rU3kAeIR61Myttw==
"@mui/private-theming@^6.4.8":
version "6.4.8"
resolved "https://registry.npmjs.org/@mui/private-theming/-/private-theming-6.4.8.tgz"
integrity sha512-sWwQoNSn6elsPTAtSqCf+w5aaGoh7AASURNmpy+QTTD/zwJ0Jgwt0ZaaP6mXq2IcgHxYnYloM/+vJgHPMkRKTQ==
dependencies:
"@babel/runtime" "^7.26.0"
"@mui/utils" "^6.1.6"
"@mui/utils" "^6.4.8"
prop-types "^15.8.1"
"@mui/styled-engine@^6.1.6":
version "6.1.6"
resolved "https://registry.npmjs.org/@mui/styled-engine/-/styled-engine-6.1.6.tgz"
integrity sha512-I+yS1cSuSvHnZDBO7e7VHxTWpj+R7XlSZvTC4lS/OIbUNJOMMSd3UDP6V2sfwzAdmdDNBi7NGCRv2SZ6O9hGDA==
"@mui/styled-engine@^6.4.8":
version "6.4.8"
resolved "https://registry.npmjs.org/@mui/styled-engine/-/styled-engine-6.4.8.tgz"
integrity sha512-oyjx1b1FvUCI85ZMO4trrjNxGm90eLN3Ohy0AP/SqK5gWvRQg1677UjNf7t6iETOKAleHctJjuq0B3aXO2gtmw==
dependencies:
"@babel/runtime" "^7.26.0"
"@emotion/cache" "^11.13.1"
"@emotion/serialize" "^1.3.2"
"@emotion/cache" "^11.13.5"
"@emotion/serialize" "^1.3.3"
"@emotion/sheet" "^1.4.0"
csstype "^3.1.3"
prop-types "^15.8.1"
"@mui/system@^6.1.6":
version "6.1.6"
resolved "https://registry.npmjs.org/@mui/system/-/system-6.1.6.tgz"
integrity sha512-qOf1VUE9wK8syiB0BBCp82oNBAVPYdj4Trh+G1s+L+ImYiKlubWhhqlnvWt3xqMevR+D2h1CXzA1vhX2FvA+VQ==
"@mui/system@^6.4.8":
version "6.4.8"
resolved "https://registry.npmjs.org/@mui/system/-/system-6.4.8.tgz"
integrity sha512-gV7iBHoqlsIenU2BP0wq14BefRoZcASZ/4LeyuQglayBl+DfLX5rEd3EYR3J409V2EZpR0NOM1LATAGlNk2cyA==
dependencies:
"@babel/runtime" "^7.26.0"
"@mui/private-theming" "^6.1.6"
"@mui/styled-engine" "^6.1.6"
"@mui/types" "^7.2.19"
"@mui/utils" "^6.1.6"
"@mui/private-theming" "^6.4.8"
"@mui/styled-engine" "^6.4.8"
"@mui/types" "~7.2.24"
"@mui/utils" "^6.4.8"
clsx "^2.1.1"
csstype "^3.1.3"
prop-types "^15.8.1"
"@mui/types@^7.2.14", "@mui/types@^7.2.15", "@mui/types@^7.2.19":
version "7.2.19"
resolved "https://registry.npmjs.org/@mui/types/-/types-7.2.19.tgz"
integrity sha512-6XpZEM/Q3epK9RN8ENoXuygnqUQxE+siN/6rGRi2iwJPgBUR25mphYQ9ZI87plGh58YoZ5pp40bFvKYOCDJ3tA==
"@mui/types@^7.2.14", "@mui/types@^7.2.15", "@mui/types@~7.2.24":
version "7.2.24"
resolved "https://registry.npmjs.org/@mui/types/-/types-7.2.24.tgz"
integrity sha512-3c8tRt/CbWZ+pEg7QpSwbdxOk36EfmhbKf6AGZsD1EcLDLTSZoxxJ86FVtcjxvjuhdyBiWKSTGZFaXCnidO2kw==
"@mui/utils@^5.15.14":
version "5.16.6"
@ -1054,17 +1061,17 @@
prop-types "^15.8.1"
react-is "^18.3.1"
"@mui/utils@^6.1.6":
version "6.1.6"
resolved "https://registry.npmjs.org/@mui/utils/-/utils-6.1.6.tgz"
integrity sha512-sBS6D9mJECtELASLM+18WUcXF6RH3zNxBRFeyCRg8wad6NbyNrdxLuwK+Ikvc38sTZwBzAz691HmSofLqHd9sQ==
"@mui/utils@^6.1.6", "@mui/utils@^6.4.8":
version "6.4.8"
resolved "https://registry.npmjs.org/@mui/utils/-/utils-6.4.8.tgz"
integrity sha512-C86gfiZ5BfZ51KqzqoHi1WuuM2QdSKoFhbkZeAfQRB+jCc4YNhhj11UXFVMMsqBgZ+Zy8IHNJW3M9Wj/LOwRXQ==
dependencies:
"@babel/runtime" "^7.26.0"
"@mui/types" "^7.2.19"
"@types/prop-types" "^15.7.13"
"@mui/types" "~7.2.24"
"@types/prop-types" "^15.7.14"
clsx "^2.1.1"
prop-types "^15.8.1"
react-is "^18.3.1"
react-is "^19.0.0"
"@nodelib/fs.scandir@2.1.5":
version "2.1.5"
@ -1677,10 +1684,10 @@
resolved "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.2.tgz"
integrity sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==
"@types/prop-types@*", "@types/prop-types@^15.7.12", "@types/prop-types@^15.7.13":
version "15.7.13"
resolved "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.13.tgz"
integrity sha512-hCZTSvwbzWGvhqxp/RqVqwU999pBf2vp7hzIjiYOsl8wqOmUxkQ6ddw1cV3l8811+kdUFus/q4d1Y3E3SyEifA==
"@types/prop-types@*", "@types/prop-types@^15.7.12", "@types/prop-types@^15.7.14":
version "15.7.14"
resolved "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.14.tgz"
integrity sha512-gNMvNH49DJ7OJYv+KAKn0Xp45p8PLl6zo2YnvDIbTd4J6MER2BmWN49TG7n9LvkyihINxeKW8+3bfS2yDC9dzQ==
"@types/react-dom@*", "@types/react-dom@^18.3.1":
version "18.3.1"
@ -1696,12 +1703,10 @@
dependencies:
"@types/react" "*"
"@types/react-transition-group@^4.4.11":
version "4.4.11"
resolved "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.11.tgz"
integrity sha512-RM05tAniPZ5DZPzzNFP+DmrcOdD0efDUxMy3145oljWSl3x9ZV5vhme98gTxFrj2lhXvmGNnUiuDyJgY9IKkNA==
dependencies:
"@types/react" "*"
"@types/react-transition-group@^4.4.12":
version "4.4.12"
resolved "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.12.tgz"
integrity sha512-8TV6R3h2j7a91c+1DXdJi3Syo69zzIZbz7Lg5tORM5LEJG7X/E6a1V3drRyBRZq7/utz7A+c4OgYLiLcYGHG6w==
"@types/react@*", "@types/react@^16.8.0 || ^17.0.0 || ^18.0.0", "@types/react@^16.9.0 || ^17.0.0 || ^18.0.0", "@types/react@^17.0.0 || ^18.0.0", "@types/react@^17.0.0 || ^18.0.0 || ^19.0.0", "@types/react@^18.3.12", "@types/react@16 || 17 || 18":
version "18.3.12"
@ -2624,6 +2629,8 @@ fsevents@~2.3.2, fsevents@~2.3.3:
version "2.3.3"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
function-bind@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"
integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==
@ -3796,6 +3803,11 @@ react-is@^18.3.1:
resolved "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz"
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==
react-is@^19.0.0:
version "19.0.0"
resolved "https://registry.npmjs.org/react-is/-/react-is-19.0.0.tgz"
integrity sha512-H91OHcwjZsbq3ClIDHMzBShc1rotbfACdWENsmEf0IFvZ3FgGPtdHMcsv45bQ1hAbgdfiA8SnxTKfDS+x/8m2g==
react-leaflet@^4.2.1:
version "4.2.1"
resolved "https://registry.npmjs.org/react-leaflet/-/react-leaflet-4.2.1.tgz"