Compare commits
96 Commits
main
...
Feature#77
Author | SHA1 | Date | |
---|---|---|---|
786072777e | |||
e69ea6462a | |||
cba91f0025 | |||
7480f9c1d8 | |||
8a3a0dc483 | |||
ede1b85c1c | |||
a0e063ac9a | |||
f1b652ace1 | |||
5988089b49 | |||
5a2eb1894d | |||
fb4384b58d | |||
e5d0fcb8df | |||
1d93ee104f | |||
0a1d2e8459 | |||
eb08519c6d | |||
41d3230325 | |||
4123a5ca1e | |||
678fd50768 | |||
ee6c8069d0 | |||
7b39ee59f4 | |||
3d847444bb | |||
303420409c | |||
00d91ad8dd | |||
fb865cbe4f | |||
d34fadfc6d | |||
3424c79594 | |||
dce477f6cd | |||
b1fa01e2c9 | |||
007b08f335 | |||
9bc5f84c83 | |||
0944a8d78c | |||
22ef95d6b7 | |||
6b830c5063 | |||
ca2ed451d8 | |||
d78f90f700 | |||
182ae887d8 | |||
24d7bd52d2 | |||
2122d7e959 | |||
e388906b80 | |||
e1f5bb8baf | |||
9df4b20ff0 | |||
bd1dabdd68 | |||
945d5b1546 | |||
ce66c137aa | |||
fca24d4081 | |||
977ab05e61 | |||
bc6e66b25c | |||
e5d97e3105 | |||
b1586a8cfb | |||
de7ca102fd | |||
2f3fd2dacf | |||
92f5566fce | |||
f404320179 | |||
a11edec002 | |||
bd308a57dd | |||
8a237eb4bf | |||
f44bba5083 | |||
034099c23a | |||
c14fdae4f7 | |||
9a1fba347a | |||
eaf49b513d | |||
719c916af3 | |||
23ee4a83d1 | |||
cf719205d9 | |||
195a88c1e4 | |||
f4f8a61445 | |||
7b2a4ea834 | |||
de689b0af8 | |||
289a732600 | |||
5e93798d01 | |||
209e1341de | |||
ab737a80d4 | |||
f30430c254 | |||
f6e18e0482 | |||
fa9736b620 | |||
a23ca8a412 | |||
00b3a3420e | |||
6c276a3c8d | |||
5209b78df7 | |||
5f6a00f9f2 | |||
9bbd2dd014 | |||
280715d62f | |||
2ab2a1d8bd | |||
dbdb7a1299 | |||
a4f3a6f0ed | |||
e5f528547c | |||
5c4a5c0620 | |||
364d67647f | |||
8b0c62ff70 | |||
2a3a4b91fe | |||
e49145914f | |||
e379f0e348 | |||
7024413710 | |||
4427d71980 | |||
295e63ec7f | |||
037359cdfc |
@ -27,6 +27,7 @@
|
||||
<link rel="stylesheet" href="/assets/vendor/css/theme-default.css" class="template-customizer-theme-css" />
|
||||
<link rel="stylesheet" href="/assets/css/core-extend.css" />
|
||||
<link rel="stylesheet" href="/assets/css/default.css" />
|
||||
<link rel="stylesheet" href="/assets/css/skeleton.css" />
|
||||
|
||||
<link rel="stylesheet" href="/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />
|
||||
|
||||
|
32
public/assets/css/skeleton.css
vendored
Normal file
32
public/assets/css/skeleton.css
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/* skeleton.css */
|
||||
.skeleton {
|
||||
background-color: #e2e8f0; /* Tailwind's gray-300 */
|
||||
border-radius: 0.25rem; /* Tailwind's rounded */
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.skeleton::after {
|
||||
content: '';
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0; left: -150px;
|
||||
height: 100%;
|
||||
width: 150px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
rgba(255, 255, 255, 0.4),
|
||||
transparent
|
||||
);
|
||||
animation: pulse 1.5s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0% {
|
||||
left: -150px;
|
||||
}
|
||||
100% {
|
||||
left: 100%;
|
||||
}
|
||||
}
|
326
src/components/Expenses/ExpenseList.jsx
Normal file
326
src/components/Expenses/ExpenseList.jsx
Normal file
@ -0,0 +1,326 @@
|
||||
import React, { useState } from "react";
|
||||
import { useDeleteExpense, useExpenseList } from "../../hooks/useExpense";
|
||||
import Avatar from "../common/Avatar";
|
||||
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";
|
||||
import { ExpenseTableSkeleton } from "./ExpenseSkeleton";
|
||||
import ConfirmModal from "../common/ConfirmModal";
|
||||
import { useProfile } from "../../hooks/useProfile";
|
||||
|
||||
const ExpenseList = ({filters}) => {
|
||||
const [deletingId, setDeletingId] = useState(null);
|
||||
const [IsDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||
const { setViewExpense, setManageExpenseModal } = useExpenseContext();
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const pageSize = 10;
|
||||
const { profile } = useProfile();
|
||||
|
||||
|
||||
const { mutate: DeleteExpense, isPending } = useDeleteExpense();
|
||||
const { data, isLoading, isError, isInitialLoading, error, isFetching } =
|
||||
useExpenseList(10, currentPage, filters);
|
||||
|
||||
const handleDelete = (id) => {
|
||||
setDeletingId(id);
|
||||
DeleteExpense(
|
||||
{ id },
|
||||
{
|
||||
onSettled: () => {
|
||||
setDeletingId(null);
|
||||
setIsDeleteModalOpen(false);
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
if (isInitialLoading) return <ExpenseTableSkeleton />;
|
||||
if (isError) return <div>{error}</div>;
|
||||
const items = data?.data ?? [];
|
||||
const totalPages = data?.totalPages ?? 1;
|
||||
const hasMore = currentPage < totalPages;
|
||||
|
||||
const paginate = (page) => {
|
||||
if (page >= 1 && page <= totalPages) {
|
||||
setCurrentPage(page);
|
||||
}
|
||||
};
|
||||
const STATUS_ORDER = [
|
||||
"Draft",
|
||||
"Review Pending",
|
||||
"Approval Pending",
|
||||
"Process Pending",
|
||||
"Processed",
|
||||
"Paid",
|
||||
"Rejected",
|
||||
];
|
||||
|
||||
const groupExpensesByDateAndStatus = (expenses) => {
|
||||
const grouped = {};
|
||||
|
||||
expenses.forEach((expense) => {
|
||||
const dateKey = expense.transactionDate.split("T")[0];
|
||||
if (!grouped[dateKey]) grouped[dateKey] = [];
|
||||
grouped[dateKey].push(expense);
|
||||
});
|
||||
|
||||
const sortedDates = Object.keys(grouped).sort(
|
||||
(a, b) => new Date(b) - new Date(a)
|
||||
);
|
||||
|
||||
return sortedDates.map((date) => ({
|
||||
date,
|
||||
expenses: grouped[date].sort((a, b) => {
|
||||
return (
|
||||
STATUS_ORDER.indexOf(a.status.name) -
|
||||
STATUS_ORDER.indexOf(b.status.name)
|
||||
);
|
||||
}),
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{IsDeleteModalOpen && (
|
||||
<div
|
||||
className={`modal fade ${IsDeleteModalOpen ? "show" : ""}`}
|
||||
tabIndex="-1"
|
||||
role="dialog"
|
||||
style={{
|
||||
display: IsDeleteModalOpen ? "block" : "none",
|
||||
backgroundColor: IsDeleteModalOpen
|
||||
? "rgba(0,0,0,0.5)"
|
||||
: "transparent",
|
||||
}}
|
||||
aria-hidden="false"
|
||||
>
|
||||
<ConfirmModal
|
||||
type={"delete"}
|
||||
header={"Delete Expense"}
|
||||
message={"Are you sure you want delete?"}
|
||||
onSubmit={handleDelete}
|
||||
onClose={() => setIsDeleteModalOpen(false)}
|
||||
loading={isPending}
|
||||
paramData={deletingId}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="card ">
|
||||
<div className="card-datatable table-responsive">
|
||||
<div
|
||||
id="DataTables_Table_0_wrapper"
|
||||
className="dataTables_wrapper no-footer px-2"
|
||||
>
|
||||
<table
|
||||
className="datatables-users table border-top dataTable no-footer dtr-column text-nowrap px-3"
|
||||
aria-describedby="DataTables_Table_0_info"
|
||||
id="horizontal-example"
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
{/* <th
|
||||
className="sorting sorting_desc"
|
||||
tabIndex="0"
|
||||
aria-controls="DataTables_Table_0"
|
||||
rowSpan="1"
|
||||
colSpan="2"
|
||||
aria-label="Date: activate to sort column ascending"
|
||||
aria-sort="descending"
|
||||
>
|
||||
<div className="text-start ms-6">Date Time</div>
|
||||
</th> */}
|
||||
<th
|
||||
className="sorting sorting_desc d-none d-sm-table-cell"
|
||||
tabIndex="0"
|
||||
aria-controls="DataTables_Table_0"
|
||||
rowSpan="1"
|
||||
colSpan="1"
|
||||
aria-label="Expense Type: activate to sort column ascending"
|
||||
aria-sort="descending"
|
||||
>
|
||||
<div className="text-start ms-5">Expense Type</div>
|
||||
</th>
|
||||
<th
|
||||
className="sorting sorting_desc d-table-cell"
|
||||
tabIndex="0"
|
||||
aria-controls="DataTables_Table_0"
|
||||
rowSpan="1"
|
||||
colSpan="1"
|
||||
aria-label="Payment Mode: activate to sort column ascending"
|
||||
aria-sort="descending"
|
||||
>
|
||||
<div className="text-start ">Payment Mode</div>
|
||||
</th>
|
||||
<th
|
||||
className="sorting sorting_desc d-table-cell"
|
||||
tabIndex="0"
|
||||
aria-controls="DataTables_Table_0"
|
||||
rowSpan="1"
|
||||
colSpan="1"
|
||||
aria-label="Paid By: activate to sort column ascending"
|
||||
aria-sort="descending"
|
||||
>
|
||||
<div className="text-start ms-5">Paid By</div>
|
||||
</th>
|
||||
<th
|
||||
className="sorting d-table-cell"
|
||||
tabIndex="0"
|
||||
aria-controls="DataTables_Table_0"
|
||||
rowSpan="1"
|
||||
colSpan="1"
|
||||
aria-label="Amount: activate to sort column ascending"
|
||||
>
|
||||
Amount
|
||||
</th>
|
||||
<th
|
||||
className="sorting"
|
||||
tabIndex="0"
|
||||
aria-controls="DataTables_Table_0"
|
||||
rowSpan="1"
|
||||
colSpan="1"
|
||||
aria-label="Status: activate to sort column ascending"
|
||||
>
|
||||
Status
|
||||
</th>
|
||||
<th
|
||||
className="sorting"
|
||||
tabIndex="0"
|
||||
aria-controls="DataTables_Table_0"
|
||||
rowSpan="1"
|
||||
colSpan="1"
|
||||
aria-label="Status: activate to sort column ascending"
|
||||
>
|
||||
Action
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody >
|
||||
{!isInitialLoading &&
|
||||
groupExpensesByDateAndStatus(items).map(
|
||||
({ date, expenses }) => (
|
||||
<>
|
||||
<tr key={`date-${date}`} className="tr-group text-dark">
|
||||
<td colSpan={7} className="text-start">
|
||||
<strong>{formatUTCToLocalTime(date)}</strong>
|
||||
</td>
|
||||
</tr> {expenses.map((expense) => (
|
||||
<tr key={expense.id} >
|
||||
<td className="text-start d-table-cell ms-5">
|
||||
{expense.expensesType?.name || "N/A"}
|
||||
</td>
|
||||
<td className="text-start d-table-cell ms-5">
|
||||
{expense.paymentMode?.name || "N/A"}
|
||||
</td>
|
||||
<td className="text-start d-table-cell ms-5">
|
||||
<div className="d-flex align-items-center">
|
||||
<Avatar
|
||||
size="xs"
|
||||
classAvatar="m-0"
|
||||
firstName={expense.paidBy?.firstName}
|
||||
lastName={expense.paidBy?.lastName}
|
||||
/>
|
||||
<span>
|
||||
{`${expense.paidBy?.firstName ?? ""} ${
|
||||
expense.paidBy?.lastName ?? ""
|
||||
}`.trim() || "N/A"}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="d-table-cell text-end">
|
||||
<i className="bx bx-rupee b-xs"></i>
|
||||
{expense?.amount}
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
className={`badge bg-label-${
|
||||
getColorNameFromHex(expense?.status?.color) ||
|
||||
"secondary"
|
||||
}`}
|
||||
>
|
||||
{expense.status?.displayName || "Unknown"}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div className="d-flex justify-content-center align-items-center gap-2">
|
||||
<span className="cursor-pointer">
|
||||
<i
|
||||
className="bx bx-show text-primary"
|
||||
onClick={() =>
|
||||
setViewExpense({
|
||||
expenseId: expense.id,
|
||||
view: true,
|
||||
})
|
||||
}
|
||||
></i>
|
||||
</span>
|
||||
|
||||
<span className="cursor-pointer">
|
||||
{(expense.status.name === "Draft" ||
|
||||
expense.status.name === "Rejected") &&
|
||||
expense.createdBy.id ===
|
||||
profile?.employeeInfo.id ? (
|
||||
<i
|
||||
className="bx bx-edit bx-sm text-secondary"
|
||||
onClick={() =>
|
||||
setManageExpenseModal({
|
||||
IsOpen: true,
|
||||
expenseId: expense.id,
|
||||
})
|
||||
}
|
||||
></i>
|
||||
) : (
|
||||
<i
|
||||
className="bx bx-edit bx-sm"
|
||||
style={{ visibility: "hidden" }}
|
||||
></i>
|
||||
)}
|
||||
</span>
|
||||
|
||||
<span className="cursor-pointer">
|
||||
{expense.status.name === "Draft" ? (
|
||||
<i
|
||||
className="bx bx-trash bx-sm text-danger"
|
||||
onClick={() => {
|
||||
setIsDeleteModalOpen(true);
|
||||
setDeletingId(expense.id);
|
||||
}}
|
||||
></i>
|
||||
) : (
|
||||
<i
|
||||
className="bx bx-trash bx-sm"
|
||||
style={{ visibility: "hidden" }}
|
||||
></i>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</>
|
||||
)
|
||||
)}
|
||||
|
||||
{!isInitialLoading && items.length === 0 && <tr rowSpan={8} style={{height:"200px"}}>
|
||||
<td colSpan={8}>
|
||||
No Expnese Found
|
||||
</td>
|
||||
</tr>}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{!isInitialLoading && items.length > 0 && (
|
||||
<Pagination
|
||||
currentPage={currentPage}
|
||||
totalPages={totalPages}
|
||||
onPageChange={paginate}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ExpenseList;
|
111
src/components/Expenses/ExpenseSchema.js
Normal file
111
src/components/Expenses/ExpenseSchema.js
Normal file
@ -0,0 +1,111 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
const ALLOWED_TYPES = [
|
||||
"application/pdf",
|
||||
"image/png",
|
||||
"image/jpg",
|
||||
"image/jpeg",
|
||||
];
|
||||
|
||||
|
||||
export const ExpenseSchema = (expenseTypes) => {
|
||||
return z
|
||||
.object({
|
||||
projectId: z.string().min(1, { message: "Project is required" }),
|
||||
expensesTypeId: z.string().min(1, { message: "Expense type is required" }),
|
||||
paymentModeId: z.string().min(1, { message: "Payment mode is required" }),
|
||||
paidById: z.string().min(1, { message: "Employee name is required" }),
|
||||
transactionDate: z.string().min(1, { message: "Date is required" }),
|
||||
transactionId: z.string().optional(),
|
||||
description: z.string().min(1, { message: "Description is required" }),
|
||||
location: z.string().min(1, { message: "Location is required" }),
|
||||
supplerName: z.string().min(1, { message: "Supplier name is required" }),
|
||||
amount: z
|
||||
.coerce
|
||||
.number({ invalid_type_error: "Amount is required and must be a number" })
|
||||
.min(1, "Amount must be Enter")
|
||||
.refine((val) => /^\d+(\.\d{1,2})?$/.test(val.toString()), {
|
||||
message: "Amount must have at most 2 decimal places",
|
||||
}),
|
||||
noOfPersons: z.coerce
|
||||
.number()
|
||||
.optional(),
|
||||
billAttachments: z
|
||||
.array(
|
||||
z.object({
|
||||
fileName: z.string().min(1, { message: "Filename is required" }),
|
||||
base64Data: z.string().nullable(),
|
||||
contentType: z.string().refine((val) => ALLOWED_TYPES.includes(val), {
|
||||
message: "Only PDF, PNG, JPG, or JPEG files are allowed",
|
||||
}),
|
||||
documentId:z.string().optional(),
|
||||
fileSize: z.number().max(MAX_FILE_SIZE, {
|
||||
message: "File size must be less than or equal to 5MB",
|
||||
}),
|
||||
description: z.string().optional(),
|
||||
isActive:z.boolean().default(true)
|
||||
})
|
||||
)
|
||||
.nonempty({ message: "At least one file attachment is required" }),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
return !data.projectId || (data.paidById && data.paidById.trim() !== "");
|
||||
},
|
||||
{
|
||||
message: "Please select who paid (employee)",
|
||||
path: ["paidById"],
|
||||
}
|
||||
)
|
||||
.superRefine((data, ctx) => {
|
||||
const expenseType = expenseTypes.find((et) => et.id === data.expensesTypeId);
|
||||
if (expenseType?.noOfPersonsRequired && (!data.noOfPersons || data.noOfPersons < 1)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "No. of Persons is required and must be at least 1",
|
||||
path: ["noOfPersons"],
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const defaultExpense = {
|
||||
projectId: "",
|
||||
expensesTypeId: "",
|
||||
paymentModeId: "",
|
||||
paidById: "",
|
||||
transactionDate: "",
|
||||
transactionId: "",
|
||||
description: "",
|
||||
location: "",
|
||||
supplerName: "",
|
||||
amount: "",
|
||||
noOfPersons: "",
|
||||
billAttachments: [],
|
||||
}
|
||||
|
||||
export const ActionSchema = z.object({
|
||||
comment : z.string().min(1,{message:"Please leave comment"}),
|
||||
selectedStatus: z.string().min(1, { message: "Please select a status" }),
|
||||
})
|
||||
|
||||
|
||||
export const SearchSchema = z.object({
|
||||
projectIds: z.array(z.string()).optional(),
|
||||
statusIds: z.array(z.string()).optional(),
|
||||
createdByIds: z.array(z.string()).optional(),
|
||||
paidById: z.array(z.string()).optional(),
|
||||
startDate: z.string().optional(),
|
||||
endDate: z.string().optional(),
|
||||
|
||||
});
|
||||
|
||||
export const defaultFilter = {
|
||||
projectIds:[],
|
||||
statusIds:[],
|
||||
createdByIds:[],
|
||||
paidById:[],
|
||||
startDate:null,
|
||||
endDate:null
|
||||
}
|
224
src/components/Expenses/ExpenseSkeleton.jsx
Normal file
224
src/components/Expenses/ExpenseSkeleton.jsx
Normal file
@ -0,0 +1,224 @@
|
||||
import React from "react";
|
||||
|
||||
|
||||
const SkeletonLine = ({ height = 20, width = "100%", className = "" }) => (
|
||||
<div
|
||||
className={`skeleton mb-2 ${className}`}
|
||||
style={{
|
||||
height,
|
||||
width,
|
||||
}}
|
||||
></div>
|
||||
);
|
||||
|
||||
|
||||
const ExpenseSkeleton = () => {
|
||||
return (
|
||||
<div className="container p-3">
|
||||
<div className="d-flex justify-content-center">
|
||||
<SkeletonLine height={20} width="200px" />
|
||||
</div>
|
||||
|
||||
{[...Array(5)].map((_, idx) => (
|
||||
<div className="row my-2" key={idx}>
|
||||
<div className="col-md-6">
|
||||
<SkeletonLine />
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<SkeletonLine />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div className="row my-2">
|
||||
<div className="col-md-12">
|
||||
<SkeletonLine height={60} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row my-2">
|
||||
<div className="col-md-12">
|
||||
<SkeletonLine height={120} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="d-flex justify-content-center gap-2 mt-3">
|
||||
<SkeletonLine height={35} width="100px" />
|
||||
<SkeletonLine height={35} width="100px" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ExpenseSkeleton;
|
||||
|
||||
|
||||
|
||||
|
||||
export const ExpenseDetailsSkeleton = () => {
|
||||
return (
|
||||
<div className="container px-3">
|
||||
<div className="row mb-3">
|
||||
<div className="d-flex justify-content-center mb-3">
|
||||
<SkeletonLine height={20} width="180px" className="mb-2" />
|
||||
</div>
|
||||
|
||||
{[...Array(3)].map((_, i) => (
|
||||
<div className="col-12 col-md-4 mb-3" key={`row-1-${i}`}>
|
||||
<SkeletonLine height={14} className="mb-1" />
|
||||
<SkeletonLine />
|
||||
</div>
|
||||
))}
|
||||
|
||||
{[...Array(6)].map((_, i) => (
|
||||
<div className="col-12 col-md-4 mb-3" key={`row-2-${i}`}>
|
||||
<SkeletonLine height={14} className="mb-1" />
|
||||
<SkeletonLine />
|
||||
</div>
|
||||
))}
|
||||
|
||||
|
||||
|
||||
<div className="col-12 my-2">
|
||||
<SkeletonLine height={14} width="100px" className="mb-2" />
|
||||
{[...Array(2)].map((_, i) => (
|
||||
<div
|
||||
className="list-group-item d-flex align-items-center mb-2"
|
||||
key={i}
|
||||
>
|
||||
<div
|
||||
className="rounded me-2"
|
||||
style={{
|
||||
height: "50px",
|
||||
width: "80px",
|
||||
backgroundColor: "#dcdcdc",
|
||||
borderRadius: "4px",
|
||||
}}
|
||||
/>
|
||||
<div className="w-100">
|
||||
<SkeletonLine height={14} width="60%" className="mb-1" />
|
||||
<SkeletonLine height={14} width="20%" />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<hr className="divider my-1" />
|
||||
|
||||
<div className="col-12 mb-3">
|
||||
<SkeletonLine height={14} width="80px" className="mb-1" />
|
||||
<SkeletonLine height={60} className="mb-2" />
|
||||
<div className="d-flex gap-2 flex-wrap">
|
||||
{[...Array(2)].map((_, i) => (
|
||||
<SkeletonLine
|
||||
key={i}
|
||||
height={30}
|
||||
width="100px"
|
||||
className="rounded"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
const SkeletonCell = ({ width = "100%", height = 20, className = "", style = {} }) => (
|
||||
<div
|
||||
className={`skeleton ${className}`}
|
||||
style={{
|
||||
width,
|
||||
height,
|
||||
borderRadius: 4,
|
||||
...style,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
export const ExpenseTableSkeleton = ({ groups = 3, rowsPerGroup = 3 }) => {
|
||||
return (
|
||||
<div className="card px-2">
|
||||
<table
|
||||
className="card-body table border-top dataTable no-footer dtr-column text-nowrap"
|
||||
aria-describedby="DataTables_Table_0_info"
|
||||
id="horizontal-example"
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="d-none d-sm-table-cell">
|
||||
<div className="text-start ms-5">Expense Type</div>
|
||||
</th>
|
||||
<th className="d-none d-sm-table-cell">
|
||||
<div className="text-start ms-5">Payment Mode</div>
|
||||
</th>
|
||||
<th className="d-none d-sm-table-cell">Paid By</th>
|
||||
<th className="d-none d-md-table-cell">Amount</th>
|
||||
<th>Status</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{[...Array(groups)].map((_, groupIdx) => (
|
||||
<React.Fragment key={`group-${groupIdx}`}>
|
||||
{/* Fake Date Group Header Row */}
|
||||
<tr className="bg-light">
|
||||
<td colSpan={8}>
|
||||
<SkeletonCell width="150px" height={20} />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{/* Rows under this group */}
|
||||
{[...Array(rowsPerGroup)].map((__, rowIdx) => (
|
||||
<tr key={`row-${groupIdx}-${rowIdx}`} className={rowIdx % 2 === 0 ? "odd" : "even"}>
|
||||
{/* Expense Type */}
|
||||
<td className="text-start d-none d-sm-table-cell ms-5">
|
||||
<SkeletonCell width="90px" height={16} />
|
||||
</td>
|
||||
|
||||
{/* Payment Mode */}
|
||||
<td className="text-start d-none d-sm-table-cell ms-5">
|
||||
<SkeletonCell width="90px" height={16} />
|
||||
</td>
|
||||
|
||||
{/* Paid By (Avatar + name) */}
|
||||
<td className="text-start d-none d-sm-table-cell ms-5">
|
||||
<div className="d-flex align-items-center gap-2">
|
||||
<SkeletonCell width="30px" height={30} className="rounded-circle" />
|
||||
<SkeletonCell width="80px" height={16} />
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* Amount */}
|
||||
<td className="d-none d-md-table-cell text-end">
|
||||
<SkeletonCell width="60px" height={16} />
|
||||
</td>
|
||||
|
||||
{/* Status */}
|
||||
<td>
|
||||
<SkeletonCell width="80px" height={22} className="rounded" />
|
||||
</td>
|
||||
|
||||
{/* Action */}
|
||||
<td>
|
||||
<div className="d-flex justify-content-center align-items-center gap-2">
|
||||
{[...Array(3)].map((__, i) => (
|
||||
<SkeletonCell
|
||||
key={i}
|
||||
width={20}
|
||||
height={20}
|
||||
className="rounded"
|
||||
style={{ display: "inline-block" }}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
};
|
553
src/components/Expenses/ManageExpense.jsx
Normal file
553
src/components/Expenses/ManageExpense.jsx
Normal file
@ -0,0 +1,553 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { defaultExpense, ExpenseSchema } from "./ExpenseSchema";
|
||||
import { formatFileSize } from "../../utils/appUtils";
|
||||
import { useProjectName } from "../../hooks/useProjects";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { changeMaster } from "../../slices/localVariablesSlice";
|
||||
import useMaster, {
|
||||
useExpenseStatus,
|
||||
useExpenseType,
|
||||
usePaymentMode,
|
||||
} from "../../hooks/masterHook/useMaster";
|
||||
import {
|
||||
useEmployeesAllOrByProjectId,
|
||||
useEmployeesByProject,
|
||||
} from "../../hooks/useEmployees";
|
||||
import Avatar from "../common/Avatar";
|
||||
import {
|
||||
useCreateExpnse,
|
||||
useExpense,
|
||||
useUpdateExpense,
|
||||
} from "../../hooks/useExpense";
|
||||
import ExpenseSkeleton from "./ExpenseSkeleton";
|
||||
|
||||
const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
|
||||
const {
|
||||
data,
|
||||
isLoading,
|
||||
error: ExpenseErrorLoad,
|
||||
} = useExpense(expenseToEdit);
|
||||
const [ExpenseType, setExpenseType] = useState();
|
||||
const dispatch = useDispatch();
|
||||
const {
|
||||
ExpenseTypes,
|
||||
loading: ExpenseLoading,
|
||||
error: ExpenseError,
|
||||
} = useExpenseType();
|
||||
const schema = ExpenseSchema(ExpenseTypes);
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
watch,
|
||||
setValue,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: defaultExpense,
|
||||
});
|
||||
|
||||
const selectedproject = watch("projectId");
|
||||
const selectedProject = useSelector(
|
||||
(store) => store.localVariables.projectId
|
||||
);
|
||||
const { projectNames, loading: projectLoading, error } = useProjectName();
|
||||
|
||||
const {
|
||||
PaymentModes,
|
||||
loading: PaymentModeLoading,
|
||||
error: PaymentModeError,
|
||||
} = usePaymentMode();
|
||||
const {
|
||||
ExpenseStatus,
|
||||
loading: StatusLoadding,
|
||||
error: stausError,
|
||||
} = useExpenseStatus();
|
||||
const {
|
||||
employees,
|
||||
loading: EmpLoading,
|
||||
error: EmpError,
|
||||
} = useEmployeesByProject(selectedproject);
|
||||
|
||||
const files = watch("billAttachments");
|
||||
const onFileChange = async (e) => {
|
||||
const newFiles = Array.from(e.target.files);
|
||||
if (newFiles.length === 0) return;
|
||||
|
||||
const existingFiles = watch("billAttachments") || [];
|
||||
|
||||
const parsedFiles = await Promise.all(
|
||||
newFiles.map(async (file) => {
|
||||
const base64Data = await toBase64(file);
|
||||
return {
|
||||
fileName: file.name,
|
||||
base64Data,
|
||||
contentType: file.type,
|
||||
fileSize: file.size,
|
||||
description: "",
|
||||
isActive:true
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
const combinedFiles = [
|
||||
...existingFiles,
|
||||
...parsedFiles.filter(
|
||||
(newFile) =>
|
||||
!existingFiles.some(
|
||||
(f) =>
|
||||
f.fileName === newFile.fileName && f.fileSize === newFile.fileSize
|
||||
)
|
||||
),
|
||||
];
|
||||
|
||||
setValue("billAttachments", combinedFiles, {
|
||||
shouldDirty: true,
|
||||
shouldValidate: true,
|
||||
});
|
||||
};
|
||||
|
||||
const toBase64 = (file) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = () => resolve(reader.result.split(",")[1]);
|
||||
reader.onerror = (error) => reject(error);
|
||||
});
|
||||
const removeFile = (index) => {
|
||||
if (expenseToEdit) {
|
||||
const newFiles = files.map((file, i) => {
|
||||
if (file.documentId !== index) return file;
|
||||
return {
|
||||
...file,
|
||||
isActive: false,
|
||||
};
|
||||
});
|
||||
setValue("billAttachments", newFiles, { shouldValidate: true });
|
||||
} else {
|
||||
const newFiles = files.filter((_, i) => i !== index);
|
||||
setValue("billAttachments", newFiles, { shouldValidate: true });
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (expenseToEdit && data && employees) {
|
||||
reset({
|
||||
projectId: data.project.id || "",
|
||||
expensesTypeId: data.expensesType.id || "",
|
||||
paymentModeId: data.paymentMode.id || "",
|
||||
paidById: data.paidBy.id || "",
|
||||
transactionDate: data.transactionDate?.slice(0, 10) || "",
|
||||
transactionId: data.transactionId || "",
|
||||
description: data.description || "",
|
||||
location: data.location || "",
|
||||
supplerName: data.supplerName || "",
|
||||
amount: data.amount || "",
|
||||
noOfPersons: data.noOfPersons || "",
|
||||
billAttachments: data.documents
|
||||
? data.documents.map((doc) => ({
|
||||
fileName: doc.fileName,
|
||||
base64Data: null,
|
||||
contentType: doc.contentType,
|
||||
documentId: doc.documentId,
|
||||
fileSize: 0,
|
||||
description: "",
|
||||
preSignedUrl: doc.preSignedUrl,
|
||||
isActive: doc.isActive ?? true,
|
||||
}))
|
||||
: [],
|
||||
});
|
||||
}
|
||||
}, [data, reset, employees]);
|
||||
const { mutate: ExpenseUpdate, isPending } = useUpdateExpense(() =>
|
||||
handleClose()
|
||||
);
|
||||
const { mutate: CreateExpense, isPending: createPending } = useCreateExpnse(
|
||||
() => {
|
||||
handleClose();
|
||||
}
|
||||
);
|
||||
const onSubmit = (payload) => {
|
||||
debugger
|
||||
if (expenseToEdit) {
|
||||
const editPayload = { ...payload, id: data.id };
|
||||
ExpenseUpdate({ id: data.id, payload: editPayload });
|
||||
} else {
|
||||
CreateExpense(payload);
|
||||
}
|
||||
};
|
||||
const ExpenseTypeId = watch("expensesTypeId");
|
||||
|
||||
useEffect(() => {
|
||||
setExpenseType(ExpenseTypes?.find((type) => type.id === ExpenseTypeId));
|
||||
}, [ExpenseTypeId]);
|
||||
|
||||
const handleClose = () => {
|
||||
reset();
|
||||
closeModal();
|
||||
};
|
||||
if (
|
||||
StatusLoadding ||
|
||||
projectLoading ||
|
||||
ExpenseLoading ||
|
||||
isLoading
|
||||
)
|
||||
return <ExpenseSkeleton />;
|
||||
return (
|
||||
<div className="container p-3">
|
||||
<h5 className="m-0">
|
||||
{expenseToEdit ? "Update Expense " : "Create New Expense"}
|
||||
</h5>
|
||||
<form id="expenseForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="row my-2">
|
||||
<div className="col-md-6">
|
||||
<label htmlFor="projectId" className="form-label">
|
||||
Select Project
|
||||
</label>
|
||||
<select
|
||||
className="form-select form-select-sm"
|
||||
{...register("projectId")}
|
||||
>
|
||||
<option value="">Select Project</option>
|
||||
{projectLoading ? (
|
||||
<option>Loading...</option>
|
||||
) : (
|
||||
projectNames?.map((project) => (
|
||||
<option key={project.id} value={project.id}>
|
||||
{project.name}
|
||||
</option>
|
||||
))
|
||||
)}
|
||||
</select>
|
||||
{errors.projectId && (
|
||||
<small className="danger-text">{errors.projectId.message}</small>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="col-md-6">
|
||||
<label for="expensesTypeId" className="form-label ">
|
||||
Expense Type
|
||||
</label>
|
||||
<select
|
||||
className="form-select form-select-sm"
|
||||
id="expensesTypeId"
|
||||
{...register("expensesTypeId")}
|
||||
>
|
||||
<option value="" disabled>
|
||||
Select Type
|
||||
</option>
|
||||
{ExpenseLoading ? (
|
||||
<option disabled>Loading...</option>
|
||||
) : (
|
||||
ExpenseTypes?.map((expense) => (
|
||||
<option key={expense.id} value={expense.id}>
|
||||
{expense.name}
|
||||
</option>
|
||||
))
|
||||
)}
|
||||
</select>
|
||||
{errors.expensesTypeId && (
|
||||
<small className="danger-text">
|
||||
{errors.expensesTypeId.message}
|
||||
</small>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row my-2">
|
||||
<div className="col-md-6">
|
||||
<label for="paymentModeId" className="form-label ">
|
||||
Payment Mode
|
||||
</label>
|
||||
<select
|
||||
className="form-select form-select-sm"
|
||||
id="paymentModeId"
|
||||
{...register("paymentModeId")}
|
||||
>
|
||||
<option value="" disabled>
|
||||
Select Mode
|
||||
</option>
|
||||
{PaymentModeLoading ? (
|
||||
<option disabled>Loading...</option>
|
||||
) : (
|
||||
PaymentModes?.map((payment) => (
|
||||
<option key={payment.id} value={payment.id}>
|
||||
{payment.name}
|
||||
</option>
|
||||
))
|
||||
)}
|
||||
</select>
|
||||
{errors.paymentModeId && (
|
||||
<small className="danger-text">
|
||||
{errors.paymentModeId.message}
|
||||
</small>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="col-md-6">
|
||||
<label for="paidById" className="form-label ">
|
||||
Paid By
|
||||
</label>
|
||||
<select
|
||||
className="form-select form-select-sm"
|
||||
id="paymentModeId"
|
||||
{...register("paidById")}
|
||||
disabled={!selectedproject}
|
||||
>
|
||||
<option value="" disabled>
|
||||
Select Person
|
||||
</option>
|
||||
{EmpLoading ? (
|
||||
<option disabled>Loading...</option>
|
||||
) : (
|
||||
employees?.map((emp) => (
|
||||
<option key={emp.id} value={emp.id}>
|
||||
{`${emp.firstName} ${emp.lastName} `}
|
||||
</option>
|
||||
))
|
||||
)}
|
||||
</select>
|
||||
{errors.paidById && (
|
||||
<small className="danger-text">{errors.paidById.message}</small>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row my-2">
|
||||
<div className="col-md-6">
|
||||
<label for="transactionDate" className="form-label ">
|
||||
Transaction Date
|
||||
</label>
|
||||
<input
|
||||
type="date"
|
||||
className="form-control form-control-sm"
|
||||
placeholder="YYYY-MM-DD"
|
||||
id="flatpickr-date"
|
||||
{...register("transactionDate")}
|
||||
/>
|
||||
{errors.transactionDate && (
|
||||
<small className="danger-text">
|
||||
{errors.transactionDate.message}
|
||||
</small>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="col-md-6">
|
||||
<label for="amount" className="form-label ">
|
||||
Amount
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
id="amount"
|
||||
className="form-control form-control-sm"
|
||||
min="1"
|
||||
step="0.01"
|
||||
inputMode="decimal"
|
||||
{...register("amount", { valueAsNumber: true })}
|
||||
/>
|
||||
{errors.amount && (
|
||||
<small className="danger-text">{errors.amount.message}</small>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row my-2">
|
||||
<div className="col-md-6">
|
||||
<label for="supplerName" className="form-label ">
|
||||
Supplier Name
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="supplerName"
|
||||
className="form-control form-control-sm"
|
||||
{...register("supplerName")}
|
||||
/>
|
||||
{errors.supplerName && (
|
||||
<small className="danger-text">
|
||||
{errors.supplerName.message}
|
||||
</small>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="col-md-6">
|
||||
<label for="location" className="form-label ">
|
||||
Location
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="location"
|
||||
className="form-control form-control-sm"
|
||||
{...register("location")}
|
||||
/>
|
||||
{errors.location && (
|
||||
<small className="danger-text">{errors.location.message}</small>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="row my-2">
|
||||
<div className="col-md-6">
|
||||
<label for="statusId" className="form-label ">
|
||||
TransactionId
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="transactionId"
|
||||
className="form-control form-control-sm"
|
||||
min="1"
|
||||
{...register("transactionId")}
|
||||
/>
|
||||
{errors.transactionId && (
|
||||
<small className="danger-text">
|
||||
{errors.transactionId.message}
|
||||
</small>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{ExpenseType?.noOfPersonsRequired && (
|
||||
<div className="col-md-6">
|
||||
<label htmlFor="noOfPersons" >
|
||||
No. of Persons
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
id="noOfPersons"
|
||||
className="form-control form-control-sm"
|
||||
{...register("noOfPersons")}
|
||||
inputMode="numeric"
|
||||
/>
|
||||
{errors.noOfPersons && (
|
||||
<small className="danger-text">
|
||||
{errors.noOfPersons.message}
|
||||
</small>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="row my-2">
|
||||
<div className="col-md-12" >
|
||||
<label for="description">Description</label>
|
||||
<textarea
|
||||
id="description"
|
||||
className="form-control form-control-sm"
|
||||
{...register("description")}
|
||||
rows="2"
|
||||
></textarea>
|
||||
{errors.description && (
|
||||
<small className="danger-text">
|
||||
{errors.description.message}
|
||||
</small>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row my-2">
|
||||
<div className="col-md-12">
|
||||
<label className="form-label ">Upload Bill </label>
|
||||
|
||||
<div
|
||||
className="border border-secondary border-dashed rounded p-4 text-center bg-textMuted position-relative"
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() => document.getElementById("billAttachments").click()}
|
||||
>
|
||||
<i className="bx bx-cloud-upload d-block bx-lg"></i>
|
||||
<span className="text-muted d-block">
|
||||
Click to select or click here to browse
|
||||
</span>
|
||||
<small className="text-muted">(PDF, JPG, PNG, max 5MB)</small>
|
||||
|
||||
<input
|
||||
type="file"
|
||||
id="billAttachments"
|
||||
accept=".pdf,.jpg,.jpeg,.png"
|
||||
multiple
|
||||
style={{ display: "none" }}
|
||||
{...register("billAttachments")}
|
||||
onChange={(e) => {
|
||||
onFileChange(e);
|
||||
e.target.value = "";
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{errors.billAttachments && (
|
||||
<small className="danger-text">
|
||||
{errors.billAttachments.message}
|
||||
</small>
|
||||
)}
|
||||
{files.length > 0 && (
|
||||
<div className="d-block">
|
||||
{files
|
||||
.filter((file) => {
|
||||
if (expenseToEdit) {
|
||||
return file.isActive;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.map((file, idx) => (
|
||||
<a
|
||||
key={idx}
|
||||
className="d-flex justify-content-between text-start p-1"
|
||||
href={file.preSignedUrl || "#"}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<div>
|
||||
<span className="mb-0 text-secondary small d-block">
|
||||
{file.fileName}
|
||||
</span>
|
||||
<span className="text-body-secondary small d-block">
|
||||
{file.fileSize ? formatFileSize(file.fileSize) : ""}
|
||||
</span>
|
||||
</div>
|
||||
<i
|
||||
className="bx bx-trash bx-sm cursor-pointer text-danger"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
removeFile(expenseToEdit ? file.documentId : idx);
|
||||
}}
|
||||
></i>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{Array.isArray(errors.billAttachments) &&
|
||||
errors.billAttachments.map((fileError, index) => (
|
||||
<div key={index} className="danger-text small mt-1">
|
||||
{
|
||||
(fileError?.fileSize?.message ||
|
||||
fileError?.contentType?.message ||
|
||||
fileError?.base64Data?.message,
|
||||
fileError?.documentId?.message)
|
||||
}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="d-flex justify-content-center gap-2">
|
||||
{" "}
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-primary btn-sm mt-3"
|
||||
disabled={isPending || createPending}
|
||||
>
|
||||
{isPending || createPending ? "Please Wait..." : expenseToEdit ? "Update" : "Submit"}
|
||||
</button>
|
||||
<button
|
||||
type="reset"
|
||||
disabled={isPending || createPending}
|
||||
onClick={handleClose}
|
||||
className="btn btn-secondary btn-sm mt-3"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ManageExpense;
|
28
src/components/Expenses/PreviewDocument.jsx
Normal file
28
src/components/Expenses/PreviewDocument.jsx
Normal file
@ -0,0 +1,28 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
const PreviewDocument = ({ imageUrl }) => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
return (
|
||||
<div className="d-flex justify-content-center align-items-center" style={{ minHeight: "50vh" }}>
|
||||
{loading && (
|
||||
<div className="text-secondary text-center mb-2">
|
||||
Loading...
|
||||
</div>
|
||||
)}
|
||||
<img
|
||||
src={imageUrl}
|
||||
alt="Full View"
|
||||
className="img-fluid"
|
||||
style={{
|
||||
maxHeight: "100vh",
|
||||
objectFit: "contain",
|
||||
display: loading ? "none" : "block",
|
||||
}}
|
||||
onLoad={() => setLoading(false)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PreviewDocument;
|
264
src/components/Expenses/ViewExpense.jsx
Normal file
264
src/components/Expenses/ViewExpense.jsx
Normal file
@ -0,0 +1,264 @@
|
||||
import React, { useState } from "react";
|
||||
import { useActionOnExpense, useExpense } from "../../hooks/useExpense";
|
||||
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { ActionSchema } from "./ExpenseSchema";
|
||||
import { useExpenseContext } from "../../pages/Expense/ExpensePage";
|
||||
import { getColorNameFromHex } from "../../utils/appUtils";
|
||||
import { ExpenseDetailsSkeleton } from "./ExpenseSkeleton";
|
||||
|
||||
const ViewExpense = ({ ExpenseId }) => {
|
||||
const { data, isLoading, isError, error } = useExpense(ExpenseId);
|
||||
const [imageLoaded, setImageLoaded] = useState({});
|
||||
const { setDocumentView } = useExpenseContext();
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
resolver: zodResolver(ActionSchema),
|
||||
defaultValues: {
|
||||
comment: "",
|
||||
selectedStatus: "",
|
||||
},
|
||||
});
|
||||
|
||||
const { mutate: MakeAction } = useActionOnExpense(() => reset());
|
||||
|
||||
const onSubmit = (formData) => {
|
||||
const Payload = {
|
||||
expenseId: ExpenseId,
|
||||
statusId: formData.selectedStatus,
|
||||
comment: formData.comment,
|
||||
};
|
||||
|
||||
MakeAction(Payload);
|
||||
};
|
||||
|
||||
if (isLoading) return <ExpenseDetailsSkeleton />;
|
||||
const handleImageLoad = (id) => {
|
||||
setImageLoaded((prev) => ({ ...prev, [id]: true }));
|
||||
};
|
||||
|
||||
return (
|
||||
<form className="container px-3" onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="row mb-3">
|
||||
<div className="col-12 mb-3">
|
||||
<h5 className="fw-semibold">Expense Details</h5>
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
{/* Expense Info Rows */}
|
||||
<div className="col-12 col-md-6 mb-3">
|
||||
<div className="d-flex">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Transaction Date :
|
||||
</label>
|
||||
<div className="text-muted">
|
||||
{formatUTCToLocalTime(data.transactionDate)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 col-md-6 mb-3">
|
||||
<div className="d-flex">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Expense Type :
|
||||
</label>
|
||||
<div className="text-muted">{data.expensesType.name}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 col-md-4 mb-3">
|
||||
<div className="d-flex">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Supplier :
|
||||
</label>
|
||||
<div className="text-muted">{data.supplerName}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 col-md-4 mb-3">
|
||||
<div className="d-flex">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">Amount :</label>
|
||||
<div className="text-muted">₹ {data.amount}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 col-md-4 mb-3">
|
||||
<div className="d-flex">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Payment Mode :
|
||||
</label>
|
||||
<div className="text-muted">{data.paymentMode.name}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 col-md-4 mb-3">
|
||||
<div className="d-flex">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Paid By :
|
||||
</label>
|
||||
<div className="text-muted">
|
||||
{data.paidBy.firstName} {data.paidBy.lastName}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 text-start col-md-4 mb-3">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">Status :</label>
|
||||
|
||||
<span
|
||||
className={`badge bg-label-${
|
||||
getColorNameFromHex(data?.status?.color) || "secondary"
|
||||
}`}
|
||||
>
|
||||
{data?.status?.displayName}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="col-12 text-start d-flex col-md-4 mb-3">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Pre-Approved :
|
||||
</label>
|
||||
<div className="text-muted">{data.preApproved ? "Yes" : "No"}</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 col-md-4 mb-3">
|
||||
<div className="d-flex">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Project :
|
||||
</label>
|
||||
<div className="text-muted text-start">{data?.project?.name}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 col-md-4 mb-3">
|
||||
<div className="d-flex">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Created By :
|
||||
</label>
|
||||
<div className="text-muted">
|
||||
{data?.createdBy?.firstName} {data?.createdBy?.lastName}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 col-md-4 mb-3">
|
||||
<div className="d-flex">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Created At :
|
||||
</label>
|
||||
<div className="text-muted">
|
||||
{formatUTCToLocalTime(data?.createdAt, true)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-start">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">Description:</label>
|
||||
<div className="text-muted">{data?.description}</div>
|
||||
</div>
|
||||
<div className="col-12 my-2 text-start ">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">
|
||||
Attachement :
|
||||
</label>
|
||||
{data?.documents &&
|
||||
data?.documents?.map((doc) => (
|
||||
<div
|
||||
className="list-group-item list-group-item-action d-flex align-items-center"
|
||||
key={doc.id}
|
||||
>
|
||||
<div
|
||||
className="rounded me-1 d-flex align-items-center justify-content-center cursor-pointer"
|
||||
style={{ height: "50px", width: "80px", position: "relative" }}
|
||||
>
|
||||
{doc.contentType === "application/pdf" ? (
|
||||
<div>
|
||||
<i
|
||||
className="bx bxs-file-pdf"
|
||||
style={{ fontSize: "45px" }}
|
||||
></i>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{!imageLoaded[doc.id] && (
|
||||
<div className="position-absolute text-secondary">
|
||||
Loading...
|
||||
</div>
|
||||
)}
|
||||
<img
|
||||
src={doc.thumbPreSignedUrl}
|
||||
alt={doc.fileName}
|
||||
className="img-fluid rounded"
|
||||
style={{
|
||||
maxHeight: "100%",
|
||||
maxWidth: "100%",
|
||||
objectFit: "cover",
|
||||
opacity: imageLoaded[doc.id] ? 1 : 0,
|
||||
transition: "opacity 0.3s ease-in-out",
|
||||
}}
|
||||
onLoad={() => handleImageLoad(doc.id)}
|
||||
onClick={() =>
|
||||
setDocumentView({
|
||||
IsOpen: true,
|
||||
Image: doc.preSignedUrl,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="w-100">
|
||||
<small className="mb-0 small">{doc.fileName}</small>
|
||||
<div className="d">
|
||||
<i className="bx bx-cloud-download cursor-pointer"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<hr className="divider my-1" />
|
||||
|
||||
{Array.isArray(data.nextStatus) && data.nextStatus.length > 0 && (
|
||||
<div className="col-12 mb-3 text-start">
|
||||
<label className="form-label me-2 mb-0 fw-semibold">Comment:</label>
|
||||
<textarea
|
||||
className="form-control form-control-sm"
|
||||
{...register("comment")}
|
||||
rows="2"
|
||||
/>
|
||||
{errors.comment && (
|
||||
<small className="danger-text">{errors.comment.message}</small>
|
||||
)}
|
||||
|
||||
<input type="hidden" {...register("selectedStatus")} />
|
||||
|
||||
<div className="text-center flex-wrap gap-2 my-2">
|
||||
{data.nextStatus.map((status, index) => (
|
||||
<button
|
||||
key={index}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setValue("selectedStatus", status.id);
|
||||
handleSubmit(onSubmit)();
|
||||
}}
|
||||
className="btn btn-primary btn-sm cursor-pointer mx-2 border-0"
|
||||
>
|
||||
{status.displayName || status.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export default ViewExpense;
|
@ -1,6 +1,8 @@
|
||||
import React, { useEffect, useRef } from "react";
|
||||
|
||||
const DateRangePicker = ({
|
||||
md,
|
||||
sm,
|
||||
onRangeChange,
|
||||
DateDifference = 7,
|
||||
endDateMode = "yesterday",
|
||||
@ -25,11 +27,12 @@ const DateRangePicker = ({
|
||||
altInput: true,
|
||||
altFormat: "d-m-Y",
|
||||
defaultDate: [startDate, endDate],
|
||||
static: true,
|
||||
static: false,
|
||||
appendTo: document.body,
|
||||
clickOpens: true,
|
||||
maxDate: endDate, // ✅ Disable future dates
|
||||
onChange: (selectedDates, dateStr) => {
|
||||
const [startDateString, endDateString] = dateStr.split(" to ");
|
||||
const [startDateString, endDateString] = dateStr.split(" To ");
|
||||
onRangeChange?.({ startDate: startDateString, endDate: endDateString });
|
||||
},
|
||||
});
|
||||
@ -45,13 +48,29 @@ const DateRangePicker = ({
|
||||
}, [onRangeChange, DateDifference, endDateMode]);
|
||||
|
||||
return (
|
||||
<input
|
||||
type="text"
|
||||
className="form-control form-control-sm ms-1"
|
||||
placeholder="From to End"
|
||||
id="flatpickr-range"
|
||||
ref={inputRef}
|
||||
/>
|
||||
<div className={`col-${sm} col-sm-${md} px-1 position-relative`}>
|
||||
<input
|
||||
type="text"
|
||||
className="form-control form-control-sm ps-2 pe-5 "
|
||||
placeholder="From to End"
|
||||
id="flatpickr-range"
|
||||
ref={inputRef}
|
||||
/>
|
||||
|
||||
<i
|
||||
className="bx bx-calendar calendar-icon cursor-pointer"
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
right: "12px",
|
||||
transform: "translateY(-50%)",
|
||||
color: "#6c757d",
|
||||
fontSize: "1.1rem",
|
||||
|
||||
}}
|
||||
></i>
|
||||
</div>
|
||||
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -68,6 +68,21 @@ useEffect(() => {
|
||||
backgroundColor: 'rgba(0,0,0,0.3)',
|
||||
};
|
||||
|
||||
const getPositionClass = (type) => {
|
||||
switch (type) {
|
||||
case 'top':
|
||||
return 'mt-3';
|
||||
case 'bottom':
|
||||
return 'mt-auto mb-0 d-flex flex-column';
|
||||
case 'left':
|
||||
return 'position-absolute top-50 start-0 translate-middle-y me-auto';
|
||||
case 'right':
|
||||
return 'position-absolute top-50 end-0 translate-middle-y ms-auto';
|
||||
case 'center':
|
||||
default:
|
||||
return 'modal-dialog-centered';
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
@ -80,7 +95,7 @@ useEffect(() => {
|
||||
{...dataAttributesProps}
|
||||
style={backdropStyle}
|
||||
>
|
||||
<div className={`modal-dialog ${dialogClass} ${modalSizeClass } mx-sm-auto mx-1`} role={role} >
|
||||
<div className={`modal-dialog ${modalSizeClass} ${getPositionClass(modalType)} ${dialogClass} mx-sm-auto mx-1`} role={role}>
|
||||
<div className="modal-content">
|
||||
<div className="modal-header p-0">
|
||||
{/* Close button inside the modal header */}
|
||||
|
84
src/components/common/Pagination.jsx
Normal file
84
src/components/common/Pagination.jsx
Normal file
@ -0,0 +1,84 @@
|
||||
import React from "react";
|
||||
|
||||
const getPaginationRange = (currentPage, totalPages, delta = 1) => {
|
||||
const range = [];
|
||||
const rangeWithDots = [];
|
||||
let l;
|
||||
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
if (
|
||||
i === 1 ||
|
||||
i === totalPages ||
|
||||
(i >= currentPage - delta && i <= currentPage + delta)
|
||||
) {
|
||||
range.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i of range) {
|
||||
if (l) {
|
||||
if (i - l === 2) {
|
||||
rangeWithDots.push(l + 1);
|
||||
} else if (i - l !== 1) {
|
||||
rangeWithDots.push("...");
|
||||
}
|
||||
}
|
||||
rangeWithDots.push(i);
|
||||
l = i;
|
||||
}
|
||||
|
||||
return rangeWithDots;
|
||||
};
|
||||
|
||||
const Pagination = ({ currentPage, totalPages, onPageChange }) => {
|
||||
if (totalPages <= 1) return null;
|
||||
|
||||
const paginationRange = getPaginationRange(currentPage, totalPages);
|
||||
|
||||
return (
|
||||
<nav aria-label="Page navigation">
|
||||
<ul className="pagination pagination-sm justify-content-end py-1 mx-1">
|
||||
<li className={`page-item ${currentPage === 1 ? "disabled" : ""}`}>
|
||||
<button
|
||||
className="page-link btn-xs"
|
||||
onClick={() => onPageChange(currentPage - 1)}
|
||||
>
|
||||
«
|
||||
</button>
|
||||
</li>
|
||||
|
||||
{paginationRange.map((page, index) => (
|
||||
<li
|
||||
key={index}
|
||||
className={`page-item ${
|
||||
page === currentPage ? "active" : ""
|
||||
} ${page === "..." ? "disabled" : ""}`}
|
||||
>
|
||||
{page === "..." ? (
|
||||
<span className="page-link">…</span>
|
||||
) : (
|
||||
<button className="page-link" onClick={() => onPageChange(page)}>
|
||||
{page}
|
||||
</button>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
|
||||
<li
|
||||
className={`page-item ${
|
||||
currentPage === totalPages ? "disabled" : ""
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
className="page-link"
|
||||
onClick={() => onPageChange(currentPage + 1)}
|
||||
>
|
||||
»
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
|
||||
export default Pagination;
|
@ -1,12 +1,13 @@
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import { useFormContext } from "react-hook-form";
|
||||
import { createPortal } from "react-dom";
|
||||
import "./MultiSelectDropdown.css";
|
||||
|
||||
const SelectMultiple = ({
|
||||
name,
|
||||
options = [],
|
||||
label = "Select options",
|
||||
labelKey = "name",
|
||||
labelKey = "name", // Can now be a function or a string
|
||||
valueKey = "id",
|
||||
placeholder = "Please select...",
|
||||
IsLoading = false,
|
||||
@ -16,11 +17,18 @@ const SelectMultiple = ({
|
||||
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const containerRef = useRef(null);
|
||||
const dropdownRef = useRef(null);
|
||||
|
||||
const [dropdownStyles, setDropdownStyles] = useState({ top: 0, left: 0, width: 0 });
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (e) => {
|
||||
if (dropdownRef.current && !dropdownRef.current.contains(e.target)) {
|
||||
if (
|
||||
containerRef.current &&
|
||||
!containerRef.current.contains(e.target) &&
|
||||
(!dropdownRef.current || !dropdownRef.current.contains(e.target))
|
||||
) {
|
||||
setIsOpen(false);
|
||||
}
|
||||
};
|
||||
@ -28,6 +36,21 @@ const SelectMultiple = ({
|
||||
return () => document.removeEventListener("mousedown", handleClickOutside);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && containerRef.current) {
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
setDropdownStyles({
|
||||
top: rect.bottom + window.scrollY,
|
||||
left: rect.left + window.scrollX,
|
||||
width: rect.width,
|
||||
});
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
const getLabel = (item) => {
|
||||
return typeof labelKey === "function" ? labelKey(item) : item[labelKey];
|
||||
};
|
||||
|
||||
const handleCheckboxChange = (value) => {
|
||||
const updated = selectedValues.includes(value)
|
||||
? selectedValues.filter((v) => v !== value)
|
||||
@ -36,96 +59,113 @@ const SelectMultiple = ({
|
||||
setValue(name, updated, { shouldValidate: true });
|
||||
};
|
||||
|
||||
const filteredOptions = options.filter((item) =>
|
||||
item[labelKey]?.toLowerCase().includes(searchText.toLowerCase())
|
||||
);
|
||||
const filteredOptions = options.filter((item) => {
|
||||
const label = getLabel(item);
|
||||
return label?.toLowerCase().includes(searchText.toLowerCase());
|
||||
});
|
||||
|
||||
return (
|
||||
<div ref={dropdownRef} className="multi-select-dropdown-container">
|
||||
<label className="form-label mb-1">{label}</label>
|
||||
|
||||
<div
|
||||
className="multi-select-dropdown-header"
|
||||
onClick={() => setIsOpen((prev) => !prev)}
|
||||
>
|
||||
<span
|
||||
className={
|
||||
selectedValues.length > 0
|
||||
? "placeholder-style-selected"
|
||||
: "placeholder-style"
|
||||
}
|
||||
>
|
||||
<div className="selected-badges-container">
|
||||
{selectedValues.length > 0 ? (
|
||||
selectedValues.map((val) => {
|
||||
const found = options.find((opt) => opt[valueKey] === val);
|
||||
return (
|
||||
<span
|
||||
key={val}
|
||||
className="badge badge-selected-item mx-1 mb-1"
|
||||
>
|
||||
{found ? found[labelKey] : ""}
|
||||
</span>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<span className="placeholder-text">{placeholder}</span>
|
||||
)}
|
||||
</div>
|
||||
</span>
|
||||
<i className="bx bx-chevron-down"></i>
|
||||
const dropdownElement = (
|
||||
<div
|
||||
ref={dropdownRef}
|
||||
className="multi-select-dropdown-options"
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: dropdownStyles.top,
|
||||
left: dropdownStyles.left,
|
||||
width: dropdownStyles.width,
|
||||
zIndex: 9999,
|
||||
backgroundColor: "white",
|
||||
boxShadow: "0 2px 8px rgba(0,0,0,0.15)",
|
||||
borderRadius: 4,
|
||||
maxHeight: 300,
|
||||
overflowY: "auto",
|
||||
}}
|
||||
>
|
||||
<div className="multi-select-dropdown-search" style={{ padding: 8 }}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search..."
|
||||
value={searchText}
|
||||
onChange={(e) => setSearchText(e.target.value)}
|
||||
className="multi-select-dropdown-search-input"
|
||||
style={{ width: "100%", padding: 4 }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{isOpen && (
|
||||
<div className="multi-select-dropdown-options">
|
||||
<div className="multi-select-dropdown-search">
|
||||
{filteredOptions.map((item) => {
|
||||
const labelVal = getLabel(item);
|
||||
const valueVal = item[valueKey];
|
||||
const isChecked = selectedValues.includes(valueVal);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={valueVal}
|
||||
className={`multi-select-dropdown-option ${isChecked ? "selected" : ""}`}
|
||||
style={{ display: "flex", alignItems: "center", padding: "4px 8px" }}
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search..."
|
||||
value={searchText}
|
||||
onChange={(e) => setSearchText(e.target.value)}
|
||||
className="multi-select-dropdown-search-input"
|
||||
type="checkbox"
|
||||
className="custom-checkbox form-check-input"
|
||||
checked={isChecked}
|
||||
onChange={() => handleCheckboxChange(valueVal)}
|
||||
style={{ marginRight: 8 }}
|
||||
/>
|
||||
<label className="text-secondary">{labelVal}</label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
{filteredOptions.map((item) => {
|
||||
const labelVal = item[labelKey];
|
||||
const valueVal = item[valueKey];
|
||||
const isChecked = selectedValues.includes(valueVal);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={valueVal}
|
||||
className={`multi-select-dropdown-option ${
|
||||
isChecked ? "selected" : ""
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
className="custom-checkbox form-check-input"
|
||||
checked={isChecked}
|
||||
onChange={() => handleCheckboxChange(valueVal)}
|
||||
/>
|
||||
<label className="text-secondary">{labelVal}</label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{!IsLoading && filteredOptions.length === 0 && (
|
||||
<div className="multi-select-dropdown-Not-found">
|
||||
<label className="text-muted">
|
||||
Not Found {`'${searchText}'`}
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
{IsLoading && filteredOptions.length === 0 && (
|
||||
<div className="multi-select-dropdown-Not-found">
|
||||
<label className="text-muted">Loading...</label>
|
||||
</div>
|
||||
)}
|
||||
{!IsLoading && filteredOptions.length === 0 && (
|
||||
<div className="multi-select-dropdown-Not-found" style={{ padding: 8 }}>
|
||||
<label className="text-muted">Not Found {`'${searchText}'`}</label>
|
||||
</div>
|
||||
)}
|
||||
{IsLoading && filteredOptions.length === 0 && (
|
||||
<div className="multi-select-dropdown-Not-found" style={{ padding: 8 }}>
|
||||
<label className="text-muted">Loading...</label>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div ref={containerRef} className="multi-select-dropdown-container" style={{ position: "relative" }}>
|
||||
<label className="form-label mb-1">{label}</label>
|
||||
|
||||
<div
|
||||
className="multi-select-dropdown-header"
|
||||
onClick={() => setIsOpen((prev) => !prev)}
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
<span
|
||||
className={
|
||||
selectedValues.length > 0 ? "placeholder-style-selected" : "placeholder-style"
|
||||
}
|
||||
>
|
||||
<div className="selected-badges-container">
|
||||
{selectedValues.length > 0 ? (
|
||||
selectedValues.map((val) => {
|
||||
const found = options.find((opt) => opt[valueKey] === val);
|
||||
const label = found ? getLabel(found) : "";
|
||||
return (
|
||||
<span key={val} className="badge badge-selected-item mx-1 mb-1">
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<span className="placeholder-text">{placeholder}</span>
|
||||
)}
|
||||
</div>
|
||||
</span>
|
||||
<i className="bx bx-chevron-down"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isOpen && createPortal(dropdownElement, document.body)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SelectMultiple;
|
||||
|
113
src/components/master/ManageExpenseType.jsx
Normal file
113
src/components/master/ManageExpenseType.jsx
Normal file
@ -0,0 +1,113 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import {
|
||||
useCreateExpenseType,
|
||||
useUpdateExpenseType,
|
||||
} from "../../hooks/masterHook/useMaster";
|
||||
|
||||
const ExpnseSchema = z.object({
|
||||
name: z.string().min(1, { message: "Name is required" }),
|
||||
noOfPersonsRequired: z.boolean().default(false),
|
||||
description: z.string().min(1, { message: "Description is required" }),
|
||||
});
|
||||
|
||||
const ManageExpenseType = ({ data = null, onClose }) => {
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
resolver: zodResolver(ExpnseSchema),
|
||||
defaultValues: { name: "", noOfPersonsRequired: false, description: "" },
|
||||
});
|
||||
const { mutate: UpdateExpenseType, isPending:isPendingUpdate } = useUpdateExpenseType(
|
||||
() => onClose?.()
|
||||
);
|
||||
const { mutate: CreateExpenseType, isPending } = useCreateExpenseType(() =>
|
||||
onClose?.()
|
||||
);
|
||||
|
||||
const onSubmit = (payload) => {
|
||||
if (data) {
|
||||
UpdateExpenseType({
|
||||
id: data.id,
|
||||
payload: { ...payload, id: data.id },
|
||||
});
|
||||
} else {
|
||||
CreateExpenseType(payload);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
reset({
|
||||
name: data.name ?? "",
|
||||
noOfPersonsRequired: data.noOfPersonsRequired ?? false,
|
||||
description: data.description ?? "",
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
return (
|
||||
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="col-12 col-md-12">
|
||||
<label className="form-label">Expesne Type Name</label>
|
||||
<input
|
||||
type="text"
|
||||
{...register("name")}
|
||||
className={`form-control ${errors.name ? "is-invalids" : ""}`}
|
||||
/>
|
||||
{errors.name && <p className="danger-text">{errors.name.message}</p>}
|
||||
</div>
|
||||
<div className="col-12 col-md-12">
|
||||
<label className="form-label" htmlFor="description">
|
||||
Description
|
||||
</label>
|
||||
<textarea
|
||||
rows="3"
|
||||
{...register("description")}
|
||||
className={`form-control ${errors.description ? "is-invalids" : ""}`}
|
||||
></textarea>
|
||||
|
||||
{errors.description && (
|
||||
<p className="danger-text">{errors.description.message}</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="col-12 col-md-12 d-flex align-items-center">
|
||||
<label className="from-label">No. of Persons Required </label>{" "}
|
||||
<input
|
||||
type="checkbox"
|
||||
className="form-check-input ms-2"
|
||||
{...register("noOfPersonsRequired")}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-12 text-center">
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-sm btn-primary me-3"
|
||||
disabled={isPending || isPendingUpdate}
|
||||
>
|
||||
{isPending || isPendingUpdate
|
||||
? "Please Wait..."
|
||||
: data
|
||||
? "Update"
|
||||
: "Submit"}
|
||||
</button>
|
||||
<button
|
||||
type="reset"
|
||||
className="btn btn-sm btn-label-secondary "
|
||||
data-bs-dismiss="modal"
|
||||
aria-label="Close"
|
||||
disabled={isPending || isPendingUpdate}
|
||||
onClick={()=>onClose()}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export default ManageExpenseType;
|
95
src/components/master/ManagePaymentMode.jsx
Normal file
95
src/components/master/ManagePaymentMode.jsx
Normal file
@ -0,0 +1,95 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useCreatePaymentMode, useUpdatePaymentMode } from "../../hooks/masterHook/useMaster";
|
||||
|
||||
const ExpnseSchema = z.object({
|
||||
name: z.string().min(1, { message: "Name is required" }),
|
||||
description: z.string().min(1, { message: "Description is required" }),
|
||||
});
|
||||
|
||||
const ManagePaymentMode = ({ data = null, onClose }) => {
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
resolver: zodResolver(ExpnseSchema),
|
||||
defaultValues: { name: "", description: "" },
|
||||
});
|
||||
|
||||
const { mutate: CreatePaymentMode, isPending } = useCreatePaymentMode(() =>
|
||||
onClose?.()
|
||||
);
|
||||
const {mutate:UpdatePaymentMode,isPending:Updating} = useUpdatePaymentMode(()=>onClose?.())
|
||||
|
||||
const onSubmit = (payload) => {
|
||||
if(data){
|
||||
UpdatePaymentMode({id:data.id,payload:{...payload,id:data.id}})
|
||||
}else(
|
||||
CreatePaymentMode(payload)
|
||||
)
|
||||
|
||||
};
|
||||
|
||||
useEffect(()=>{
|
||||
if(data){
|
||||
reset({
|
||||
name:data.name ?? "",
|
||||
description:data.description ?? ""
|
||||
})
|
||||
}
|
||||
},[data])
|
||||
|
||||
|
||||
return (
|
||||
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="col-12 col-md-12">
|
||||
<label className="form-label">Payment Mode Name</label>
|
||||
<input
|
||||
type="text"
|
||||
{...register("name")}
|
||||
className={`form-control ${errors.name ? "is-invalids" : ""}`}
|
||||
/>
|
||||
{errors.name && <p className="danger-text">{errors.name.message}</p>}
|
||||
</div>
|
||||
<div className="col-12 col-md-12">
|
||||
<label className="form-label" htmlFor="description">
|
||||
Description
|
||||
</label>
|
||||
<textarea
|
||||
rows="3"
|
||||
{...register("description")}
|
||||
className={`form-control ${errors.description ? "is-invalids" : ""}`}
|
||||
></textarea>
|
||||
|
||||
{errors.description && (
|
||||
<p className="danger-text">{errors.description.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="col-12 text-center">
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-sm btn-primary me-3"
|
||||
disabled={isPending || Updating}
|
||||
>
|
||||
{isPending || Updating? "Please Wait..." : Updating ? "Update" : "Submit"}
|
||||
</button>
|
||||
<button
|
||||
type="reset"
|
||||
className="btn btn-sm btn-label-secondary "
|
||||
data-bs-dismiss="modal"
|
||||
aria-label="Close"
|
||||
disabled={isPending || Updating}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export default ManagePaymentMode;
|
@ -1,5 +1,4 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
|
||||
import CreateRole from "./CreateRole";
|
||||
import DeleteMaster from "./DeleteMaster";
|
||||
import EditRole from "./EditRole";
|
||||
@ -18,67 +17,44 @@ import CreateContactTag from "./CreateContactTag";
|
||||
import EditContactCategory from "./EditContactCategory";
|
||||
import EditContactTag from "./EditContactTag";
|
||||
import { useDeleteMasterItem } from "../../hooks/masterHook/useMaster";
|
||||
import ManageExpenseType from "./ManageExpenseType";
|
||||
import ManagePaymentMode from "./ManagePaymentMode";
|
||||
|
||||
|
||||
const MasterModal = ({ modaldata, closeModal }) => {
|
||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||
const { mutate: deleteMasterItem, isPending } = useDeleteMasterItem();
|
||||
|
||||
// const handleSelectedMasterDeleted = async () =>
|
||||
// {
|
||||
// debugger
|
||||
// const deleteFn = MasterRespository[modaldata.masterType];
|
||||
// if (!deleteFn) {
|
||||
// showToast(`No delete strategy defined for master type`,"error");
|
||||
// return false;
|
||||
// }
|
||||
// try
|
||||
// {
|
||||
// const response = await deleteFn( modaldata?.item?.id );
|
||||
// const selected_cachedData = getCachedData( modaldata?.masterType );
|
||||
// const updated_master = selected_cachedData?.filter(item => item.id !== modaldata?.item.id);
|
||||
// cacheData( modaldata?.masterType, updated_master )
|
||||
|
||||
// showToast(`${modaldata?.masterType} is deleted successfully`, "success");
|
||||
// handleCloseDeleteModal()
|
||||
|
||||
// } catch ( error )
|
||||
// {
|
||||
// const message = error.response.data.message || error.message || "Error occured api during call"
|
||||
// showToast(message, "success");
|
||||
// }
|
||||
// }
|
||||
|
||||
const handleSelectedMasterDeleted = () => {
|
||||
if (!modaldata?.masterType || !modaldata?.item?.id) {
|
||||
const { masterType, item, validateFn } = modaldata || {};
|
||||
if (!masterType || !item?.id) {
|
||||
showToast("Missing master type or item", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
deleteMasterItem(
|
||||
{
|
||||
masterType: modaldata.masterType,
|
||||
item: modaldata.item,
|
||||
validateFn: modaldata.validateFn, // optional
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
handleCloseDeleteModal();
|
||||
},
|
||||
}
|
||||
{ masterType, item, validateFn },
|
||||
{ onSuccess: handleCloseDeleteModal }
|
||||
);
|
||||
};
|
||||
|
||||
const handleCloseDeleteModal = () => {
|
||||
setIsDeleteModalOpen(false);
|
||||
closeModal();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (modaldata?.modalType === "delete") {
|
||||
setIsDeleteModalOpen(true);
|
||||
}
|
||||
}, [modaldata]);
|
||||
|
||||
const handleCloseDeleteModal = () => {
|
||||
setIsDeleteModalOpen(false);
|
||||
if (!modaldata?.modalType) {
|
||||
closeModal();
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
if (modaldata?.modalType === "delete" && isDeleteModalOpen) {
|
||||
if (modaldata.modalType === "delete" && isDeleteModalOpen) {
|
||||
return (
|
||||
<div
|
||||
className="modal fade show"
|
||||
@ -90,86 +66,67 @@ const MasterModal = ({ modaldata, closeModal }) => {
|
||||
<ConfirmModal
|
||||
type="delete"
|
||||
header={`Delete ${modaldata.masterType}`}
|
||||
message={"Are you sure you want delete?"}
|
||||
message="Are you sure you want delete?"
|
||||
onSubmit={handleSelectedMasterDeleted}
|
||||
onClose={handleCloseDeleteModal}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const renderModalContent = () => {
|
||||
const { modalType, item, masterType } = modaldata;
|
||||
|
||||
const modalComponents = {
|
||||
"Application Role": <CreateRole masmodalType={masterType} onClose={closeModal} />,
|
||||
"Edit-Application Role": <EditRole master={modaldata} onClose={closeModal} />,
|
||||
"Job Role": <CreateJobRole onClose={closeModal} />,
|
||||
"Edit-Job Role": <EditJobRole data={item} onClose={closeModal} />,
|
||||
"Activity": <CreateActivity onClose={closeModal} />,
|
||||
"Edit-Activity": <EditActivity activityData={item} onClose={closeModal} />,
|
||||
"Work Category": <CreateWorkCategory onClose={closeModal} />,
|
||||
"Edit-Work Category": <EditWorkCategory data={item} onClose={closeModal} />,
|
||||
"Contact Category": <CreateCategory data={item} onClose={closeModal} />,
|
||||
"Edit-Contact Category": <EditContactCategory data={item} onClose={closeModal} />,
|
||||
"Contact Tag": <CreateContactTag data={item} onClose={closeModal} />,
|
||||
"Edit-Contact Tag": <EditContactTag data={item} onClose={closeModal} />,
|
||||
"Expense Type":<ManageExpenseType onClose={closeModal} />,
|
||||
"Edit-Expense Type":<ManageExpenseType data={item} onClose={closeModal} />,
|
||||
"Payment Mode":<ManagePaymentMode onClose={closeModal}/>,
|
||||
"Edit-Payment Mode":<ManagePaymentMode data={item} onClose={closeModal}/>
|
||||
};
|
||||
|
||||
return modalComponents[modalType] || null;
|
||||
};
|
||||
|
||||
const isLargeModal = ["Application Role", "Edit-Application Role"].includes(
|
||||
modaldata.modalType
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="modal fade"
|
||||
className="modal fade show"
|
||||
id="master-modal"
|
||||
tabIndex="-1"
|
||||
aria-hidden="true"
|
||||
role="dialog"
|
||||
aria-hidden="true"
|
||||
aria-labelledby="modalToggleLabel"
|
||||
style={{ display: "block" }}
|
||||
>
|
||||
<div
|
||||
className={`modal-dialog mx-sm-auto mx-1 ${
|
||||
["Application Role", "Edit-Application Role"].includes(
|
||||
modaldata?.modalType
|
||||
)
|
||||
? "modal-lg"
|
||||
: "modal-md"
|
||||
} modal-simple`}
|
||||
>
|
||||
<div className={`modal-dialog mx-sm-auto mx-1 ${isLargeModal ? "modal-lg" : "modal-md"} modal-simple`}>
|
||||
<div className="modal-content">
|
||||
<div className="modal-body p-sm-4 p-0">
|
||||
<div className="d-flex justify-content-between">
|
||||
<h6>{`${modaldata?.modalType} `}</h6>
|
||||
<h6>{modaldata?.modalType}</h6>
|
||||
<button
|
||||
type="button"
|
||||
className="btn-close"
|
||||
data-bs-dismiss="modal"
|
||||
aria-label="Close"
|
||||
onClick={closeModal}
|
||||
></button>
|
||||
/>
|
||||
</div>
|
||||
|
||||
{modaldata.modalType === "Application Role" && (
|
||||
<CreateRole
|
||||
masmodalType={modaldata.masterType}
|
||||
onClose={closeModal}
|
||||
/>
|
||||
)}
|
||||
{modaldata.modalType === "Edit-Application Role" && (
|
||||
<EditRole master={modaldata} onClose={closeModal} />
|
||||
)}
|
||||
{modaldata.modalType === "Job Role" && (
|
||||
<CreateJobRole onClose={closeModal} />
|
||||
)}
|
||||
{modaldata.modalType === "Edit-Job Role" && (
|
||||
<EditJobRole data={modaldata.item} onClose={closeModal} />
|
||||
)}
|
||||
{modaldata.modalType === "Activity" && (
|
||||
<CreateActivity onClose={closeModal} />
|
||||
)}
|
||||
{modaldata.modalType === "Edit-Activity" && (
|
||||
<EditActivity
|
||||
activityData={modaldata.item}
|
||||
onClose={closeModal}
|
||||
/>
|
||||
)}
|
||||
{modaldata.modalType === "Work Category" && (
|
||||
<CreateWorkCategory onClose={closeModal} />
|
||||
)}
|
||||
{modaldata.modalType === "Edit-Work Category" && (
|
||||
<EditWorkCategory data={modaldata.item} onClose={closeModal} />
|
||||
)}
|
||||
{modaldata.modalType === "Contact Category" && (
|
||||
<CreateCategory data={modaldata.item} onClose={closeModal} />
|
||||
)}
|
||||
{modaldata.modalType === "Edit-Contact Category" && (
|
||||
<EditContactCategory data={modaldata.item} onClose={closeModal} />
|
||||
)}
|
||||
{modaldata.modalType === "Contact Tag" && (
|
||||
<CreateContactTag data={modaldata.item} onClose={closeModal} />
|
||||
)}
|
||||
{modaldata.modalType === "Edit-Contact Tag" && (
|
||||
<EditContactTag data={modaldata.item} onClose={closeModal} />
|
||||
)}
|
||||
{renderModalContent()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,153 +1,157 @@
|
||||
// it important ------
|
||||
export const mastersList = [ {id: 1, name: "Application Role"}, {id: 2, name: "Job Role"}, {id: 3, name: "Activity"},{id: 4, name:"Work Category"},{id:5,name:"Contact Category"},{id:6,name:"Contact Tag"}]
|
||||
export const mastersList = [
|
||||
{ id: 1, name: "Application Role" },
|
||||
{ id: 2, name: "Job Role" },
|
||||
{ id: 3, name: "Activity" },
|
||||
{ id: 4, name: "Work Category" },
|
||||
{ id: 5, name: "Contact Category" },
|
||||
{ id: 6, name: "Contact Tag" },
|
||||
{ id: 7, name: "Expense Type" },
|
||||
{ id: 8, name: "Payment Mode" },
|
||||
{ id: 9, name: "Expense Status" },
|
||||
];
|
||||
// -------------------
|
||||
|
||||
export const dailyTask = [
|
||||
{
|
||||
id:1,
|
||||
project:{
|
||||
projectName:"Project Name1",
|
||||
building:"buildName1",
|
||||
floor:"floorName1",
|
||||
workArea:"workarea1"
|
||||
},
|
||||
target:80,
|
||||
employees:[
|
||||
{
|
||||
id:1,
|
||||
name:"Vishal Patil",
|
||||
role:"helper"
|
||||
},
|
||||
{
|
||||
id:202,
|
||||
name:"Vishal Patil",
|
||||
role:"helper"
|
||||
},
|
||||
{
|
||||
id:101,
|
||||
name:"Kushal Patil",
|
||||
role:"Engineer"
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
id:2,
|
||||
project:{
|
||||
projectName:"Project Name1",
|
||||
building:"buildName1",
|
||||
floor:"floorName1",
|
||||
workArea:"workarea1"
|
||||
},
|
||||
target:90,
|
||||
employees:[
|
||||
{
|
||||
id:1,
|
||||
name:"Vishal Patil",
|
||||
role:"welder"
|
||||
},
|
||||
{
|
||||
id:202,
|
||||
name:"Vishal Patil",
|
||||
role:"welder"
|
||||
},
|
||||
{
|
||||
id:101,
|
||||
name:"Kushal Patil",
|
||||
role:"Site Engineer"
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
export const jobRoles =[
|
||||
{
|
||||
id:1,
|
||||
name:"Project Manager"
|
||||
},
|
||||
{
|
||||
id:2,
|
||||
name:"Software Developer"
|
||||
},
|
||||
{
|
||||
id:3,
|
||||
name:"Estimation Engineer"
|
||||
},
|
||||
{
|
||||
id:4,
|
||||
name:"Designer"
|
||||
},
|
||||
{
|
||||
id:5,
|
||||
name:"Site Engineer"
|
||||
}
|
||||
]
|
||||
|
||||
export const employee =[
|
||||
{
|
||||
id:1,
|
||||
FirtsName:"Pramod",
|
||||
LastName:"Mahajan",
|
||||
JobRoleId:2,
|
||||
},
|
||||
{
|
||||
id:2,
|
||||
FirtsName:"Akahsy",
|
||||
LastName:"Patil",
|
||||
JobRoleId:1,
|
||||
},
|
||||
{
|
||||
id:3,
|
||||
FirtsName:"janvi",
|
||||
LastName:"Potdar",
|
||||
JobRoleId:3,
|
||||
},
|
||||
{
|
||||
id:4,
|
||||
FirtsName:"Aboli",
|
||||
LastName:"Patil",
|
||||
JobRoleId:2,
|
||||
},
|
||||
{
|
||||
id:5,
|
||||
FirtsName:"Shubham",
|
||||
LastName:"Tamboli",
|
||||
JobRoleId:1,
|
||||
},
|
||||
{
|
||||
id:6,
|
||||
FirtsName:"Alwin",
|
||||
LastName:"Joy",
|
||||
JobRoleId:4,
|
||||
},
|
||||
{
|
||||
id:7,
|
||||
FirtsName:"John",
|
||||
LastName:"kwel",
|
||||
JobRoleId:4,
|
||||
},
|
||||
{
|
||||
id:8,
|
||||
FirtsName:"Gita",
|
||||
LastName:"shaha",
|
||||
JobRoleId:1,
|
||||
},{
|
||||
id:9,
|
||||
FirtsName:"Pratik",
|
||||
LastName:"Joshi",
|
||||
JobRoleId:5,
|
||||
},
|
||||
{
|
||||
id:10,
|
||||
FirtsName:"Nikil",
|
||||
LastName:"Patil",
|
||||
JobRoleId:5,
|
||||
}
|
||||
]
|
||||
// export const dailyTask = [
|
||||
// {
|
||||
// id:1,
|
||||
// project:{
|
||||
// projectName:"Project Name1",
|
||||
// building:"buildName1",
|
||||
// floor:"floorName1",
|
||||
// workArea:"workarea1"
|
||||
// },
|
||||
// target:80,
|
||||
// employees:[
|
||||
// {
|
||||
// id:1,
|
||||
// name:"Vishal Patil",
|
||||
// role:"helper"
|
||||
// },
|
||||
// {
|
||||
// id:202,
|
||||
// name:"Vishal Patil",
|
||||
// role:"helper"
|
||||
// },
|
||||
// {
|
||||
// id:101,
|
||||
// name:"Kushal Patil",
|
||||
// role:"Engineer"
|
||||
// }
|
||||
// ]
|
||||
|
||||
// },
|
||||
// {
|
||||
// id:2,
|
||||
// project:{
|
||||
// projectName:"Project Name1",
|
||||
// building:"buildName1",
|
||||
// floor:"floorName1",
|
||||
// workArea:"workarea1"
|
||||
// },
|
||||
// target:90,
|
||||
// employees:[
|
||||
// {
|
||||
// id:1,
|
||||
// name:"Vishal Patil",
|
||||
// role:"welder"
|
||||
// },
|
||||
// {
|
||||
// id:202,
|
||||
// name:"Vishal Patil",
|
||||
// role:"welder"
|
||||
// },
|
||||
// {
|
||||
// id:101,
|
||||
// name:"Kushal Patil",
|
||||
// role:"Site Engineer"
|
||||
// }
|
||||
// ]
|
||||
|
||||
// }
|
||||
// ]
|
||||
|
||||
// export const jobRoles =[
|
||||
// {
|
||||
// id:1,
|
||||
// name:"Project Manager"
|
||||
// },
|
||||
// {
|
||||
// id:2,
|
||||
// name:"Software Developer"
|
||||
// },
|
||||
// {
|
||||
// id:3,
|
||||
// name:"Estimation Engineer"
|
||||
// },
|
||||
// {
|
||||
// id:4,
|
||||
// name:"Designer"
|
||||
// },
|
||||
// {
|
||||
// id:5,
|
||||
// name:"Site Engineer"
|
||||
// }
|
||||
// ]
|
||||
|
||||
// export const employee =[
|
||||
// {
|
||||
// id:1,
|
||||
// FirtsName:"Pramod",
|
||||
// LastName:"Mahajan",
|
||||
// JobRoleId:2,
|
||||
// },
|
||||
// {
|
||||
// id:2,
|
||||
// FirtsName:"Akahsy",
|
||||
// LastName:"Patil",
|
||||
// JobRoleId:1,
|
||||
// },
|
||||
// {
|
||||
// id:3,
|
||||
// FirtsName:"janvi",
|
||||
// LastName:"Potdar",
|
||||
// JobRoleId:3,
|
||||
// },
|
||||
// {
|
||||
// id:4,
|
||||
// FirtsName:"Aboli",
|
||||
// LastName:"Patil",
|
||||
// JobRoleId:2,
|
||||
// },
|
||||
// {
|
||||
// id:5,
|
||||
// FirtsName:"Shubham",
|
||||
// LastName:"Tamboli",
|
||||
// JobRoleId:1,
|
||||
// },
|
||||
// {
|
||||
// id:6,
|
||||
// FirtsName:"Alwin",
|
||||
// LastName:"Joy",
|
||||
// JobRoleId:4,
|
||||
// },
|
||||
// {
|
||||
// id:7,
|
||||
// FirtsName:"John",
|
||||
// LastName:"kwel",
|
||||
// JobRoleId:4,
|
||||
// },
|
||||
// {
|
||||
// id:8,
|
||||
// FirtsName:"Gita",
|
||||
// LastName:"shaha",
|
||||
// JobRoleId:1,
|
||||
// },{
|
||||
// id:9,
|
||||
// FirtsName:"Pratik",
|
||||
// LastName:"Joshi",
|
||||
// JobRoleId:5,
|
||||
// },
|
||||
// {
|
||||
// id:10,
|
||||
// FirtsName:"Nikil",
|
||||
// LastName:"Patil",
|
||||
// JobRoleId:5,
|
||||
// }
|
||||
// ]
|
||||
|
@ -66,6 +66,12 @@
|
||||
"available": true,
|
||||
"link": "/gallary"
|
||||
},
|
||||
{
|
||||
"text": "Expense",
|
||||
"icon": "bx bx-receipt",
|
||||
"available": true,
|
||||
"link": "/expenses"
|
||||
},
|
||||
{
|
||||
"text": "Administration",
|
||||
"icon": "bx bx-box",
|
||||
|
@ -12,213 +12,6 @@ import showToast from "../../services/toastService";
|
||||
|
||||
|
||||
|
||||
// const useMaster = () => {
|
||||
|
||||
// const selectedMaster = useSelector((store)=>store.localVariables.selectedMaster);
|
||||
// const [data, setData] = useState([]);
|
||||
// const [loading, setLoading] = useState(true);
|
||||
// const [error, setError] = useState("");
|
||||
// useEffect(() => {
|
||||
// const fetchData = async () => {
|
||||
// if (!selectedMaster) return;
|
||||
// setLoading(true);
|
||||
// try {
|
||||
// const cachedData = getCachedData(selectedMaster);
|
||||
// if (cachedData) {
|
||||
|
||||
// setData(cachedData);
|
||||
|
||||
// } else {
|
||||
// let response;
|
||||
// switch (selectedMaster) {
|
||||
// case "Application Role":
|
||||
// response = await MasterRespository.getRoles();
|
||||
// response = response.data;
|
||||
// break;
|
||||
// case "Job Role":
|
||||
// response = await MasterRespository.getJobRole();
|
||||
// response = response.data
|
||||
// break;
|
||||
// case "Activity":
|
||||
// response = await MasterRespository.getActivites();
|
||||
// response = response.data
|
||||
// break;
|
||||
// case "Work Category":
|
||||
// response = await MasterRespository.getWorkCategory();
|
||||
// response = response.data
|
||||
// break;
|
||||
// case "Contact Category":
|
||||
// response = await MasterRespository.getContactCategory();
|
||||
// response = response.data
|
||||
// break;
|
||||
// case "Contact Tag":
|
||||
// response = await MasterRespository.getContactTag();
|
||||
// response = response.data
|
||||
// break;
|
||||
// case "Status":
|
||||
// response = [{description: null,featurePermission: null,id: "02dd4761-363c-49ed-8851-3d2489a3e98d",status:"status 1"},{description: null,featurePermission: null,id: "03dy9761-363c-49ed-8851-3d2489a3e98d",status:"status 2"},{description: null,featurePermission: null,id: "03dy7761-263c-49ed-8851-3d2489a3e98d",status:"Status 3"}];
|
||||
// break;
|
||||
// default:
|
||||
// response = [];
|
||||
// }
|
||||
|
||||
// if (response) {
|
||||
// setData(response);
|
||||
// cacheData(selectedMaster, response);
|
||||
// }
|
||||
// }
|
||||
// } catch (err) {
|
||||
// setError("Failed to fetch data.");
|
||||
// } finally {
|
||||
// setLoading(false);
|
||||
// }
|
||||
// };
|
||||
|
||||
// if ( selectedMaster )
|
||||
// {
|
||||
|
||||
// fetchData();
|
||||
// }
|
||||
|
||||
// }, [selectedMaster]);
|
||||
|
||||
|
||||
|
||||
// return { data, loading, error }
|
||||
// };
|
||||
|
||||
|
||||
|
||||
|
||||
// export const useActivitiesMaster = () =>
|
||||
// {
|
||||
// const [ activities, setActivites ] = useState( [] )
|
||||
// const [ loading, setloading ] = useState( false );
|
||||
// const [ error, setError ] = useState()
|
||||
// const fetchActivities =async () => {
|
||||
// setloading(true);
|
||||
// try {
|
||||
// const response = await MasterRespository.getActivites();
|
||||
// setActivites(response.data);
|
||||
// cacheData( "ActivityMaster", response.data );
|
||||
// setloading(false);
|
||||
// } catch (err) {
|
||||
// setError(err);
|
||||
// setloading(false);
|
||||
// }
|
||||
// }
|
||||
// useEffect( () =>
|
||||
// {
|
||||
// const cacheddata = getCachedData( "ActivityMaster" );
|
||||
// if ( !cacheddata )
|
||||
// {
|
||||
// fetchActivities()
|
||||
// } else
|
||||
// {
|
||||
// setActivites(cacheddata);
|
||||
// }
|
||||
// }, [] )
|
||||
|
||||
// return {activities,loading,error}
|
||||
// }
|
||||
|
||||
// export const useWorkCategoriesMaster = () =>
|
||||
// {
|
||||
// const [ categories, setCategories ] = useState( [] )
|
||||
// const [ categoryLoading, setloading ] = useState( false );
|
||||
// const [ categoryError, setError ] = useState( "" )
|
||||
|
||||
// const fetchCategories =async () => {
|
||||
// const cacheddata = getCachedData("Work Category");
|
||||
|
||||
// if (!cacheddata) {
|
||||
// setloading(true);
|
||||
// try {
|
||||
// const response = await MasterRespository.getWorkCategory();
|
||||
// setCategories(response.data);
|
||||
// cacheData("Work Category", response.data);
|
||||
// } catch (err) {
|
||||
// setError(err);
|
||||
// console.log(err);
|
||||
// } finally {
|
||||
// setloading(false);
|
||||
// }
|
||||
// } else {
|
||||
// setCategories(cacheddata);
|
||||
// }
|
||||
// }
|
||||
// useEffect( () =>
|
||||
// {
|
||||
// fetchCategories()
|
||||
// }, [] )
|
||||
|
||||
// return {categories,categoryLoading,categoryError}
|
||||
// }
|
||||
|
||||
// export const useContactCategory = () =>
|
||||
// {
|
||||
// const [ contactCategory, setContactCategory ] = useState( [] )
|
||||
// const [ loading, setLoading ] = useState( false )
|
||||
// const [ Error, setError ] = useState()
|
||||
|
||||
// const fetchConatctCategory = async() =>
|
||||
// {
|
||||
// const cache_Category = getCachedData( "Contact Category" );
|
||||
// if ( !cache_Category )
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// let resp = await MasterRespository.getContactCategory();
|
||||
// setContactCategory( resp.data );
|
||||
// cacheData("Contact Category",resp.data)
|
||||
// } catch ( error )
|
||||
// {
|
||||
// setError(error)
|
||||
// }
|
||||
// } else
|
||||
// {
|
||||
// setContactCategory(cache_Category)
|
||||
// }
|
||||
// }
|
||||
|
||||
// useEffect( () =>
|
||||
// {
|
||||
// fetchConatctCategory()
|
||||
// }, [] )
|
||||
// return { contactCategory,loading,Error}
|
||||
// }
|
||||
// export const useContactTags = () => {
|
||||
// const [contactTags, setContactTags] = useState([]);
|
||||
// const [loading, setLoading] = useState(false);
|
||||
// const [error, setError] = useState(null);
|
||||
|
||||
// useEffect(() => {
|
||||
// const fetchContactTag = async () => {
|
||||
// const cache_Tags = getCachedData("Contact Tag");
|
||||
|
||||
// if (!cache_Tags) {
|
||||
// setLoading(true);
|
||||
// try {
|
||||
// const resp = await MasterRespository.getContactTag();
|
||||
// setContactTags(resp.data);
|
||||
// cacheData("Contact Tag", resp.data);
|
||||
// } catch (err) {
|
||||
// setError(err);
|
||||
// } finally {
|
||||
// setLoading(false);
|
||||
// }
|
||||
// } else {
|
||||
// setContactTags(cache_Tags);
|
||||
// }
|
||||
// };
|
||||
|
||||
// fetchContactTag();
|
||||
// }, []);
|
||||
|
||||
// return { contactTags, loading, error };
|
||||
// };
|
||||
|
||||
// Separate matser-------------
|
||||
|
||||
export const useActivitiesMaster = () =>
|
||||
{
|
||||
@ -300,6 +93,76 @@ export const useContactTags = () => {
|
||||
return { contactTags, loading, error };
|
||||
};
|
||||
|
||||
|
||||
export const useExpenseType =()=>{
|
||||
const {
|
||||
data: ExpenseTypes = [],
|
||||
isLoading: loading,
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ["Expense Type"],
|
||||
queryFn: async () => {
|
||||
const res = await MasterRespository.getExpenseType()
|
||||
return res.data;
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(
|
||||
error?.response?.data?.message ||
|
||||
error.message ||
|
||||
"Failed to fetch Expense Type",
|
||||
"error"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
return { ExpenseTypes, loading, error };
|
||||
}
|
||||
export const usePaymentMode =()=>{
|
||||
const {
|
||||
data: PaymentModes = [],
|
||||
isLoading: loading,
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ["Payment Mode"],
|
||||
queryFn: async () => {
|
||||
const res = await MasterRespository.getPaymentMode()
|
||||
return res.data;
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(
|
||||
error?.response?.data?.message ||
|
||||
error.message ||
|
||||
"Failed to fetch Payment Mode",
|
||||
"error"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
return { PaymentModes, loading, error };
|
||||
}
|
||||
export const useExpenseStatus =()=>{
|
||||
const {
|
||||
data: ExpenseStatus = [],
|
||||
isLoading: loading,
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ["Expense Status"],
|
||||
queryFn: async () => {
|
||||
const res = await MasterRespository.getExpenseStatus()
|
||||
return res.data;
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(
|
||||
error?.response?.data?.message ||
|
||||
error.message ||
|
||||
"Failed to fetch Expense Status",
|
||||
"error"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
return { ExpenseStatus, loading, error };
|
||||
}
|
||||
// ===Application Masters Query=================================================
|
||||
|
||||
const fetchMasterData = async (masterType) => {
|
||||
@ -316,6 +179,12 @@ const fetchMasterData = async (masterType) => {
|
||||
return (await MasterRespository.getContactCategory()).data;
|
||||
case "Contact Tag":
|
||||
return (await MasterRespository.getContactTag()).data;
|
||||
case "Expense Type":
|
||||
return (await MasterRespository.getExpenseType()).data;
|
||||
case "Payment Mode":
|
||||
return (await MasterRespository.getPaymentMode()).data;
|
||||
case "Expense Status":
|
||||
return (await MasterRespository.getExpenseStatus()).data;
|
||||
case "Status":
|
||||
return [
|
||||
{
|
||||
@ -666,6 +535,98 @@ export const useUpdateContactTag = (onSuccessCallback) =>
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------Expense Type------------------
|
||||
export const useCreateExpenseType = (onSuccessCallback)=>{
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation( {
|
||||
mutationFn: async ( payload ) =>
|
||||
{
|
||||
const resp = await MasterRespository.createExpenseType(payload);
|
||||
return resp.data;
|
||||
},
|
||||
onSuccess: ( data ) =>
|
||||
{
|
||||
queryClient.invalidateQueries( {queryKey:[ "masterData", "Expense Type" ]} )
|
||||
showToast( "Expense Type added successfully", "success" );
|
||||
if(onSuccessCallback) onSuccessCallback(data)
|
||||
},
|
||||
onError: ( error ) =>
|
||||
{
|
||||
showToast(error.message || "Something went wrong", "error");
|
||||
}
|
||||
})
|
||||
}
|
||||
export const useUpdateExpenseType = (onSuccessCallback) =>
|
||||
{
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ( {id, payload} ) =>
|
||||
{
|
||||
const response = await MasterRespository.updateExpenseType(id,payload);
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: (data, variables) => {
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["masterData", "Expense Type"],
|
||||
});
|
||||
showToast("Expense Type updated successfully.", "success");
|
||||
|
||||
if (onSuccessCallback) onSuccessCallback(data);
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(error.message || "Something went wrong", "error");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------Payment Mode -------------
|
||||
|
||||
export const useCreatePaymentMode = (onSuccessCallback)=>{
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation( {
|
||||
mutationFn: async ( payload ) =>
|
||||
{
|
||||
const resp = await MasterRespository.createPaymentMode(payload);
|
||||
return resp.data;
|
||||
},
|
||||
onSuccess: ( data ) =>
|
||||
{
|
||||
queryClient.invalidateQueries( {queryKey:[ "masterData", "Payment Mode" ]} )
|
||||
showToast( "Payment Mode added successfully", "success" );
|
||||
if(onSuccessCallback) onSuccessCallback(data)
|
||||
},
|
||||
onError: ( error ) =>
|
||||
{
|
||||
showToast(error.message || "Something went wrong", "error");
|
||||
}
|
||||
})
|
||||
}
|
||||
export const useUpdatePaymentMode = (onSuccessCallback)=>{
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation( {
|
||||
mutationFn: async ( {id,payload} ) =>
|
||||
{
|
||||
const resp = await MasterRespository.updatePaymentMode(id,payload);
|
||||
return resp.data;
|
||||
},
|
||||
onSuccess: ( data ) =>
|
||||
{
|
||||
queryClient.invalidateQueries( {queryKey:[ "masterData", "Payment Mode" ]} )
|
||||
showToast( "Payment Mode Updated successfully", "success" );
|
||||
if(onSuccessCallback) onSuccessCallback(data)
|
||||
},
|
||||
onError: ( error ) =>
|
||||
{
|
||||
showToast(error.message || "Something went wrong", "error");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// -Delete Master --------
|
||||
export const useDeleteMasterItem = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
198
src/hooks/useExpense.js
Normal file
198
src/hooks/useExpense.js
Normal file
@ -0,0 +1,198 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import ExpenseRepository from "../repositories/ExpsenseRepository";
|
||||
import showToast from "../services/toastService";
|
||||
import { queryClient } from "../layouts/AuthLayout";
|
||||
|
||||
// -------------------Query------------------------------------------------------
|
||||
export const useExpenseList = (pageSize, pageNumber, filter) => {
|
||||
return useQuery({
|
||||
queryKey: ["Expenses", pageNumber, pageSize, filter],
|
||||
queryFn: async () =>
|
||||
await ExpenseRepository.GetExpenseList(pageSize, pageNumber, filter).then(
|
||||
(res) => res.data
|
||||
),
|
||||
keepPreviousData: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const useExpense = (ExpenseId) => {
|
||||
return useQuery({
|
||||
queryKey: ["Expense", ExpenseId],
|
||||
queryFn: async () =>
|
||||
await ExpenseRepository.GetExpenseDetails(ExpenseId).then(
|
||||
(res) => res.data
|
||||
),
|
||||
enabled: !!ExpenseId,
|
||||
});
|
||||
};
|
||||
|
||||
// ---------------------------Mutation---------------------------------------------
|
||||
|
||||
export const useCreateExpnse = (onSuccessCallBack) => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (payload) => {
|
||||
await ExpenseRepository.CreateExpense(payload);
|
||||
},
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ["Expenses"] });
|
||||
showToast("Expense Created Successfully", "success");
|
||||
if (onSuccessCallBack) onSuccessCallBack();
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(
|
||||
error.message || "Something went wrong please try again !",
|
||||
"error"
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateExpense = (onSuccessCallBack) => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, payload }) => {
|
||||
const response = await ExpenseRepository.UpdateExpense(id, payload);
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: (updatedExpense, variables) => {
|
||||
// queryClient.setQueriesData(
|
||||
// {queryKey:['expenses'],exact:true},
|
||||
// (oldData) => {
|
||||
// if (!oldData || !oldData.data) return oldData;
|
||||
|
||||
// const updatedList = oldData.data.map((expense) => {
|
||||
// if (expense.id !== variables.id) return expense;
|
||||
|
||||
// return {
|
||||
// ...expense,
|
||||
// project:
|
||||
// expense.project.id !== updatedExpense.project.id
|
||||
// ? updatedExpense.project
|
||||
// : expense.project,
|
||||
// expensesType:
|
||||
// expense.expensesType.id !== updatedExpense.expensesType.id
|
||||
// ? updatedExpense.expensesType
|
||||
// : expense.expensesType,
|
||||
// paymentMode:
|
||||
// expense.paymentMode.id !== updatedExpense.paymentMode.id
|
||||
// ? updatedExpense.paymentMode
|
||||
// : expense.paymentMode,
|
||||
// paidBy:
|
||||
// expense.paidBy.id !== updatedExpense.paidBy.id
|
||||
// ? updatedExpense.paidBy
|
||||
// : expense.paidBy,
|
||||
// createdBy:
|
||||
// expense.createdBy.id !== updatedExpense.createdBy.id
|
||||
// ? updatedExpense.createdBy
|
||||
// : expense.createdBy,
|
||||
// createdAt: updatedExpense.createdAt,
|
||||
// status: updatedExpense.status,
|
||||
// nextStatus: updatedExpense.nextStatus,
|
||||
// preApproved: updatedExpense.preApproved,
|
||||
// transactionDate: updatedExpense.transactionDate,
|
||||
// amount: updatedExpense.amount,
|
||||
// };
|
||||
// });
|
||||
|
||||
// return {
|
||||
// ...oldData,
|
||||
// data: updatedList,
|
||||
// };
|
||||
// }
|
||||
// );
|
||||
queryClient.removeQueries({ queryKey: ["Expense", variables.id] });
|
||||
queryClient.invalidateQueries({ queryKey: ["Expenses"] });
|
||||
showToast("Expense updated Successfully", "success");
|
||||
|
||||
if (onSuccessCallBack) onSuccessCallBack();
|
||||
},
|
||||
onError:(error)=>{
|
||||
showToast( "Something went wrong.Please try again later.", "error");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useActionOnExpense = (onSuccessCallBack) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (payload) => {
|
||||
const response = await ExpenseRepository.ActionOnExpense(payload);
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: (updatedExpense, variables) => {
|
||||
showToast("Request processed successfully.", "success");
|
||||
|
||||
queryClient.setQueriesData(
|
||||
{
|
||||
queryKey: ["Expenses"],
|
||||
exact: false,
|
||||
},
|
||||
(oldData) => {
|
||||
if (!oldData) return oldData;
|
||||
return {
|
||||
...oldData,
|
||||
data: oldData.data.map((item) =>
|
||||
item.id === updatedExpense.id
|
||||
? {
|
||||
...item,
|
||||
nextStatus: updatedExpense.nextStatus,
|
||||
status: updatedExpense.status,
|
||||
}
|
||||
: item
|
||||
),
|
||||
};
|
||||
}
|
||||
);
|
||||
queryClient.setQueriesData(
|
||||
{ queryKey: ["Expense", updatedExpense.id] },
|
||||
(oldData) => {
|
||||
return {
|
||||
...oldData,
|
||||
nextStatus: updatedExpense.nextStatus,
|
||||
status: updatedExpense.status,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
if (onSuccessCallBack) onSuccessCallBack();
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(
|
||||
error.message || "Something went wrong.Please try again later.",
|
||||
"error"
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteExpense = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ id }) => {
|
||||
const response = await ExpenseRepository.DeleteExpense(id);
|
||||
return response.data;
|
||||
},
|
||||
onSuccess: (data, variables) => {
|
||||
queryClient.setQueryData(["Expenses"], (oldData) => {
|
||||
if (!oldData || !oldData.data) return queryClient.invalidateQueries({queryKey:["Expenses"]});
|
||||
|
||||
const updatedList = oldData.data.filter(
|
||||
(expense) => expense.id !== variables.id
|
||||
);
|
||||
|
||||
return {
|
||||
...oldData,
|
||||
data: updatedList,
|
||||
};
|
||||
});
|
||||
|
||||
showToast(data.message || "Expense deleted successfully", "success");
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(error.message || error.response.message || "Something went wrong.Please try again later.", "error");
|
||||
},
|
||||
});
|
||||
}
|
426
src/pages/Expense/ExpensePage.jsx
Normal file
426
src/pages/Expense/ExpensePage.jsx
Normal file
@ -0,0 +1,426 @@
|
||||
import React, {
|
||||
createContext,
|
||||
useContext,
|
||||
useState,
|
||||
useRef,
|
||||
useEffect,
|
||||
} from "react";
|
||||
import {
|
||||
useForm,
|
||||
useFieldArray,
|
||||
FormProvider,
|
||||
useFormContext,
|
||||
Controller,
|
||||
} from "react-hook-form";
|
||||
import ExpenseList from "../../components/Expenses/ExpenseList";
|
||||
import ViewExpense from "../../components/Expenses/ViewExpense";
|
||||
import Breadcrumb from "../../components/common/Breadcrumb";
|
||||
import GlobalModel from "../../components/common/GlobalModel";
|
||||
import PreviewDocument from "../../components/Expenses/PreviewDocument";
|
||||
import ManageExpense from "../../components/Expenses/ManageExpense";
|
||||
import { useProjectName } from "../../hooks/useProjects";
|
||||
import { useExpenseStatus } from "../../hooks/masterHook/useMaster";
|
||||
import {
|
||||
useEmployees,
|
||||
useEmployeesAllOrByProjectId,
|
||||
} from "../../hooks/useEmployees";
|
||||
import { useSelector } from "react-redux";
|
||||
import DateRangePicker from "../../components/common/DateRangePicker";
|
||||
import SelectMultiple from "../../components/common/SelectMultiple";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import {
|
||||
defaultFilter,
|
||||
SearchSchema,
|
||||
} from "../../components/Expenses/ExpenseSchema";
|
||||
|
||||
const SelectDropdown = ({
|
||||
label,
|
||||
options = [],
|
||||
loading = false,
|
||||
placeholder = "Select...",
|
||||
valueKey = "id",
|
||||
labelKey = "name",
|
||||
selectedValues = [],
|
||||
onChange,
|
||||
isMulti = false,
|
||||
}) => {
|
||||
const handleChange = (e) => {
|
||||
const selected = Array.from(
|
||||
e.target.selectedOptions,
|
||||
(option) => option.value
|
||||
);
|
||||
onChange && onChange(selected);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="select-dropdown">
|
||||
<label>{label}</label>
|
||||
<div className="dropdown-menu show">
|
||||
{options.map((option) => {
|
||||
const checked = selectedValues.includes(option[valueKey]);
|
||||
return (
|
||||
<div key={option[valueKey]} className="form-check">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="form-check-input"
|
||||
id={`checkbox-${option[valueKey]}`}
|
||||
checked={checked}
|
||||
onChange={() => {
|
||||
let newSelected;
|
||||
if (checked) {
|
||||
newSelected = selectedValues.filter(
|
||||
(val) => val !== option[valueKey]
|
||||
);
|
||||
} else {
|
||||
newSelected = [...selectedValues, option[valueKey]];
|
||||
}
|
||||
onChange(newSelected);
|
||||
}}
|
||||
/>
|
||||
<label
|
||||
className="form-check-label"
|
||||
htmlFor={`checkbox-${option[valueKey]}`}
|
||||
>
|
||||
{option[labelKey] || option[valueKey]}
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const ExpenseContext = createContext();
|
||||
export const useExpenseContext = () => useContext(ExpenseContext);
|
||||
|
||||
const ExpensePage = () => {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [filters,setFilter] = useState()
|
||||
const dropdownRef = useRef(null);
|
||||
const shouldCloseOnOutsideClick = useRef(false);
|
||||
const selectedProjectId = useSelector(
|
||||
(store) => store.localVariables.projectId
|
||||
);
|
||||
const [ManageExpenseModal, setManageExpenseModal] = useState({
|
||||
IsOpen: null,
|
||||
expenseId: null,
|
||||
});
|
||||
const [viewExpense, setViewExpense] = useState({
|
||||
expenseId: null,
|
||||
view: false,
|
||||
});
|
||||
const [ViewDocument, setDocumentView] = useState({
|
||||
IsOpen: false,
|
||||
Image: null,
|
||||
});
|
||||
|
||||
const contextValue = {
|
||||
setViewExpense,
|
||||
setManageExpenseModal,
|
||||
setDocumentView,
|
||||
};
|
||||
|
||||
const methods = useForm({
|
||||
resolver: zodResolver(SearchSchema),
|
||||
defaultValues: defaultFilter,
|
||||
});
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
control,
|
||||
getValues,
|
||||
trigger,
|
||||
setValue,
|
||||
watch,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = methods;
|
||||
|
||||
const { projectNames, loading: projectLoading } = useProjectName();
|
||||
const { ExpenseStatus, loading: statusLoading, error } = useExpenseStatus();
|
||||
const { employees, loading: empLoading } = useEmployeesAllOrByProjectId(
|
||||
true,
|
||||
selectedProjectId,
|
||||
true
|
||||
);
|
||||
|
||||
const onSubmit = (data) => {
|
||||
setFilter(data)
|
||||
};
|
||||
const isValidDate = (date) => {
|
||||
return date instanceof Date && !isNaN(date);
|
||||
};
|
||||
|
||||
const setDateRange = ({ startDate, endDate }) => {
|
||||
const parsedStart = new Date(startDate);
|
||||
const parsedEnd = new Date(endDate);
|
||||
|
||||
setValue(
|
||||
"startDate",
|
||||
isValidDate(parsedStart) ? parsedStart.toISOString().split("T")[0] : null
|
||||
);
|
||||
setValue(
|
||||
"endDate",
|
||||
isValidDate(parsedEnd) ? parsedEnd.toISOString().split("T")[0] : null
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const toggleDropdown = () => {
|
||||
setIsOpen((prev) => {
|
||||
shouldCloseOnOutsideClick.current = !prev;
|
||||
return !prev;
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
function handleClickOutside(event) {
|
||||
if (
|
||||
shouldCloseOnOutsideClick.current &&
|
||||
dropdownRef.current &&
|
||||
dropdownRef.current.contains(event.target)
|
||||
) {
|
||||
setIsOpen(false);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
return () => {
|
||||
document.removeEventListener("mousedown", handleClickOutside);
|
||||
};
|
||||
}, []);
|
||||
const clearFilter =()=>{
|
||||
setFilter(
|
||||
{
|
||||
projectIds: [],
|
||||
statusIds: [],
|
||||
createdByIds: [],
|
||||
paidById: [],
|
||||
startDate: null,
|
||||
endDate: null,
|
||||
})
|
||||
reset()
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<ExpenseContext.Provider value={contextValue}>
|
||||
<div className="container-fluid">
|
||||
<Breadcrumb
|
||||
data={[
|
||||
{ label: "Home", link: "/" },
|
||||
{ label: "Expense", link: null },
|
||||
]}
|
||||
/>
|
||||
<div className="card my-1 text-start px-0">
|
||||
<div className="card-body py-1 px-1">
|
||||
<div className="row">
|
||||
<div className="col-5 col-sm-4 d-flex aligin-items-center">
|
||||
<div
|
||||
className="dropdown d-inline-block mt-2 align-items-center"
|
||||
ref={dropdownRef}
|
||||
>
|
||||
<i
|
||||
className="bx bx-slider-alt ms-2"
|
||||
role="button"
|
||||
aria-expanded={isOpen}
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() => setIsOpen((v) => !v)}
|
||||
></i>
|
||||
{isOpen && (
|
||||
<div
|
||||
className="dropdown-menu p-3 overflow-hidden show d-flex align-items-center"
|
||||
style={{ minWidth: "500px" }}
|
||||
>
|
||||
<FormProvider {...methods}>
|
||||
<form
|
||||
className="p-2 p-sm-0"
|
||||
onSubmit={handleSubmit((data) => {
|
||||
onSubmit(data);
|
||||
setIsOpen(false);
|
||||
})}
|
||||
>
|
||||
<div className="w-100">
|
||||
<DateRangePicker
|
||||
onRangeChange={setDateRange}
|
||||
endDateMode="today"
|
||||
DateDifference="6"
|
||||
dateFormat="DD-MM-YYYY"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="row g-2">
|
||||
<div className="col-12 ">
|
||||
<label className="form-label d-block text-secondary">
|
||||
Select Status
|
||||
</label>
|
||||
<div className="d-flex flex-wrap">
|
||||
{ExpenseStatus.map((status) => (
|
||||
<Controller
|
||||
key={status.id}
|
||||
control={control}
|
||||
name="statusIds"
|
||||
render={({
|
||||
field: { value = [], onChange },
|
||||
}) => (
|
||||
<div className="d-flex align-items-center me-4 mb-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="form-check-input form-check-input-sm"
|
||||
value={status.id}
|
||||
checked={value.includes(status.id)}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) {
|
||||
onChange([...value, status.id]);
|
||||
} else {
|
||||
onChange(
|
||||
value.filter(
|
||||
(v) => v !== status.id
|
||||
)
|
||||
);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<label className="ms-2 mb-0">
|
||||
{status.displayName}
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row g-2">
|
||||
<SelectMultiple
|
||||
name="projectIds"
|
||||
label="Select Projects"
|
||||
options={projectNames}
|
||||
labelKey="name"
|
||||
valueKey="id"
|
||||
IsLoading={projectLoading}
|
||||
/>
|
||||
<SelectMultiple
|
||||
name="createdByIds"
|
||||
label="Select creator"
|
||||
options={employees}
|
||||
labelKey={(item) =>
|
||||
`${item.firstName} ${item.lastName}`
|
||||
}
|
||||
valueKey="id"
|
||||
IsLoading={empLoading}
|
||||
/>
|
||||
<SelectMultiple
|
||||
name="paidById"
|
||||
label="Select Paid by"
|
||||
options={employees}
|
||||
labelKey={(item) =>
|
||||
`${item.firstName} ${item.lastName}`
|
||||
}
|
||||
valueKey="id"
|
||||
IsLoading={empLoading}
|
||||
/>
|
||||
</div>
|
||||
<div className="d-flex justify-content-end py-1 gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary btn-xs"
|
||||
onClick={() => {
|
||||
clearFilter()
|
||||
setIsOpen(false);
|
||||
}}
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-primary btn-xs"
|
||||
>
|
||||
Apply
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-7 col-sm-8 text-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-offset="0,8"
|
||||
data-bs-placement="top"
|
||||
data-bs-custom-class="tooltip"
|
||||
title="Add New Expense"
|
||||
className={`p-1 me-2 bg-primary rounded-circle `}
|
||||
onClick={() =>
|
||||
setManageExpenseModal({
|
||||
IsOpen: true,
|
||||
expenseId: null,
|
||||
})
|
||||
}
|
||||
>
|
||||
<i className="bx bx-plus fs-4 text-white"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ExpenseList filters={filters} />
|
||||
{ManageExpenseModal.IsOpen && (
|
||||
<GlobalModel
|
||||
isOpen={ManageExpenseModal.IsOpen}
|
||||
size="lg"
|
||||
closeModal={() =>
|
||||
setManageExpenseModal({
|
||||
IsOpen: null,
|
||||
expenseId: null,
|
||||
})
|
||||
}
|
||||
>
|
||||
<ManageExpense
|
||||
key={ManageExpenseModal.expenseId ?? "new"}
|
||||
expenseToEdit={ManageExpenseModal.expenseId}
|
||||
closeModal={() =>
|
||||
setManageExpenseModal({ IsOpen: null, expenseId: null })
|
||||
}
|
||||
/>
|
||||
</GlobalModel>
|
||||
)}
|
||||
|
||||
{viewExpense.view && (
|
||||
<GlobalModel
|
||||
isOpen={viewExpense.view}
|
||||
size="lg"
|
||||
modalType="top"
|
||||
closeModal={() =>
|
||||
setViewExpense({
|
||||
expenseId: null,
|
||||
view: false,
|
||||
})
|
||||
}
|
||||
>
|
||||
<ViewExpense ExpenseId={viewExpense.expenseId} />
|
||||
</GlobalModel>
|
||||
)}
|
||||
|
||||
{ViewDocument.IsOpen && (
|
||||
<GlobalModel
|
||||
size="lg"
|
||||
key={ViewDocument.IsOpen ?? "new"}
|
||||
isOpen={ViewDocument.IsOpen}
|
||||
closeModal={() => setDocumentView({ IsOpen: false, Image: null })}
|
||||
>
|
||||
<PreviewDocument imageUrl={ViewDocument.Image} />
|
||||
</GlobalModel>
|
||||
)}
|
||||
</div>
|
||||
</ExpenseContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default ExpensePage;
|
@ -16,6 +16,10 @@ const MasterTable = ({ data, columns, loading, handleModalData }) => {
|
||||
"tenantId",
|
||||
"checkLists",
|
||||
"isSystem",
|
||||
"isActive",
|
||||
"noOfPersonsRequired",
|
||||
"color",
|
||||
"displayName"
|
||||
];
|
||||
|
||||
const safeData = Array.isArray(data) ? data : [];
|
||||
|
23
src/repositories/ExpsenseRepository.jsx
Normal file
23
src/repositories/ExpsenseRepository.jsx
Normal file
@ -0,0 +1,23 @@
|
||||
import { api } from "../utils/axiosClient";
|
||||
|
||||
|
||||
const ExpenseRepository = {
|
||||
GetExpenseList: ( pageSize, pageNumber, filter ) => {
|
||||
const payloadJsonString = JSON.stringify(filter);
|
||||
|
||||
|
||||
|
||||
return api.get(`/api/expense/list?pageSize=${pageSize}&pageNumber=${pageNumber}&filter=${payloadJsonString}`);
|
||||
},
|
||||
|
||||
GetExpenseDetails:(id)=>api.get(`/api/Expense/details/${id}`),
|
||||
CreateExpense:(data)=>api.post("/api/Expense/create",data),
|
||||
UpdateExpense:(id,data)=>api.put(`/api/Expense/edit/${id}`,data),
|
||||
DeleteExpense:(id)=>api.delete(`/api/Expense/delete/${id}`),
|
||||
|
||||
ActionOnExpense:(data)=>api.post('/api/expense/action',data),
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default ExpenseRepository;
|
@ -12,50 +12,66 @@ export const RolesRepository = {
|
||||
createRoles: (data) => api.post("/users", data),
|
||||
updateRoles: (id, data) => api.put(`/users/${id}`, data),
|
||||
deleteRoles: (id) => api.delete(`/users/${id}`),
|
||||
|
||||
|
||||
getEmployeeRoles:(id)=>api.get(`/api/employee/roles/${id}`),
|
||||
createEmployeeRoles:(data)=>api.post("/api/roles/assign-roles",data)
|
||||
getEmployeeRoles: (id) => api.get(`/api/employee/roles/${id}`),
|
||||
createEmployeeRoles: (data) => api.post("/api/roles/assign-roles", data),
|
||||
};
|
||||
|
||||
|
||||
export const MasterRespository = {
|
||||
getRoles: () => api.get("/api/roles"),
|
||||
createRole: (data) => api.post("/api/roles", data),
|
||||
updateRoles:(id,data) => api.put(`/api/roles/${id}`,data),
|
||||
getFeatures: () => api.get( `/api/feature` ),
|
||||
updateRoles: (id, data) => api.put(`/api/roles/${id}`, data),
|
||||
getFeatures: () => api.get(`/api/feature`),
|
||||
|
||||
createJobRole: (data) => api.post("api/roles/jobrole", data),
|
||||
getJobRole: () => api.get("/api/roles/jobrole"),
|
||||
updateJobRole: (id, data) => api.put(`/api/roles/jobrole/${id}`, data),
|
||||
|
||||
createJobRole:(data)=>api.post('api/roles/jobrole',data),
|
||||
getJobRole :()=>api.get("/api/roles/jobrole"),
|
||||
updateJobRole: ( id, data ) => api.put( `/api/roles/jobrole/${ id }`, data ),
|
||||
getActivites: () => api.get("api/master/activities"),
|
||||
createActivity: (data) => api.post("api/master/activity", data),
|
||||
updateActivity: (id, data) =>
|
||||
api.post(`api/master/activity/edit/${id}`, data),
|
||||
getIndustries: () => api.get("api/master/industries"),
|
||||
|
||||
|
||||
getActivites: () => api.get( 'api/master/activities' ),
|
||||
createActivity: (data) => api.post( 'api/master/activity',data ),
|
||||
updateActivity:(id,data) =>api.post(`api/master/activity/edit/${id}`,data),
|
||||
getIndustries: () => api.get( 'api/master/industries' ),
|
||||
|
||||
// delete
|
||||
"Job Role": ( id ) => api.delete( `/api/roles/jobrole/${ id }` ),
|
||||
"Activity": ( id ) => api.delete( `/api/master/activity/delete/${ id }` ),
|
||||
"Application Role":(id)=>api.delete(`/api/roles/${id}`),
|
||||
"Work Category": ( id ) => api.delete( `api/master/work-category/${ id }` ),
|
||||
"Contact Category": ( id ) => api.delete( `/api/master/contact-category/${id}` ),
|
||||
"Contact Tag" :(id)=>api.delete(`/api/master/contact-tag/${id}`),
|
||||
"Job Role": (id) => api.delete(`/api/roles/jobrole/${id}`),
|
||||
Activity: (id) => api.delete(`/api/master/activity/delete/${id}`),
|
||||
"Application Role": (id) => api.delete(`/api/roles/${id}`),
|
||||
"Work Category": (id) => api.delete(`api/master/work-category/${id}`),
|
||||
"Contact Category": (id) => api.delete(`/api/master/contact-category/${id}`),
|
||||
"Contact Tag": (id) => api.delete(`/api/master/contact-tag/${id}`),
|
||||
"Expense Type": (id, isActive) =>
|
||||
api.delete(`/api/Master/expenses-type/delete/${id}`, (isActive = false)),
|
||||
"Payment Mode": (id,isActive) =>
|
||||
api.delete(`/api/Master/payment-mode/delete/${id}`, (isActive = false)),
|
||||
|
||||
getWorkCategory:() => api.get(`/api/master/work-categories`),
|
||||
createWorkCategory: (data) => api.post(`/api/master/work-category`,data),
|
||||
updateWorkCategory: ( id, data ) => api.post( `/api/master/work-category/edit/${ id }`, data ),
|
||||
|
||||
getContactCategory: () => api.get( `/api/master/contact-categories` ),
|
||||
createContactCategory: (data ) => api.post( `/api/master/contact-category`, data ),
|
||||
updateContactCategory: ( id, data ) => api.post( `/api/master/contact-category/edit/${ id }`, data ),
|
||||
|
||||
getContactTag: () => api.get( `/api/master/contact-tags` ),
|
||||
createContactTag: (data ) => api.post( `/api/master/contact-tag`, data ),
|
||||
updateContactTag: ( id, data ) => api.post( `/api/master/contact-tag/edit/${ id }`, data ),
|
||||
getWorkCategory: () => api.get(`/api/master/work-categories`),
|
||||
createWorkCategory: (data) => api.post(`/api/master/work-category`, data),
|
||||
updateWorkCategory: (id, data) =>
|
||||
api.post(`/api/master/work-category/edit/${id}`, data),
|
||||
|
||||
getAuditStatus:()=>api.get('/api/Master/work-status')
|
||||
|
||||
}
|
||||
getContactCategory: () => api.get(`/api/master/contact-categories`),
|
||||
createContactCategory: (data) =>
|
||||
api.post(`/api/master/contact-category`, data),
|
||||
updateContactCategory: (id, data) =>
|
||||
api.post(`/api/master/contact-category/edit/${id}`, data),
|
||||
|
||||
getContactTag: () => api.get(`/api/master/contact-tags`),
|
||||
createContactTag: (data) => api.post(`/api/master/contact-tag`, data),
|
||||
updateContactTag: (id, data) =>
|
||||
api.post(`/api/master/contact-tag/edit/${id}`, data),
|
||||
|
||||
getAuditStatus: () => api.get("/api/Master/work-status"),
|
||||
|
||||
getExpenseType: () => api.get("/api/Master/expenses-types"),
|
||||
createExpenseType: (data) => api.post("/api/Master/expenses-type", data),
|
||||
updateExpenseType: (id, data) =>
|
||||
api.put(`/api/Master/expenses-type/edit/${id}`, data),
|
||||
|
||||
getPaymentMode: () => api.get("/api/Master/payment-modes"),
|
||||
createPaymentMode: (data) => api.post(`/api/Master/payment-mode`, data),
|
||||
updatePaymentMode: (id, data) =>
|
||||
api.put(`/api/Master/payment-mode/edit/${id}`, data),
|
||||
|
||||
getExpenseStatus: () => api.get("/api/Master/expenses-status"),
|
||||
};
|
||||
|
@ -38,6 +38,7 @@ import LegalInfoCard from "../pages/TermsAndConditions/LegalInfoCard";
|
||||
import ProtectedRoute from "./ProtectedRoute";
|
||||
import Directory from "../pages/Directory/Directory";
|
||||
import LoginWithOtp from "../pages/authentication/LoginWithOtp";
|
||||
import ExpensePage from "../pages/Expense/ExpensePage";
|
||||
|
||||
const router = createBrowserRouter(
|
||||
[
|
||||
@ -76,6 +77,7 @@ const router = createBrowserRouter(
|
||||
{ path: "/activities/task", element: <TaskPlannng /> },
|
||||
{ path: "/activities/reports", element: <Reports /> },
|
||||
{ path: "/gallary", element: <ImageGallary /> },
|
||||
{ path: "/expenses", element: <ExpensePage /> },
|
||||
{ path: "/masters", element: <MasterPage /> },
|
||||
{ path: "/help/support", element: <Support /> },
|
||||
{ path: "/help/docs", element: <Documentation /> },
|
||||
|
36
src/utils/appUtils.js
Normal file
36
src/utils/appUtils.js
Normal file
@ -0,0 +1,36 @@
|
||||
export const formatFileSize=(bytes)=> {
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
else if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + " KB";
|
||||
else return (bytes / (1024 * 1024)).toFixed(2) + " MB";
|
||||
}
|
||||
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 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; //
|
||||
};
|
@ -41,5 +41,20 @@ export const DIRECTORY_MANAGER = "62668630-13ce-4f52-a0f0-db38af2230c5"
|
||||
|
||||
export const DIRECTORY_USER = "0f919170-92d4-4337-abd3-49b66fc871bb"
|
||||
|
||||
export const VIEW_SELF_EXPENSE = "385be49f-8fde-440e-bdbc-3dffeb8dd116"
|
||||
|
||||
export const VIEW_ALL_EXPNESE = "01e06444-9ca7-4df4-b900-8c3fa051b92f";
|
||||
|
||||
export const CREATE_EXEPENSE = "0f57885d-bcb2-4711-ac95-d841ace6d5a7";
|
||||
|
||||
export const REVIEW_EXPENSE = "1f4bda08-1873-449a-bb66-3e8222bd871b";
|
||||
|
||||
export const APPROVE_EXPENSE = "eaafdd76-8aac-45f9-a530-315589c6deca";
|
||||
|
||||
|
||||
export const PROCESS_EXPENSE = "ea5a1529-4ee8-4828-80ea-0e23c9d4dd11"
|
||||
|
||||
export const EXPENSE_MANAGE = "ea5a1529-4ee8-4828-80ea-0e23c9d4dd11"
|
||||
|
||||
export const BASE_URL = process.env.VITE_BASE_URL;
|
||||
// export const BASE_URL = "https://api.marcoaiot.com";
|
@ -67,9 +67,13 @@ export const formatNumber = (num) => {
|
||||
if (num == null || isNaN(num)) return "NA";
|
||||
return Number.isInteger(num) ? num : num.toFixed(2);
|
||||
};
|
||||
export const formatUTCToLocalTime = (datetime) =>{
|
||||
return moment.utc(datetime).local().format("MMMM DD, YYYY [at] hh:mm A");
|
||||
}
|
||||
|
||||
|
||||
export const formatUTCToLocalTime = (datetime, timeRequired = false) => {
|
||||
return timeRequired
|
||||
? moment.utc(datetime).local().format("DD MMMM YYYY hh:mm A")
|
||||
: moment.utc(datetime).local().format("DD MMMM YYYY");
|
||||
};
|
||||
|
||||
export const getCompletionPercentage = (completedWork, plannedWork)=> {
|
||||
if (!plannedWork || plannedWork === 0) return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user