Added Emplyee Access missing names
This commit is contained in:
parent
aa59b1dce1
commit
83c9e20aae
|
|
@ -27,7 +27,8 @@ import {
|
|||
} from '../../../Features/Offer/Offernew/Offernew.js';
|
||||
|
||||
import { Messages } from '../../../Components/Notifications/Messages.jsx';
|
||||
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 OfferListNew = () => {
|
||||
|
|
@ -39,6 +40,8 @@ const OfferListNew = () => {
|
|||
const AppId = getSession('AppId');
|
||||
const CompId = getSession('CompId');
|
||||
const BranchId = getSession('BranchId');
|
||||
const UserType = getSession('UserType');
|
||||
const UserId = getSession('UserId');
|
||||
|
||||
const [messageType, setMessageType] = useState(null);
|
||||
const [messageData, setMessageData] = useState(null);
|
||||
|
|
@ -46,6 +49,10 @@ const OfferListNew = () => {
|
|||
const [page, setpage] = useState(1);
|
||||
const [sortedInfo, setSortedInfo] = useState({});
|
||||
|
||||
const { SadminuserAccess } = useAuth();
|
||||
let SAAccessCommonMaster = SadminuserAccess?.find(
|
||||
(e) => e?.MenuName === 'Product Based'
|
||||
);
|
||||
console.log(products, 'products');
|
||||
|
||||
const [allOffers, setAllOffers] = useState([]);
|
||||
|
|
@ -54,6 +61,8 @@ const OfferListNew = () => {
|
|||
offer: null,
|
||||
newToDate: null,
|
||||
});
|
||||
const [empData, setEmpData] = useState();
|
||||
const [addnewAccess, setaddnewAccess] = useState(true);
|
||||
|
||||
const items = [
|
||||
{
|
||||
|
|
@ -540,6 +549,37 @@ const OfferListNew = () => {
|
|||
// ])
|
||||
};
|
||||
|
||||
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 === 'Product Based'
|
||||
);
|
||||
setEmpData(datas?.[0]);
|
||||
};
|
||||
function ExtractDateFormate(dateString) {
|
||||
if (!dateString) return '';
|
||||
|
||||
|
|
@ -683,73 +723,131 @@ const OfferListNew = () => {
|
|||
dataIndex: 'extend',
|
||||
key: 'extend',
|
||||
align: 'center',
|
||||
render: (_, record) =>
|
||||
record?.ActiveStatus === 'A' ? (
|
||||
render: (_, record) => {
|
||||
|
||||
const canUpdate =
|
||||
UserType === 'Super Admin' ||
|
||||
UserType === 'Admin' ||
|
||||
(UserType === 'Super Admin User' &&
|
||||
SAAccessCommonMaster?.UpdateAccess === 'Y') ||
|
||||
(UserType === 'Employee' && empData?.UpdateAccess === 'Y');
|
||||
|
||||
const canEdit =
|
||||
record?.ActiveStatus === 'A' && canUpdate;
|
||||
|
||||
return record?.ActiveStatus === 'A' ? (
|
||||
<div
|
||||
className="extend-button"
|
||||
onClick={() =>
|
||||
setExtendModal({ open: true, offer: record, newToDate: null })
|
||||
}
|
||||
className={canEdit ? 'extend-button' : 'extendisabled'}
|
||||
onClick={() => {
|
||||
if (!canEdit) return;
|
||||
setExtendModal({
|
||||
open: true,
|
||||
offer: record,
|
||||
newToDate: null,
|
||||
});
|
||||
}}
|
||||
style={{
|
||||
height: '32px',
|
||||
width: '100px',
|
||||
padding: '1 12px',
|
||||
padding: '1px 12px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
cursor: canEdit ? 'pointer' : 'not-allowed',
|
||||
opacity: canEdit ? 1 : 0.5,
|
||||
}}
|
||||
>
|
||||
Extend
|
||||
</div>
|
||||
) : (
|
||||
<div className="extendisabled">Extend</div>
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
title: 'Actions',
|
||||
dataIndex: 'actions',
|
||||
key: 'actions',
|
||||
render: (_, record, index) => (
|
||||
render: (_, record, index) => {
|
||||
|
||||
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' }}>
|
||||
<IoEyeOutline
|
||||
color="#2563EA"
|
||||
size={18}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={(e) => {
|
||||
(e.stopPropagation(),
|
||||
setOpen((prev) => !prev),
|
||||
setProducts(record));
|
||||
e.stopPropagation();
|
||||
setOpen((prev) => !prev);
|
||||
setProducts(record);
|
||||
}}
|
||||
/>
|
||||
{record.ActiveStatus == 'A' && (
|
||||
|
||||
{/* Edit */}
|
||||
{record?.ActiveStatus === 'A' && (
|
||||
<FiEdit
|
||||
color="#2563EA"
|
||||
style={{
|
||||
cursor: canUpdate ? 'pointer' : 'not-allowed',
|
||||
opacity: canUpdate ? 1 : 0.5,
|
||||
}}
|
||||
onClick={(e) => {
|
||||
(e.stopPropagation(), actionsFormatter(record, index));
|
||||
e.stopPropagation();
|
||||
if (!canUpdate) return;
|
||||
actionsFormatter(record, index);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{record?.ActiveStatus == 'A' ? (
|
||||
{record?.ActiveStatus === 'A' ? (
|
||||
<RiDeleteBinLine
|
||||
color="#2563EA"
|
||||
size={16}
|
||||
style={{
|
||||
cursor: canDelete ? 'pointer' : 'not-allowed',
|
||||
opacity: canDelete ? 1 : 0.5,
|
||||
}}
|
||||
onClick={(e) => {
|
||||
(e.stopPropagation(), statusFormatter(record, index));
|
||||
e.stopPropagation();
|
||||
if (!canDelete) return;
|
||||
statusFormatter(record, index);
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<ReloadOutlined
|
||||
color="#2563EA"
|
||||
size={16}
|
||||
style={{
|
||||
cursor: canDelete ? 'pointer' : 'not-allowed',
|
||||
opacity: canDelete ? 1 : 0.5,
|
||||
}}
|
||||
onClick={(e) => {
|
||||
(e.stopPropagation(), statusFormatter(record, index));
|
||||
e.stopPropagation();
|
||||
if (!canDelete) return;
|
||||
statusFormatter(record, index);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
];
|
||||
|
||||
const handleNewOffer = () => {
|
||||
|
|
@ -797,7 +895,9 @@ const OfferListNew = () => {
|
|||
<h3 className="offers-card__title">Product Offers</h3>
|
||||
</div>
|
||||
|
||||
<button className="CreateNewOfferBtn" onClick={handleNewOffer}>
|
||||
<button className="CreateNewOfferBtn"
|
||||
onClick={handleNewOffer}
|
||||
disabled={addnewAccess}>
|
||||
Create New Offer
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue