From ec9b1ed1a63d648fad90436f38616d731477c952 Mon Sep 17 00:00:00 2001 From: Srinath Date: Thu, 29 Jan 2026 09:35:21 +0530 Subject: [PATCH] Added Emplyee Access missing names --- .../Offer/LoyaltyBased/LoyaltyBasedList.jsx | 118 +++++++++++++++--- 1 file changed, 99 insertions(+), 19 deletions(-) diff --git a/src/Pages/Offer/LoyaltyBased/LoyaltyBasedList.jsx b/src/Pages/Offer/LoyaltyBased/LoyaltyBasedList.jsx index 074e3bc..fca20ad 100644 --- a/src/Pages/Offer/LoyaltyBased/LoyaltyBasedList.jsx +++ b/src/Pages/Offer/LoyaltyBased/LoyaltyBasedList.jsx @@ -18,23 +18,31 @@ import { deleteLoyaltyData, getLoyaltiPointsProductData, putLayoltiPointsData } import { ReloadOutlined, } from '@ant-design/icons'; -import { changeBreadCrumb } from '../../../Features/AppPage/CenterPage.js'; +import { changeBreadCrumb, getEmpAccess } from '../../../Features/AppPage/CenterPage.js'; +import { useAuth } from '../../../AuthContext.jsx'; const subDirectory = import.meta.env.ENV_BASE_URL; const LoyaltyBasedList = () => { dayjs.extend(isSameOrBefore); + const { SadminuserAccess } = useAuth(); + let SAAccessCommonMaster = SadminuserAccess?.find( + (e) => e?.MenuName === 'Loyalty Points' + ); const navigate = useNavigate(); const dispatch = useDispatch(); const AppId = getSession("AppId") const CompId = getSession('CompId'); const BranchId = getSession('BranchId'); const UserId = getSession('UserId'); + const UserType = getSession('UserType'); const [productdata, setProductdata] = useState() const [searchText, setSearchText] = useState(""); const [messageType, setMessageType] = useState(null); const [messageData, setMessageData] = useState(null); + const [empData, setEmpData] = useState(); + const [addnewAccess, setaddnewAccess] = useState(true); const [variantModal, setVariantModal] = useState({ open: false, reward: null, @@ -69,6 +77,37 @@ const LoyaltyBasedList = () => { useEffect(() => { dispatch(changeBreadCrumb({ items: items })); }, []); + useEffect(() => { + let hasAccess = false; + if (UserType === 'Admin' || UserType === 'Super Admin') { + hasAccess = true; + } else if (UserType === 'Employee') { + hasAccess = empData?.AddAccess === 'Y'; + } else if (UserType === 'Super Admin User') { + hasAccess = SAAccessCommonMaster?.AddAccess === 'Y'; + } + + setaddnewAccess(!hasAccess); + }, [empData, SAAccessCommonMaster, UserType]); + + useEffect(() => { + if (UserType === "Employee") { + fetchApi() + } + }, [UserType]) + const fetchApi = async () => { + let data = { + CompId: CompId, + BranchId: BranchId, + AppId: AppId, + EmpId: UserId, + }; + let response = await dispatch(getEmpAccess(data)).unwrap(); + let datas = response?.data?.data?.[0]?.EmpAccessDetails?.filter( + (item) => item.ConfigName === 'Loyalty Points' + ); + setEmpData(datas?.[0]); + }; const onSearch = (value) => { setSearchText(value.toLowerCase()); @@ -224,18 +263,31 @@ const LoyaltyBasedList = () => { { title: "Extend Days", key: "extend", - // align: "center", - render: (_, record) => ( + render: (_, record) => { + const canExtend = + record.ActiveStatus === "A" && + ( + UserType === "Super Admin" || + UserType === "Admin" || + (UserType === "Super Admin User" && SAAccessCommonMaster?.UpdateAccess === "Y") || + (UserType === "Employee" && empData?.UpdateAccess === "Y") + ); + + return ( - ), + ); + } }, { title: "Actions", key: "actions", - render: (_, record) => ( + render: (_, record) => { + // Permission checks + const canUpdate = + UserType === "Super Admin" || + UserType === "Admin" || + (UserType === "Super Admin User" && SAAccessCommonMaster?.UpdateAccess === "Y") || + (UserType === "Employee" && empData?.UpdateAccess === "Y"); + + const canDelete = + UserType === "Super Admin" || + UserType === "Admin" || + (UserType === "Super Admin User" && SAAccessCommonMaster?.DeleteAccess === "Y") || + (UserType === "Employee" && empData?.DeleteAccess === "Y"); + + return (
{/* View - only if RewardType !== Cash */} {record?.RewardType !== "Cash" && ( @@ -259,10 +326,7 @@ const LoyaltyBasedList = () => { style={{ cursor: "pointer" }} onClick={(e) => { e.stopPropagation(); - setVariantModal({ - open: true, - product: record, - }); + setVariantModal({ open: true, product: record }); }} /> )} @@ -272,9 +336,13 @@ const LoyaltyBasedList = () => { { e.stopPropagation(); + if (!canUpdate) return; navigate(`${subDirectory}setting/loyalty-based/update`, { state: { formType: "edit", editLoyalty: record }, }); @@ -287,25 +355,37 @@ const LoyaltyBasedList = () => { { e.stopPropagation(); + if (!canDelete) return; statusFormatter(record, "D"); // deactivate }} /> ) : ( { e.stopPropagation(); + if (!canDelete) return; statusFormatter(record, "A"); // reactivate }} /> )}
- ), + ); + }, } + ]; @@ -326,7 +406,7 @@ const LoyaltyBasedList = () => {

Loyalty Points

-