Added Emplyee Access missing names

This commit is contained in:
Srinath 2026-01-29 09:34:37 +05:30
parent aa59b1dce1
commit 83c9e20aae
1 changed files with 120 additions and 20 deletions

View File

@ -27,7 +27,8 @@ import {
} from '../../../Features/Offer/Offernew/Offernew.js'; } from '../../../Features/Offer/Offernew/Offernew.js';
import { Messages } from '../../../Components/Notifications/Messages.jsx'; 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 subDirectory = import.meta.env.ENV_BASE_URL;
const OfferListNew = () => { const OfferListNew = () => {
@ -39,6 +40,8 @@ const OfferListNew = () => {
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 UserType = getSession('UserType');
const UserId = getSession('UserId');
const [messageType, setMessageType] = useState(null); const [messageType, setMessageType] = useState(null);
const [messageData, setMessageData] = useState(null); const [messageData, setMessageData] = useState(null);
@ -46,6 +49,10 @@ const OfferListNew = () => {
const [page, setpage] = useState(1); const [page, setpage] = useState(1);
const [sortedInfo, setSortedInfo] = useState({}); const [sortedInfo, setSortedInfo] = useState({});
const { SadminuserAccess } = useAuth();
let SAAccessCommonMaster = SadminuserAccess?.find(
(e) => e?.MenuName === 'Product Based'
);
console.log(products, 'products'); console.log(products, 'products');
const [allOffers, setAllOffers] = useState([]); const [allOffers, setAllOffers] = useState([]);
@ -54,6 +61,8 @@ const OfferListNew = () => {
offer: null, offer: null,
newToDate: null, newToDate: null,
}); });
const [empData, setEmpData] = useState();
const [addnewAccess, setaddnewAccess] = useState(true);
const items = [ 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) { function ExtractDateFormate(dateString) {
if (!dateString) return ''; if (!dateString) return '';
@ -683,73 +723,131 @@ const OfferListNew = () => {
dataIndex: 'extend', dataIndex: 'extend',
key: 'extend', key: 'extend',
align: 'center', align: 'center',
render: (_, record) => render: (_, record) => {
record?.ActiveStatus === 'A' ? (
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 <div
className="extend-button" className={canEdit ? 'extend-button' : 'extendisabled'}
onClick={() => onClick={() => {
setExtendModal({ open: true, offer: record, newToDate: null }) if (!canEdit) return;
} setExtendModal({
open: true,
offer: record,
newToDate: null,
});
}}
style={{ style={{
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',
cursor: canEdit ? 'pointer' : 'not-allowed',
opacity: canEdit ? 1 : 0.5,
}} }}
> >
Extend Extend
</div> </div>
) : ( ) : (
<div className="extendisabled">Extend</div> <div className="extendisabled">Extend</div>
), );
}
}, },
{ {
title: 'Actions', title: 'Actions',
dataIndex: 'actions', dataIndex: 'actions',
key: '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' }}> <div style={{ display: 'flex', gap: '8px' }}>
<IoEyeOutline <IoEyeOutline
color="#2563EA" color="#2563EA"
size={18} size={18}
style={{ cursor: 'pointer' }}
onClick={(e) => { onClick={(e) => {
(e.stopPropagation(), e.stopPropagation();
setOpen((prev) => !prev), setOpen((prev) => !prev);
setProducts(record)); setProducts(record);
}} }}
/> />
{record.ActiveStatus == 'A' && (
{/* Edit */}
{record?.ActiveStatus === 'A' && (
<FiEdit <FiEdit
color="#2563EA" color="#2563EA"
style={{
cursor: canUpdate ? 'pointer' : 'not-allowed',
opacity: canUpdate ? 1 : 0.5,
}}
onClick={(e) => { onClick={(e) => {
(e.stopPropagation(), actionsFormatter(record, index)); e.stopPropagation();
if (!canUpdate) return;
actionsFormatter(record, index);
}} }}
/> />
)} )}
{record?.ActiveStatus == 'A' ? ( {record?.ActiveStatus === 'A' ? (
<RiDeleteBinLine <RiDeleteBinLine
color="#2563EA" color="#2563EA"
size={16} size={16}
style={{
cursor: canDelete ? 'pointer' : 'not-allowed',
opacity: canDelete ? 1 : 0.5,
}}
onClick={(e) => { onClick={(e) => {
(e.stopPropagation(), statusFormatter(record, index)); e.stopPropagation();
if (!canDelete) return;
statusFormatter(record, index);
}} }}
/> />
) : ( ) : (
<ReloadOutlined <ReloadOutlined
color="#2563EA" color="#2563EA"
size={16} size={16}
style={{
cursor: canDelete ? 'pointer' : 'not-allowed',
opacity: canDelete ? 1 : 0.5,
}}
onClick={(e) => { onClick={(e) => {
(e.stopPropagation(), statusFormatter(record, index)); e.stopPropagation();
if (!canDelete) return;
statusFormatter(record, index);
}} }}
/> />
)} )}
</div> </div>
), );
}, },
}
]; ];
const handleNewOffer = () => { const handleNewOffer = () => {
@ -797,7 +895,9 @@ const OfferListNew = () => {
<h3 className="offers-card__title">Product Offers</h3> <h3 className="offers-card__title">Product Offers</h3>
</div> </div>
<button className="CreateNewOfferBtn" onClick={handleNewOffer}> <button className="CreateNewOfferBtn"
onClick={handleNewOffer}
disabled={addnewAccess}>
Create New Offer Create New Offer
</button> </button>
</div> </div>