added utils fun that has code convert into bootstrap color like priamery.

This commit is contained in:
pramod mahajan 2025-07-23 11:44:59 +05:30
parent 182ae887d8
commit d78f90f700
3 changed files with 33 additions and 43 deletions

View File

@ -5,6 +5,7 @@ import { useExpenseContext } from "../../pages/Expense/ExpensePage";
import { formatDate, formatUTCToLocalTime } from "../../utils/dateUtils";
import Pagination from "../common/Pagination";
import { ITEMS_PER_PAGE } from "../../utils/constants";
import { AppColorconfig, getColorNameFromHex } from "../../utils/appUtils";
const ExpenseList = () => {
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>;
const items = data.data ?? [];
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>
<span
style={{
backgroundColor: expense.status?.color || "#e2e3e5",
color: "#ffff",
padding: "2px 8px",
borderRadius: "0.375rem",
fontSize: "0.75rem",
fontWeight: 500,
}}
className={`badge bg-label-${getColorNameFromHex(expense.status.color) || 'secondary'}`}
>
{expense.status?.name || "Unknown"}
{expense.status?.name || "Unknown"}
</span>
</td>
<td >

View File

@ -257,7 +257,7 @@ const ViewExpense = ({ ExpenseId }) => {
fontSize: "0.85rem",
}}
>
{status.displayName || status.name}
{status.displayName || status.name}
</button>
))}
</div>

View File

@ -3,39 +3,34 @@ export const formatFileSize=(bytes)=> {
else if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + " KB";
else return (bytes / (1024 * 1024)).toFixed(2) + " MB";
}
export const getExpenseIcon = (type) => {
switch (type.toLowerCase()) {
case 'vendor/supplier payments':
return 'bx-briefcase'; // Business-related
case 'transport':
return 'bx-car'; // Vehicle or logistics
case 'compliance & safety':
return 'bx-shield-quarter'; // Security/safety
case 'mobilization':
return 'bx-building-house'; // Setup / site infra
case 'procurement':
return 'bx-package'; // Box/package/supplies
case 'maintenance & utilities':
return 'bx-wrench'; // Repair/maintenance
case 'travelling':
return 'bx-plane'; // Personnel delivery
case 'employee welfare':
return 'bx-user-heart'; // Welfare / people
default:
return 'bx-folder'; // Fallback icon
export const AppColorconfig = {
colors: {
primary: '#696cff',
secondary: '#8592a3',
success: '#71dd37',
info: '#03c3ec',
warning: '#ffab00',
danger: '#ff3e1d',
dark: '#233446',
black: '#000',
white: '#fff',
cardColor: '#fff',
bodyBg: '#f5f5f9',
bodyColor: '#697a8d',
headingColor: '#566a7f',
textMuted: '#a1acb8',
borderColor: '#eceef1'
}
};
export const getPaymentModeIcon = (mode) => {
switch (mode.toLowerCase()) {
case 'cash':
return 'bx-money'; // Cash/coins
case 'upi':
return 'bx-mobile-alt'; // Mobile payment
case 'cheque':
return 'bx-receipt'; // Paper receipt
case 'netbanking':
return 'bx-globe'; // Online/internet
default:
return 'bx-credit-card'; // Generic fallback
export const getColorNameFromHex = (hex) => {
const normalizedHex = hex?.replace(/'/g, '').toLowerCase();
const colors = AppColorconfig.colors;
for (const [name, value] of Object.entries(colors)) {
if (value.toLowerCase() === normalizedHex) {
return name;
}
}
return null; //
};