diff --git a/src/views/Dashboard/DashboardProject.js b/src/views/Dashboard/DashboardProject.js index b9a0fd8..f2f812a 100644 --- a/src/views/Dashboard/DashboardProject.js +++ b/src/views/Dashboard/DashboardProject.js @@ -7,7 +7,6 @@ import { CardScheduleHealthPerDivision, } from "../../components/CardDashboard/CardDashboard"; import L from "leaflet"; -import { useParams } from "react-router-dom"; import "../../assets/css/customscroll.css"; import moment from "moment"; import { renderFormatRupiah } from "../../const/CustomFunc"; @@ -31,7 +30,7 @@ import { } from "./Components"; import { Fab, Action } from "react-tiny-fab"; import "react-tiny-fab/dist/styles.css"; -import { useHistory } from "react-router-dom"; +import { useHistory, useLocation, useParams } from "react-router-dom"; const { TextArea } = Input; @@ -126,8 +125,9 @@ const DashboardProject = () => { const [isReadyGanttParents, setIsReadyGanttParents] = useState(false); const [calculationStatus, setCalculationStatus] = useState(false); const [isHierarchy, setIsHierarchy] = useState(false); - const [isScurve, setIsScurve] = useState(false); let history = useHistory(); + let location = useLocation(); + const isDashboardProject = location.pathname.includes('dashboard-project'); useEffect(() => { getProjectDetail(); @@ -137,12 +137,6 @@ const DashboardProject = () => { getComments(); getGantt(); getGanttParents(); - const currentURL = window.location.href; - if (currentURL.includes("dashboard-project")) { - setIsScurve(true); - } else { - setIsScurve(false); - } return () => { console.log("unmount RenderMap"); }; @@ -1025,7 +1019,7 @@ const DashboardProject = () => { - +
{
- {isScurve === true ? ( + {isDashboardProject ? (
{ - {isScurve === true ? ( + {isDashboardProject ? (
{ + const token = localStorage.getItem("token") + const company_id = localStorage.getItem("company_id") + const HEADER = { + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + } + } + const [alertDelete, setAlertDelete] = useState(false) + const [clickOpenModal, setClickOpenModal] = useState(false) + const [clickOpenModalShift, setClickOpenModalShift] = useState(false) + const [currentPage, setCurrentPage] = useState(1) + const [dataEdit, setDataEdit] = useState([]) + const [dataExport, setDataExport] = useState([]) + const [dataTable, setDatatable] = useState([]) + const [divisiList, setDivisiList] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [openDialog, setOpenDialog] = useState(false) + const [openDialogShift, setOpenDialogShift] = useState(false) + const [roleList, setRoleList] = useState([]) + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') + const [totalPage, setTotalPage] = useState(0) + const [typeDialog, setTypeDialog] = useState('Save') + const [typeDialogShift, setTypeDialogShift] = useState('Save') + const pageName = params.name; + const { t } = useTranslation(); + useEffect(() => { + getRoleList() + getDivisiList() + }, []) + + useEffect(() => { + getDataUser() + }, [search, rowsPerPage, currentPage]) + + useEffect(() => { + const cekData = dataExport || [] + if (cekData.length > 0) { + exportExcel() + } + }, [dataExport]) + + const onShowSizeChange = (current, pageSize) => { + setRowsPerPage(pageSize) + } + + const onPagination = (current, pageSize) => { + setCurrentPage(current) + } + + const getRoleList = async () => { + const formData = { + "paging": { "start": 0, "length": -1 }, + "orders": { "columns": ["id"], "ascending": false } + } + + const result = await axios + .post(ROLE_SEARCH, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + setRoleList(result.data.data); + } + } + + const getDivisiList = async () => { + const formData = { + "paging": { "start": 0, "length": -1 }, + "orders": { "columns": ["id"], "ascending": false } + } + + const result = await axios + .post(DIVISI_SEARCH, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + setDivisiList(result.data.data); + } else { + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + const getDataUser = async () => { + + let start = 0; + + if (currentPage !== 1 && currentPage > 1) { + start = (currentPage * rowsPerPage) - rowsPerPage + } + + const payload = { + "paging": { + "start": start, + "length": rowsPerPage + }, + "columns": [], + "group_column": { + "operator": "AND", + "group_operator": "OR", + "where": [ + { + "name": "name", + "logic_operator": "~*", + "value": search + }, + { + "name": "phone_number", + "logic_operator": "~*", + "value": search + }, + { + "name": "email", + "logic_operator": "~*", + "value": search + }, + { + "name": "status_resource", + "logic_operator": "~*", + "value": search + }, + ] + }, + "joins": [ + + ], + "orders": { + "columns": [ + "id" + ], + "ascending": false + } + } + + const result = await axios + .post(COMPANY_MANAGEMENT_SEARCH, payload, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + setDatatable(result.data.data); + setTotalPage(result.data.totalRecord); + } else { + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + const handleSearch = e => { + const value = e.target.value + setSearch(value); + setCurrentPage(1) + }; + + const handleOpenDialog = async (type) => { + await setTypeDialog(type) + setOpenDialog(true) + + } + + const handleOpenDialogShift = async (type) => { + await setTypeDialogShift(type) + setOpenDialogShift(true) + + } + + const handleSync = async () => { + await axios.get(USER_SYNC, HEADER) + .then(res => res) + .catch((error) => error.response) + } + + const handleExportExcel = async () => { + + let start = 0; + + if (currentPage !== 1 && currentPage > 1) { + start = (currentPage * rowsPerPage) - rowsPerPage + } + + const payload = { + "paging": { + "start": start, + "length": -1 + }, + "columns": [], + "group_column": { + "operator": "AND", + "group_operator": "OR", + "where": [ + { + "name": "name", + "logic_operator": "~*", + "value": search + }, + + { + "name": "name", + "logic_operator": "~*", + "value": search, + "table_name": "m_divisi" + }, + { + "name": "name", + "logic_operator": "~*", + "value": search, + "table_name": "m_roles" + }, + { + "name": "phone_number", + "logic_operator": "~*", + "value": search + }, + { + "name": "email", + "logic_operator": "~*", + "value": search + }, + { + "name": "status_resource", + "logic_operator": "~*", + "value": search + }, + ] + }, + "joins": [ + { + "name": "m_roles", + "column_join": "role_id", + "column_results": [ + "name", + "description" + ] + } + ], + "orders": { + "columns": [ + "id" + ], + "ascending": false + } + } + const result = await axios + .post(USER_SEARCH, payload, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let resData = result.data.data; + const excelData = []; + resData.map((n, index) => { + let dataRow = { + "NIK (Nomor Induk Karyawan)": n.ktp_number, + "Employee Name": n.name, + "Divisi": n.join_second_name, + "Employee Type": n.employee_type, + "Role": n.join_first_name, + "Phone No": n.phone_number, + } + excelData.push(dataRow) + }) + await setDataExport(excelData); + } else { + NotificationManager.error('Gagal Export Data!!', 'Failed'); + } + } + + const exportExcel = () => { + const dataExcel = dataExport || []; + const fileName = `Data ${pageName}.xlsx`; + const ws = XLSX.utils.json_to_sheet(dataExcel); + const wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`); + XLSX.writeFile(wb, fileName); + setDataExport([]) + } + + const handleEdit = (data) => { + setDataEdit(data) + handleOpenDialog('Edit'); + } + + const handleSetWorker = async (data) => { + await setDataEdit(data) + handleOpenDialog('Set'); + } + + const handleSetUserShift = async (data) => { + await setDataEdit(data) + handleOpenDialogShift('Save'); + } + + const handleDelete = async (id) => { + await setAlertDelete(true) + await setIdDelete(id) + } + + const handleCloseDialog = (type, data) => { + if (type === "save") { + saveUser(data); + } else if (type === "edit") { + editUser(data); + } + setDataEdit([]) + setOpenDialog(false) + } + + const handleCloseDialogShift = (type, data) => { + if (type === "save") { + saveUserShift(data); + } + setDataEdit([]) + setOpenDialogShift(false) + } + + const saveUser = async (data) => { + const formData = data + const result = await axios.post(USER_ADD, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataUser(); + NotificationManager.success(`Data resource berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } + + const saveUserShift = async (data) => { + const formData = data + const result = await axios.post(USER_SHIFT_ADD, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataUser(); + NotificationManager.success(`Data resource berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } + + const editUser = async (data) => { + + let urlEdit = USER_EDIT(data.id) + const formData = data + + const result = await axios.put(urlEdit, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataUser(); + NotificationManager.success(`Data resource berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, `Failed!!`); + } + } + + const toggleAddDialog = () => { + setOpenDialog(!openDialog) + } + + const toggleAddDialogShift = () => { + setOpenDialogShift(!openDialogShift) + } + + const onConfirmDelete = async () => { + let url = USER_DELETE(idDelete); + + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataUser() + setIdDelete(0) + setAlertDelete(false) + NotificationManager.success(`Data user berhasil dihapus!`, 'Success!!'); + } else { + setIdDelete(0) + setAlertDelete(false) + NotificationManager.error(`Data user gagal dihapus!}`, 'Failed!!'); + } + } + + const cancelDelete = () => { + setAlertDelete(false) + setIdDelete(0) + } + + const RenderTable = useMemo(() => { + const columns = [ + { + title: t('action'), + dataIndex: '', + key: 'x', + render: (text, record) => <> + + + + + + + + + + + , + }, + + { title: "Number Registration", dataIndex: 'registration_no', key: 'registration_no' }, + { title: "Name", dataIndex: 'company_name', key: 'company_name' }, + { title: 'Phone No.', dataIndex: 'phone_no', key: 'phone_no' }, + { title: 'Email', dataIndex: 'email', key: 'email' }, + { title: 'Status', dataIndex: 'is_active', key: 'is_active', render: (text, record) => <>{text && text !== false ? "Active" : 'Inactive'} } + ]; + return ( + + ) + }, [dataTable]) + + return ( +
+ + cancelDelete()} + focusCancelBtn + > + {t('deleteMsg')} + + {/* toggleAddDialog} + typeDialog={typeDialog} + dataEdit={dataEdit} + clickOpenModal={clickOpenModal} + roleList={roleList} + divisiList={divisiList} + /> */} + + +

{pageName}

+ +
+ + + + + + + + + + + + + + + + + {RenderTable} + + + + + ) +} + +export default MasterCompany; diff --git a/src/views/Master/MasterMenu/DialogForm.js b/src/views/Master/MasterMenu/DialogForm.js index 0aed72e..fd9458c 100644 --- a/src/views/Master/MasterMenu/DialogForm.js +++ b/src/views/Master/MasterMenu/DialogForm.js @@ -7,7 +7,6 @@ import 'antd/dist/antd.css'; import { useTranslation } from 'react-i18next'; const { Option } = Select -const company_id = window.localStorage.getItem('company_id'); const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, dataMenu }) => { const [id, setId] = useState(0) const [name, setName] = useState('') @@ -69,7 +68,6 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi sequence: parseInt(sequence), icon, alias_name: aliasName, - company_id } if (parentId && parentId > 0) { @@ -85,7 +83,6 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi sequence: parseInt(sequence), icon, alias_name: aliasName, - company_id } if (parentId && parentId > 0) { diff --git a/src/views/Master/MasterMenu/index.js b/src/views/Master/MasterMenu/index.js index 090a897..88919c4 100644 --- a/src/views/Master/MasterMenu/index.js +++ b/src/views/Master/MasterMenu/index.js @@ -10,8 +10,6 @@ import { NotificationContainer, NotificationManager } from 'react-notifications' import { Pagination, Tooltip, Table } from 'antd'; import { useTranslation } from 'react-i18next'; const token = window.localStorage.getItem('token'); -const company_id = window.localStorage.getItem('company_id'); -const role_name = window.localStorage.getItem('role_name'); const column = [ { name: "Nama" }, { name: "Url" }, @@ -106,16 +104,6 @@ const Index = ({ params }) => { }], "orders": { "columns": ["id"], "ascending": false } } - if (role_name !== "Super Admin") { - payload.columns.push( - { "name": "company_id", "logic_operator": "=", "value": company_id, "operator": "AND" }, - ) - } else { - payload.columns.push( - { "name": "company_id", "logic_operator": "is null", "value": "", "operator": "AND" }, - ) - } - const result = await axios .post(MENU_SEARCH, payload, config) diff --git a/src/views/SimproV2/ResourceWorker/index.js b/src/views/SimproV2/ResourceWorker/index.js index 4451a32..8b42928 100644 --- a/src/views/SimproV2/ResourceWorker/index.js +++ b/src/views/SimproV2/ResourceWorker/index.js @@ -25,7 +25,8 @@ const config = { "Content-type": `application/json` } }; - +const role_name = window.localStorage.getItem('role_name'); +const company_id = window.localStorage.getItem('company_id'); const ResourceWorker = ({ params }) => { const token = localStorage.getItem("token") const company_id = localStorage.getItem("company_id") @@ -172,11 +173,6 @@ const ResourceWorker = ({ params }) => { "logic_operator": "~*", "value": search }, - { - "name": "company_id", - "logic_operator": "=", - "value": company_id - }, ] }, "joins": [ @@ -204,6 +200,16 @@ const ResourceWorker = ({ params }) => { } } + if (role_name !== "Super Admin") { + payload.group_column.where.push( + { "name": "company_id", "logic_operator": "=", "value": company_id, "operator": "AND" }, + ) + } else { + payload.group_column.where.push( + { "name": "company_id", "logic_operator": "is null", "value": "", "operator": "AND" }, + ) + } + const result = await axios .post(USER_SEARCH, payload, config) .then(res => res)