From b3e23efb77f34658e1f4c661ba202b9611e45a5d Mon Sep 17 00:00:00 2001 From: wahyuun Date: Thu, 9 Nov 2023 10:51:29 +0700 Subject: [PATCH 01/18] handle login customer --- src/views/Pages/Login/Login.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/views/Pages/Login/Login.js b/src/views/Pages/Login/Login.js index 7bda490..9c49869 100644 --- a/src/views/Pages/Login/Login.js +++ b/src/views/Pages/Login/Login.js @@ -133,7 +133,7 @@ class Login extends Component { } } - getDataMenu = async (token, role_id) => { + getDataMenu = async (token, role_id,user_id) => { const config = { headers: { @@ -157,15 +157,28 @@ class Login extends Component { this.props.history.push("/dashboard-customer/58/63"); } else { - this.props.history.push("/dashboard"); + this.props.history.push({ + pathname: "/dashboard", + state: { role_id: role_id, user_id: user_id } + }); } if (this.state.defaultPage) { - this.props.history.push(this.state.defaultPage); + if (role_id === 44) { + this.props.history.push({ + pathname: this.state.defaultPage, + state: { role_id: role_id, user_id: user_id } + }); + } else { + this.props.history.push(this.state.defaultPage); + } } else if (role_id == 28) { this.props.history.push("/dashboard-customer/58/63"); } else { - this.props.history.push("/dashboard"); + this.props.history.push({ + pathname: "/dashboard", + state: { role_id: role_id, user_id: user_id } + }); } } else { NotificationManager.error('Login Failed', 'Failed'); @@ -209,7 +222,7 @@ class Login extends Component { if (doLogin && doLogin.data && doLogin.data.code === 200) { const { access_token, data_user } = doLogin.data.data this.getDataRole(access_token, data_user.role_id) - this.getDataMenu(access_token, data_user.role_id) + this.getDataMenu(access_token, data_user.role_id, data_user.id) window.localStorage.setItem('isLogin', true); window.localStorage.setItem('token', access_token); window.localStorage.setItem('user_id', data_user.id); From ea05e49b611d89b5a66078e8f8d98e7c7e44d872 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Thu, 9 Nov 2023 10:52:02 +0700 Subject: [PATCH 02/18] handle login customer by role_id --- src/views/SimproV2/CreatedProyek/index.js | 35 ++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/views/SimproV2/CreatedProyek/index.js b/src/views/SimproV2/CreatedProyek/index.js index b29b17a..726326c 100644 --- a/src/views/SimproV2/CreatedProyek/index.js +++ b/src/views/SimproV2/CreatedProyek/index.js @@ -89,17 +89,27 @@ import AssignK3Project from "./AssignK3Project"; import ViewProject from "./ViewProject"; import ReportAnalysis from "./ReportAnalysis"; import { Icon } from "@iconify/react"; -// import { Link } from 'react-router-dom'; // import SubProyekComp from './SubProyekComp'; -import { Link, useHistory } from "react-router-dom"; +import { Link, useHistory, withRouter } from "react-router-dom"; const url = ""; -const proyek_id = localStorage.getItem("proyek_id"); -const role_id = localStorage.getItem("role_id"); -const user_id = localStorage.getItem("user_id"); +// const proyek_id = localStorage.getItem("proyek_id"); +// const role_id = localStorage.getItem("role_id"); +// const user_id = localStorage.getItem("user_id"); const format = "DD-MM-YYYY"; const CreatedProyek = ({ params, ...props }) => { + let role_id = '', user_id='',proyek_id=''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + console.log('role_id:', role_id); + } else { + role_id = localStorage.getItem("role_id"); + proyek_id = localStorage.getItem("proyek_id"); + user_id = localStorage.getItem("user_id"); + console.error('Role ID is undefined in props.location.state'); + } const history = useHistory(); const token = localStorage.getItem("token"); const HEADER = { @@ -200,7 +210,7 @@ const CreatedProyek = ({ params, ...props }) => { }, [openDialogProyek]); useEffect(() => { - role_id !== "44" ? getDataProyek() : getDataProyekByCustomer(); + parseInt(role_id) !== 44 ? getDataProyek() : getDataProyekByCustomer(); }, [search, rowsPerPage, currentPage]); useEffect(() => { @@ -894,7 +904,7 @@ const CreatedProyek = ({ params, ...props }) => { .catch((error) => error.response); if (result && result.data && result.data.code === 200) { - role_id !== "44" ? getDataProyek() : getDataProyekByCustomer(); + parseInt(role_id) !== 44 ? getDataProyek() : getDataProyekByCustomer(); getProjectImage(idDelete); deleteImage(idDelete); setIdDelete(0); @@ -965,7 +975,7 @@ const CreatedProyek = ({ params, ...props }) => { NotificationManager.success(`${result.data.message}`, "Success!!"); } - role_id !== "44" ? getDataProyek() : getDataProyekByCustomer(); + parseInt(role_id) !== 44 ? getDataProyek() : getDataProyekByCustomer(); } else { NotificationManager.error(`${result.data.message}`, "Failed!!"); } @@ -1144,7 +1154,7 @@ const CreatedProyek = ({ params, ...props }) => { ); } if (result && result.status === 200) { - role_id !== "44" ? getDataProyek() : getDataProyekByCustomer(); + parseInt(role_id) !== 44 ? getDataProyek() : getDataProyekByCustomer(); NotificationManager.success(`Data proyek berhasil Ubah`, "Success!!"); } else { NotificationManager.error(`${result.data.message}`, "Failed!!"); @@ -1618,7 +1628,7 @@ const CreatedProyek = ({ params, ...props }) => { dataIndex: "", key: "x", render: (text, record) => - role_id == "44" ? ( + parseInt(role_id) == 44 ? ( <> {" "} From db582f48082672520d2d071916502437d9d7a49d Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 10 Nov 2023 10:32:31 +0700 Subject: [PATCH 07/18] add props --- src/views/SimproV2/Gantt/index.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/views/SimproV2/Gantt/index.js b/src/views/SimproV2/Gantt/index.js index c1c2dda..b46b34d 100644 --- a/src/views/SimproV2/Gantt/index.js +++ b/src/views/SimproV2/Gantt/index.js @@ -11,18 +11,30 @@ import { Fab, Action } from "react-tiny-fab"; import "react-tiny-fab/dist/styles.css"; import { useHistory } from "react-router-dom"; import GanttFrame from "./GanttFrame"; -const token = localStorage.getItem("token"); -const userId = parseInt(localStorage.getItem("user_id")); -const HEADER = { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, - }, -}; let roCount = 0; const Gantt = (props) => { + let role_id = '', userId='',isLogin='',token=''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + userId = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + console.log('props.location.state success'); + } else { + role_id = localStorage.getItem("role_id"); + userId = localStorage.getItem("user_id"); + token = localStorage.getItem("token"); + isLogin = localStorage.getItem("isLogin"); + console.error('Undefined in props.location.state'); + } + const HEADER = { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }; const versionGanttId = props.match.params ? props.match.params.id : 0; const idProject = props.match.params.project ? props.match.params.project : 0; const timestamp = props.match.params.timestamp From 018fc431b6771ff9fc0ac35c7c50335b13b31f3a Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 10 Nov 2023 10:33:03 +0700 Subject: [PATCH 08/18] add props --- src/views/SimproV2/Gantt/GanttFrame.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/views/SimproV2/Gantt/GanttFrame.js b/src/views/SimproV2/Gantt/GanttFrame.js index f175154..51efdde 100644 --- a/src/views/SimproV2/Gantt/GanttFrame.js +++ b/src/views/SimproV2/Gantt/GanttFrame.js @@ -1,16 +1,31 @@ import React, { useEffect, useState } from 'react'; -import { useHistory } from 'react-router-dom'; +import { useHistory, withRouter } from 'react-router-dom'; import { BASE_SIMPRO_LUMEN } from '../../../const/ApiConst'; const GanttFrame = React.memo((props) => { + let role_id = '', user_id='',proyek_id='',isLogin='',token=''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + isLogin = props.location.state.isLogin; + token = props.location.state.token; + console.log('props.location.state success'); + } else { + role_id = localStorage.getItem("role_id"); + proyek_id = localStorage.getItem("proyek_id"); + user_id = localStorage.getItem("user_id"); + isLogin = localStorage.getItem("isLogin"); + token = localStorage.getItem("token"); + console.error('Undefined in props.location.state'); + } const history = useHistory(); - const { versionGanttId, idProject, token, ro, timestamp } = props; - const iframeSrc = `https://adw-gantt.ospro.id/edit-mode/index.html?base_url=${BASE_SIMPRO_LUMEN}&gantt_id=${versionGanttId}&proyek_id=${idProject}&token=${token}&ro=${ro}×tamp=${timestamp}`; + const { versionGanttId, idProject, ro, timestamp } = props; + const iframeSrc = `http://localhost:8444/adw-gantt/edit-mode/index.html?base_url=${BASE_SIMPRO_LUMEN}&gantt_id=${versionGanttId}&proyek_id=${idProject}&token=${token}&ro=${ro}×tamp=${timestamp}&role_id=${role_id}&user_id=${user_id}&isLogin=${isLogin}`; const [batchEntityData, setBatchEntityData] = useState(null); - + useEffect(() => { const handleMessage = (event) => { if (event.data && event.data.batchEntity) { @@ -46,4 +61,4 @@ const GanttFrame = React.memo((props) => { ); }); -export default GanttFrame; +export default withRouter(GanttFrame); From bf26374fa424c59456db0733f980bebd9eae8e43 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 10 Nov 2023 10:34:17 +0700 Subject: [PATCH 09/18] add props --- src/views/Dashboard/DashboardCustomer.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/views/Dashboard/DashboardCustomer.js b/src/views/Dashboard/DashboardCustomer.js index 63ee536..5928cef 100644 --- a/src/views/Dashboard/DashboardCustomer.js +++ b/src/views/Dashboard/DashboardCustomer.js @@ -25,8 +25,21 @@ const center = { lng: 106.816666 } -const DashboardCustomer = () => { - const token = localStorage.getItem("token") +const DashboardCustomer = (props) => { + let role_id = '', user_id='',isLogin='',token=''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + console.log('props.location.state success'); + } else { + role_id = localStorage.getItem("role_id"); + user_id = localStorage.getItem("user_id"); + token = localStorage.getItem("token"); + isLogin = localStorage.getItem("isLogin"); + console.error('Undefined in props.location.state'); + } const HEADER = { headers: { "Content-Type": "application/json", @@ -34,7 +47,7 @@ const DashboardCustomer = () => { } } const { PROJECT_ID, GANTT_ID, SCURVE } = useParams(); - const URL_GANTT = `https://adw-gantt.ospro.id/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; + const URL_GANTT = `http://localhost:8444/adw-gantt/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; const mapRef = useRef() const [projectName, setProjectName] = useState(""); const [projectManagerName, setProjectManagerName] = useState(''); From 5b15013f06ef74a294145be9f5f89c55b3891c19 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 10 Nov 2023 10:43:20 +0700 Subject: [PATCH 10/18] update URL_GANTT --- src/views/Dashboard/DashboardCustomer.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/views/Dashboard/DashboardCustomer.js b/src/views/Dashboard/DashboardCustomer.js index 5928cef..7d482e8 100644 --- a/src/views/Dashboard/DashboardCustomer.js +++ b/src/views/Dashboard/DashboardCustomer.js @@ -47,8 +47,7 @@ const DashboardCustomer = (props) => { } } const { PROJECT_ID, GANTT_ID, SCURVE } = useParams(); - const URL_GANTT = `http://localhost:8444/adw-gantt/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; - const mapRef = useRef() + const URL_GANTT = `https://adw-gantt.ospro.id/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; const mapRef = useRef() const [projectName, setProjectName] = useState(""); const [projectManagerName, setProjectManagerName] = useState(''); const [customerName, setCustomerName] = useState(""); From 0a4b6e9b44baf263d876d6c4626a38067878a351 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 10 Nov 2023 10:43:57 +0700 Subject: [PATCH 11/18] update url iframeSrc --- src/views/SimproV2/Gantt/GanttFrame.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/views/SimproV2/Gantt/GanttFrame.js b/src/views/SimproV2/Gantt/GanttFrame.js index 51efdde..ec90a85 100644 --- a/src/views/SimproV2/Gantt/GanttFrame.js +++ b/src/views/SimproV2/Gantt/GanttFrame.js @@ -20,8 +20,7 @@ const GanttFrame = React.memo((props) => { } const history = useHistory(); const { versionGanttId, idProject, ro, timestamp } = props; - const iframeSrc = `http://localhost:8444/adw-gantt/edit-mode/index.html?base_url=${BASE_SIMPRO_LUMEN}&gantt_id=${versionGanttId}&proyek_id=${idProject}&token=${token}&ro=${ro}×tamp=${timestamp}&role_id=${role_id}&user_id=${user_id}&isLogin=${isLogin}`; - + const iframeSrc = `https://adw-gantt.ospro.id/edit-mode/index.html?base_url=${BASE_SIMPRO_LUMEN}&gantt_id=${versionGanttId}&proyek_id=${idProject}&token=${token}&ro=${ro}×tamp=${timestamp}`; const [batchEntityData, setBatchEntityData] = useState(null); From 4109188206b3ee570981b6f2c3e8310489c9cfcf Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 10 Nov 2023 11:20:39 +0700 Subject: [PATCH 12/18] add loader --- .../SimproV2/CreatedProyek/DialogHierarchy.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/views/SimproV2/CreatedProyek/DialogHierarchy.js b/src/views/SimproV2/CreatedProyek/DialogHierarchy.js index a6ac1b1..feeedf9 100644 --- a/src/views/SimproV2/CreatedProyek/DialogHierarchy.js +++ b/src/views/SimproV2/CreatedProyek/DialogHierarchy.js @@ -1,7 +1,7 @@ import React, { useEffect, useState, useMemo } from 'react' import { Modal, ModalHeader, ModalBody, } from 'reactstrap'; import { Button } from 'reactstrap'; -import { Space, Table, Tooltip } from 'antd'; +import { Space, Table, Tooltip, Spin } from 'antd'; import 'antd/dist/antd.css'; import moment from 'moment'; import SweetAlert from 'react-bootstrap-sweetalert'; @@ -41,8 +41,10 @@ const DialogHierarchy = ({ openDialog, closeDialog, toggleDialog, idTask, proyek const [idGantt, setIdGantt] = useState(0) const [humanResource, setHumanResource] = useState([]) const { t } = useTranslation(); + const [loading, setLoading] = useState(true); useEffect(() => { if (idTask > 0) { + setLoading(true); getdataHierarchy(); } }, [saveHierarchy, idTask, openDialog, closeDialog, openDialogFormGantt]) @@ -157,7 +159,9 @@ const DialogHierarchy = ({ openDialog, closeDialog, toggleDialog, idTask, proyek if (result && result.status == 200) { const sortedData = _.orderBy(result.data.data, ['name'], ['asc']); setDataHierarchy(sortedData); + setLoading(false); } else { + setLoading(false); NotificationManager.error(`Data gantt project gagal terload silahkan coba lagi!`, 'Failed!!'); } } @@ -285,9 +289,11 @@ const DialogHierarchy = ({ openDialog, closeDialog, toggleDialog, idTask, proyek -
- {RenderTable} -
+ +
+ {RenderTable} +
+
{/* From 77f0b886b3d354dc96df054275e28f7168780c0a Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 10 Nov 2023 11:20:56 +0700 Subject: [PATCH 13/18] update loader --- src/views/SimproV2/CreatedProyek/DialogGantt.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/SimproV2/CreatedProyek/DialogGantt.js b/src/views/SimproV2/CreatedProyek/DialogGantt.js index 5dbb28f..3af6883 100644 --- a/src/views/SimproV2/CreatedProyek/DialogGantt.js +++ b/src/views/SimproV2/CreatedProyek/DialogGantt.js @@ -47,6 +47,7 @@ const DialogGantt = ({ openDialog, closeDialog, toggleDialog, idTask, proyekName useEffect(() => { if (openDialog && hierarchyId > 0 || idTask > 0 && !openDialogHierarchy) { + setLoading(true); getdataGantt(); } if (!openDialog) { From 890483ae7d056336dcae2aa2c64ae1f6b41a0cd0 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Fri, 10 Nov 2023 13:31:58 +0700 Subject: [PATCH 14/18] update dashboard-customer --- src/routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes.js b/src/routes.js index 85e3523..4df1073 100644 --- a/src/routes.js +++ b/src/routes.js @@ -53,7 +53,7 @@ const routes = [ { path: '/', exact: true, name: 'Home' }, // { path: '/dashboard', name: 'Dashboard', component: Dashboard}, { path: '/dashboard', name: 'DashboardBOD', component: DashboardBOD }, - { path: '/dashboard-customer/:PROJECT_ID/:GANTT_ID', name: 'DashboardCustomer', component: DashboardCustomer }, + // { path: '/dashboard-customer/:PROJECT_ID/:GANTT_ID', name: 'DashboardCustomer', component: DashboardCustomer }, { path: '/dashboard-customer/:PROJECT_ID/:GANTT_ID/:SCURVE', name: 'DashboardCustomer', component: DashboardCustomer }, { path: '/dashboard-project/:PROJECT_ID/:GANTT_ID', exact: true, name: 'Dashboard Project', component: DashboardProject }, { path: '/dashboard-project/:PROJECT_ID/:GANTT_ID/:SCURVE', exact: true, name: 'Dashboard Project', component: DashboardProject }, From 4de2693554b73167d9a3dca5e74218c0569f252b Mon Sep 17 00:00:00 2001 From: farhan048 Date: Fri, 10 Nov 2023 13:47:23 +0700 Subject: [PATCH 15/18] filter by hierarchy --- src/views/Pages/Login/Login.js | 1 + src/views/SimproV2/CreatedProyek/index.js | 46 ++++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/views/Pages/Login/Login.js b/src/views/Pages/Login/Login.js index 7973899..2d397e8 100644 --- a/src/views/Pages/Login/Login.js +++ b/src/views/Pages/Login/Login.js @@ -217,6 +217,7 @@ class Login extends Component { window.localStorage.setItem('role_id', data_user.role_id); window.localStorage.setItem('company_id', data_user.company_id); window.localStorage.setItem('role_name', data_user.role.name); + window.localStorage.setItem('hierarchy', JSON.stringify(data_user.hierarchy)); } else { console.log("kode : ", doLogin.data.code); // NotificationManager.error('Cek username atau password anda!', 'Gagal Login!'); diff --git a/src/views/SimproV2/CreatedProyek/index.js b/src/views/SimproV2/CreatedProyek/index.js index 9a08500..b234c91 100644 --- a/src/views/SimproV2/CreatedProyek/index.js +++ b/src/views/SimproV2/CreatedProyek/index.js @@ -292,7 +292,8 @@ const CreatedProyek = ({ params, ...props }) => { const getDataProyek = async () => { let start = 0; - + let hierarchy = []; + hierarchy.push(JSON.parse(localStorage.getItem("hierarchy"))); if (currentPage !== 1 && currentPage > 1) { start = currentPage * rowsPerPage - rowsPerPage; } @@ -335,6 +336,7 @@ const CreatedProyek = ({ params, ...props }) => { if (parseInt(role_id) !== 1) { payload["columns"] = [ { name: "id", logic_operator: "=", value: proyek_id, operator: "AND" }, + { name: "created_by_id", logic_operator: "IN", value: hierarchy, operator: "AND" } ]; } @@ -574,7 +576,7 @@ const CreatedProyek = ({ params, ...props }) => { "checklist_k3_id" ], "columns": [ - { "name": "proyek_id", "logic_operator": "=", "value": id, "operator": "AND" } + { "name": "proyek_id", "logic_operator": "=", "value": id, "operator": "AND" } ] } const URL = `${BASE_OSPRO}/api/project-to-checklist-k3/search`; @@ -583,11 +585,11 @@ const CreatedProyek = ({ params, ...props }) => { .then(res => res) .catch((error) => error.response); - if(result && result.status==200){ - console.log("cek get project to checklist k3",result.data.data) + if (result && result.status == 200) { + console.log("cek get project to checklist k3", result.data.data) let dataRes = result.data.data; if (dataRes.length > 0) { - setK3Search(dataRes); + setK3Search(dataRes); } } } @@ -611,8 +613,8 @@ const CreatedProyek = ({ params, ...props }) => { .catch((error) => error.response); if (result && result.data && result.data.code == 200) { - const {value_proyek,area_kerja,scoupe_of_work, kode_sortname,nama,mulai_proyek,rencana_biaya,keterangan,durasi_proyek,project_objectives,potential_risk,currency_symbol, nama_divisi, late_consequence, assumtion, considered_success_when} = result.data.data; - const dataToSend = {value_proyek,area_kerja,scoupe_of_work, kode_sortname, nama, mulai_proyek, rencana_biaya, keterangan, durasi_proyek, project_objectives, potential_risk, currency_symbol, nama_divisi, late_consequence, assumtion, considered_success_when}; + const { value_proyek, area_kerja, scoupe_of_work, kode_sortname, nama, mulai_proyek, rencana_biaya, keterangan, durasi_proyek, project_objectives, potential_risk, currency_symbol, nama_divisi, late_consequence, assumtion, considered_success_when } = result.data.data; + const dataToSend = { value_proyek, area_kerja, scoupe_of_work, kode_sortname, nama, mulai_proyek, rencana_biaya, keterangan, durasi_proyek, project_objectives, potential_risk, currency_symbol, nama_divisi, late_consequence, assumtion, considered_success_when }; setProjectCharter(dataToSend); } else { NotificationManager.error("Gagal Mengambil Data!!", "Failed"); @@ -1096,7 +1098,7 @@ const CreatedProyek = ({ params, ...props }) => { .post(IMAGE_UPLOAD, formData, HEADER_MULTIPART) .then(res => res) .catch((error) => error.response); - return "berhasil"; + return "berhasil"; }; const deleteImage = async (id) => { @@ -1106,7 +1108,7 @@ const CreatedProyek = ({ params, ...props }) => { .delete(URL, HEADER) .then(res => res) .catch((error) => error.response); - return "berhasil"; + return "berhasil"; }; const editProyek = async (data) => { @@ -1501,16 +1503,16 @@ const CreatedProyek = ({ params, ...props }) => { Request Tools */} {/* */} - { - /*text.type_proyek_id != 9 ?*/ -
handleOpenDialogGantt(text)}> - - - - Gantt -
- /*: null*/ - } + { + /*text.type_proyek_id != 9 ?*/ +
handleOpenDialogGantt(text)}> + + + + Gantt +
+ /*: null*/ + }
handleSCurve(text)}> @@ -2026,12 +2028,12 @@ const CreatedProyek = ({ params, ...props }) => { } - // visible={visible} - // onVisibleChange={handleVisibleChange} + // visible={visible} + // onVisibleChange={handleVisibleChange} > From 65edbefebc4306a0953163948cd80bdf22e392ff Mon Sep 17 00:00:00 2001 From: farhan048 Date: Fri, 10 Nov 2023 13:52:11 +0700 Subject: [PATCH 16/18] update master company --- src/views/Master/MasterCompany/DialogForm.js | 533 +++++++++++++++++-- src/views/Master/MasterCompany/FormMenu.js | 285 ++++++++++ src/views/Master/MasterCompany/FormUser.js | 267 ++++++++++ src/views/Master/MasterCompany/index.js | 196 +------ 4 files changed, 1045 insertions(+), 236 deletions(-) create mode 100644 src/views/Master/MasterCompany/FormMenu.js create mode 100644 src/views/Master/MasterCompany/FormUser.js diff --git a/src/views/Master/MasterCompany/DialogForm.js b/src/views/Master/MasterCompany/DialogForm.js index 9b39d14..936a6c2 100644 --- a/src/views/Master/MasterCompany/DialogForm.js +++ b/src/views/Master/MasterCompany/DialogForm.js @@ -1,17 +1,18 @@ import React, { useState, useMemo, useEffect } from 'react' import { Modal, ModalHeader, ModalBody, ModalFooter, - Button, Form, FormGroup, Label, Input, Col, Row, Card, CardBody, Fade + Button, Form, FormGroup, Row, Col, Label, Input, } from 'reactstrap'; -import { Pagination, Table, Tooltip, Select, Input as InputAntd } from 'antd'; -import moment from 'moment'; +import { Pagination, Table, Tooltip, Select } from 'antd'; +import SweetAlert from 'react-bootstrap-sweetalert'; import { NotificationContainer, NotificationManager } from 'react-notifications'; -import DialogFormUser from './DialogFormUser'; +import DialogFormUser from './FormUser'; +import DialogFormMenu from './FormMenu'; import 'antd/dist/antd.css'; import { useTranslation } from 'react-i18next'; import axios from "../../../const/interceptorApi" import { - USER_SEARCH, USER_EDIT, USER_DELETE, ROLE_SEARCH, DIVISI_SEARCH, + USER_SEARCH, USER_EDIT, USER_DELETE, ROLE_SEARCH, DIVISI_SEARCH, MENU_COMPANY_SEARCH } from '../../../const/ApiConst'; const token = window.localStorage.getItem('token'); const config = { @@ -21,8 +22,8 @@ const config = { "Content-type": `application/json` } }; -const { Option } = Select -const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, roleList, companyID }) => { +const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, companyID, companyNameProp }) => { + const { Option } = Select const { t } = useTranslation() const [registrationnumber, setRegistrationNumber] = useState('') const [companyName, setCompanyName] = useState('') @@ -38,8 +39,10 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi const [htmlTitle, setHtmlTitle] = useState('') const [appName, setAppName] = useState('') const [baseUrl, setBaseUrl] = useState([]) - const [statusCompany, setStatusCompany] = useState('active') + const [statusCompany, setStatusCompany] = useState(true) const [template, setTemplate] = useState('') + const [lastIdxURL, setLastIdxURL] = useState(0); + const [dataTable, setDatatable] = useState([]) const [openDialogUser, setOpenDialogUser] = useState(false) @@ -48,12 +51,27 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi const [rowsPerPage, setRowsPerPage] = useState(10) const [totalPage, setTotalPage] = useState(0) const [search, setSearch] = useState('') - + const [idDelete, setIdDelete] = useState(0) + const [alertDelete, setAlertDelete] = useState(false) + const [dataEdit, setDataEdit] = useState([]) + const [roleList, setRoleList] = useState([]) + + + const [dataTableMenu, setDatatableMenu] = useState([]) + const [currentPageMenu, setCurrentPageMenu] = useState(1) + const [rowsPerPageMenu, setRowsPerPageMenu] = useState(10) + const [totalPageMenu, setTotalPageMenu] = useState(0) + const [openDialogMenu, setOpenDialogMenu] = useState(false) + const [typeDialogMenu, setTypeDialogMenu] = useState("add") useEffect(() => { - if (companyID) { + if (companyID && typeDialog === 'Set') { getDataUser() + getRoleList() + } else { + getDataMenu() } - }, [companyID, rowsPerPage, currentPage]) + }, [typeDialog, companyID, rowsPerPage, currentPage, rowsPerPageMenu, currentPageMenu]) + const onShowSizeChange = (current, pageSize) => { setRowsPerPage(pageSize) @@ -62,6 +80,30 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi const onPagination = (current, pageSize) => { setCurrentPage(current) } + const onShowSizeChangeMenu = (current, pageSize) => { + setRowsPerPageMenu(pageSize) + } + + const onPaginationMenu = (current, pageSize) => { + setCurrentPageMenu(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 getDataUser = async () => { let start = 0; @@ -167,6 +209,46 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi } } + const getDataMenu = async () => { + let start = 0; + + if (currentPage !== 1 && currentPage > 1) { + start = (currentPage * rowsPerPage) - rowsPerPage + } + + const payload = { + "paging": { + "start": start, + "length": rowsPerPage + }, + "columns": [{ + "name": "company_id", + "logic_operator": "=", + "value": companyID, + "operator": "AND" + }], + "joins": [{ + "name": "m_menu", + "column_join": "menu_id", + "column_results": [ + "name" + ] + }], + "orders": { "columns": ["id"], "ascending": false } + } + + const result = await axios + .post(MENU_COMPANY_SEARCH, payload, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + setDatatableMenu(result.data.data); + setTotalPageMenu(result.data.totalRecord); + } else { + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } const handleAddUser = async () => { @@ -174,8 +256,51 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi setOpenDialogUser(true) } - const closeDialogUser = () => { + const handleEditUser = async (data) => { + setDataEdit(data) + await setTypeDialogUser('Edit') + setOpenDialogUser(true) + } + const handleDeleteUser = async (id) => { + await setAlertDelete(true) + await setIdDelete(id) + } + + const closeDialogUser = (type, message) => { setOpenDialogUser(false); + if (type == 'success') { + NotificationManager.success(`${message}`, "Success!!"); + getDataUser() + } else if (type == 'Failed') { + NotificationManager.error(`${message}`, "Failed!!"); + } + }; + + const handleAddMenu = async () => { + await setTypeDialogMenu("Save") + setOpenDialogMenu(true) + } + + const handleEditMenu = async (data) => { + setDataEdit(data) + await setTypeDialogMenu('Edit') + setOpenDialogMenu(true) + } + + const handleDeleteMenu = async (id) => { + await setAlertDelete(true) + await setIdDelete(id) + } + + const closeDialogMenu = (type, message) => { + setOpenDialogMenu(false); + if (type == 'success') { + NotificationManager.success(`${message}`, "Success!!"); + getDataMenu() + } else if (type == 'Failed') { + NotificationManager.error(`${message}`, "Failed!!"); + } + }; const handleSave = () => { @@ -263,27 +388,114 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi } } + const isValidEmail = (email) => { + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return emailRegex.test(email); + }; + const handleCancel = () => { closeDialog('cancel', 'none') + setDatatable([]) } - const isValidEmail = (email) => { - const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - return emailRegex.test(email); + 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 addBaseUrl = () => { + baseUrl.push({ + id: lastIdxURL + 1, + url: "", + }); + setBaseUrl(baseUrl); + setLastIdxURL(lastIdxURL + 1); }; - const setupSelectRole = () => { - return ( - <> - {roleList.map((val, index) => { - return ( - - ) - })} - - ) + const handleChangeBaseURL = (value, index) => { + const newBaseURL = [...baseUrl]; + newBaseURL[index] = value; + setBaseUrl(newBaseURL); + } + + const deleteBaseURL = (id) => { + if (baseUrl && baseUrl.length > 0) { + let checkIdx = baseUrl.findIndex((o) => o.id === id); + if (checkIdx > -1) { + baseUrl.splice(checkIdx, 1); + setBaseUrl(baseUrl.filter((_, i2) => i2 !== id)); + } + } } + const handleLogoHeader = (content) => { + const newLogoHeader = [...logoHeader, { + type: "image", + content: content, + }]; + setLogoHeader(newLogoHeader); + } + + const RenderBaseURL = () => { + if (baseUrl.length > 0) { + return baseUrl.map((item, index) => { + return ( + + + handleChangeBaseURL(e, index)} + /> + + + + + + ); + }); + } else if (baseUrl.length < 1) { + return ( +
+ No Base URL found +
+ ); + } + }; + const renderFromCompany = () => { return ( @@ -293,14 +505,169 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi *required. + + + + + setRegistrationNumber(e.target.value)} placeholder='Input Number Registration' /> + + + + + + setCompanyName(e.target.value)} placeholder=' Input Company Name' /> + + + + + + + + setEmailCompany(e.target.value)} placeholder={t('inputEmail')} + onBlur={(e) => { + if (!isValidEmail(e.target.value)) { + alert("Masukkan email yang valid."); + } + }} + /> + + + + + + setPhoneNumber(e.target.value.replace(/[^0-9]/g, ''))} placeholder={t('inputNoPhone')} maxLength="15" /> + + + + + + + + setAddressCompany(e.target.value)} placeholder=' Input Address' /> + + + + + + setAbout(e.target.value)} placeholder=' Input Company Name' /> + + + + + + + + setAppName(e.target.value)} placeholder=' Input App Name' /> + + + + + + setHtmlTitle(e.target.value)} placeholder=' Input HTML Title' /> + + + + + + + + + + + + + + + + + + + + + + + +

