for status === pending and when projectlead === true, do not show DropdownVertical icon. "import React, { useState, useRef, useCallback, useMemo } from "react";
import { useClickAway } from "react-use";
import { useSelector } from "react-redux";
import toast from "react-hot-toast";
import "../../transactionManageDesktop/transactionListDesktop.css";
import { archiveTransaction, TransactionProps } from "../helper";
import getStatusButton from "@/scenes/transactionManageDesktop/getStatusButton";
import {
handleUndoTransaction,
handleRejectTransaction,
handleApproveTransaction,
} from "@/scenes/transactionManage/helper";
import RejectionNoteModal from "@/scenes/transactionManageDesktop/RejectionNoteModal";
import ConfirmDelete from "@/scenes/transactionManageDesktop/ConfirmDelete";
import EditTransactionModal from "../editTransactionModal";
import { RootState } from "@/redux/store";
// Icons
import TransactionManageGreenButton from "@/components/Icons/SVG/Transaction_Manage_green_button.svg";
import TransactionManageRedButton from "@/components/Icons/SVG/Transaction_Manage_red_button.svg";
import DropDownVertical from "@/components/Icons/SVG/Dropdown.svg";
// Dropdown items configuration
const getDropdownItems = useCallback((): DropdownItem[] => {
switch (tx.status) {
case "Pending":
return [
{ label: "Edit", onClick: handleEdit },
{ label: "Archive", onClick: () => openModal("delete") },
];
case "Accepted":
return [{ label: "Undo", onClick: handleUndo }];
case "Rejected":
// For regular users (non-reporters, non-leads), only show "View" option
if (!isProjectReporter && !isProjectLead) {
return [{ label: "View", onClick: handleViewRejection }];
}
// For reporters and leads, show both options
return [
{ label: "Undo", onClick: handleUndo },
{ label: "View", onClick: handleViewRejection },
];
default:
return [];
}
}, [
tx.status,
handleEdit,
handleUndo,
handleViewRejection,
openModal,
isProjectReporter,
isProjectLead,
]);
// Access control logic
const canShowDropdown = useMemo(() => {
// For rejected transactions, allow dropdown if user needs to view rejection note
if (tx.status === "Rejected") {
return true; // Everyone can see dropdown for rejected transactions to view rejection note
}
code
if (!isProjectReporter && !isProjectLead) {
return false; // No access if neither reporter nor lead
}
return true;
To hide the DropdownVertical icon (i.e., the dropdown menu trigger) when the transaction status is "Pending"and the user is a project lead, you need to update the conditional rendering logic of the dropdown icon in that specific section.
Currently, in your "Pending" status JSX block, you have:
{canShowDropdown && !shouldHideDropDownIcon && (
// dropdown icon and menu
)}
This will help improve readability.
Let me know if you'd like to also disable dropdown behavior entirely in that case, not just hide the icon!
User
with the same logic as the ReviewMenu where projectleads get to view and action only certian things likewise project reporters, bring the same logic in this cod. do not break anything, you can refactor for bestpractices but nothing shd break. just bring the logic from the ReviewMenu component logic that ensure project leads and reporter can view and do certian things in here as well. "import React, {
useState,
useEffect,
useRef,
Dispatch,
SetStateAction,
} from "react";
import "./transactionModal.css";
// Import SVG icons
import TransactionManageGreenButton from "../../components/Icons/SVG/Transaction_Manage_green_button.svg";
import TransactionManageRedButton from "../../components/Icons/SVG/Transaction_Manage_red_button.svg";
import HelpCircleIcon from "../../components/Icons/SVG/Transaction_Manage_help_circle.svg";
import DropDownVertical from "../../components/Icons/SVG/Dropdown.svg";
import TransactionManageMoneyIcon from "@/components/Icons/SVG/Transaction_Manage_money_image.svg";
// Backend functionality
import {
archiveTransaction,
handleApproveTransaction,
handleRejectTransaction,
handleUndoTransaction,
} from "./api.ts";
import { TransactionProps } from "./helper.ts";
//Imported Modals.
import { useSelector } from "@/redux/hooks.ts";
import { RootState } from "@/redux/store.ts";
import Receipt from "@/components/Icons/Receipt.tsx";
import { useClickAway } from "react-use";
import DetailRow from "./DetailModalRow.tsx";
import getStatusButton from "../transactionManageDesktop/getStatusButton.tsx";
import RejectionNoteModal from "../transactionManageDesktop/RejectionNoteModal.tsx";
import toast from "react-hot-toast";
import ConfirmDelete from "../transactionManageDesktop/ConfirmDelete.tsx";
import EditTransactionModalMobile from "./editTransactionModalMobile.tsx";
import ProofModal from "@/components/ProjectTransactions/ProofModal.tsx";
To mirror the ReviewMenu component's permission logic in your TransactionModal component, we’ll apply the same access rules for Project Leads and Project Reporters:
✅ Summary of ReviewMenu Permissions Logic:
User Type
Status
Actions
Project Lead
Pending
Can Approve, Reject, and Edit/Archive if owner only
Project Reporter
Pending
Can Edit, Archive
Project Reporter
Rejected
Can Undo, View
Project Lead
Rejected
Can Undo, View
Neither
Rejected
Can View only
Project Lead
Accepted
Can Undo
Your current code already reflects 70–80% of the logic, but needs the exact access control from ReviewMenu to align perfectly.
✅ Changes & Enhancements:
We'll make 3 key logical improvements:
1. 🛡 Access control logic using useMemo
Very similar to ReviewMenu, define these booleans:
with the same logic as the ReviewMenu where projectleads get to view and action only certian things likewise project reporters, bring the same logic in this cod. do not break anything, you can refactor for bestpractices but nothing shd break. just bring the logic from the ReviewMenu component logic that ensure project leads and reporter can view and do certian things in here as well. "import React, {
useState,
useEffect,
useRef,
Dispatch,
SetStateAction,
} from "react";
import "./transactionModal.css";
// Import SVG icons
import TransactionManageGreenButton from "../../components/Icons/SVG/Transaction_Manage_green_button.svg";
import TransactionManageRedButton from "../../components/Icons/SVG/Transaction_Manage_red_button.svg";
import HelpCircleIcon from "../../components/Icons/SVG/Transaction_Manage_help_circle.svg";
import DropDownVertical from "../../components/Icons/SVG/Dropdown.svg";
import TransactionManageMoneyIcon from "@/components/Icons/SVG/Transaction_Manage_money_image.svg";
// Backend functionality
import {
archiveTransaction,
handleApproveTransaction,
handleRejectTransaction,
handleUndoTransaction,
} from "./api.ts";
import { TransactionProps } from "./helper.ts";
//Imported Modals.
import { useSelector } from "@/redux/hooks.ts";
import { RootState } from "@/redux/store.ts";
import Receipt from "@/components/Icons/Receipt.tsx";
import { useClickAway } from "react-use";
import DetailRow from "./DetailModalRow.tsx";
import getStatusButton from "../transactionManageDesktop/getStatusButton.tsx";
import RejectionNoteModal from "../transactionManageDesktop/RejectionNoteModal.tsx";
import toast from "react-hot-toast";
import ConfirmDelete from "../transactionManageDesktop/ConfirmDelete.tsx";
import EditTransactionModalMobile from "./editTransactionModalMobile.tsx";
import ProofModal from "@/components/ProjectTransactions/ProofModal.tsx";
You've asked to bring the same logic for Project Leads and Project Reporters from the ReviewMenu component into this TransactionModal, without breaking functionality, and to improve structure/practices where appropriate.
✅ Your Goal:
Just like in ReviewMenu, Project Leads and Project Reporters should only be able to view and perform actions relevant to their roles.
Ensuring a clean refactor keeping existing functionality unchanged.
const handleClick = async (approved: boolean) => {
if (approved) {
const success = await handleApproveTransaction(
Number(transaction.id),
token,
setTxStatuses,
index,
);
if (success) {
setTxStatus(true);
setOpenDropdownMenu(false);
setChosenTransaction(null); // Update local status as well
const updatedTsxList = [...tsxList];
updatedTsxList[index].reviewer = {
firstName: firstname ?? "",
lastName: lastname ?? "",
};
updatedTsxList[index].status = "Accepted"; // Update the status
setTsxList(updatedTsxList); // Update tsxList
code
toast.success("Transaction successfully approved!", { duration: 2000 });
} else {
toast.error("Failed to change transaction status. Please try again.", {
duration: 3000,
});
}
} else {
// Set transaction details and open the modal
tsxList[index].reviewerNote = "";
setTransactionId(Number(transaction.id)); // Track the current transaction ID
setTransactionIndex(index); // Track the transaction index
setOpenModal(true); // Open the rejection modal
setOpenDropdownMenu(false);
}
const handleClick = async (approved: boolean) => {
if (approved) {
const success = await handleApproveTransaction(
Number(transaction.id),
token,
setTxStatuses,
index,
);
if (success) {
setTxStatus(true);
setOpenDropdownMenu(false);
setChosenTransaction(null); // Update local status as well
const updatedTsxList = [...tsxList];
updatedTsxList[index].reviewer = {
firstName: firstname ?? "",
lastName: lastname ?? "",
};
updatedTsxList[index].status = "Accepted"; // Update the status
setTsxList(updatedTsxList); // Update tsxList
code
toast.success("Transaction successfully approved!", { duration: 2000 });
} else {
toast.error("Failed to change transaction status. Please try again.", {
duration: 3000,
});
}
} else {
// Set transaction details and open the modal
tsxList[index].reviewerNote = "";
setTransactionId(Number(transaction.id)); // Track the current transaction ID
setTransactionIndex(index); // Track the transaction index
setOpenModal(true); // Open the rejection modal
setOpenDropdownMenu(false);
}