Added Emplyee Access missing names

This commit is contained in:
Srinath 2026-01-29 09:35:21 +05:30
parent b3c8b45a5d
commit ec9b1ed1a6
1 changed files with 99 additions and 19 deletions

View File

@ -18,23 +18,31 @@ import { deleteLoyaltyData, getLoyaltiPointsProductData, putLayoltiPointsData }
import { import {
ReloadOutlined, ReloadOutlined,
} from '@ant-design/icons'; } 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 subDirectory = import.meta.env.ENV_BASE_URL;
const LoyaltyBasedList = () => { const LoyaltyBasedList = () => {
dayjs.extend(isSameOrBefore); dayjs.extend(isSameOrBefore);
const { SadminuserAccess } = useAuth();
let SAAccessCommonMaster = SadminuserAccess?.find(
(e) => e?.MenuName === 'Loyalty Points'
);
const navigate = useNavigate(); const navigate = useNavigate();
const dispatch = useDispatch(); const dispatch = useDispatch();
const AppId = getSession("AppId") const AppId = getSession("AppId")
const CompId = getSession('CompId'); const CompId = getSession('CompId');
const BranchId = getSession('BranchId'); const BranchId = getSession('BranchId');
const UserId = getSession('UserId'); const UserId = getSession('UserId');
const UserType = getSession('UserType');
const [productdata, setProductdata] = useState() const [productdata, setProductdata] = useState()
const [searchText, setSearchText] = useState(""); const [searchText, setSearchText] = useState("");
const [messageType, setMessageType] = useState(null); const [messageType, setMessageType] = useState(null);
const [messageData, setMessageData] = useState(null); const [messageData, setMessageData] = useState(null);
const [empData, setEmpData] = useState();
const [addnewAccess, setaddnewAccess] = useState(true);
const [variantModal, setVariantModal] = useState({ const [variantModal, setVariantModal] = useState({
open: false, open: false,
reward: null, reward: null,
@ -69,6 +77,37 @@ const LoyaltyBasedList = () => {
useEffect(() => { useEffect(() => {
dispatch(changeBreadCrumb({ items: items })); 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) => { const onSearch = (value) => {
setSearchText(value.toLowerCase()); setSearchText(value.toLowerCase());
@ -224,18 +263,31 @@ const LoyaltyBasedList = () => {
{ {
title: "Extend Days", title: "Extend Days",
key: "extend", 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 (
<Button <Button
className="extend-button" className="extend-button"
onClick={() => handleView(record)} onClick={() => {
disabled={record.ActiveStatus !== "A"} if (!canExtend) return;
handleView(record);
}}
disabled={!canExtend}
style={{ style={{
opacity: record.ActiveStatus === "A" ? 1 : 0.6, opacity: canExtend ? 1 : 0.6,
pointerEvents: record.ActiveStatus === "A" ? "auto" : "none", pointerEvents: canExtend ? "auto" : "none",
cursor: canExtend ? "pointer" : "not-allowed",
height: "32px", height: "32px",
width: '100px', width: '100px',
padding: "1 12px", padding: "1px 12px",
display: "flex", display: "flex",
alignItems: "center", alignItems: "center",
justifyContent: "center" justifyContent: "center"
@ -243,13 +295,28 @@ const LoyaltyBasedList = () => {
> >
Extend Extend
</Button> </Button>
), );
}
}, },
{ {
title: "Actions", title: "Actions",
key: "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 (
<div style={{ display: "flex", gap: "8px" }}> <div style={{ display: "flex", gap: "8px" }}>
{/* View - only if RewardType !== Cash */} {/* View - only if RewardType !== Cash */}
{record?.RewardType !== "Cash" && ( {record?.RewardType !== "Cash" && (
@ -259,10 +326,7 @@ const LoyaltyBasedList = () => {
style={{ cursor: "pointer" }} style={{ cursor: "pointer" }}
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.stopPropagation();
setVariantModal({ setVariantModal({ open: true, product: record });
open: true,
product: record,
});
}} }}
/> />
)} )}
@ -272,9 +336,13 @@ const LoyaltyBasedList = () => {
<FiEdit <FiEdit
color="#2563EA" color="#2563EA"
size={14} size={14}
style={{ cursor: "pointer" }} style={{
cursor: canUpdate ? "pointer" : "not-allowed",
opacity: canUpdate ? 1 : 0.5,
}}
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.stopPropagation();
if (!canUpdate) return;
navigate(`${subDirectory}setting/loyalty-based/update`, { navigate(`${subDirectory}setting/loyalty-based/update`, {
state: { formType: "edit", editLoyalty: record }, state: { formType: "edit", editLoyalty: record },
}); });
@ -287,25 +355,37 @@ const LoyaltyBasedList = () => {
<RiDeleteBinLine <RiDeleteBinLine
color="#2563EA" color="#2563EA"
size={16} size={16}
style={{ cursor: "pointer" }} style={{
cursor: canDelete ? "pointer" : "not-allowed",
opacity: canDelete ? 1 : 0.5,
}}
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.stopPropagation();
if (!canDelete) return;
statusFormatter(record, "D"); // deactivate statusFormatter(record, "D"); // deactivate
}} }}
/> />
) : ( ) : (
<ReloadOutlined <ReloadOutlined
style={{ color: "#2563EA", fontSize: "14px", cursor: "pointer" }} style={{
color: "#2563EA",
fontSize: "14px",
cursor: canDelete ? "pointer" : "not-allowed",
opacity: canDelete ? 1 : 0.5,
}}
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.stopPropagation();
if (!canDelete) return;
statusFormatter(record, "A"); // reactivate statusFormatter(record, "A"); // reactivate
}} }}
/> />
)} )}
</div> </div>
), );
},
} }
]; ];
@ -326,7 +406,7 @@ const LoyaltyBasedList = () => {
<div className="offers-card"> <div className="offers-card">
<h3 className="offers-card__title">Loyalty Points</h3> <h3 className="offers-card__title">Loyalty Points</h3>
<button className='CreateNewOfferBtn' onClick={handleNewOffer}> <button className='CreateNewOfferBtn' onClick={handleNewOffer} disabled={addnewAccess}>
Create New Offer Create New Offer
</button> </button>
</div> </div>