Refactor_Expenses #321
@ -5,6 +5,7 @@ import { useExpenseContext } from "../../pages/Expense/ExpensePage";
|
|||||||
import { formatDate, formatUTCToLocalTime } from "../../utils/dateUtils";
|
import { formatDate, formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||||
import Pagination from "../common/Pagination";
|
import Pagination from "../common/Pagination";
|
||||||
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
||||||
|
import { AppColorconfig, getColorNameFromHex } from "../../utils/appUtils";
|
||||||
|
|
||||||
const ExpenseList = () => {
|
const ExpenseList = () => {
|
||||||
const { setViewExpense,setExpenseModal } = useExpenseContext();
|
const { setViewExpense,setExpenseModal } = useExpenseContext();
|
||||||
@ -21,7 +22,7 @@ const ExpenseList = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const { data, isLoading, isError,isInitialLoading } = useExpenseList(2, currentPage, filter);
|
const { data, isLoading, isError,isInitialLoading } = useExpenseList(10, currentPage, filter);
|
||||||
if (isInitialLoading) return <div>Loading...</div>;
|
if (isInitialLoading) return <div>Loading...</div>;
|
||||||
const items = data.data ?? [];
|
const items = data.data ?? [];
|
||||||
const totalPages = data?.totalPages ?? 1;
|
const totalPages = data?.totalPages ?? 1;
|
||||||
@ -173,16 +174,10 @@ const ExpenseList = () => {
|
|||||||
<td className="d-none d-md-table-cell text-end"><i className='bx bx-rupee b-xs'></i>{expense.amount}</td>
|
<td className="d-none d-md-table-cell text-end"><i className='bx bx-rupee b-xs'></i>{expense.amount}</td>
|
||||||
<td>
|
<td>
|
||||||
<span
|
<span
|
||||||
style={{
|
className={`badge bg-label-${getColorNameFromHex(expense.status.color) || 'secondary'}`}
|
||||||
backgroundColor: expense.status?.color || "#e2e3e5",
|
|
||||||
color: "#ffff",
|
|
||||||
padding: "2px 8px",
|
|
||||||
borderRadius: "0.375rem",
|
|
||||||
fontSize: "0.75rem",
|
|
||||||
fontWeight: 500,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{expense.status?.name || "Unknown"}
|
|
||||||
|
{expense.status?.name || "Unknown"}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td >
|
<td >
|
||||||
|
@ -3,39 +3,34 @@ export const formatFileSize=(bytes)=> {
|
|||||||
else if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + " KB";
|
else if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + " KB";
|
||||||
else return (bytes / (1024 * 1024)).toFixed(2) + " MB";
|
else return (bytes / (1024 * 1024)).toFixed(2) + " MB";
|
||||||
}
|
}
|
||||||
export const getExpenseIcon = (type) => {
|
export const AppColorconfig = {
|
||||||
switch (type.toLowerCase()) {
|
colors: {
|
||||||
case 'vendor/supplier payments':
|
primary: '#696cff',
|
||||||
return 'bx-briefcase'; // Business-related
|
secondary: '#8592a3',
|
||||||
case 'transport':
|
success: '#71dd37',
|
||||||
return 'bx-car'; // Vehicle or logistics
|
info: '#03c3ec',
|
||||||
case 'compliance & safety':
|
warning: '#ffab00',
|
||||||
return 'bx-shield-quarter'; // Security/safety
|
danger: '#ff3e1d',
|
||||||
case 'mobilization':
|
dark: '#233446',
|
||||||
return 'bx-building-house'; // Setup / site infra
|
black: '#000',
|
||||||
case 'procurement':
|
white: '#fff',
|
||||||
return 'bx-package'; // Box/package/supplies
|
cardColor: '#fff',
|
||||||
case 'maintenance & utilities':
|
bodyBg: '#f5f5f9',
|
||||||
return 'bx-wrench'; // Repair/maintenance
|
bodyColor: '#697a8d',
|
||||||
case 'travelling':
|
headingColor: '#566a7f',
|
||||||
return 'bx-plane'; // Personnel delivery
|
textMuted: '#a1acb8',
|
||||||
case 'employee welfare':
|
borderColor: '#eceef1'
|
||||||
return 'bx-user-heart'; // Welfare / people
|
|
||||||
default:
|
|
||||||
return 'bx-folder'; // Fallback icon
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const getPaymentModeIcon = (mode) => {
|
export const getColorNameFromHex = (hex) => {
|
||||||
switch (mode.toLowerCase()) {
|
const normalizedHex = hex?.replace(/'/g, '').toLowerCase();
|
||||||
case 'cash':
|
const colors = AppColorconfig.colors;
|
||||||
return 'bx-money'; // Cash/coins
|
|
||||||
case 'upi':
|
for (const [name, value] of Object.entries(colors)) {
|
||||||
return 'bx-mobile-alt'; // Mobile payment
|
if (value.toLowerCase() === normalizedHex) {
|
||||||
case 'cheque':
|
return name;
|
||||||
return 'bx-receipt'; // Paper receipt
|
}
|
||||||
case 'netbanking':
|
|
||||||
return 'bx-globe'; // Online/internet
|
|
||||||
default:
|
|
||||||
return 'bx-credit-card'; // Generic fallback
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null; //
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user