diff --git a/src/components/Expenses/ViewExpense.jsx b/src/components/Expenses/ViewExpense.jsx
index a9f7ae0f..f6aeb09e 100644
--- a/src/components/Expenses/ViewExpense.jsx
+++ b/src/components/Expenses/ViewExpense.jsx
@@ -1,5 +1,9 @@
-import React, { useState } from "react";
-import { useActionOnExpense, useExpense } from "../../hooks/useExpense";
+import React, { useState, useMemo } from "react";
+import {
+ useActionOnExpense,
+ useExpense,
+ useHasAnyPermission,
+} from "../../hooks/useExpense";
import { formatUTCToLocalTime } from "../../utils/dateUtils";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
@@ -7,11 +11,18 @@ import { ActionSchema } from "./ExpenseSchema";
import { useExpenseContext } from "../../pages/Expense/ExpensePage";
import { getColorNameFromHex } from "../../utils/appUtils";
import { ExpenseDetailsSkeleton } from "./ExpenseSkeleton";
+import { useHasUserPermission } from "../../hooks/useHasUserPermission";
+import { REVIEW_EXPENSE } from "../../utils/constants";
+import { useProfile } from "../../hooks/useProfile";
+import { useSelector } from "react-redux";
+import { useNavigate } from "react-router-dom";
const ViewExpense = ({ ExpenseId }) => {
const { data, isLoading, isError, error } = useExpense(ExpenseId);
+ const IsReview = useHasUserPermission(REVIEW_EXPENSE);
const [imageLoaded, setImageLoaded] = useState({});
const { setDocumentView } = useExpenseContext();
+ const navigate = useNavigate();
const {
register,
handleSubmit,
@@ -26,6 +37,24 @@ const ViewExpense = ({ ExpenseId }) => {
},
});
+ const userPermissions = useSelector(
+ (state) => state?.globalVariables?.loginUser?.featurePermissions || []
+ );
+
+ const nextStatusWithPermission = useMemo(() => {
+ if (!Array.isArray(data?.nextStatus)) return [];
+
+ return data.nextStatus.filter((status) => {
+ const permissionIds = Array.isArray(status?.permissionIds)
+ ? status.permissionIds
+ : [];
+
+ if (permissionIds.length === 0) return true;
+
+ return permissionIds.some((id) => userPermissions.includes(id));
+ });
+ }, [data, userPermissions]);
+
const { mutate: MakeAction } = useActionOnExpense(() => reset());
const onSubmit = (formData) => {
@@ -163,12 +192,27 @@ const ViewExpense = ({ ExpenseId }) => {
{data?.description}
-
-
- {data?.documents &&
- data?.documents?.map((doc) => (
+
+
+
+ {data?.documents?.map((doc) => {
+ const getIconByType = (type) => {
+ if (!type) return "bx bx-file";
+
+ if (type.includes("pdf")) return "bxs-file-pdf";
+ if (type.includes("word")) return "bxs-file-doc";
+ if (type.includes("excel") || type.includes("spreadsheet"))
+ return "bxs-file-xls";
+ if (type.includes("image")) return "bxs-file-image";
+ if (type.includes("zip") || type.includes("rar"))
+ return "bxs-file-archive";
+
+ return "bx bx-file"; // Default
+ };
+
+ const isImage = doc.contentType?.includes("image");
+
+ return (
{
{
+ if (isImage) {
+ setDocumentView({
+ IsOpen: true,
+ Image: doc.preSignedUrl,
+ });
+ }
+ }}
>
- {doc.contentType === "application/pdf" ? (
-
-
-
- ) : (
- <>
- {!imageLoaded[doc.id] && (
-
- Loading...
-
- )}
-

handleImageLoad(doc.id)}
- onClick={() =>
- setDocumentView({
- IsOpen: true,
- Image: doc.preSignedUrl,
- })
- }
- />
- >
- )}
+
- ))}
+ );
+ })}
- {Array.isArray(data.nextStatus) && data.nextStatus.length > 0 && (
+ {Array.isArray(data?.nextStatus) && data.nextStatus.length > 0 && (
)}
diff --git a/src/hooks/useExpense.js b/src/hooks/useExpense.js
index 7be658f4..534c3e82 100644
--- a/src/hooks/useExpense.js
+++ b/src/hooks/useExpense.js
@@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import ExpenseRepository from "../repositories/ExpsenseRepository";
import showToast from "../services/toastService";
import { queryClient } from "../layouts/AuthLayout";
+import { useSelector } from "react-redux";
// -------------------Query------------------------------------------------------
export const useExpenseList = (pageSize, pageNumber, filter) => {
@@ -196,3 +197,21 @@ export const useDeleteExpense = () => {
},
});
}
+
+
+
+
+export const useHasAnyPermission = (permissionIdsInput) => {
+ const permissions = useSelector(
+ (state) => state?.profile?.permissions || []
+ );
+
+ const permissionIds = Array.isArray(permissionIdsInput)
+ ? permissionIdsInput
+ : [];
+
+ // No permission needed
+ if (permissionIds.length === 0) return true;
+
+ return permissionIds.some((id) => permissions.includes(id));
+};
\ No newline at end of file
diff --git a/src/pages/Expense/ExpensePage.jsx b/src/pages/Expense/ExpensePage.jsx
index 3b29f74f..12e758b6 100644
--- a/src/pages/Expense/ExpensePage.jsx
+++ b/src/pages/Expense/ExpensePage.jsx
@@ -32,6 +32,8 @@ import {
defaultFilter,
SearchSchema,
} from "../../components/Expenses/ExpenseSchema";
+import { useHasUserPermission } from "../../hooks/useHasUserPermission";
+import { CREATE_EXEPENSE } from "../../utils/constants";
const SelectDropdown = ({
label,
@@ -97,6 +99,7 @@ export const useExpenseContext = () => useContext(ExpenseContext);
const ExpensePage = () => {
const [isOpen, setIsOpen] = useState(false);
const [filters,setFilter] = useState()
+ const IsCreatedAble = useHasUserPermission(CREATE_EXEPENSE)
const dropdownRef = useRef(null);
const shouldCloseOnOutsideClick = useRef(false);
const selectedProjectId = useSelector(
@@ -348,7 +351,8 @@ const setDateRange = ({ startDate, endDate }) => {
-
+ )}
+