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