Added Emplyee Access missing names

This commit is contained in:
Srinath 2026-01-29 09:34:54 +05:30
parent 83c9e20aae
commit b3c8b45a5d
1 changed files with 104 additions and 17 deletions

View File

@ -19,23 +19,31 @@ import { deleteOfferCodeData, getCodeBaseProductData, putOfferCodeData } from '.
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 CodeBaseList = () => {
dayjs.extend(isSameOrBefore);
const { SadminuserAccess } = useAuth();
let SAAccessCommonMaster = SadminuserAccess?.find(
(e) => e?.MenuName === 'Code Based'
);
const navigate = useNavigate();
const dispatch = useDispatch();
const AppId = getSession("AppId")
const CompId = getSession('CompId');
const BranchId = getSession('BranchId');
const UserType = getSession('UserType');
const UserId = getSession('UserId');
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,
variants: [],
@ -68,6 +76,38 @@ const CodeBaseList = () => {
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 === 'Code Based'
);
setEmpData(datas?.[0]);
};
const onSearch = (value) => {
setSearchText(value.toLowerCase());
}
@ -137,6 +177,13 @@ const CodeBaseList = () => {
setMessageType(null);
}, []);
const canUpdate =
UserType === 'Super Admin' ||
UserType === 'Admin' ||
(UserType === 'Super Admin User' &&
SAAccessCommonMaster?.UpdateAccess === 'Y') ||
(UserType === 'Employee' && empData?.UpdateAccess === 'Y');
const generalColumns = [
{
title: 'Sl.No',
@ -231,40 +278,63 @@ const CodeBaseList = () => {
title: "Extend Date",
key: "extend",
align: "center",
render: (_, record) => (
render: (_, record) => {
const canExtend =
record?.ActiveStatus === 'A' && canUpdate;
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",
height: "32px",
width: '100px',
padding: "1 12px",
width: "100px",
padding: "1px 12px",
display: "flex",
alignItems: "center",
justifyContent: "center"
justifyContent: "center",
cursor: canExtend ? "pointer" : "not-allowed",
}}
>
Extend
</Button>
),
);
},
},
{
title: "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();
setVariantModal({
open: true,
product: record, // store the selected product
product: record,
variants: record?.ProdOfferDetails || [],
});
}}
@ -272,9 +342,13 @@ const CodeBaseList = () => {
{record.ActiveStatus === "A" && (
<FiEdit
color="#2563EA"
style={{ cursor: "pointer" }}
style={{
cursor: canUpdate ? "pointer" : "not-allowed",
opacity: canUpdate ? 1 : 0.5,
}}
onClick={(e) => {
e.stopPropagation();
if (!canUpdate) return;
navigate(`${subDirectory}setting/code-base/new`, {
state: { formType: "edit", editOffer: record },
});
@ -285,25 +359,37 @@ const CodeBaseList = () => {
<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", index);
}}
/>
) : (
<ReloadOutlined
style={{ color: "#2563EA", fontSize: "16px", cursor: "pointer" }}
style={{
color: "#2563EA",
fontSize: "16px",
cursor: canDelete ? "pointer" : "not-allowed",
opacity: canDelete ? 1 : 0.5,
}}
onClick={(e) => {
e.stopPropagation();
if (!canDelete) return;
statusFormatter(record, "A", index);
}}
/>
)}
</div>
),
);
},
}
];
@ -324,7 +410,8 @@ const CodeBaseList = () => {
<div className="offers-card">
<h3 className="offers-card__title">Code Base Offers</h3>
<button className='CreateNewOfferBtn' onClick={handleNewOffer}>
<button className='CreateNewOfferBtn' onClick={handleNewOffer}
disabled={addnewAccess}>
Create New Offer
</button>
</div>