Added Emplyee Access missing names
This commit is contained in:
parent
b3c8b45a5d
commit
ec9b1ed1a6
|
|
@ -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 (
|
||||
<Button
|
||||
className="extend-button"
|
||||
onClick={() => handleView(record)}
|
||||
disabled={record.ActiveStatus !== "A"}
|
||||
onClick={() => {
|
||||
if (!canExtend) return;
|
||||
handleView(record);
|
||||
}}
|
||||
disabled={!canExtend}
|
||||
style={{
|
||||
opacity: record.ActiveStatus === "A" ? 1 : 0.6,
|
||||
pointerEvents: record.ActiveStatus === "A" ? "auto" : "none",
|
||||
opacity: canExtend ? 1 : 0.6,
|
||||
pointerEvents: canExtend ? "auto" : "none",
|
||||
cursor: canExtend ? "pointer" : "not-allowed",
|
||||
height: "32px",
|
||||
width: '100px',
|
||||
padding: "1 12px",
|
||||
padding: "1px 12px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center"
|
||||
|
|
@ -243,13 +295,28 @@ const LoyaltyBasedList = () => {
|
|||
>
|
||||
Extend
|
||||
</Button>
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
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 (
|
||||
<div style={{ display: "flex", gap: "8px" }}>
|
||||
{/* 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 = () => {
|
|||
<FiEdit
|
||||
color="#2563EA"
|
||||
size={14}
|
||||
style={{ cursor: "pointer" }}
|
||||
style={{
|
||||
cursor: canUpdate ? "pointer" : "not-allowed",
|
||||
opacity: canUpdate ? 1 : 0.5,
|
||||
}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (!canUpdate) return;
|
||||
navigate(`${subDirectory}setting/loyalty-based/update`, {
|
||||
state: { formType: "edit", editLoyalty: record },
|
||||
});
|
||||
|
|
@ -287,25 +355,37 @@ const LoyaltyBasedList = () => {
|
|||
<RiDeleteBinLine
|
||||
color="#2563EA"
|
||||
size={16}
|
||||
style={{ cursor: "pointer" }}
|
||||
style={{
|
||||
cursor: canDelete ? "pointer" : "not-allowed",
|
||||
opacity: canDelete ? 1 : 0.5,
|
||||
}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (!canDelete) return;
|
||||
statusFormatter(record, "D"); // deactivate
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<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) => {
|
||||
e.stopPropagation();
|
||||
if (!canDelete) return;
|
||||
statusFormatter(record, "A"); // reactivate
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
|
@ -326,7 +406,7 @@ const LoyaltyBasedList = () => {
|
|||
|
||||
<div className="offers-card">
|
||||
<h3 className="offers-card__title">Loyalty Points</h3>
|
||||
<button className='CreateNewOfferBtn' onClick={handleNewOffer}>
|
||||
<button className='CreateNewOfferBtn' onClick={handleNewOffer} disabled={addnewAccess}>
|
||||
Create New Offer
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue