296 lines
8.6 KiB
JavaScript
296 lines
8.6 KiB
JavaScript
import { useState, useEffect, useCallback } from 'react';
|
|
import { useDispatch } from 'react-redux';
|
|
import { Space } from 'antd';
|
|
import { EditFilled, PlusOutlined } from '@ant-design/icons';
|
|
import {
|
|
changeBreadCrumb,
|
|
getEmpAccess,
|
|
} from '../../Features/AppPage/CenterPage.js';
|
|
import { PricingAppPricingName } from '../../Features/BrachLogin/BranchLogin.js';
|
|
import { Tables } from '../../Components/Tables/Table';
|
|
import FormHeader from '../PageComponents/FormHeader.jsx';
|
|
import { useNavigate, useLocation } from 'react-router-dom';
|
|
import Search from '../../Components/Forms/Search.jsx';
|
|
import Buttons from '../../Components/Forms/Buttons';
|
|
import { getSession } from '../../Services/Others';
|
|
import { Messages } from '../../Components/Notifications/Messages';
|
|
import '../../Styles/Employee/EmpMaster.scss';
|
|
import { useAuth } from '../../AuthContext.jsx';
|
|
import { getEmpScreenRights } from '../../Features/EmpScreenRights/EmpScreenRights.js';
|
|
const subDirectory = import.meta.env.BASE_URL;
|
|
|
|
const items = [
|
|
{
|
|
name: 'Home',
|
|
link: `${subDirectory}app-page/home`,
|
|
},
|
|
|
|
{
|
|
name: 'EmployeeScreenRights',
|
|
link: `${subDirectory}setting/employee-screenrights`,
|
|
},
|
|
];
|
|
|
|
const EmployeeScreenAccess = () => {
|
|
const { SadminuserAccess } = useAuth();
|
|
|
|
let SAAccessCommonMaster = SadminuserAccess?.find(
|
|
(e) => e?.MenuName === 'Employee Screen Rights'
|
|
);
|
|
console.log(SadminuserAccess, 'SadminuserAccessSadminuserAccess');
|
|
const navigate = useNavigate();
|
|
const location = useLocation();
|
|
const dispatch = useDispatch();
|
|
|
|
const [messageType, setMessageType] = useState(null);
|
|
const [messageData, setMessageData] = useState(null);
|
|
const [TableData, setTableData] = useState([]);
|
|
const [filteredInfo, setFilteredInfo] = useState({});
|
|
const [sortedInfo, setSortedInfo] = useState({});
|
|
const [searchedText, setSearchedText] = useState('');
|
|
const [page, setpage] = useState(1);
|
|
const [Advance, setAdvance] = useState(false);
|
|
const [empData, setEmpData] = useState();
|
|
const [addnewAccess, setaddnewAccess] = useState(true);
|
|
|
|
const AppId = getSession('AppId');
|
|
const CompId = getSession('CompId');
|
|
const BranchId = getSession('BranchId');
|
|
const UserId = getSession('UserId');
|
|
const UserType = getSession('UserType');
|
|
|
|
async function fetchData() {
|
|
if (location?.state?.Notiffy) {
|
|
setMessageType(location?.state?.Notiffy.messageType);
|
|
setMessageData(location?.state?.Notiffy.messageData);
|
|
}
|
|
|
|
let data = {
|
|
CompId: CompId,
|
|
BranchId: BranchId,
|
|
AppId: AppId,
|
|
UserType: 'E',
|
|
};
|
|
const gettingTableData = await dispatch(getEmpScreenRights(data)).unwrap();
|
|
if (gettingTableData?.data?.statusCode === 1) {
|
|
setTableData(gettingTableData?.data?.data);
|
|
}
|
|
}
|
|
const getPricingName = async () => {
|
|
if (AppId != undefined && UserId != undefined) {
|
|
let data = {
|
|
appId: AppId,
|
|
userId: UserId,
|
|
};
|
|
const Response = await dispatch(PricingAppPricingName(data)).unwrap();
|
|
if (Response?.data?.statusCode == 1) {
|
|
let ResponseData = Response?.data?.data?.some(
|
|
(item) => item.PricingName === 'Advance'
|
|
);
|
|
ResponseData ? setAdvance(true) : setAdvance(false);
|
|
}
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
try {
|
|
fetchData();
|
|
getPricingName();
|
|
} catch (err) {
|
|
console.log(err, 'err');
|
|
}
|
|
// if (UserType === "Employee") {
|
|
// fetchApi()
|
|
// }
|
|
}, []);
|
|
useEffect(() => {
|
|
if (UserType === 'Employee') {
|
|
fetchApi();
|
|
}
|
|
}, [UserType]);
|
|
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]);
|
|
|
|
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 === 'Employee Screen Rights'
|
|
);
|
|
setEmpData(datas?.[0]);
|
|
};
|
|
|
|
useEffect(() => {
|
|
dispatch(changeBreadCrumb({ items: items }));
|
|
}, []);
|
|
|
|
const handleChange = (pagination, filters, sorter) => {
|
|
setFilteredInfo(filters);
|
|
setSortedInfo(sorter);
|
|
};
|
|
|
|
const handlePageChange = (current) => {
|
|
setpage(current);
|
|
};
|
|
|
|
const actionsFormatter = async (row, rowIndex) => {
|
|
if (row.ActiveStatus !== 'D') {
|
|
navigate(
|
|
`${subDirectory}setting/employee-screenrights/update`,
|
|
{ state: { editstate: row, PricingName: Advance } },
|
|
{ key: rowIndex }
|
|
);
|
|
}
|
|
};
|
|
|
|
const onSearch = (value) => {
|
|
setSearchedText(value);
|
|
};
|
|
const onSearchChange = (e) => {
|
|
setSearchedText(e?.target?.value);
|
|
};
|
|
|
|
const columns = [
|
|
{
|
|
title: 'Sl.No',
|
|
key: 'sno',
|
|
align: 'center',
|
|
width: '80px',
|
|
render: (text, object, index) => (
|
|
<a style={{ color: 'black' }}>{(page - 1) * 10 + index + 1}</a>
|
|
),
|
|
},
|
|
{
|
|
title: 'Employee Name',
|
|
dataIndex: 'EmpName',
|
|
key: 'EmpName',
|
|
width: '180px',
|
|
render: (text, row) => (
|
|
<a style={{ color: 'black', width: '200px' }}>{row.EmpName}</a>
|
|
),
|
|
filteredValue: [searchedText],
|
|
onFilter: (value, record) => {
|
|
return String(record.EmpName)
|
|
?.toLowerCase()
|
|
?.includes(value?.toLowerCase());
|
|
},
|
|
sorter: (a, b) => a?.EmpName?.length - b?.EmpName?.length,
|
|
sortOrder: sortedInfo.columnKey === 'EmpName' ? sortedInfo.order : null,
|
|
ellipsis: true,
|
|
},
|
|
{
|
|
title: 'Designation',
|
|
dataIndex: 'EmpDesignation',
|
|
key: 'EmpDesignation',
|
|
width: '150px',
|
|
render: (text) => <a style={{ color: 'black' }}>{text}</a>,
|
|
filteredValue: filteredInfo.EmpDesignationName || null,
|
|
onFilter: (value, record) => record.EmpDesignation?.includes(value),
|
|
sorter: (a, b) => a?.EmpDesignation?.length - b?.EmpDesignation?.length,
|
|
sortOrder:
|
|
sortedInfo.columnKey === 'EmpDesignation' ? sortedInfo.order : null,
|
|
ellipsis: true,
|
|
},
|
|
|
|
{
|
|
title: 'Edit',
|
|
key: 'Edit',
|
|
dataIndex: 'Edit',
|
|
width: '180px',
|
|
render: (_, record, index) =>
|
|
TableData.length >= 1 ? (
|
|
<Space size="middle">
|
|
{/* edit cmd */}
|
|
<a>
|
|
<EditFilled
|
|
style={{
|
|
color: record.ActiveStatus === 'A' ? '#1292EE' : '#dadada',
|
|
}}
|
|
onClick={() =>
|
|
UserType === 'Super Admin' ||
|
|
(UserType === 'Super Admin User' &&
|
|
SAAccessCommonMaster?.UpdateAccess === 'Y') ||
|
|
(UserType === 'Employee' && empData?.UpdateAccess === 'Y') ||
|
|
UserType === 'Admin'
|
|
? actionsFormatter(record, index)
|
|
: null
|
|
}
|
|
/>
|
|
</a>
|
|
</Space>
|
|
) : null,
|
|
},
|
|
];
|
|
|
|
const onComplete = useCallback(() => {
|
|
setMessageData(null);
|
|
setMessageType(null);
|
|
}, []);
|
|
|
|
const handelAddButton = () => {
|
|
navigate(`${subDirectory}setting/employee-screenrights/new`);
|
|
};
|
|
|
|
return (
|
|
<div className="userPageTable">
|
|
<div className="userPageContent">
|
|
<Messages
|
|
messageType={messageType}
|
|
messageData={messageData}
|
|
onComplete={onComplete}
|
|
/>
|
|
<div className="formAddNew">
|
|
<div>
|
|
<FormHeader title={'Employee Screen Rights'} />
|
|
</div>
|
|
<div className="searchAddDiv">
|
|
<div className="formSearch">
|
|
<Search
|
|
placeholder="Search"
|
|
onSearch={onSearch}
|
|
onSearchChange={onSearchChange}
|
|
/>
|
|
</div>
|
|
<Buttons
|
|
buttonText={'Add New'}
|
|
handleSubmit={() => handelAddButton()}
|
|
disabled={addnewAccess}
|
|
color="901D77"
|
|
icon={<PlusOutlined />}
|
|
>
|
|
OPEN
|
|
</Buttons>
|
|
</div>
|
|
</div>
|
|
<div className="reportTable">
|
|
<Tables
|
|
columns={columns}
|
|
data={TableData}
|
|
dataSource={TableData}
|
|
pagination={handlePageChange}
|
|
onChange={handleChange}
|
|
/>{' '}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default EmployeeScreenAccess;
|