URL

+ + +

Action

+ + + + + + +
+
{RenderBaseURL()}
+ + + + + + + handleLogoHeader(e.target.files[0])} + /> + + + + + + handleLogoHeader(e.target.files[0])} + /> + + + + + + setProjectStructureOrg(e.target.files[0])} + /> + + + +
) } - const RenderTable = useMemo(() => { + const RenderTableUser = useMemo(() => { const columns = [ + { + title: t('action'), + dataIndex: '', + key: 'x', + render: (text, record) => <> + + + {" "} + + + + , + }, + { title: t('nik'), dataIndex: 'ktp_number', key: 'ktp_number' }, { title: t('nameHR'), dataIndex: 'name', key: 'name' }, @@ -314,28 +681,6 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi { title: 'Phone No.', dataIndex: 'phone_number', key: 'phone_number' }, { title: 'Email', dataIndex: 'email', key: 'email' }, { title: 'Status', dataIndex: 'status_resource', key: 'status_status' } - // 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 ( { + const columns = [ + { + title: t('action'), + dataIndex: '', + key: 'x', + render: (text, record) => <> + + handleDeleteMenu(text.id)}> + + + handleEditMenu(text)}> + + , + }, + { title: t('name'), dataIndex: 'join_first_name', key: 'join_first_name' }, + { title: 'Url', dataIndex: 'url', key: 'url' }, + { title: t('icon'), dataIndex: 'icon', key: 'icon' }, + { title: 'Alias', dataIndex: 'alias_name', key: 'alias_name' }, + { title: t('order'), dataIndex: 'sequence', key: 'sequence' }, + { title: t('parentMenu'), dataIndex: 'join_first_name', key: 'join_first_name', render: (text, record) => (text ? text : "-") } + ]; + return ( +
+ ) + }, [dataTableMenu]) + return ( <> + + cancelDelete()} + focusCancelBtn + > + {t('deleteMsg')} + + - {typeDialog === "Save" ? `Add` : typeDialog === "Set" ? "Manage Admin" : "Edit"} Company - {typeDialog === "Set" && ( - + {typeDialog === "Set-Menu" ? `Menu ${companyNameProp}` : typeDialog === "Save" ? `Add Data Company` : typeDialog === "Set" ? `Manage User ${companyNameProp}` : `Edit ${companyNameProp}`} + {typeDialog === "Set" ? ( + - )} + ) : + ( + + + + )} - {typeDialog !== "Set" && renderFromCompany()} + {typeDialog !== "Set" && typeDialog !== "Set-Menu" && renderFromCompany()} {typeDialog === "Set" && ( <> - {RenderTable} + {RenderTableUser} )} + {typeDialog === "Set-Menu" && ( + <> + {renderTableMenu} + + + )} - {typeDialog !== "Set" && ( + {typeDialog !== "Set" && typeDialog !== "Set-Menu" && ( )} diff --git a/src/views/Master/MasterCompany/FormMenu.js b/src/views/Master/MasterCompany/FormMenu.js new file mode 100644 index 0000000..a7178d2 --- /dev/null +++ b/src/views/Master/MasterCompany/FormMenu.js @@ -0,0 +1,285 @@ +import React, { useState, useEffect } from 'react' +import { + Modal, ModalHeader, ModalBody, ModalFooter, + Button, Form, FormGroup, Label, Input, Col, Row +} from 'reactstrap'; +import { Transfer, Select } from 'antd'; +import 'antd/dist/antd.css'; +import { useTranslation } from 'react-i18next'; +import { MENU_LIST, MENU_COMPANY_ADD, MENU_COMPANY_EDIT } from '../../../const/ApiConst.js'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; +import axios from 'axios'; +const token = window.localStorage.getItem('token'); +const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, companyName, companyID }) => { + const { Option } = Select + const [targetKeys, setTargetKeys] = useState([]) + const [menuResource, setmenuResource] = useState([]) + const [id, setId] = useState(0) + const [name, setName] = useState('') + const [url, setUrl] = useState('') + const [aliasName, setAliasName] = useState('') + const [icon, setIcon] = useState('') + const [sequence, setSequence] = useState(0) + const [parentId, setParentId] = useState(null) + const { t } = useTranslation() + const config = { + headers: + { + Authorization: `Bearer ${token}`, + "Content-type": `application/json` + } + }; + + const handleCLearData = () => { + // setId(0) + setTargetKeys([]) + } + + useEffect(() => { + if (!openDialog) { + handleCLearData() + } else { + getDataAllMenu(); + } + }, [openDialog]) + + const getDataAllMenu = async () => { + const result = await axios + .get(MENU_LIST, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + setTransferMenu(result.data.data); + } else { + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + const setTransferMenu = (data) => { + const finalData = [] + data.map((val, index) => { + let data = { + key: val.id, + name: val.name, + url: val.url, + alias_name: val.alias_name, + icon: val.icon, + parent_id: val.parent_id, + sequence: val.sequence, + } + finalData.push(data) + }); + setmenuResource(finalData) + } + + + const handleSave = async () => { + await saveMenuCompany() + handleCLearData() + } + + useEffect(() => { + if (typeDialog === "Edit") { + setId(dataEdit.id) + setIcon(dataEdit.icon) + setParentId(dataEdit.parent_id) + setSequence(dataEdit.sequence) + } else { + setId(0) + setName('') + setUrl('') + setIcon('') + setParentId(null) + setSequence(0) + setAliasName('') + } + }, [dataEdit, openDialog]) + + const validation = () => { + if (!icon || icon === "") { + alert("Icon cannot be empty!"); + return true; + } + if (sequence < 0) { + alert("Order cannot be empty!"); + return true; + } + } + + const saveMenuCompany = async () => { + let data = ''; + const err = validation(); + if (!err) { + if (typeDialog === "Edit") { + data = { + id, + sequence: parseInt(sequence), + icon, + } + + if (parentId && parentId > 0) { + data['parent_id'] = parentId + } + + const formData = data + const url = MENU_COMPANY_EDIT(data.id) + const result = await axios.put(url, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + closeDialog('success', 'Data menu berhasil diubah') + } else { + closeDialog('failed', 'Data menu gagal diubah') + } + } + setId(0) + setName('') + setUrl('') + setIcon('') + setParentId(null) + setSequence(0) + setAliasName('') + } else { + const selectedData = menuResource.filter(item => targetKeys.includes(item.key)); + const formDatas = selectedData.map(data => ({ + menu_id: data.key, + parent_id: data.parent_id, + company_id: companyID, + icon: data.icon, + alias_name: data.alias_name, + url: data.url, + sequence: data.sequence + })); + const result = await axios + .post(MENU_COMPANY_ADD, formDatas, config) + .then(res => res) + .catch((error) => error.response); + if (result && result.status == 200) { + closeDialog('success', result.data.message) + } else { + closeDialog('failed', result.data.message) + } + } + } + + const handleCancel = () => { + closeDialog('cancel', 'none') + setId(0) + setName('') + setUrl('') + setIcon('') + setParentId(null) + setSequence(0) + setAliasName('') + } + + const handleChange = targetKeys => { + setTargetKeys(targetKeys) + }; + + const onChangeParent = (val) => { + setParentId(val) + } + + const setupSelectParent = () => { + return ( + <> + {menuResource.map((val, index) => { + return ( + + ) + })} + + ) + } + + const renderForm = () => { + return ( +
+ +
+
+ item.name} + /> +
+ + + + + ) + } + const renderFormEdit = () => { + return ( + + + + * Wajib diisi. + + + + + {/* + + setName(e.target.value)} placeholder={t('inputName')} /> + + + + setUrl(e.target.value)} placeholder={t('inputUrl')} /> + */} + + + setIcon(e.target.value)} placeholder={t('inputIcon')} /> + + + + + + setSequence(e.target.value.replace(/[^0-9]/g, ''))} placeholder={t('inputOrder')} /> + + + + + + {/* + + setAliasName(e.target.value)} placeholder={t('inputAliasMenu')} /> + */} + + + + + ) + } + return ( + <> + + + Add Data Menu + + + {typeDialog !== 'Edit' ? renderForm() : renderFormEdit()} + + + {''} + + + + + ) + +} +export default FormMenu; \ No newline at end of file diff --git a/src/views/Master/MasterCompany/FormUser.js b/src/views/Master/MasterCompany/FormUser.js new file mode 100644 index 0000000..e4d1fc5 --- /dev/null +++ b/src/views/Master/MasterCompany/FormUser.js @@ -0,0 +1,267 @@ +import React, { useState, useEffect } from 'react' +import { + Modal, ModalHeader, ModalBody, ModalFooter, + Button, Form, FormGroup, Label, Input, Col, Row +} from 'reactstrap'; +import { Select } from 'antd'; +import { USER_ADD, USER_EDIT } from '../../../const/ApiConst.js'; +import 'antd/dist/antd.css'; +import { useTranslation } from 'react-i18next'; +import axios from 'axios'; +const { Option } = Select +const token = window.localStorage.getItem('token'); +const config = { + headers: + { + Authorization: `Bearer ${token}`, + "Content-type": `application/json` + } +}; +const FormUser = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, roleList, companyID }) => { + const { t } = useTranslation() + const [id, setId] = useState('') + const [resourceName, setResourceName] = useState('') + const [username, setUsername] = useState('') + const [password, setPassword] = useState('') + const [employeeType, setEmployeeType] = useState('') + const [phoneNo, setPhoneNo] = useState('') + const [email, setEmail] = useState('') + const [gender, setGender] = useState('') + const [ktpNumber, setKtpNumber] = useState('') + const [roleId, setRoleId] = useState('') + const [statusResource, setStatusResource] = useState('active') + + useEffect(() => { + if (typeDialog === "Edit") { + console.log(dataEdit); + setId(dataEdit.id) + setResourceName(dataEdit.name) + setUsername(dataEdit.username) + setPassword('') + setEmployeeType(dataEdit.employee_type) + setPhoneNo(dataEdit.phone_number) + setEmail(dataEdit.email) + setGender(dataEdit.gender) + setKtpNumber(dataEdit.ktp_number ? dataEdit.ktp_number : '') + setRoleId(dataEdit.role_id) + } else { + setId(0) + setResourceName('') + setUsername('') + setPassword('') + setEmployeeType('') + setPhoneNo('') + setEmail('') + setGender('') + setRoleId('') + } + }, [dataEdit, openDialog]) + + + const handleSave = async () => { + let data = ''; + if (typeDialog === "Save") { + data = { + name: resourceName, + employee_type: employeeType, + phone_number: phoneNo, + email, + gender, + ktp_number: ktpNumber, + role_id: roleId, + status_resource: statusResource, + company_id: companyID, + username, + password, + } + const formData = data + const result = await axios.post(USER_ADD, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + closeDialog('success', `Data resource berhasil ditambah`) + } else { + closeDialog('failed', result.data.message) + } + } else { + + data = { + id, + name: resourceName, + username, + employee_type: employeeType, + phone_number: phoneNo, + email, + gender, + ktp_number: ktpNumber, + role_id: roleId, + status_resource: statusResource, + company_id: companyID, + username, + password, + } + if (password == '') { + data.password = dataEdit.password; + } + let urlEdit = USER_EDIT(data.id) + const formData = data + + const result = await axios.put(urlEdit, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + closeDialog('success', `Data resource berhasil diedit`) + } else { + closeDialog('failed', result.data.message) + } + + } + } + + const handleCancel = () => { + closeDialog('cancel', 'none') + } + + const isValidEmail = (email) => { + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return emailRegex.test(email); + }; + + const setupSelectRole = () => { + return ( + <> + {roleList.map((val, index) => { + return ( + + ) + })} + + ) + } + + + const renderFormSetAdmin = () => { + return ( + + + + *required. + + + + + + + setKtpNumber(e.target.value.replace(/[^0-9]/g, ''))} placeholder={t('inputNik')} maxLength="16" /> + + + + + + setResourceName(e.target.value)} placeholder={t('inputName')} /> + + + + + + + + + + + + + + + setPhoneNo(e.target.value.replace(/[^0-9]/g, ''))} placeholder={t('inputNoPhone')} maxLength="15" /> + + + + + + + + setEmail(e.target.value)} placeholder={t('inputEmail')} + onBlur={(e) => { + if (!isValidEmail(e.target.value)) { + alert("Masukkan email yang valid."); + } + }} + /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + setUsername(e.target.value)} placeholder={`Username...`} /> + + + + + + + + setPassword(e.target.value)} placeholder={`Password...`} /> + + + + + ) + } + + return ( + <> + + + {typeDialog === "Save" ? `Add` : typeDialog === "Set" ? "Add " : "Edit"} User + + + {renderFormSetAdmin()} + + + {''} + + + + + ) + +} +export default FormUser; \ No newline at end of file diff --git a/src/views/Master/MasterCompany/index.js b/src/views/Master/MasterCompany/index.js index c3d692a..e48af19 100644 --- a/src/views/Master/MasterCompany/index.js +++ b/src/views/Master/MasterCompany/index.js @@ -2,19 +2,14 @@ import * as XLSX from 'xlsx'; import React, { useState, useEffect, useMemo } from 'react'; import SweetAlert from 'react-bootstrap-sweetalert'; import axios from "../../../const/interceptorApi" -import moment from 'moment' import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import DialogForm from './DialogForm' import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Table, Button, Tooltip } from 'antd'; import { - COMPANY_MANAGEMENT_SEARCH, USER_ADD, USER_SEARCH, USER_EDIT, USER_DELETE, ROLE_SEARCH, DIVISI_SEARCH, USER_SHIFT_ADD, USER_SYNC + COMPANY_MANAGEMENT_SEARCH, USER_ADD, USER_SEARCH, USER_EDIT, USER_DELETE, DIVISI_SEARCH, USER_SHIFT_ADD, USER_SYNC } from '../../../const/ApiConst'; import { useTranslation } from 'react-i18next'; -const url = ""; -const proyek_id = localStorage.getItem('proyek_id'); -const role_id = localStorage.getItem('role_id'); -const format = "DD-MM-YYYY"; const token = window.localStorage.getItem('token'); const config = { headers: @@ -23,8 +18,7 @@ const config = { "Content-type": `application/json` } }; -const role_name = window.localStorage.getItem('role_name'); -const company_id = window.localStorage.getItem('company_id'); + const MasterCompany = ({ params }) => { const token = localStorage.getItem("token") const company_id = localStorage.getItem("company_id") @@ -45,17 +39,16 @@ const MasterCompany = ({ params }) => { 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 [companyID, setCompanyID] = useState('') + const [companyName, setCompanyName] = useState('') const pageName = params.name; const { t } = useTranslation(); useEffect(() => { - getRoleList() getDivisiList() }, []) @@ -63,12 +56,7 @@ const MasterCompany = ({ params }) => { getDataUser() }, [search, rowsPerPage, currentPage]) - useEffect(() => { - const cekData = dataExport || [] - if (cekData.length > 0) { - exportExcel() - } - }, [dataExport]) + const onShowSizeChange = (current, pageSize) => { setRowsPerPage(pageSize) @@ -78,22 +66,6 @@ const MasterCompany = ({ params }) => { 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 }, @@ -188,122 +160,7 @@ const MasterCompany = ({ params }) => { } - 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) @@ -312,15 +169,19 @@ const MasterCompany = ({ params }) => { const handleSetWorker = async (data) => { setCompanyID(data.id) + setCompanyName(data.company_name) await setDataEdit(data) handleOpenDialog('Set'); } - const handleSetUserShift = async (data) => { + const handleSetMenu = async (data) => { + setCompanyID(data.id) + setCompanyName(data.company_name) await setDataEdit(data) - handleOpenDialogShift('Save'); + handleOpenDialog('Set-Menu'); } + const handleDelete = async (id) => { await setAlertDelete(true) await setIdDelete(id) @@ -336,13 +197,6 @@ const MasterCompany = ({ params }) => { setOpenDialog(false) } - const handleCloseDialogShift = (type, data) => { - if (type === "save") { - saveUserShift(data); - } - setDataEdit([]) - setOpenDialogShift(false) - } const saveUser = async (data) => { const formData = data @@ -358,20 +212,6 @@ const MasterCompany = ({ params }) => { } } - 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) @@ -393,9 +233,7 @@ const MasterCompany = ({ params }) => { setOpenDialog(!openDialog) } - const toggleAddDialogShift = () => { - setOpenDialogShift(!openDialogShift) - } + const onConfirmDelete = async () => { let url = USER_DELETE(idDelete); @@ -431,13 +269,15 @@ const MasterCompany = ({ params }) => { - + + + , }, @@ -481,9 +321,9 @@ const MasterCompany = ({ params }) => { typeDialog={typeDialog} dataEdit={dataEdit} clickOpenModal={clickOpenModal} - roleList={roleList} divisiList={divisiList} companyID={companyID} + companyNameProp={companyName} /> @@ -497,12 +337,6 @@ const MasterCompany = ({ params }) => { - {/* - - - - - */} From 7385e6dc94cd9ce6c94b64a0d7cd9723e2b2a7a3 Mon Sep 17 00:00:00 2001 From: farhan048 Date: Fri, 10 Nov 2023 13:53:06 +0700 Subject: [PATCH 17/18] remove console and file --- .../Master/MasterCompany/DialogFormUser.js | 258 ------------------ src/views/Pages/Login/Login.js | 1 - 2 files changed, 259 deletions(-) delete mode 100644 src/views/Master/MasterCompany/DialogFormUser.js diff --git a/src/views/Master/MasterCompany/DialogFormUser.js b/src/views/Master/MasterCompany/DialogFormUser.js deleted file mode 100644 index d95e4a3..0000000 --- a/src/views/Master/MasterCompany/DialogFormUser.js +++ /dev/null @@ -1,258 +0,0 @@ -import React, { useState, useMemo } from 'react' -import { - Modal, ModalHeader, ModalBody, ModalFooter, - Button, Form, FormGroup, Label, Input, Col, Row, Card, CardBody, Fade -} from 'reactstrap'; -import { DatePicker, Table, Tooltip, Select, Input as InputAntd } from 'antd'; -import moment from 'moment'; -import 'antd/dist/antd.css'; -import { useTranslation } from 'react-i18next'; -const { Option } = Select -const DialogFormUser = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, roleList }) => { - const { t } = useTranslation() - - const [resourceName, setResourceName] = useState('') - const [username, setUsername] = useState('') - const [password, setPassword] = useState('') - const [retryPassword, setRetryPassword] = useState('') - const [employeeType, setEmployeeType] = useState('') - const [phoneNo, setPhoneNo] = useState('') - const [email, setEmail] = useState('') - const [gender, setGender] = useState('') - const [birthDate, setBirthDate] = useState('') - const [birthPlace, setBirthPlace] = useState('') - const [ktpNumber, setKtpNumber] = useState('') - const [roleId, setRoleId] = useState('') - const [address, setAddress] = useState('') - const [statusResource, setStatusResource] = useState('active') - const [statusRestriction, setStatusRestriction] = useState(false) - - - - const handleSave = () => { - let data = ''; - - if (typeDialog === "Save") { - data = { - // registration_no: registrationnumber, - // company_name: companyName, - // address: addressCompany, - // phone_no: phoneNumber, - // email: emailCompany, - // description: description, - // logo_login: logoLogin, - // logo_header: logoHeader, - // favicon_image: favIcon, - // login_instruction: loginInstruction, - // about: about, - // html_title: htmlTitle, - // app_name: appName, - // base_url: baseUrl, - // is_active: statusCompany, - // template_id: template - } - console.log(data) - - closeDialog('save', data); - } else if (typeDialog === "Set") { - // if (!password && password === "") { - // alert("Please fill password"); - // return; - // } - // if (password !== retryPassword) { - // alert("Password doesn't match"); - // return; - // } - // if (password.length < 8) { - // alert("Password minimum 8 character"); - // return; - // } - // data = { - // id, - // username, - // password, - // email, - // } - - closeDialog('edit', data); - } else { - - // data = { - // id, - // name: resourceName, - // username, - // employee_type: employeeType, - // phone_number: phoneNo, - // email, - // gender, - // birth_place: birthPlace, - // blood_type: bloodType, - // ktp_number: ktpNumber, - // biaya_per_jam: biayaPerJam.replace('.', ''), - // role_id: roleId, - // divisi_id: divisionId, - // address, - // status_resource: statusResource, - // status_boundary: statusRestriction, - // company_id: company_id - // } - - // if (birthDate && birthDate != "") { - // data['birth_date'] = birthDate; - // } - - closeDialog('edit', data); - } - } - - const handleCancel = () => { - closeDialog('cancel', 'none') - } - - const isValidEmail = (email) => { - const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - return emailRegex.test(email); - }; - - const setupSelectRole = () => { - return ( - <> - {roleList.map((val, index) => { - return ( - - ) - })} - - ) - } - - - const renderFormSetAdmin = () => { - return ( -
- -
- *required. - - - - - - - setKtpNumber(e.target.value.replace(/[^0-9]/g, ''))} placeholder={t('inputNik')} maxLength="16" /> - - - - - - setResourceName(e.target.value)} placeholder={t('inputName')} /> - - - - - - - - - - - - - - - setPhoneNo(e.target.value.replace(/[^0-9]/g, ''))} placeholder={t('inputNoPhone')} maxLength="15" /> - - - - - - - - setEmail(e.target.value)} placeholder={t('inputEmail')} - onBlur={(e) => { - if (!isValidEmail(e.target.value)) { - alert("Masukkan email yang valid."); - } - }} - /> - - - - - - - - - - - - - - setBirthPlace(e.target.value)} placeholder={t('inputBrithPlace')} /> - - - - - - setBirthDate(date)} /> - - - - - - - - - - - - - - - - - - - - - setAddress(e.target.value)} placeholder={t('inputAddress')} /> - - - - - - ) - } - - return ( - <> - - - {typeDialog === "Save" ? `Add` : typeDialog === "Set" ? "Add " : "Edit"} User - - - {renderFormSetAdmin()} - - - {''} - - - - - ) - -} -export default DialogFormUser; \ No newline at end of file diff --git a/src/views/Pages/Login/Login.js b/src/views/Pages/Login/Login.js index 07e6890..3d74ebc 100644 --- a/src/views/Pages/Login/Login.js +++ b/src/views/Pages/Login/Login.js @@ -232,7 +232,6 @@ class Login extends Component { window.localStorage.setItem('role_name', data_user.role.name); window.localStorage.setItem('hierarchy', JSON.stringify(data_user.hierarchy)); } else { - console.log("kode : ", doLogin.data.code); // NotificationManager.error('Cek username atau password anda!', 'Gagal Login!'); NotificationManager.error(doLogin.data.message, 'Login Failed!'); this.setState({ loader: false }); From 551139b40849305cc7af1065cd024ecf94efddea Mon Sep 17 00:00:00 2001 From: farhan048 Date: Fri, 10 Nov 2023 13:58:25 +0700 Subject: [PATCH 18/18] update Apiconst Menu Company --- src/const/ApiConst.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/const/ApiConst.js b/src/const/ApiConst.js index 9d0f30e..8000af6 100644 --- a/src/const/ApiConst.js +++ b/src/const/ApiConst.js @@ -745,3 +745,17 @@ export const COMPANY_MANAGEMENT_DELETE = (id) => { return `${BASE_SIMPRO_LUMEN}/company-management/delete/${id}`; }; export const COMPANY_MANAGEMENT_LIST = `${BASE_SIMPRO_LUMEN}/company-management/list`; + + +export const MENU_COMPANY_ADD = `${BASE_SIMPRO_LUMEN}/menu-company/add-multiple`; +export const MENU_COMPANY_MANAGEMENT = (id) => { + return `${BASE_SIMPRO_LUMEN}/menu-company/management/${id}`; +}; +export const MENU_COMPANY_SEARCH = `${BASE_SIMPRO_LUMEN}/menu-company/search`; +export const MENU_COMPANY_LIST = `${BASE_SIMPRO_LUMEN}/menu-company/list`; +export const MENU_COMPANY_EDIT = (id) => { + return `${BASE_SIMPRO_LUMEN}/menu-company/update/${id}`; +}; +export const MENU_COMPANY_DELETE = (id) => { + return `${BASE_SIMPRO_LUMEN}/menu-company/delete/${id}`; +};