From 783d75fcd1d0944c783d1bb9eb684ce491c7abfa Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Thu, 7 Jul 2022 20:51:34 +0700 Subject: [PATCH] remove comments --- src/views/Master/ConfigAlert/index.js | 344 +++---- src/views/Master/MasterBroadcast/index.js | 309 ++---- src/views/Master/MasterMenu/index.js | 124 +-- src/views/Master/MasterRoles/index.js | 921 ++++++++---------- src/views/Master/RoleProject/index.js | 765 +++++++-------- src/views/SimproV2/ChecklistK3/index.js | 53 +- src/views/SimproV2/Closing/index.js | 167 +--- src/views/SimproV2/ControlMonitoring/index.js | 13 +- src/views/SimproV2/CreatedProyek/index.js | 141 +-- src/views/SimproV2/Divisi/index.js | 674 ++++++------- src/views/SimproV2/PanicButton/index.js | 105 +- src/views/SimproV2/ProjectType/index.js | 770 +++++++-------- src/views/SimproV2/ResourceMaterial/index.js | 100 +- src/views/SimproV2/ResourceTools/index.js | 80 +- src/views/SimproV2/ResourceWorker/index.js | 117 +-- src/views/SimproV2/Satuan/index.js | 669 ++++++------- 16 files changed, 2257 insertions(+), 3095 deletions(-) diff --git a/src/views/Master/ConfigAlert/index.js b/src/views/Master/ConfigAlert/index.js index 93b26b4..53be7d9 100644 --- a/src/views/Master/ConfigAlert/index.js +++ b/src/views/Master/ConfigAlert/index.js @@ -1,194 +1,172 @@ +import Bell from '@iconify/icons-ion/notifications-outline'; +import BellOff from '@iconify/icons-ion/notifications-off-outline'; import React, { useState, useEffect } from 'react'; -import { Card, CardBody, CardHeader, Input } from 'reactstrap'; import axios from 'axios'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { Card as ACard,Row, Col, Switch } from 'antd'; import { CALERTUSER_SEARCH,CONFIGALERT_SEARCH,CALERTUSER_DELETE, CALERTUSER_ADD } from '../../../const/ApiConst.js'; +import { Card as ACard,Row, Col, Switch } from 'antd'; +import { Card, CardBody, CardHeader, Input } from 'reactstrap'; import { Icon } from '@iconify/react'; -import Bell from '@iconify/icons-ion/notifications-outline'; -import BellOff from '@iconify/icons-ion/notifications-off-outline'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; const token = window.localStorage.getItem('token'); const userID = window.localStorage.getItem('user_id'); const Index = ({params}) => { - const [dataTable, setDatatable] = useState([]) - const [alertUser, setAlertUser] = useState([]) - const [checked, setChecked] = useState({}) - const [onSetSwitch, setOnSetSwitch] = useState(false) - const pageName = params.name; - - const config = { - headers: - { - Authorization : `Bearer ${token}`, - "Content-type" : `application/json` - } - }; - - - useEffect(()=> { - getDataConfigAlert(); - // getDataConfigAlertUser(); - },[]) - - useEffect(() => { - getDataConfigAlertUser(); - },[dataTable]) - - - - const getDataConfigAlert = async () => { - const payload = { - "paging": {"start": 0, "length": -1}, - "columns": [ - {"name": "nama", "logic_operator": "like", "value": "", "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - - - - const result = await axios - .post(CONFIGALERT_SEARCH, payload, config) - .then(res => res) - .catch((error) => error.response); - - // console.log(result) - - if(result && result.data && result.data.code == 200){ - let resData = result.data.data - let checkedAlert = {} - resData.map((val, index) => { - checkedAlert[val.id] = false - }); - setChecked(checkedAlert); - setDatatable(resData); - // getDataConfigAlertUser(); - }else{ - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - const getDataConfigAlertUser = async () => { - const payload = { - "paging": {"start": 0, "length": -1}, - "columns": [ - {"name": "user_id", "logic_operator": "=", "value": localStorage.getItem('user_id'), "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - - const result = await axios - .post(CALERTUSER_SEARCH, payload, config) - .then(res => res) - .catch((error) => error.response); - - - - if(result && result.data && result.data.code == 200){ - let resData = result.data.data - // console.log("resData", resData) - // console.log("dataTable", dataTable) - let configAlert = []; - resData.map((val, index) => { - configAlert.push(val.config_alert_id); - let indexRes = dataTable.findIndex(x => x.id === val.config_alert_id); - // console.log("indexRes", indexRes) - if(indexRes >= 0){ - let id = dataTable[indexRes].id; - let tempChecked = checked; - tempChecked[id] = true; - // console.log("tempChecked", tempChecked) - setChecked(tempChecked); - } - }); - window.localStorage.setItem('userConfigAlert', configAlert.join()); - console.log("configAlert.join()", configAlert.join()) - setOnSetSwitch(false) - setAlertUser(result.data.data); - }else{ - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - const onChange = (checked, id) => { - setOnSetSwitch(true) - // console.log(`switch to ${checked} ${id}`); - if(checked){ - addConfigAlertUser(id); - }else{ - setDeleteConfigAlertUser(id) - } - } - - const addConfigAlertUser = async (id) => { - const formData = { - "user_id":parseInt(localStorage.getItem('user_id')), - "config_alert_id":id - } - - const result = await axios.post(CALERTUSER_ADD, formData, config) - .then(res => res) - .catch((error) => error.response); - - if(result && result.data && result.data.code===200){ - getDataConfigAlertUser(); - // NotificationManager.success(`Data menu berhasil ditambah`, 'Success!!'); - } - } - - const setDeleteConfigAlertUser = async (id) => { - let indexCek = alertUser.findIndex(x => x.user_id === parseInt(localStorage.getItem('user_id')) && x.config_alert_id === id); - // console.log("cekcekckecke", indexCek) - if(indexCek >= 0){ - let idAlert = alertUser[indexCek].id - // console.log("cek idAlert", idAlert); - deleteConfigAlertUser(idAlert) - } - } - - const deleteConfigAlertUser = async (id) => { - const url = CALERTUSER_DELETE(id) - - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataConfigAlert(); - } - } - - - return ( -
- - - -

{pageName}

-
- - - {dataTable.map((val, index) => ( - - onChange(checked, val.id)} disabled={onSetSwitch} />, - ]}> -
- -

{val.nama}

-
-
- - ))} -
-
-
-
- ) + + const [alertUser, setAlertUser] = useState([]) + const [checked, setChecked] = useState({}) + const [dataTable, setDatatable] = useState([]) + const [onSetSwitch, setOnSetSwitch] = useState(false) + const pageName = params.name; + + const config = { + headers: + { + Authorization : `Bearer ${token}`, + "Content-type" : `application/json` + } + }; + + useEffect(()=> { + getDataConfigAlert(); + },[]) + + useEffect(() => { + getDataConfigAlertUser(); + },[dataTable]) + + const getDataConfigAlert = async () => { + const payload = { + "paging": {"start": 0, "length": -1}, + "columns": [ + {"name": "nama", "logic_operator": "like", "value": "", "operator": "AND"} + ], + "joins": [], + "orders": {"columns": ["id"], "ascending": false} + } + + const result = await axios + .post(CONFIGALERT_SEARCH, payload, config) + .then(res => res) + .catch((error) => error.response); + + if(result && result.data && result.data.code == 200){ + let resData = result.data.data + let checkedAlert = {} + resData.map((val, index) => { + checkedAlert[val.id] = false + }); + setChecked(checkedAlert); + setDatatable(resData); + }else{ + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + const getDataConfigAlertUser = async () => { + const payload = { + "paging": {"start": 0, "length": -1}, + "columns": [ + {"name": "user_id", "logic_operator": "=", "value": localStorage.getItem('user_id'), "operator": "AND"} + ], + "joins": [], + "orders": {"columns": ["id"], "ascending": false} + } + + const result = await axios + .post(CALERTUSER_SEARCH, payload, config) + .then(res => res) + .catch((error) => error.response); + + if(result && result.data && result.data.code == 200){ + let resData = result.data.data + let configAlert = []; + resData.map((val, index) => { + configAlert.push(val.config_alert_id); + let indexRes = dataTable.findIndex(x => x.id === val.config_alert_id); + if(indexRes >= 0){ + let id = dataTable[indexRes].id; + let tempChecked = checked; + tempChecked[id] = true; + setChecked(tempChecked); + } + }); + window.localStorage.setItem('userConfigAlert', configAlert.join()); + setOnSetSwitch(false) + setAlertUser(result.data.data); + }else{ + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + const onChange = (checked, id) => { + setOnSetSwitch(true) + if(checked){ + addConfigAlertUser(id); + }else{ + setDeleteConfigAlertUser(id) + } + } + + const addConfigAlertUser = async (id) => { + const formData = { + "user_id":parseInt(localStorage.getItem('user_id')), + "config_alert_id":id + } + + const result = await axios.post(CALERTUSER_ADD, formData, config) + .then(res => res) + .catch((error) => error.response); + + if(result && result.data && result.data.code===200){ + getDataConfigAlertUser(); + } + } + + const setDeleteConfigAlertUser = async (id) => { + let indexCek = alertUser.findIndex(x => x.user_id === parseInt(localStorage.getItem('user_id')) && x.config_alert_id === id); + if(indexCek >= 0){ + let idAlert = alertUser[indexCek].id + deleteConfigAlertUser(idAlert) + } + } + + const deleteConfigAlertUser = async (id) => { + const url = CALERTUSER_DELETE(id) + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code === 200) { + getDataConfigAlert(); + } + } + + return ( +
+ + + +

{pageName}

+
+ + + {dataTable.map((val, index) => ( + + onChange(checked, val.id)} disabled={onSetSwitch} />, + ]}> +
+ +

{val.nama}

+
+
+ + ))} +
+
+
+
+ ) } -export default Index; \ No newline at end of file +export default Index; diff --git a/src/views/Master/MasterBroadcast/index.js b/src/views/Master/MasterBroadcast/index.js index 0d4c556..301dbbf 100644 --- a/src/views/Master/MasterBroadcast/index.js +++ b/src/views/Master/MasterBroadcast/index.js @@ -1,22 +1,21 @@ -import { DatePicker, Pagination } from 'antd'; -import axios from 'axios'; -import moment from 'moment'; +import * as XLSX from 'xlsx'; +import DialogDetail from './DialogDetail'; +import DialogForm from './DialogForm'; import React, { Component } from 'react'; import SweetAlert from 'react-bootstrap-sweetalert'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { Button, Card, CardBody, CardHeader, DropdownItem, DropdownMenu, DropdownToggle, Input, InputGroup, InputGroupButtonDropdown, Table, Row, Col } from 'reactstrap'; -import * as XLSX from 'xlsx'; +import axios from 'axios'; +import moment from 'moment'; import { API_BROADCAST_SIMPRO, BASE_SIMPRO, BASE_URL_GEOHR_API2 } from '../../../const/ApiConst'; -import DialogForm from './DialogForm'; -import DialogDetail from './DialogDetail'; +import { Button, Card, CardBody, CardHeader, DropdownItem, DropdownMenu, DropdownToggle, Input, InputGroup, InputGroupButtonDropdown, Table, Row, Col } from 'reactstrap'; +import { DatePicker, Pagination } from 'antd'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Tooltip } from 'reactstrap'; - const { RangePicker } = DatePicker; const token = window.localStorage.getItem('token'); const config = { - headers: - { + headers: + { Authorization : `Bearer ${token}`, "Content-type" : `application/json` } @@ -27,7 +26,6 @@ const roleName = window.localStorage.getItem('role_name'); const column = [ { name: "Aksi" }, - { name: "Judul" }, { name: "Pesan" }, { name: "Deskripsi" }, @@ -41,40 +39,40 @@ export default class index extends Component { constructor(props) { super(props) this.state = { - dataTable: [], - dataExport: [], - openDialog: false, - typeDialog: 'Save', - dataEdit: null, + alertBroadcast: false, alertDelete: false, - idDelete: 0, + currentDay: 'today', + currentPage: 1, + dataDetail:[], + dataEdit: null, + dataExport: [], + dataExport:[], dataGs: [], dataIdHo: [], - search: "", + dataTable: [], + endDate: moment(moment().format("YYYY-M-D")), + idDelete: 0, + idSend: 0, + openDialog: false, + openDialogDetail: false, page: 0, rowsPerPage: LENGTH_DATA, - currentPage: 1, - totalPage: 0, - tooltipEdit: false, - tooltipDelete: false, - typeClock: "All", - startDate: moment(moment().format("YYYY-M-D")), - endDate: moment(moment().format("YYYY-M-D")), - dataExport:[], - currentDay: 'today', + search: "", searchDetail: "Judul", searchDetailField: "title_notif", splitButtonOpen: false, - alertBroadcast: false, + startDate: moment(moment().format("YYYY-M-D")), statusSend: '', - idSend: 0, - dataDetail:[], - openDialogDetail: false, toltipDetail:false, + tooltipDelete: false, + tooltipEdit: false, + tooltipExport:false, + tooltipTambah:false, tooltipresend:false, tooltipsend:false, - tooltipTambah:false, - tooltipExport:false, + totalPage: 0, + typeClock: "All", + typeDialog: 'Save', } } @@ -94,7 +92,6 @@ export default class index extends Component { }; getDataBroadcast = async () => { - // let url = `${API_BROADCAST}/search`; let url = BASE_SIMPRO + `/broadcast/search`; const { searchDetail } = this.state @@ -134,42 +131,9 @@ export default class index extends Component { } } - // const formData = new FormData(); - // formData.append("start", start); - // formData.append("id_org", id_org); - // formData.append("length", this.state.rowsPerPage); - // formData.append("startDate", dateStart.format("YYYY-M-D")+" 00:00:00"); - // formData.append("endDate", dateEnd.format("YYYY-M-D")+" 23:59:59"); - // formData.append('field', this.state.searchDetailField); if(this.state.search!=="" && this.state.search!==null){ - // formData.append('value', this.state.search); } - // const param = { - // "paging": { "start": start, "length": this.state.rowsPerPage }, - // ...searchDetail === "Semua" && - // { - // "filter_columns": [ - // { "name": "title_notif", "value": this.state.search.toString() }, - // { "name": "message_notif", "value": this.state.search.toString() }, - // { "name": "description", "value": this.state.search.toString() }, - // { "name": "status_send", "value": this.state.search.toString() }, - // ], - // }, - // ...searchDetail !== "Semua" && - // { - // "columns": [ - // { "name": this.state.searchDetailField, "logic_operator": "like", "operator": "and", "value": this.state.search.toString() } - // ] - // }, - // "orders": { "columns": ["created_date"], "descending": true } - // } - - // const result = await axios - // .post(url, param) - // .then(res => res) - // .catch((error) => error.response); - const result = await axios .post(url, payload, config) .then(res => res) @@ -183,15 +147,6 @@ export default class index extends Component { } else { NotificationManager.error('Failed retreiving data!!', 'Failed'); } - - // console.log("data result", result) - // if(result && result.data){ - // if (result.status === 200) { - // this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord }); - // } else { - // NotificationManager.error('Gagal Menerima Data!!', 'Failed'); - // } - // } } handleOpenDialog = (type) => { @@ -232,26 +187,19 @@ export default class index extends Component { } saveBroadcast = async (type, data) => { - // let url = `${API_BROADCAST}/add`; let url = BASE_SIMPRO + `/broadcast/add`; - // const param = { - // "title_notif": data.title, - // "message_notif": data.message, - // "description": data.description, - // "status_send": type - // } const param = { - "title_notif": data.title, - "status_send": type, + "title_notif": data.title, + "status_send": type, "send_to_type": "all", "message_notif": data.message, "description": data.description, - } + } const paramRoles = { - "title_notif": data.title, - "status_send": type, + "title_notif": data.title, + "status_send": type, "send_to_type": "roles", "message_notif": data.message, "description": data.description, @@ -259,106 +207,69 @@ export default class index extends Component { } const paramUsers = { - "title_notif": data.title, - "status_send": type, + "title_notif": data.title, + "status_send": type, "send_to_type": "users", "message_notif": data.message, "description": data.description, "send_to_id": data.id.map((id, index) => id) - } - // const formData = new FormData(); - // formData.append("title", data.title); - // formData.append("message", data.message); - // formData.append("description", data.description); - // formData.append("send_to_type", data.send_to_type); - // if(type==="send"){ - // formData.append('status_send', "complete"); - // }else{ - // formData.append('status_send', "registered"); - // } - - - // if(data.send_to_type==="roles"){ - // formData.append('id', data.id); - // }else if(data.send_to_type==="users"){ - // data.id.map((id, index)=> { - // formData.append('id[]', id); - // console.log("test", id); - // }) - // }else{ - // formData.append('id', "all"); - // } - // const param = { - // "title_notif": data.title, - // "message_notif": data.message, - // "description": data.description, - // "status_send": type, - // "send_to_type": data.send_to_type, - // "send_to_id": data.id - // } - // console.log("cek param", param) - - if(data.send_to_type === "all") { - const result = await axios.post(url, param, config) - .then(res => res) - .catch((error) => error.response); - - if (result) { - if(result.data){ - if(result.data.code===200){ - this.getDataBroadcast(); - NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!'); - }else{ - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - }else{ - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - }else{ - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - - } else if(data.send_to_type === "roles") { - const result = await axios.post(url, paramRoles, config) - .then(res => res) - .catch((error) => error.response); - - console.log('test result broadcast all', result) - if (result) { - if(result.data){ - if(result.data.code===200){ - this.getDataBroadcast(); - NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!'); - }else{ - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - }else{ - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - }else{ - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - - } else if(data.send_to_type === "users") { - const result = await axios.post(url, paramUsers, config) - .then(res => res) - .catch((error) => error.response); - - if (result) { - if(result.data){ - if(result.data.code === 200){ - this.getDataBroadcast(); - NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!'); - }else{ - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - }else{ - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - }else{ - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - } + } + + if(data.send_to_type === "all") { + const result = await axios.post(url, param, config) + .then(res => res) + .catch((error) => error.response); + if (result) { + if(result.data){ + if(result.data.code===200){ + this.getDataBroadcast(); + NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!'); + }else{ + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + }else{ + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + }else{ + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } else if(data.send_to_type === "roles") { + const result = await axios.post(url, paramRoles, config) + .then(res => res) + .catch((error) => error.response); + if (result) { + if(result.data){ + if(result.data.code===200){ + this.getDataBroadcast(); + NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!'); + }else{ + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + }else{ + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + }else{ + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } else if(data.send_to_type === "users") { + const result = await axios.post(url, paramUsers, config) + .then(res => res) + .catch((error) => error.response); + if (result) { + if(result.data){ + if(result.data.code === 200){ + this.getDataBroadcast(); + NotificationManager.success('Broadcast berhasil terkirimkan', 'Success!!'); + }else{ + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + }else{ + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + }else{ + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } } @@ -438,21 +349,14 @@ export default class index extends Component { this.exportExcel(); }); }else{ - // NotificationManager.error('Failed retreiving data!!', 'Failed'); } } else { - // NotificationManager.error('Failed retreiving data!!', 'Failed'); } } exportExcel = () => { const dataExcel = this.state.dataExport || []; const dataExport = []; - // {n.title_notif} - // {n.message_notif !== "" ? n.message_notif : "-"} - // {n.description !== "" ? n.description : "-"} - // {n.status_send !== "" ? n.status_send : "-"} - // {n.created_date !== "" ? moment.utc(n.created_date).for dataExcel.map((val) => { let row = { "Tanggal Broadcast": moment(val.created_date).format("YYYY-MM-DD HH:mm:ss"), @@ -493,7 +397,6 @@ export default class index extends Component { renderBtnResend = (n) => { return ( - {/* */} this.handleEdit(n, 'resend')}> this.toggleTooltip("resend")}> Kirim Ulang @@ -503,7 +406,6 @@ export default class index extends Component { } renderBtnSend = (n) => { - // return ( this.handleEdit(n, 'send')}> @@ -567,31 +469,28 @@ export default class index extends Component { const val = e.target.value; this.setState({ currentDay:val }); if(val==="today"){ - // console.log("test 1 test",val); this.setState({ startDate:moment(moment().format("YYYY-M-D")), - endDate:moment(moment().format("YYYY-M-D")), + endDate:moment(moment().format("YYYY-M-D")), currentPage: 1 }) }else if(val==="3 day"){ - // console.log("test test",val); this.setState({ startDate:moment(moment().subtract(3, "days").format("YYYY-M-D")), - endDate:moment(moment().format("YYYY-M-D")), + endDate:moment(moment().format("YYYY-M-D")), currentPage: 1 }) }else if(val==="7 day"){ - // console.log("test test",val); this.setState({ startDate:moment(moment().subtract(7, "days").format("YYYY-M-D")), - endDate:moment(moment().format("YYYY-M-D")), + endDate:moment(moment().format("YYYY-M-D")), currentPage: 1 }) }else{ console.log("test 2 test",val); this.setState({ startDate:moment(moment().format("YYYY-M-D")), - endDate:moment(moment().format("YYYY-M-D")), + endDate:moment(moment().format("YYYY-M-D")), currentPage: 1 }) } @@ -625,7 +524,7 @@ export default class index extends Component { showDialog={showDialog => this.showChildDialog = showDialog} dataHs={this.state.dataIdHo} /> - this.toggleDialogDetail} @@ -639,7 +538,6 @@ export default class index extends Component { - {/* */} this.toggle("tambah")}> Tambah Broadcast @@ -672,11 +570,6 @@ export default class index extends Component { > - {/* this.setState({ - searchDetail: "Nama Karyawan", - searchDetailField: "name" - })}>Nama Karyawan */} this.setState({ searchDetail: "Judul", diff --git a/src/views/Master/MasterMenu/index.js b/src/views/Master/MasterMenu/index.js index 9cf4241..f239028 100644 --- a/src/views/Master/MasterMenu/index.js +++ b/src/views/Master/MasterMenu/index.js @@ -1,13 +1,13 @@ -import React, { useState, useEffect, useMemo } from 'react'; -import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; -import { Button } from 'reactstrap'; -import axios from 'axios'; import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; import DialogForm from './DialogForm'; +import React, { useState, useEffect, useMemo } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from 'axios'; +import { Button } from 'reactstrap'; +import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; +import { MENU_ADD,MENU_SEARCH,MENU_EDIT,MENU_DELETE } from '../../../const/ApiConst.js'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Tooltip, Table } from 'antd'; -import { MENU_ADD,MENU_SEARCH,MENU_EDIT,MENU_DELETE } from '../../../const/ApiConst.js'; const token = window.localStorage.getItem('token'); @@ -21,29 +21,29 @@ const column = [ ] const Index = ({params}) => { - const [dataTable, setDatatable] = useState([]) - const [search, setSearch] = useState('') - const [currentPage, setCurrentPage] = useState(1) - const [totalPage, setTotalPage] = useState(0) - const [openDialog, setOpenDialog] = useState(false) - const [typeDialog, setTypeDialog] = useState('Save') - const [idDelete, setIdDelete] = useState(0) const [alertDelete, setAlertDelete] = useState(false) + const [allDataMenu, setAllDataMenu] = useState([]) + const [clickOpenModal, setClickOpenModal] = useState(false) + const [currentPage, setCurrentPage] = useState(1) const [dataEdit, setDataEdit] = useState([]) + const [dataExport, setDataExport] = useState([]) + const [dataTable, setDatatable] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [openDialog, setOpenDialog] = useState(false) const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') const [tooltipDelete, setTooltipDelete] = useState(false) const [tooltipEdit, setTooltipEdit] = useState(false) - const [tooltipTambah, setTooltipTambah] = useState(false) const [tooltipExport, setTooltipExport] = useState(false) - const [clickOpenModal, setClickOpenModal] = useState(false) - const [dataExport, setDataExport] = useState([]) - const [allDataMenu, setAllDataMenu] = useState([]) + const [tooltipTambah, setTooltipTambah] = useState(false) + const [totalPage, setTotalPage] = useState(0) + const [typeDialog, setTypeDialog] = useState('Save') const pageName = params.name; const config = { - headers: - { + headers: + { Authorization : `Bearer ${token}`, "Content-type" : `application/json` } @@ -51,10 +51,8 @@ const Index = ({params}) => { useEffect(()=> { - // for select in form add or edit getDataMenu(); getDataAllMenu(); - console.log("cek config", config) },[]) useEffect(()=> { @@ -75,7 +73,6 @@ const Index = ({params}) => { }; const getDataAllMenu = async () => { - const payload = { "paging": {"start": 0, "length": -1}, "columns": [ @@ -84,26 +81,18 @@ const Index = ({params}) => { "joins": [], "orders": {"columns": ["id"], "ascending": false} } - - - const result = await axios .post(MENU_SEARCH, payload, config) .then(res => res) .catch((error) => error.response); - // console.log(result) - if(result && result.data && result.data.code == 200){ setAllDataMenu(result.data.data); }else{ - // NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); } } const getDataMenu = async () => { - - let start = 0; if (currentPage !== 1 && currentPage > 1) { @@ -124,19 +113,14 @@ const Index = ({params}) => { }], "orders": {"columns": ["id"], "ascending": false} } - - const result = await axios .post(MENU_SEARCH, payload, config) .then(res => res) .catch((error) => error.response); - // console.log(result) - if(result && result.data && result.data.code == 200){ setDatatable(result.data.data); - console.log("resdata", result.data.data) setTotalPage(result.data.totalRecord); }else{ NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); @@ -163,13 +147,10 @@ const Index = ({params}) => { } const onConfirmDelete = async () => { - const url = MENU_DELETE(idDelete) - const result = await axios.delete(url, config) .then(res => res) .catch((error) => error.response); - if (result && result.data && result.data.code === 200) { getDataMenu() setIdDelete(0) @@ -182,42 +163,38 @@ const Index = ({params}) => { } } - const saveMenu = async (data) => { + const saveMenu = async (data) => { const formData = data const result = await axios.post(MENU_ADD, formData, config) .then(res => res) .catch((error) => error.response); - + if(result && result.data && result.data.code===200){ getDataMenu(); getDataAllMenu(); NotificationManager.success(`Data menu berhasil ditambah`, 'Success!!'); } else { NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - + } + } const editMenu = async (data) => { - console.log("cek data edit", data) const formData = data const url = MENU_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){ getDataMenu(); NotificationManager.success(`Data menu berhasil diedit`, 'Success!!'); } else { NotificationManager.error(`Data menu gagal di edit`, `Failed!!`); } - - } - const handleEdit = (data) => { setDataEdit(data) handleOpenDialog('Edit'); @@ -249,7 +226,6 @@ const Index = ({params}) => { } const handleExportExcel = async () => { - const payload = { "paging": {"start": 0, "length": -1}, "columns": [ @@ -264,19 +240,14 @@ const Index = ({params}) => { }], "orders": {"columns": ["id"], "ascending": false} } - - const result = await axios .post(MENU_SEARCH, payload, config) .then(res => res) .catch((error) => error.response); - // console.log(result) - if(result && result.data && result.data.code == 200){ let resData = result.data.data; - console.log("resdata", resData) const excelData = []; resData.map((val, index) => { let dataRow = { @@ -289,12 +260,10 @@ const Index = ({params}) => { } excelData.push(dataRow) }) - // console.log("cek excel data", excelData) await setDataExport(excelData); - // exportExcel(); }else{ NotificationManager.error('Gagal Export Data!!', 'Failed'); - } + } } const exportExcel = () => { @@ -303,7 +272,6 @@ const Index = ({params}) => { 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([]) } @@ -345,7 +313,7 @@ const Index = ({params}) => { /> ) }, [dataTable]) - + return (
@@ -389,44 +357,6 @@ const Index = ({params}) => { - {/* - - - - {column.map((i, index) => { - return ( - - ) - })} - - - - {dataTable.length<=0 ? - - - : null} - {dataTable.map((n, index) => { - return ( - - - - - - - - - - ) - })} - -
{`Aksi`}{i.name}
No Data Available
- - handleDelete(n.id)}> - - - handleEdit(n)}> - - {n.name}{n.url}{n.icon}{n.alias_name}{n.sequence}{n.join_first_name ? n.join_first_name : "-"}
*/} {renderTable} { ) } -export default Index; \ No newline at end of file +export default Index; diff --git a/src/views/Master/MasterRoles/index.js b/src/views/Master/MasterRoles/index.js index 67a3ec3..219658f 100644 --- a/src/views/Master/MasterRoles/index.js +++ b/src/views/Master/MasterRoles/index.js @@ -1,14 +1,13 @@ -import React, { Component, useMemo } from 'react'; -import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; -import { Button } from 'reactstrap'; -import axios from 'axios'; import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; import DialogForm from './DialogForm'; import DialogMenuRoles from './DialogMenuRoles'; +import React, { Component, useMemo } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from 'axios'; +import { Button } from 'reactstrap'; +import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Tooltip, Table } from 'antd'; - import { ROLE_ADD, ROLE_SEARCH, ROLE_EDIT, ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; const token = window.localStorage.getItem('token'); @@ -16,503 +15,435 @@ const token = window.localStorage.getItem('token'); const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; const config = { - headers: - { - Authorization : `Bearer ${token}`, - "Content-type" : `application/json` - } + headers: + { + Authorization : `Bearer ${token}`, + "Content-type" : `application/json` + } }; const momentFormat = 'HH:mm'; - - const LENGTH_DATA = 10 export default class index extends Component { - constructor(props) { - super(props) - this.state = { - dataTable: [], - openDialog: false, - dialogMenuForm: false, - typeDialog: 'Save', - dataEdit: null, - alertDelete: false, - alertNotDelete: false, - idDelete: 0, - dataGs: [], - dataIdHo: [], - search: "", - page: 0, - rowsPerPage: LENGTH_DATA, - currentPage: 1, - totalPage: 0, - tooltipEdit: false, - tooltipDelete: false, - tooltipMenu: false, - idRoles:0, - menuRoles:[], - tooltipTambah:false, - tooltipImport:false, - tooltipExport:false, - dataExport:[] - } - - this.columns = [ - { - title: 'Action', - dataIndex: '', - key: 'x', - className:'nowrap', - render: (text, record) => <> - - this.handleMenuRoles(text.id)}> - - - - this.handleDelete(text.id)}> - - - - this.handleEdit(text)}> - - , - }, - { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, - { title: 'Description', dataIndex: 'description', key: 'description' }, - ] - } - - async componentDidMount() { - this.getDataRoles(); - } - - async componentDidUpdate(prevProps, prevState) { - const { search } = this.state - if (search !== prevState.search) this.getDataRoles() - } - - handleSearch = e => { - const value = e.target.value - this.setState({ search: value, currentPage: 1 }) - }; - - getDataRoles = async () => { - - let start = 0; - - if (this.state.currentPage !== 1 && this.state.currentPage > 1) { - start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage - } - - const formData = { - "paging": {"start": start, "length": this.state.rowsPerPage}, - "columns": [ - {"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - - const result = await axios - .post(ROLE_SEARCH, formData, config) - .then(res => res) - .catch((error) => error.response); - // console.log(result) - - if(result && result.data && result.data.code == 200){ - this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord }); - }else{ - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - handleOpenDialog = (type) => { - this.setState({ openDialog: true, typeDialog: type }) - this.showChildDialog(); - } - - - - handleCloseDialog = (type, data) => { - if (type === "save") { - this.saveRole(data); - } else if (type === "edit") { - this.editRole(data); - } - - this.setState({ openDialog: false }) - } - - - handleOpenDialogMr = () => { - this.setState({ dialogMenuForm: true }) - this.showMenuRolesDialog(); - } - handleCloseDialogMr = (type, data) => { - if(type==="save"){ - this.saveMenuRoles(data) - } - this.setState({ dialogMenuForm: false }) - } - - toggleAddDialog = () => { - this.setState({ openDialog: !this.state.openDialog }) - } - - onConfirmDelete = async () => { - const { idDelete } = this.state - const url = ROLE_DELETE(idDelete) - - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - this.deleteCurrentRoleMenu(idDelete) - this.getDataRoles() - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.success(`Data role berhasil dihapus`, 'Success!!'); - } else { - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.error(`Data role gagal dihapus`, 'Failed!!'); - } - } - - saveRole = async (data) => { - - const formData = { - name:data.name, - description:data.description - } - - const result = await axios.post(ROLE_ADD, formData, config) - .then(res => res) - .catch((error) => error.response); - - if(result && result.data && result.data.code===200){ - this.getDataRoles(); - NotificationManager.success(`Data role berhasil ditambah`, 'Success!!'); - } else { - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - - } - - editRole = async (data) => { - - const formData = { - name:data.name, - description:data.description - } - const url = ROLE_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){ - this.getDataRoles(); - NotificationManager.success(`Data role berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data role gagal di edit`, `Failed!!`); - } - - } - - - handleEdit = (data) => { - this.setState({ dataEdit: data }); - this.handleOpenDialog('Edit'); - } - - handleDelete = (id) => { - id == '1' ? this.setState({ alertNotDelete: true }) : - this.setState({ alertDelete: true, idDelete: id }); - } - - onShowSizeChange = (current, pageSize) => { - this.setState({ rowsPerPage: pageSize }, () => { - this.getDataRoles(); - }) - } - - onPagination = (current, pageSize) => { - this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { - this.getDataRoles(); - }) - } - - toggle = (param) => { - if (param === "edit") { - this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) - } else if (param === "delete") { - this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) - } else if(param === "menu"){ - this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu })) - } else if (param === "tambah") { - this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) - } else if (param === "export") { - this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) - } - } - - dataNotAvailable = () => { - if(this.state.dataTable.length===0){ - return ( - - Not Data Available - - ) - } - } - - handleMenuRoles = async (id) => { - - const formData = { - "paging": {"start": 0, "length": -1}, - "columns": [ - {"name": "role_id", "logic_operator": "=", "value": `${id}`, "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - - const result = await axios - .post(ROLEMENU_SEARCH, formData, config) - .then(res => res) - .catch((error) => error.response); - // console.log(result) - if (result && result.data && result.data.code == 200) { - this.setState({ menuRoles:result.data.data,idRoles:id },() => { - this.handleOpenDialogMr(); - }); - } else { - // NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - saveMenuRoles = async (dataArray) => { - let payloadArray = dataArray || [] - // console.log("cek", payloadArray[0]) - if(payloadArray.length > 0){ - await this.deleteCurrentRoleMenu(payloadArray[0].roles_id) - } - let promises = [] - let result = [] - console.log("test test", dataArray) - dataArray.map((val, index)=> { - if(val.checked===true){ - const formData = { - menu_id:val.menu_id, - role_id:val.roles_id - } - promises.push(axios.post(ROLEMENU_ADD, formData, config) - .then(res => result.push(res))) - } - }) - - await Promise.all(promises); - if(result){ - if(result.length > 0){ - if (result[0].data.code === 200) { - this.getDataRoles(); - NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!'); - } else { - NotificationManager.error(`${result[0].data.message}`, 'Failed!!'); - } - } - } - - } - - deleteCurrentRoleMenu = async (id) => { - let urlDel = ROLEMENU_DELETE_ROLE(id) - const result = await axios.delete(urlDel, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - return true - } else { - return false - } - } - - handleExportExcel = async () => { - let start = 0; - let end = "ALL"; - let url = BASE_URL + "roles.php?act=get_data"; - const formData = new FormData(); - formData.append('field', 'name'); - if(this.state.search !== ""){ - formData.append('value', this.state.search); - } - // console.log("test", url); - const result = await axios - .post(url,formData) - .then(res => res) - .catch((error) => error.response); - // console.log("result", result); - if (result && result.data && result.statusText == "OK") { - const dataRes = result.data.data|| []; - console.log("data result", dataRes); - const dataExport = []; - // {n.name} - // {n.url} - // {n.alias_name} - // {n.icon} - // {n.parent_name || "-"} - dataRes.map((val,index)=> { - let row = { - Nama:val.name, - Deskripsi:val.description - } - dataExport.push(row); - }) - console.log("data Export", dataExport); - this.setState({ dataExport:dataExport },()=> { - this.exportExcel(); - }); - } else { - NotificationManager.error('Failed retreiving data!!', 'Failed'); - } - } - - exportExcel = () => { - const dataExcel = this.state.dataExport || []; - const fileName = "Data Roles.xlsx"; - const ws = XLSX.utils.json_to_sheet(dataExcel); + constructor(props) { + super(props) + this.state = { + alertDelete: false, + alertNotDelete: false, + currentPage: 1, + dataEdit: null, + dataExport:[], + dataGs: [], + dataIdHo: [], + dataTable: [], + dialogMenuForm: false, + idDelete: 0, + idRoles:0, + menuRoles:[], + openDialog: false, + page: 0, + rowsPerPage: LENGTH_DATA, + search: "", + tooltipDelete: false, + tooltipEdit: false, + tooltipExport:false, + tooltipImport:false, + tooltipMenu: false, + tooltipTambah:false, + totalPage: 0, + typeDialog: 'Save', + } + + this.columns = [ + { + title: 'Action', + dataIndex: '', + key: 'x', + className:'nowrap', + render: (text, record) => <> + + this.handleMenuRoles(text.id)}> + + + + this.handleDelete(text.id)}> + + + + this.handleEdit(text)}> + + , + }, + { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, + { title: 'Description', dataIndex: 'description', key: 'description' }, + ] + } + + async componentDidMount() { + this.getDataRoles(); + } + + async componentDidUpdate(prevProps, prevState) { + const { search } = this.state + if (search !== prevState.search) this.getDataRoles() + } + + handleSearch = e => { + const value = e.target.value + this.setState({ search: value, currentPage: 1 }) + }; + + getDataRoles = async () => { + let start = 0; + if (this.state.currentPage !== 1 && this.state.currentPage > 1) { + start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage + } + + const formData = { + "paging": {"start": start, "length": this.state.rowsPerPage}, + "columns": [ + {"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"} + ], + "joins": [], + "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){ + this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord }); + }else{ + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + handleOpenDialog = (type) => { + this.setState({ openDialog: true, typeDialog: type }) + this.showChildDialog(); + } + + handleCloseDialog = (type, data) => { + if (type === "save") { + this.saveRole(data); + } else if (type === "edit") { + this.editRole(data); + } + this.setState({ openDialog: false }) + } + + handleOpenDialogMr = () => { + this.setState({ dialogMenuForm: true }) + this.showMenuRolesDialog(); + } + + handleCloseDialogMr = (type, data) => { + if(type==="save"){ + this.saveMenuRoles(data) + } + this.setState({ dialogMenuForm: false }) + } + + toggleAddDialog = () => { + this.setState({ openDialog: !this.state.openDialog }) + } + + onConfirmDelete = async () => { + const { idDelete } = this.state + const url = ROLE_DELETE(idDelete) + + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + this.deleteCurrentRoleMenu(idDelete) + this.getDataRoles() + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.success(`Data role berhasil dihapus`, 'Success!!'); + } else { + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.error(`Data role gagal dihapus`, 'Failed!!'); + } + } + + saveRole = async (data) => { + + const formData = { + name:data.name, + description:data.description + } + + const result = await axios.post(ROLE_ADD, formData, config) + .then(res => res) + .catch((error) => error.response); + + if(result && result.data && result.data.code===200){ + this.getDataRoles(); + NotificationManager.success(`Data role berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + + } + + editRole = async (data) => { + const formData = { + name:data.name, + description:data.description + } + const url = ROLE_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){ + this.getDataRoles(); + NotificationManager.success(`Data role berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data role gagal di edit`, `Failed!!`); + } + } + + handleEdit = (data) => { + this.setState({ dataEdit: data }); + this.handleOpenDialog('Edit'); + } + + handleDelete = (id) => { + id == '1' ? this.setState({ alertNotDelete: true }) : + this.setState({ alertDelete: true, idDelete: id }); + } + + onShowSizeChange = (current, pageSize) => { + this.setState({ rowsPerPage: pageSize }, () => { + this.getDataRoles(); + }) + } + + onPagination = (current, pageSize) => { + this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { + this.getDataRoles(); + }) + } + + toggle = (param) => { + if (param === "edit") { + this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) + } else if (param === "delete") { + this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) + } else if(param === "menu"){ + this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu })) + } else if (param === "tambah") { + this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) + } else if (param === "export") { + this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) + } + } + + dataNotAvailable = () => { + if(this.state.dataTable.length===0){ + return ( + + Not Data Available + + ) + } + } + + handleMenuRoles = async (id) => { + const formData = { + "paging": {"start": 0, "length": -1}, + "columns": [ + {"name": "role_id", "logic_operator": "=", "value": `${id}`, "operator": "AND"} + ], + "joins": [], + "orders": {"columns": ["id"], "ascending": false} + } + + const result = await axios + .post(ROLEMENU_SEARCH, formData, config) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code == 200) { + this.setState({ menuRoles:result.data.data,idRoles:id },() => { + this.handleOpenDialogMr(); + }); + } else { + } + } + + saveMenuRoles = async (dataArray) => { + let payloadArray = dataArray || [] + if(payloadArray.length > 0){ + await this.deleteCurrentRoleMenu(payloadArray[0].roles_id) + } + let promises = [] + let result = [] + dataArray.map((val, index)=> { + if(val.checked===true){ + const formData = { + menu_id:val.menu_id, + role_id:val.roles_id + } + promises.push(axios.post(ROLEMENU_ADD, formData, config) + .then(res => result.push(res))) + } + }) + + await Promise.all(promises); + if(result){ + if(result.length > 0){ + if (result[0].data.code === 200) { + this.getDataRoles(); + NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!'); + } else { + NotificationManager.error(`${result[0].data.message}`, 'Failed!!'); + } + } + } + } + + deleteCurrentRoleMenu = async (id) => { + let urlDel = ROLEMENU_DELETE_ROLE(id) + const result = await axios.delete(urlDel, config) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code === 200) { + return true + } else { + return false + } + } + + handleExportExcel = async () => { + let start = 0; + let end = "ALL"; + let url = BASE_URL + "roles.php?act=get_data"; + const formData = new FormData(); + formData.append('field', 'name'); + if(this.state.search !== ""){ + formData.append('value', this.state.search); + } + const result = await axios + .post(url,formData) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.statusText == "OK") { + const dataRes = result.data.data|| []; + const dataExport = []; + dataRes.map((val,index)=> { + let row = { + Nama:val.name, + Deskripsi:val.description + } + dataExport.push(row); + }) + this.setState({ dataExport:dataExport },()=> { + this.exportExcel(); + }); + } else { + NotificationManager.error('Failed retreiving data!!', 'Failed'); + } + } + + exportExcel = () => { + const dataExcel = this.state.dataExport || []; + const fileName = "Data Roles.xlsx"; + const ws = XLSX.utils.json_to_sheet(dataExcel); const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, 'Data Roles'); - XLSX.writeFile(wb, fileName); - } - - render() { - const { tooltipTambah,tooltipExport,dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete,tooltipMenu } = this.state - let noSeq = 0; - return ( -
- - this.setState({ alertDelete: false, idDelete: 0 })} - focusCancelBtn - > - Data tipe roles akan terhapus!! - - this.setState({ alertNotDelete: false})} - // focusCancelBtn - > - Data tipe roles tidak dapat di hapus!! - - this.toggleAddDialog} - typeDialog={this.state.typeDialog} - dataEdit={this.state.dataEdit} - showDialog={showDialog => this.showChildDialog = showDialog} - dataHs={this.state.dataIdHo} - /> - this.showMenuRolesDialog = showDialog} - menuRoles={this.state.menuRoles} - - /> - - -

{this.props.params.name}

- - - - - - - - - - - - - -
- - - {/*
- - - - {column.map((i, index) => { - return ( - - ) - })} - - - - {this.dataNotAvailable()} - {dataTable.map((n, index) => { - return ( - - - - - - - ) - })} - -
Aksi{i.name}
- - this.handleMenuRoles(n.id)}> - - - - this.handleDelete(n.id)}> - - - - this.handleEdit(n)}> - - {n.name}{n.description}
*/} - -
-
-
- ) - } + } + + render() { + const { tooltipTambah,tooltipExport,dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete,tooltipMenu } = this.state + let noSeq = 0; + return ( +
+ + this.setState({ alertDelete: false, idDelete: 0 })} + focusCancelBtn + > + Data tipe roles akan terhapus!! + + this.setState({ alertNotDelete: false})} + > + Data tipe roles tidak dapat di hapus!! + + this.toggleAddDialog} + typeDialog={this.state.typeDialog} + dataEdit={this.state.dataEdit} + showDialog={showDialog => this.showChildDialog = showDialog} + dataHs={this.state.dataIdHo} + /> + this.showMenuRolesDialog = showDialog} + menuRoles={this.state.menuRoles} + /> + + +

{this.props.params.name}

+ + + + + + + + + + + + + +
+ + + + + + + ) + } } diff --git a/src/views/Master/RoleProject/index.js b/src/views/Master/RoleProject/index.js index 7ec0ac0..70abc17 100644 --- a/src/views/Master/RoleProject/index.js +++ b/src/views/Master/RoleProject/index.js @@ -1,440 +1,379 @@ -import React, { Component } from 'react'; -import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; -import { Button } from 'reactstrap'; -import axios from 'axios'; import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; import DialogForm from './DialogForm'; +import React, { Component } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from 'axios'; +import { Button } from 'reactstrap'; +import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { Pagination, Tooltip, Table } from 'antd'; - import { PROJECT_ROLE_ADD, PROJECT_ROLE_SEARCH, PROJECT_ROLE_EDIT, PROJECT_ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; +import { Pagination, Tooltip, Table } from 'antd'; const token = window.localStorage.getItem('token'); const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; const config = { - headers: - { - Authorization : `Bearer ${token}`, - "Content-type" : `application/json` - } + headers: + { + Authorization : `Bearer ${token}`, + "Content-type" : `application/json` + } }; const columns = [ - { - title: 'Action', - dataIndex: '', - key: 'x', - className:'nowrap', - render: (text, record) => <> - - this.handleDelete(text.id)}> - - - - this.handleEdit(text)}> - - , - }, - { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, - { title: 'Description', dataIndex: 'description', key: 'description' }, + { + title: 'Action', + dataIndex: '', + key: 'x', + className:'nowrap', + render: (text, record) => <> + + this.handleDelete(text.id)}> + + + + this.handleEdit(text)}> + + , + }, + { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, + { title: 'Description', dataIndex: 'description', key: 'description' }, ]; const momentFormat = 'HH:mm'; const column = [ - { name: "Nama" }, - { name: "Deskripsi" }, + { name: "Nama" }, + { name: "Deskripsi" }, ] const LENGTH_DATA = 10 export default class index extends Component { - constructor(props) { - super(props) - this.state = { - dataTable: [], - openDialog: false, - dialogMenuForm: false, - typeDialog: 'Save', - dataEdit: null, - alertDelete: false, - alertNotDelete: false, - idDelete: 0, - dataGs: [], - dataIdHo: [], - search: "", - page: 0, - rowsPerPage: LENGTH_DATA, - currentPage: 1, - totalPage: 0, - tooltipEdit: false, - tooltipDelete: false, - tooltipMenu: false, - idRoles:0, - menuRoles:[], - tooltipTambah:false, - tooltipImport:false, - tooltipExport:false, - dataExport:[] - } - } - - async componentDidMount() { - this.getDataRoles(); - } - - async componentDidUpdate(prevProps, prevState) { - const { search } = this.state - if (search !== prevState.search) this.getDataRoles() - } - - handleSearch = e => { - const value = e.target.value - this.setState({ search: value, currentPage: 1 }) - }; - - getDataRoles = async () => { - - let start = 0; - - if (this.state.currentPage !== 1 && this.state.currentPage > 1) { - start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage - } - - const formData = { - "paging": {"start": start, "length": this.state.rowsPerPage}, - "columns": [ - {"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - - const result = await axios - .post(PROJECT_ROLE_SEARCH, formData, config) - .then(res => res) - .catch((error) => error.response); - // console.log(result) - - if(result && result.data && result.data.code == 200){ - this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord }); - }else{ - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - handleOpenDialog = (type) => { - this.setState({ openDialog: true, typeDialog: type }) - this.showChildDialog(); - } - - - - - handleCloseDialog = (type, data) => { - if (type === "save") { - this.saveRole(data); - } else if (type === "edit") { - this.editRole(data); - } - - this.setState({ openDialog: false }) - } - - - handleOpenDialogMr = () => { - this.setState({ dialogMenuForm: true }) - this.showMenuRolesDialog(); - } - handleCloseDialogMr = (type, data) => { - if(type==="save"){ - this.saveMenuRoles(data) - } - this.setState({ dialogMenuForm: false }) - } - - toggleAddDialog = () => { - this.setState({ openDialog: !this.state.openDialog }) - } - - onConfirmDelete = async () => { - const { idDelete } = this.state - const url = PROJECT_ROLE_DELETE(idDelete) - - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - this.getDataRoles() - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.success(`Data project role berhasil dihapus`, 'Success!!'); - } else { - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.error(`Data project role gagal dihapus`, 'Failed!!'); - } - } - - saveRole = async (data) => { - - const formData = { - name:data.name, - description:data.description - } - - const result = await axios.post(PROJECT_ROLE_ADD, formData, config) - .then(res => res) - .catch((error) => error.response); - - if(result && result.data && result.data.code===200){ - this.getDataRoles(); - NotificationManager.success(`Data project role berhasil ditambah`, 'Success!!'); - } else { - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - - } - - editRole = async (data) => { - - const formData = { - name:data.name, - description:data.description - } - const url = PROJECT_ROLE_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){ - this.getDataRoles(); - NotificationManager.success(`Data project role berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data project role gagal di edit`, `Failed!!`); - } - - } - - - handleEdit = (data) => { - this.setState({ dataEdit: data }); - this.handleOpenDialog('Edit'); - } - - handleDelete = (id) => { - this.setState({ alertDelete: true, idDelete: id }); - } - - onShowSizeChange = (current, pageSize) => { - this.setState({ rowsPerPage: pageSize }, () => { - this.getDataRoles(); - }) - } - - onPagination = (current, pageSize) => { - this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { - this.getDataRoles(); - }) - } - - toggle = (param) => { - if (param === "edit") { - this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) - } else if (param === "delete") { - this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) - } else if(param === "menu"){ - this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu })) - } else if (param === "tambah") { - this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) - } else if (param === "export") { - this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) - } - } - - dataNotAvailable = () => { - if(this.state.dataTable.length===0){ - return ( - - - - ) - } - } - - handleExportExcel = async () => { - const payload = { - "paging": {"start": 0, "length": -1}, - "columns": [ - {"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - // console.log("test", url); - const result = await axios - .post(PROJECT_ROLE_SEARCH, payload) - .then(res => res) - .catch((error) => error.response); - // console.log("result", result); - if (result && result.data && result.statusText == "OK") { - const dataRes = result.data.data|| []; - console.log("data result", dataRes); - const dataExport = []; - // - // - // - // - // - dataRes.map((val,index)=> { - let row = { - Nama:val.name, - Deskripsi:val.description - } - dataExport.push(row); - }) - console.log("data Export", dataExport); - this.setState({ dataExport:dataExport },()=> { - this.exportExcel(); - }); - } else { - NotificationManager.error('Failed retreiving data!!', 'Failed'); - } - } - - exportExcel = () => { - const dataExcel = this.state.dataExport || []; - const fileName = "Data Project Role.xlsx"; - const ws = XLSX.utils.json_to_sheet(dataExcel); + constructor(props) { + super(props) + this.state = { + alertDelete: false, + alertNotDelete: false, + currentPage: 1, + dataEdit: null, + dataExport:[], + dataGs: [], + dataIdHo: [], + dataTable: [], + dialogMenuForm: false, + idDelete: 0, + idRoles:0, + menuRoles:[], + openDialog: false, + page: 0, + rowsPerPage: LENGTH_DATA, + search: "", + tooltipDelete: false, + tooltipEdit: false, + tooltipExport:false, + tooltipImport:false, + tooltipMenu: false, + tooltipTambah:false, + totalPage: 0, + typeDialog: 'Save', + } + } + + async componentDidMount() { + this.getDataRoles(); + } + + async componentDidUpdate(prevProps, prevState) { + const { search } = this.state + if (search !== prevState.search) this.getDataRoles() + } + + handleSearch = e => { + const value = e.target.value + this.setState({ search: value, currentPage: 1 }) + }; + + getDataRoles = async () => { + let start = 0; + if (this.state.currentPage !== 1 && this.state.currentPage > 1) { + start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage + } + + const formData = { + "paging": {"start": start, "length": this.state.rowsPerPage}, + "columns": [ + {"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"} + ], + "joins": [], + "orders": {"columns": ["id"], "ascending": false} + } + + const result = await axios + .post(PROJECT_ROLE_SEARCH, formData, config) + .then(res => res) + .catch((error) => error.response); + + if(result && result.data && result.data.code == 200){ + this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord }); + }else{ + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + handleOpenDialog = (type) => { + this.setState({ openDialog: true, typeDialog: type }) + this.showChildDialog(); + } + + handleCloseDialog = (type, data) => { + if (type === "save") { + this.saveRole(data); + } else if (type === "edit") { + this.editRole(data); + } + this.setState({ openDialog: false }) + } + + + handleOpenDialogMr = () => { + this.setState({ dialogMenuForm: true }) + this.showMenuRolesDialog(); + } + handleCloseDialogMr = (type, data) => { + if(type==="save"){ + this.saveMenuRoles(data) + } + this.setState({ dialogMenuForm: false }) + } + + toggleAddDialog = () => { + this.setState({ openDialog: !this.state.openDialog }) + } + + onConfirmDelete = async () => { + const { idDelete } = this.state + const url = PROJECT_ROLE_DELETE(idDelete) + + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + this.getDataRoles() + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.success(`Data project role berhasil dihapus`, 'Success!!'); + } else { + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.error(`Data project role gagal dihapus`, 'Failed!!'); + } + } + + saveRole = async (data) => { + + const formData = { + name:data.name, + description:data.description + } + + const result = await axios.post(PROJECT_ROLE_ADD, formData, config) + .then(res => res) + .catch((error) => error.response); + + if(result && result.data && result.data.code===200){ + this.getDataRoles(); + NotificationManager.success(`Data project role berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + + } + + editRole = async (data) => { + + const formData = { + name:data.name, + description:data.description + } + const url = PROJECT_ROLE_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){ + this.getDataRoles(); + NotificationManager.success(`Data project role berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data project role gagal di edit`, `Failed!!`); + } + + } + + + handleEdit = (data) => { + this.setState({ dataEdit: data }); + this.handleOpenDialog('Edit'); + } + + handleDelete = (id) => { + this.setState({ alertDelete: true, idDelete: id }); + } + + onShowSizeChange = (current, pageSize) => { + this.setState({ rowsPerPage: pageSize }, () => { + this.getDataRoles(); + }) + } + + onPagination = (current, pageSize) => { + this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { + this.getDataRoles(); + }) + } + + toggle = (param) => { + if (param === "edit") { + this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) + } else if (param === "delete") { + this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) + } else if(param === "menu"){ + this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu })) + } else if (param === "tambah") { + this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) + } else if (param === "export") { + this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) + } + } + + dataNotAvailable = () => { + if(this.state.dataTable.length===0){ + return ( + + + + ) + } + } + + handleExportExcel = async () => { + const payload = { + "paging": {"start": 0, "length": -1}, + "columns": [ + {"name": "name", "logic_operator": "like", "value": this.state.search, "operator": "AND"} + ], + "joins": [], + "orders": {"columns": ["id"], "ascending": false} + } + const result = await axios + .post(PROJECT_ROLE_SEARCH, payload) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.statusText == "OK") { + const dataRes = result.data.data|| []; + console.log("data result", dataRes); + const dataExport = []; + dataRes.map((val,index)=> { + let row = { + Nama:val.name, + Deskripsi:val.description + } + dataExport.push(row); + }) + this.setState({ dataExport:dataExport },()=> { + this.exportExcel(); + }); + } else { + NotificationManager.error('Failed retreiving data!!', 'Failed'); + } + } + + exportExcel = () => { + const dataExcel = this.state.dataExport || []; + const fileName = "Data Project Role.xlsx"; + const ws = XLSX.utils.json_to_sheet(dataExcel); const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, 'Data Project Role'); - XLSX.writeFile(wb, fileName); - } - - render() { - const { tooltipTambah,tooltipExport,dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete,tooltipMenu } = this.state - let noSeq = 0; - return ( -
- - this.setState({ alertDelete: false, idDelete: 0 })} - focusCancelBtn - > - Data project role akan terhapus!! - - this.setState({ alertNotDelete: false})} - // focusCancelBtn - > - Data project role tidak dapat di hapus!! - - this.toggleAddDialog} - typeDialog={this.state.typeDialog} - dataEdit={this.state.dataEdit} - showDialog={showDialog => this.showChildDialog = showDialog} - dataHs={this.state.dataIdHo} - /> - {/* this.showMenuRolesDialog = showDialog} - menuRoles={this.state.menuRoles} - - /> */} - - -

{this.props.params.name}

- -
- - - - - - - - - - - - - - {/*
Tidak ada data project role
{n.name}{n.url}{n.alias_name}{n.icon}{n.parent_name || "-"}
Tidak ada data project role
- - - - {column.map((i, index) => { - return ( - - ) - })} - - - - {this.dataNotAvailable()} - {dataTable.map((n, index) => { - return ( - - - - - - - ) - })} - -
Aksi{i.name}
- - - this.handleDelete(n.id)}> - - - - this.handleEdit(n)}> - - {n.name}{n.description}
*/} - - - - - - ) - } + } + + render() { + const { tooltipTambah,tooltipExport,dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete,tooltipMenu } = this.state + let noSeq = 0; + return ( +
+ + this.setState({ alertDelete: false, idDelete: 0 })} + focusCancelBtn + > + Data project role akan terhapus!! + + this.setState({ alertNotDelete: false})} + > + Data project role tidak dapat di hapus!! + + this.toggleAddDialog} + typeDialog={this.state.typeDialog} + dataEdit={this.state.dataEdit} + showDialog={showDialog => this.showChildDialog = showDialog} + dataHs={this.state.dataIdHo} + /> + + +

{this.props.params.name}

+ +
+ + + + + + + + + + + + + +
+ + + + + ) + } } diff --git a/src/views/SimproV2/ChecklistK3/index.js b/src/views/SimproV2/ChecklistK3/index.js index feac7d7..c305303 100644 --- a/src/views/SimproV2/ChecklistK3/index.js +++ b/src/views/SimproV2/ChecklistK3/index.js @@ -1,9 +1,9 @@ -import React, { useState, useEffect, useMemo } from 'react'; -import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap'; -import axios from "../../../const/interceptorApi" import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; import DialogForm from './DialogForm'; +import React, { useState, useEffect, useMemo } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from "../../../const/interceptorApi" +import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Button, Tooltip } from 'antd'; import { @@ -18,12 +18,10 @@ const config = { "Content-type": `application/json` } }; - const column = [ { name: "Nama" }, { name: "Deskripsi" }, ] - const ChecklistK3 = ({ params }) => { const token = localStorage.getItem("token") const HEADER = { @@ -32,20 +30,21 @@ const ChecklistK3 = ({ params }) => { "Authorization": `Bearer ${token}` } } + const pageName = params.name; - const [search, setSearch] = useState('') + const [alertDelete, setAlertDelete] = useState(false) + const [allDataMenu, setAllDataMenu] = useState([]) + const [clickOpenModal, setClickOpenModal] = useState(false) const [currentPage, setCurrentPage] = useState(1) - const [openDialog, setOpenDialog] = useState(false) - const [typeDialog, setTypeDialog] = useState('Save') - const [dataExport, setDataExport] = useState([]) - const [rowsPerPage, setRowsPerPage] = useState(10) const [dataEdit, setDataEdit] = useState([]) - const [alertDelete, setAlertDelete] = useState(false) - const [idDelete, setIdDelete] = useState(0) + const [dataExport, setDataExport] = useState([]) const [dataTable, setDatatable] = useState([]) - const [clickOpenModal, setClickOpenModal] = useState(false) - const [allDataMenu, setAllDataMenu] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [openDialog, setOpenDialog] = useState(false) + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') const [totalPage, setTotalPage] = useState(0) + const [typeDialog, setTypeDialog] = useState('Save') useEffect(() => { getDataChecklistK3() @@ -86,17 +85,12 @@ const ChecklistK3 = ({ params }) => { "start": start } } - - // console.log("payload ", payload) const result = await axios .post(CHECKLIST_K3_SEARCH, payload, config) .then(res => res) .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - console.log("get data ", result.data) setDatatable(result.data.data); setTotalPage(result.data.totalRecord); } else { @@ -116,7 +110,6 @@ const ChecklistK3 = ({ params }) => { } const handleExportExcel = async () => { - console.log("cek cek cek cke") const payload = { "paging": { "start": 0, "length": -1 }, "columns": [ @@ -126,15 +119,11 @@ const ChecklistK3 = ({ params }) => { "orders": { "columns": ["id"], "ascending": false } } - - const result = await axios .post(CHECKLIST_K3_SEARCH, payload, config) .then(res => res) .catch((error) => error.response); - // console.log(result) - if (result && result.data && result.data.code == 200) { let resData = result.data.data; const excelData = []; @@ -145,9 +134,7 @@ const ChecklistK3 = ({ params }) => { } excelData.push(dataRow) }) - // console.log("cek excel data", resData) await setDataExport(excelData); - // exportExcel(); } else { NotificationManager.error('Gagal Export Data!!', 'Failed'); } @@ -155,7 +142,6 @@ const ChecklistK3 = ({ params }) => { const exportExcel = () => { const dataExcel = dataExport || []; - console.log("cek data excel", dataExcel) const fileName = `Data ${pageName}.xlsx`; const ws = XLSX.utils.json_to_sheet(dataExcel); const wb = XLSX.utils.book_new(); @@ -191,7 +177,7 @@ const ChecklistK3 = ({ params }) => { .catch((error) => error.response); if (result && result.data && result.data.code === 200) { - getDataChecklistK3() + getDataChecklistK3() NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); } else { NotificationManager.error(`${result.data.message}`, 'Failed!!'); @@ -202,9 +188,6 @@ const ChecklistK3 = ({ params }) => { let urlEdit = CHECKLIST_K3_EDIT(data.id) const formData = data - - console.log("from data edit ", formData) - const result = await axios.put(urlEdit, formData, HEADER) .then(res => res) .catch((error) => error.response); @@ -263,8 +246,6 @@ const ChecklistK3 = ({ params }) => { } } - - return (
@@ -325,11 +306,9 @@ const ChecklistK3 = ({ params }) => { return (
- // - // - // - // - // - // resData.map((n, index) => { let dataRow = { "Nama Proyek": n.nama, @@ -301,9 +249,7 @@ const Closing = ({ params, ...props }) => { } excelData.push(dataRow) }) - // console.log("cek excel data", excelData) await setDataExport(excelData); - // exportExcel(); } else { NotificationManager.error('Gagal Export Data!!', 'Failed'); } @@ -339,10 +285,8 @@ const Closing = ({ params, ...props }) => { } const handleClickGantt = (id) => { - // props.history.push("/gantt") props.history.push({ pathname: '/gantt', - // search: `?proyek_id=${id}`, state: { proyek_id: id } }) } @@ -354,24 +298,6 @@ const Closing = ({ params, ...props }) => { dataIndex: '', key: 'x', render: (text, record) => <> - {/* - - - - - - - - - - - - - - */} - {/* - - */} @@ -406,10 +332,6 @@ const Closing = ({ params, ...props }) => {
- handleDelete(n.id)}> - handleEdit(n)}> @@ -356,4 +335,4 @@ const ChecklistK3 = ({ params }) => { ) } -export default ChecklistK3; \ No newline at end of file +export default ChecklistK3; diff --git a/src/views/SimproV2/Closing/index.js b/src/views/SimproV2/Closing/index.js index df67adc..08976aa 100644 --- a/src/views/SimproV2/Closing/index.js +++ b/src/views/SimproV2/Closing/index.js @@ -1,15 +1,15 @@ +import * as XLSX from 'xlsx'; +import DialogForm from './DialogForm'; import React, { useState, useEffect, useMemo } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from "../../../const/interceptorApi"; +import moment from 'moment' +import { BASE_SIMPRO, PROYEK_ADD, PROYEK_SEARCH, PROYEK_EDIT, PROYEK_DELETE } from '../../../const/ApiConst'; import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { DownloadOutlined } from '@ant-design/icons'; -import axios from "../../../const/interceptorApi"; -import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import DialogForm from './DialogForm'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Table, Button, Tooltip } from 'antd'; -import { BASE_SIMPRO, PROYEK_ADD, PROYEK_SEARCH, PROYEK_EDIT, PROYEK_DELETE } from '../../../const/ApiConst'; import { formatRupiah } from '../../../const/CustomFunc' -import moment from 'moment' const url = ""; const proyek_id = localStorage.getItem('proyek_id'); @@ -25,29 +25,29 @@ const Closing = ({ params, ...props }) => { } } - const [idTask, setidTask] = useState(0); - const [dataTable, setDatatable] = useState([]) - const [search, setSearch] = useState('') + const [alertClose, setAlertClose] = useState(false) + const [alertDelete, setAlertDelete] = useState(false) + const [allDataMenu, setAllDataMenu] = useState([]) + const [clickOpenModal, setClickOpenModal] = useState(false) const [currentPage, setCurrentPage] = useState(1) - const [totalPage, setTotalPage] = useState(0) + const [dataCharter, setDataCharter] = useState(null) + const [dataEdit, setDataEdit] = useState([]) + const [dataEditSub, setDataEditSub] = useState([]) + const [dataExport, setDataExport] = useState([]) + const [dataTable, setDatatable] = useState([]) + const [dataView, setDataView] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [idTask, setidTask] = useState(0); const [openDialog, setOpenDialog] = useState(false) + const [openDialogMap, setOpenDialogMap] = useState(false) const [openDialogResource, setOpenDialogResource] = useState(false) const [openDialogViewDetail, setOpenDialogViewDetail] = useState(false) - const [openDialogMap, setOpenDialogMap] = useState(false) + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') + const [totalPage, setTotalPage] = useState(0) const [typeDialog, setTypeDialog] = useState('Save'); const [typeDialogSub, setTypeDialogSub] = useState('Save') - const [idDelete, setIdDelete] = useState(0) - const [alertDelete, setAlertDelete] = useState(false) - const [alertClose, setAlertClose] = useState(false) - const [dataEdit, setDataEdit] = useState([]) - const [dataEditSub, setDataEditSub] = useState([]) - const [rowsPerPage, setRowsPerPage] = useState(10) - const [clickOpenModal, setClickOpenModal] = useState(false) - const [dataExport, setDataExport] = useState([]) - const [allDataMenu, setAllDataMenu] = useState([]) const [userProyek, setUserProyek] = useState([]); - const [dataCharter, setDataCharter] = useState(null) - const [dataView, setDataView] = useState([]) const pageName = params.name; useEffect(() => { @@ -62,7 +62,6 @@ const Closing = ({ params, ...props }) => { const getDataProyek = async () => { - let start = 0; if (currentPage !== 1 && currentPage > 1) { @@ -76,7 +75,6 @@ const Closing = ({ params, ...props }) => { "joins": [ { "name": "m_users", "column_join": "pm_id", "column_results": ["name", "username"] }, { "name": "m_type_proyek", "column_join": "type_proyek_id", "column_results": ["name", "description"] }, - // { "name": "subproyeks.m_subproyek", "column_join": "parent_id", "column_results": ["nama", "biaya", "color_progress", "jumlah_pekerja", "pic", "mulai_proyek", "akhir_proyek", "biaya_actual", "persentase_progress_plan", "persentase_progress_actual"] } ], "orders": { "columns": ["id"], "ascending": true }, "paging": { "start": 0, "length": 25 } @@ -89,18 +87,13 @@ const Closing = ({ params, ...props }) => { ] } - // console.log("cek payload", payload) - const URL = `${BASE_SIMPRO}/proyek/search-detail` const result = await axios .post(URL, payload, HEADER) .then(res => res) .catch((error) => error.response); - // console.log("data sub proyek", result) - if (result && result.data && result.data.code == 200) { - console.log("cek proyek", result.data.data) let dataRes = result.data.data || [] setDatatable(dataRes); @@ -122,7 +115,6 @@ const Closing = ({ params, ...props }) => { } const handleOpenDialogViewDetail = (data) => { - console.log('handleOpenDialogViewDetail', data); setOpenDialogViewDetail(true) setidTask(data.id) setDataView(data) @@ -138,18 +130,10 @@ const Closing = ({ params, ...props }) => { } const handleCloseDialogResource = (type, payload) => { - // if (type === "add") saveProyek(payload); - - // if (type === "edit") editProyek(payload); - setOpenDialogResource(false) } const handleCloseDialogView = (type, payload) => { - // if (type === "add") saveProyek(payload); - - // if (type === "edit") editProyek(payload); - setOpenDialogViewDetail(false) } @@ -164,7 +148,6 @@ const Closing = ({ params, ...props }) => { const result = await axios.delete(urlDel, HEADER) .then(res => res) .catch((error) => error.response); - if (result && result.data && result.data.code === 200) { getDataProyek() setIdDelete(0) @@ -178,21 +161,6 @@ const Closing = ({ params, ...props }) => { } const onConfirmClose = async () => { - // let urlDel = PROYEK_DELETE(idDelete) - // const result = await axios.delete(urlDel, HEADER) - // .then(res => res) - // .catch((error) => error.response); - - // if (result && result.data && result.data.code === 200) { - // getDataProyek() - // setIdDelete(0) - // setAlertDelete(false) - // NotificationManager.success(`Data proyek berhasil dihapus`, 'Success!!'); - // } else { - // setIdDelete(0) - // setAlertDelete(false) - // NotificationManager.error(`Data proyek gagal dihapus`, 'Failed!!'); - // } setIdDelete(0) setAlertClose(false) NotificationManager.success(`Data proyek berhasil diclose`, 'Success!!'); @@ -215,7 +183,6 @@ const Closing = ({ params, ...props }) => { } const editProyek = async (data) => { - let urlEdit = PROYEK_EDIT(data.id) const formData = data @@ -229,19 +196,14 @@ const Closing = ({ params, ...props }) => { } else { NotificationManager.error(`Data proyek gagal di edit`, `Failed!!`); } - - - } const handleDelete = async (id) => { - // console.log('Delete') await setAlertDelete(true) await setIdDelete(id) } const handleCloseProject = async (id) => { - // console.log('Delete') await setAlertClose(true) await setIdDelete(id) } @@ -258,9 +220,6 @@ const Closing = ({ params, ...props }) => { const payload = { "paging": { "start": 0, "length": -1 }, - // "columns": [ - // { "name": "nama", "logic_operator": "like", "value": search, "operator": "AND" } - // ], "joins": [], "orders": { "columns": ["id"], "ascending": false } } @@ -271,25 +230,14 @@ const Closing = ({ params, ...props }) => { ] } - - const result = await axios .post(PROYEK_SEARCH, payload, HEADER) .then(res => res) .catch((error) => error.response); - // console.log(result) - if (result && result.data && result.data.code == 200) { let resData = result.data.data; const excelData = []; - // {n.nama}{n.biaya}
{n.jumlah_pekerja}{n.pic}{n.mulai_proyek ? moment(n.mulai_proyek).format("DD-MM-YYYY") : "-"}{n.akhir_proyek ? moment(n.akhir_proyek).format("DD-MM-YYYY") : "-"}
, - // rowExpandable: record => record.subproyeks2, - // }} dataSource={dataTable} /> ) @@ -424,43 +346,9 @@ const Closing = ({ params, ...props }) => { /> ), [openDialog]) - // const RenderDialogFormResources = useMemo(() => ( - // toggleAddDialogResource} - // idTask={idTask} - // userProyek={userProyek} - // /> - // ), [openDialogResource]) - - // const ViewProyek = useMemo(() => ( - // toggleAddDialogView} - // idTask={idTask} - // dataView={dataView} - // dataCharter={dataCharter} - // /> - // ), [openDialogViewDetail]) - return (
- {/* cancelDelete()} - focusCancelBtn - > - Delete this data - */} {
- {/* - - - - - - - */} - {RenderTable} @@ -501,4 +380,4 @@ const Closing = ({ params, ...props }) => { ) } -export default Closing; \ No newline at end of file +export default Closing; diff --git a/src/views/SimproV2/ControlMonitoring/index.js b/src/views/SimproV2/ControlMonitoring/index.js index c9d543f..e88afa9 100644 --- a/src/views/SimproV2/ControlMonitoring/index.js +++ b/src/views/SimproV2/ControlMonitoring/index.js @@ -1,11 +1,11 @@ +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 { DownloadOutlined } from '@ant-design/icons'; -import axios from "../../../const/interceptorApi"; -import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; import { NotificationContainer, NotificationManager } from 'react-notifications'; -import moment from 'moment' const ControlMonitoring = ({params}) => { const token = localStorage.getItem("token") @@ -18,12 +18,11 @@ const ControlMonitoring = ({params}) => { useEffect(() => { }, []) - return (
) } - - export default ControlMonitoring; \ No newline at end of file + + export default ControlMonitoring; diff --git a/src/views/SimproV2/CreatedProyek/index.js b/src/views/SimproV2/CreatedProyek/index.js index 33ad9cb..e2894ba 100644 --- a/src/views/SimproV2/CreatedProyek/index.js +++ b/src/views/SimproV2/CreatedProyek/index.js @@ -1,12 +1,24 @@ -import React, { useState, useEffect, useMemo } from 'react'; -import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; -import axios from "../../../const/interceptorApi" import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; +import AssignHrProject from './AsignHrProject'; +import AssignK3Project from './AssignK3Project'; +import DialogDocument from './DialogDocument'; import DialogForm from './DialogForm'; +import DialogFormMaterial from './DataRequestMaterial'; import DialogFormProyek from './DialogFormProyek'; +import DialogGantt from './DialogGantt'; +import DialogInitDocument from './DialogInitDocument'; +import DialogTableTools from './DialogTableTools'; +import React, { useState, useEffect, useMemo } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import ViewProject from './ViewProject'; +import axios from "../../../const/interceptorApi" +import moment from 'moment' +import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; +import { Icon } from '@iconify/react'; +import { Link } from 'react-router-dom'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Table, Button, Tooltip, Popover, Skeleton, Divider } from 'antd'; +import { formatNumber, formatRupiah, formatThousand, renderFormatRupiah } from '../../../const/CustomFunc' import { PROJECT_APPROVAL_ADD, PROJECT_APPROVAL_EDIT, PROJECT_PARTICIPANT_ADD, PROJECT_PARTICIPANT_EDIT, PROJECT_MILESTONE_ADD, PROJECT_MILESTONE_EDIT, PROJECT_PARTICIPANT_DELETE_BY_PROYEK, PROJECT_MILESTONE_DELETE_BY_PROYEK, PROJECT_APPROVAL_DELETE_BY_PROYEK, @@ -14,18 +26,6 @@ import { PROYEK_GET_ID, PROJECT_MILESTONE_SEARCH, PROJECT_PARTICIPANT_SEARCH, PROJECT_APPROVAL_SEARCH, CHECKLIST_K3_LIST, VERSION_GANTT_SEARCH } from '../../../const/ApiConst'; -import { formatNumber, formatRupiah, formatThousand, renderFormatRupiah } from '../../../const/CustomFunc' -import moment from 'moment' -import DialogFormMaterial from './DataRequestMaterial'; -import DialogTableTools from './DialogTableTools'; -import DialogDocument from './DialogDocument'; -import DialogInitDocument from './DialogInitDocument'; -import DialogGantt from './DialogGantt'; -import AssignHrProject from './AsignHrProject'; -import AssignK3Project from './AssignK3Project'; -import ViewProject from './ViewProject'; -import { Icon } from '@iconify/react'; -import { Link } from 'react-router-dom'; const url = ""; const proyek_id = localStorage.getItem('proyek_id'); @@ -41,35 +41,35 @@ const CreatedProyek = ({ params, ...props }) => { } } - const [idTask, setidTask] = useState(0); - const [dataTable, setDatatable] = useState([]) - const [search, setSearch] = useState('') - const [currentPage, setCurrentPage] = useState(1) - const [totalPage, setTotalPage] = useState(0) - const [openDialog, setOpenDialog] = useState(false) - const [openDialogViewDetail, setOpenDialogViewDetail] = useState(false) - const [openDialogMaterial, setOpenDialogMaterial] = useState(false) - const [openDialogTools, setOpenDialogTools] = useState(false) - const [openDialogGantt, setOpenDialogGantt] = useState(false) - const [openDialogAsignHR, setOpenDialogAsignHR] = useState(false) - const [openDialogAssignK3, setOpenDialogAssignK3] = useState(false) - const [dataK3, setDataK3] = useState([]) // transfer list - const [idDelete, setIdDelete] = useState(0) const [alertDelete, setAlertDelete] = useState(false) - const [rowsPerPage, setRowsPerPage] = useState(10) - const [dataExport, setDataExport] = useState([]) - const [userProyek, setUserProyek] = useState([]) - const [materialProyek, setMaterialProyek] = useState([]) + const [currentPage, setCurrentPage] = useState(1) const [dataCharter, setDataCharter] = useState(null) + const [dataExport, setDataExport] = useState([]) + const [dataK3, setDataK3] = useState([]) + const [dataPm, setDataPM] = useState([]) + const [dataTable, setDatatable] = useState([]) + const [dataTypeProyek, setDataTypeProyek] = useState([]) const [dataView, setDataView] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [idTask, setidTask] = useState(0); + const [materialProyek, setMaterialProyek] = useState([]) const [materialResource, setMaterialResource] = useState([]) - const [toolsResource, setToolsResource] = useState([]) - const [dataTypeProyek, setDataTypeProyek] = useState([]) - const [dataPm, setDataPM] = useState([]) + const [openDialog, setOpenDialog] = useState(false) + const [openDialogAsignHR, setOpenDialogAsignHR] = useState(false) + const [openDialogAssignK3, setOpenDialogAssignK3] = useState(false) const [openDialogDoc, setOpenDialogDoc] = useState(false) - const [proyekName, setProyekName] = useState(""); + const [openDialogGantt, setOpenDialogGantt] = useState(false) + const [openDialogMaterial, setOpenDialogMaterial] = useState(false) const [openDialogProyek, setOpenDialogProyek] = useState(false) - // project charter + const [openDialogTools, setOpenDialogTools] = useState(false) + const [openDialogViewDetail, setOpenDialogViewDetail] = useState(false) + const [proyekName, setProyekName] = useState(""); + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') + const [toolsResource, setToolsResource] = useState([]) + const [totalPage, setTotalPage] = useState(0) + const [userProyek, setUserProyek] = useState([]) + const [projectCharter, setProjectCharter] = useState(null) const [projectParticipant, setProjectParticipant] = useState(null) const [projectMilestone, setProjectMilestone] = useState(null) @@ -81,7 +81,6 @@ const CreatedProyek = ({ params, ...props }) => { const pageName = params.name; useEffect(() => { - // getDataUserResource() getDataMaterialResource() getDataToolsResource() handleGetTipeProject() @@ -113,7 +112,6 @@ const CreatedProyek = ({ params, ...props }) => { const handleGetTipeProject = async () => { const result = await axios.get(TYPE_PROYEK, HEADER).then(res => res).catch(err => err.response) - console.log(result) if (result && result.data && result.data.code === 200) { setDataTypeProyek(result.data.data); } else { @@ -123,7 +121,6 @@ const CreatedProyek = ({ params, ...props }) => { const handleGetDataPm = async () => { const result = await axios.get(USER_LIST, HEADER).then(res => res).catch(err => err.response) - console.log(result) if (result && result.data && result.data.code === 200) { setDataPM(result.data.data) } else { @@ -147,7 +144,6 @@ const CreatedProyek = ({ params, ...props }) => { "joins": [ { "name": "m_users", "column_join": "pm_id", "column_results": ["name", "username"] }, { "name": "m_type_proyek", "column_join": "type_proyek_id", "column_results": ["name", "description"] }, - // { "name": "subproyeks.m_subproyek", "column_join": "parent_id", "column_results": ["nama", "biaya", "color_progress", "jumlah_pekerja", "pic", "mulai_proyek", "akhir_proyek", "biaya_actual", "persentase_progress_plan", "persentase_progress_actual"] } ], "orders": { "columns": ["id"], "ascending": false }, "paging": { "start": start, "length": rowsPerPage } @@ -160,17 +156,14 @@ const CreatedProyek = ({ params, ...props }) => { ] } - // console.log("cek payload", payload) const result = await axios .post(PROYEK_SEARCH, payload, HEADER) .then(res => res) .catch((error) => error.response); - // console.log("data sub proyek", result) if (result && result.data && result.data.code == 200) { - // console.log("cek proyek", result) let dataRes = result.data.data || [] setDatatable(dataRes); @@ -187,7 +180,6 @@ const CreatedProyek = ({ params, ...props }) => { .catch((error) => error.response); if (result && result.data && result.data.code == 200) { - console.log("cek material resource", result.data.data) let dataRes = result.data.data || [] setMaterialResource(dataRes); } else { @@ -222,7 +214,6 @@ const CreatedProyek = ({ params, ...props }) => { .catch((error) => error.response); if (result && result.data && result.data.code == 200) { - console.log("cek tools resource", result.data.data) let dataRes = result.data.data || [] setToolsResource(dataRes); } else { @@ -237,7 +228,6 @@ const CreatedProyek = ({ params, ...props }) => { .catch((error) => error.response); if (result && result.data && result.data.code == 200) { - console.log("cek k3 list", result.data.data) let dataRes = result.data.data || [] const finalData = [] if (dataRes.length > 0) { @@ -261,7 +251,6 @@ const CreatedProyek = ({ params, ...props }) => { } const handleOpenDialogProyek = (id) => { - console.log('handleOpenDialogProyek', id); setOpenDialogProyek(true) setidTask(id) } @@ -301,21 +290,17 @@ const CreatedProyek = ({ params, ...props }) => { const handleOpenDialogTools = (data) => { setOpenDialogTools(true) - console.log('handleOpenDialogTools', data); setidTask(data.id) setProyekName(data.nama) setUserProyek(data.user_proyeks) } const handleOpenDialogViewDetail = async (data) => { - // console.log('handleOpenDialogViewDetail', data); setidTask(data.id) - // setDataView(data) await getDataProject(data.id) await getProjectMilestone(data.id) await getProjectParticipant(data.id) await getProjectApproval(data.id) - // await getDataProjectCharter(data.id); setOpenDialogViewDetail(true) } @@ -329,7 +314,6 @@ const CreatedProyek = ({ params, ...props }) => { if (result && result.data && result.data.code == 200) { let dataRes = result.data.data; setProjectCharter(dataRes); - // console.log("cek project-charter resource", dataRes); } else { NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); } @@ -344,7 +328,6 @@ const CreatedProyek = ({ params, ...props }) => { "orders": { "columns": ["id"], "ascending": true }, "paging": { "start": 0, "length": -1 } } - // const url = PROJECT_MI(proyek_id) const result = await axios .post(PROJECT_MILESTONE_SEARCH, payload, HEADER) .then(res => res) @@ -353,7 +336,6 @@ const CreatedProyek = ({ params, ...props }) => { if (result && result.data && result.data.code == 200) { let dataRes = result.data.data; setProjectMilestone(dataRes); - // console.log("cek project milestone", dataRes); } else { NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); } @@ -368,7 +350,6 @@ const CreatedProyek = ({ params, ...props }) => { "orders": { "columns": ["id"], "ascending": true }, "paging": { "start": 0, "length": -1 } } - // const url = PROJECT_MI(proyek_id) const result = await axios .post(PROJECT_PARTICIPANT_SEARCH, payload, HEADER) .then(res => res) @@ -378,7 +359,6 @@ const CreatedProyek = ({ params, ...props }) => { let dataRes = result.data.data; setProjectParticipant(dataRes); - // console.log("cek project participant", dataRes); } else { NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); } @@ -393,7 +373,6 @@ const CreatedProyek = ({ params, ...props }) => { "orders": { "columns": ["id"], "ascending": true }, "paging": { "start": 0, "length": -1 } } - // const url = PROJECT_MI(proyek_id) const result = await axios .post(PROJECT_APPROVAL_SEARCH, payload, HEADER) .then(res => res) @@ -402,7 +381,6 @@ const CreatedProyek = ({ params, ...props }) => { if (result && result.data && result.data.code == 200) { let dataRes = result.data.data; setProjectApproval(dataRes); - // console.log("cek project approval", dataRes); } else { NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); } @@ -471,15 +449,12 @@ const CreatedProyek = ({ params, ...props }) => { const result = await axios.post(PROYEK_ADD, formData, HEADER) .then(res => res) .catch((error) => error.response); - console.log(result) if (result && result.data && result.data.code === 200) { const { participants, milestones, approval } = data.projectCharter const resultParticipant = await saveParticipant(result.data.data_result.id, participants) const resultMilestone = await saveMilestone(result.data.data_result.id, milestones) const resultApproval = await saveApproval(result.data.data_result.id, approval) - console.log({ resultApproval, resultMilestone, resultParticipant }) if (resultParticipant === "berhasil" && resultMilestone === "berhasil" && resultApproval === "berhasil") { - // getDataProyek(); NotificationManager.success(`Data proyek berhasil ditambah`, 'Success!!'); } else { NotificationManager.success(`${result.data.message}`, 'Success!!'); @@ -502,9 +477,7 @@ const CreatedProyek = ({ params, ...props }) => { } return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER) }) - console.log(request) const arr = await Promise.all(request).then(values => values).catch(err => err.response); - console.log('result participant', arr) const result = arr.map(res => res.data.code == 200) if (result.length > 0) { return "gagal" @@ -523,9 +496,7 @@ const CreatedProyek = ({ params, ...props }) => { } return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER) }) - console.log(request) const arr = await Promise.all(request).then(values => values).catch(err => err.response); - console.log('result milestone', arr) const result = arr.map(res => res.data.code !== 200) if (result.length > 0) { return "gagal" @@ -545,9 +516,7 @@ const CreatedProyek = ({ params, ...props }) => { } return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER) }) - console.log(request) const arr = await Promise.all(request).then(values => values).catch(err => err.response); - console.log('result approval', arr) const result = arr.map(res => res.data.code !== 200) if (result.length > 0) { return "gagal" @@ -565,7 +534,6 @@ const CreatedProyek = ({ params, ...props }) => { const result = await axios.put(urlEdit, formData, HEADER) .then(res => res) .catch((error) => error.response); - console.log("cek result", result) const resultParticipant = await editParticipant(data.id, participants) const resultMilestone = await editMilestone(data.id, milestones) const resultApproval = await editApproval(data.id, approval) @@ -580,7 +548,6 @@ const CreatedProyek = ({ params, ...props }) => { const editParticipant = async (id, data) => { await axios.delete(PROJECT_PARTICIPANT_DELETE_BY_PROYEK(id), HEADER) - // if (restDelete){ const request = data.map(res => { const payload = { proyek_id: parseInt(id), @@ -589,10 +556,7 @@ const CreatedProyek = ({ params, ...props }) => { } return axios.post(PROJECT_PARTICIPANT_ADD, payload, HEADER) }) - console.log(request) const arr = await Promise.all(request).then(values => values).catch(err => err.response); - console.log('result participant', arr) - // let dataTittle = arr.data.tittle const result = arr.map(res => res.data.code !== 200) if (result.length > 0) { return "gagal" @@ -604,7 +568,6 @@ const CreatedProyek = ({ params, ...props }) => { const editMilestone = async (id, data) => { await axios.delete(PROJECT_MILESTONE_DELETE_BY_PROYEK(id), HEADER) - console.log("res due", data) const request = data.map(res => { const payload = { proyek_id: parseInt(id), @@ -614,9 +577,7 @@ const CreatedProyek = ({ params, ...props }) => { } return axios.post(PROJECT_MILESTONE_ADD, payload, HEADER) }) - console.log(request) const arr = await Promise.all(request).then(values => values).catch(err => err.response); - console.log('result milestone', arr) const result = arr.map(res => res.data.code !== 200) if (result.length > 0) { return "gagal" @@ -625,7 +586,6 @@ const CreatedProyek = ({ params, ...props }) => { } const editApproval = async (id, data) => { - console.log("cek data edit approval", data) await axios.delete(PROJECT_APPROVAL_DELETE_BY_PROYEK(id), HEADER) const request = data.map(res => { const payload = { @@ -636,20 +596,11 @@ const CreatedProyek = ({ params, ...props }) => { } return axios.post(PROJECT_APPROVAL_ADD, payload, HEADER) }) - console.log(request) const arr = await Promise.all(request).then(values => values).catch(err => err.response); - console.log('result approval', arr) - // if(arr) - - // const result = arr.map(res => res.data.code !== 200) - // if (result.length > 0) { - // return "gagal" - // } - // return "berhasil" + } const handleDelete = async (id) => { - // console.log('Delete') await setAlertDelete(true) await setIdDelete(id) } @@ -666,9 +617,6 @@ const CreatedProyek = ({ params, ...props }) => { const payload = { "paging": { "start": 0, "length": -1 }, - // "columns": [ - // { "name": "nama", "logic_operator": "like", "value": search, "operator": "AND" } - // ], "joins": [], "orders": { "columns": ["id"], "ascending": false } } @@ -686,11 +634,9 @@ const CreatedProyek = ({ params, ...props }) => { .then(res => res) .catch((error) => error.response); - // console.log(result) if (result && result.data && result.data.code == 200) { let resData = result.data.data; - console.log("resData", resData); const excelData = []; resData.map((n, index) => { let dataRow = { @@ -709,9 +655,7 @@ const CreatedProyek = ({ params, ...props }) => { } excelData.push(dataRow) }) - // console.log("cek excel data", excelData) await setDataExport(excelData); - // exportExcel(); } else { NotificationManager.error('Gagal Export Data!!', 'Failed'); } @@ -836,7 +780,6 @@ const CreatedProyek = ({ params, ...props }) => { title: 'Budget', dataIndex: 'rencana_biaya', key: 'rencana_biaya', - // render: (text, record) => { return renderFormatRupiah(text, "Rp") } render: (text, record) => { return record.currency_symbol ? `${record.currency_symbol} ${formatThousand(text)}` : `${formatThousand(text)}` } }, { @@ -937,7 +880,6 @@ const CreatedProyek = ({ params, ...props }) => { /> ), [openDialogTools]) - // DialogAsignHr const RenderDialogAsignHr = useMemo(() => ( { ), [openDialogAsignHR]) - // DialogAssignK3 const RenderDialogAssignK3 = useMemo(() => ( { ) } -export default CreatedProyek; \ No newline at end of file +export default CreatedProyek; diff --git a/src/views/SimproV2/Divisi/index.js b/src/views/SimproV2/Divisi/index.js index 3d6f544..23424ab 100644 --- a/src/views/SimproV2/Divisi/index.js +++ b/src/views/SimproV2/Divisi/index.js @@ -1,18 +1,15 @@ +import * as XLSX from 'xlsx'; +import DialogForm from './DialogForm'; 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, Table } from 'reactstrap'; +import { DIVISI_ADD, DIVISI_EDIT, DIVISI_DELETE, DIVISI_SEARCH} from '../../../const/ApiConst'; import { DownloadOutlined } from '@ant-design/icons'; -import axios from "../../../const/interceptorApi" -import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import DialogForm from './DialogForm'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Button, Tooltip } from 'antd'; import { formatRupiah, formatNumber } from '../../../const/CustomFunc' -import { - DIVISI_ADD, DIVISI_EDIT, DIVISI_DELETE, - DIVISI_SEARCH -} from '../../../const/ApiConst'; -import moment from 'moment' const url = ""; const proyek_id = localStorage.getItem('proyek_id'); @@ -20,352 +17,329 @@ const role_id = localStorage.getItem('role_id'); const format = "DD-MM-YYYY"; const token = window.localStorage.getItem('token'); const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } + headers: + { + Authorization: `Bearer ${token}`, + "Content-type": `application/json` + } }; const column = [ - { name: "Nama" }, - { name: "Deskripsi" }, + { name: "Nama" }, + { name: "Deskripsi" }, ] const ProjectType = ({ params }) => { - const token = localStorage.getItem("token") - const HEADER = { - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${token}` - } - } - const pageName = params.name; - const [search, setSearch] = useState('') - const [currentPage, setCurrentPage] = useState(1) - const [openDialog, setOpenDialog] = useState(false) - const [typeDialog, setTypeDialog] = useState('Save') - const [dataExport, setDataExport] = useState([]) - const [rowsPerPage, setRowsPerPage] = useState(10) - const [dataEdit, setDataEdit] = useState([]) - const [alertDelete, setAlertDelete] = useState(false) - const [idDelete, setIdDelete] = useState(0) - const [dataTable, setDatatable] = useState([]) - const [clickOpenModal, setClickOpenModal] = useState(false) - const [allDataMenu, setAllDataMenu] = useState([]) - const [totalPage, setTotalPage] = useState(0) - - useEffect(() => { - getDataProjectType() - }, [currentPage, rowsPerPage, search]) - - useEffect(() => { - const cekData = dataExport || [] - if (cekData.length > 0) { - exportExcel() - } - }, [dataExport]) - - const getDataProjectType = async () => { - - let start = 0; - - if (currentPage !== 1 && currentPage > 1) { - start = (currentPage * rowsPerPage) - rowsPerPage - } - - const payload = { - "columns": [ - { - "name": "name", - "logic_operator": "like", - "value": search, - "operator": "AND" - } - ], - "orders": { - "ascending": true, - "columns": [ - 'id' - ] - }, - "paging": { - "length": rowsPerPage, - "start": start - } - } - - // console.log("payload ", payload) - const result = await axios - .post(DIVISI_SEARCH, payload, config) - .then(res => res) - .catch((error) => error.response); - - - - if (result && result.data && result.data.code == 200) { - console.log("get data ", result.data) - 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 = (type) => { - setOpenDialog(true) - setTypeDialog(type) - } - - const handleExportExcel = async () => { - - let start = 0; - - const payload = { - "paging": { "start": start, "length": -1 }, - "columns": [ - { "name": "name", "logic_operator": "like", "value": search, "operator": "AND" } - ], - "joins": [], - "orders": { "columns": ["id"], "ascending": false } - } - - - - const result = await axios - .post(DIVISI_SEARCH, payload) - .then(res => res) - .catch((error) => error.response); - - // console.log(result) - - if (result && result.data && result.data.code == 200) { - let resData = result.data.data; - const excelData = []; - resData.map((val, index) => { - let dataRow = { - "Nama": val.name, - "Deskripsi": val.description, - } - excelData.push(dataRow) - }) - // console.log("cek excel data", excelData) - await setDataExport(excelData); - // exportExcel(); - } 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 handleDelete = async (id) => { - await setAlertDelete(true) - await setIdDelete(id) - } - - const handleCloseDialog = (type, data) => { - if (type === "save") { - saveProjectType(data); - } else if (type === "edit") { - editMaterialR(data); - } - setDataEdit([]) - setOpenDialog(false) - } - - const saveProjectType = async (data) => { - const formData = data - const result = await axios.post(DIVISI_ADD, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectType() - // console.log("data material s ", formData) - NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); - } else { - // console.log("data material fail ", formData) - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - } - - const editMaterialR = async (data) => { - - let urlEdit = DIVISI_EDIT(data.id) - const formData = data - - console.log("from data edit ", formData) - - const result = await axios.put(urlEdit, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectType(); - NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); - } - } - - const toggleAddDialog = () => { - setOpenDialog(!openDialog) - } - - const onConfirmDelete = async () => { - let url = DIVISI_DELETE(idDelete); - - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectType() - setIdDelete(0) - setAlertDelete(false) - NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); - } else { - setIdDelete(0) - setAlertDelete(false) - NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); - } - } - - const cancelDelete = () => { - setAlertDelete(false) - setIdDelete(0) - } - - const onShowSizeChange = (current, pageSize) => { - setRowsPerPage(pageSize) - } - - const onPagination = (current, pageSize) => { - setCurrentPage(current) - } - - const dataNotAvailable = () => { - if (dataTable.length === 0) { - return ( - - - - ) - } - } - - - - return ( -
- - cancelDelete()} - focusCancelBtn - > - Delete this data - - toggleAddDialog} - typeDialog={typeDialog} - dataEdit={dataEdit} - clickOpenModal={clickOpenModal} - dataParent={allDataMenu} - /> - - -

{pageName}

- -
- - - - - - - - - - - - - -
Tidak ada data project type
- - - - {column.map((i, index) => { - return ( - - ) - })} - - - - {dataNotAvailable()} - {dataTable.map((n, index) => { - return ( - - - - - - ) - })} - -
Aksi{i.name}
- - - handleDelete(n.id)}> - - - - handleEdit(n)}> - - {n.name}{n.description}
- -
-
-
- ) + const token = localStorage.getItem("token") + const HEADER = { + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + } + } + const pageName = params.name; + + const [alertDelete, setAlertDelete] = useState(false) + const [allDataMenu, setAllDataMenu] = useState([]) + const [clickOpenModal, setClickOpenModal] = useState(false) + const [currentPage, setCurrentPage] = useState(1) + const [dataEdit, setDataEdit] = useState([]) + const [dataExport, setDataExport] = useState([]) + const [dataTable, setDatatable] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [openDialog, setOpenDialog] = useState(false) + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') + const [totalPage, setTotalPage] = useState(0) + const [typeDialog, setTypeDialog] = useState('Save') + + useEffect(() => { + getDataProjectType() + }, [currentPage, rowsPerPage, search]) + + useEffect(() => { + const cekData = dataExport || [] + if (cekData.length > 0) { + exportExcel() + } + }, [dataExport]) + + const getDataProjectType = async () => { + + let start = 0; + + if (currentPage !== 1 && currentPage > 1) { + start = (currentPage * rowsPerPage) - rowsPerPage + } + + const payload = { + "columns": [ + { + "name": "name", + "logic_operator": "like", + "value": search, + "operator": "AND" + } + ], + "orders": { + "ascending": true, + "columns": [ + 'id' + ] + }, + "paging": { + "length": rowsPerPage, + "start": start + } + } + + const result = await axios + .post(DIVISI_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 = (type) => { + setOpenDialog(true) + setTypeDialog(type) + } + + const handleExportExcel = async () => { + let start = 0; + const payload = { + "paging": { "start": start, "length": -1 }, + "columns": [ + { "name": "name", "logic_operator": "like", "value": search, "operator": "AND" } + ], + "joins": [], + "orders": { "columns": ["id"], "ascending": false } + } + + const result = await axios + .post(DIVISI_SEARCH, payload) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let resData = result.data.data; + const excelData = []; + resData.map((val, index) => { + let dataRow = { + "Nama": val.name, + "Deskripsi": val.description, + } + 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 handleDelete = async (id) => { + await setAlertDelete(true) + await setIdDelete(id) + } + + const handleCloseDialog = (type, data) => { + if (type === "save") { + saveProjectType(data); + } else if (type === "edit") { + editMaterialR(data); + } + setDataEdit([]) + setOpenDialog(false) + } + + const saveProjectType = async (data) => { + const formData = data + const result = await axios.post(DIVISI_ADD, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code === 200) { + getDataProjectType() + NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } + + const editMaterialR = async (data) => { + let urlEdit = DIVISI_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) { + getDataProjectType(); + NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); + } + } + + const toggleAddDialog = () => { + setOpenDialog(!openDialog) + } + + const onConfirmDelete = async () => { + let url = DIVISI_DELETE(idDelete); + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataProjectType() + setIdDelete(0) + setAlertDelete(false) + NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); + } else { + setIdDelete(0) + setAlertDelete(false) + NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); + } + } + + const cancelDelete = () => { + setAlertDelete(false) + setIdDelete(0) + } + + const onShowSizeChange = (current, pageSize) => { + setRowsPerPage(pageSize) + } + + const onPagination = (current, pageSize) => { + setCurrentPage(current) + } + + const dataNotAvailable = () => { + if (dataTable.length === 0) { + return ( + + Tidak ada data project type + + ) + } + } + + return ( +
+ + cancelDelete()} + focusCancelBtn + > + Delete this data + + toggleAddDialog} + typeDialog={typeDialog} + dataEdit={dataEdit} + clickOpenModal={clickOpenModal} + dataParent={allDataMenu} + /> + + +

{pageName}

+ + + + + + + + + + + + + +
+ + + + + + {column.map((i, index) => { + return ( + + ) + })} + + + + {dataNotAvailable()} + {dataTable.map((n, index) => { + return ( + + + + + + ) + })} + +
Aksi{i.name}
+ + + handleDelete(n.id)}> + + + + handleEdit(n)}> + + {n.name}{n.description}
+ +
+
+
+ ) } -export default ProjectType; \ No newline at end of file +export default ProjectType; diff --git a/src/views/SimproV2/PanicButton/index.js b/src/views/SimproV2/PanicButton/index.js index dfdbcb9..edce254 100644 --- a/src/views/SimproV2/PanicButton/index.js +++ b/src/views/SimproV2/PanicButton/index.js @@ -1,32 +1,31 @@ +import * as XLSX from 'xlsx'; +import DialogEdit from './DialogEdit'; +import DialogForm from './DialogForm'; import React, { Component } from 'react'; -import { Card, CardBody, CardHeader, Col, Row, Table, Input, InputGroup } from 'reactstrap'; -import { Button } from 'reactstrap'; +import SweetAlert from 'react-bootstrap-sweetalert'; import axios from 'axios'; import moment from 'moment'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import DialogForm from './DialogForm'; -import DialogEdit from './DialogEdit'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { Pagination, Tooltip } from 'antd'; +import { Button } from 'reactstrap'; +import { Card, CardBody, CardHeader, Col, Row, Table, Input, InputGroup } from 'reactstrap'; import { DatePicker } from 'antd'; -import * as XLSX from 'xlsx'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; import { PANIC_BUTTON_UPDATE, PANIC_BUTTON_SEARCH } from '../../../const/ApiConst'; +import { Pagination, Tooltip } from 'antd'; const id_org = window.localStorage.getItem('id_org'); const roleName = window.localStorage.getItem('role_name'); const token = window.localStorage.getItem('token'); const config = { - headers: - { + headers: + { Authorization : `Bearer ${token}`, "Content-type" : `application/json` } }; - const { RangePicker } = DatePicker; - + const momentFormat = 'HH:mm'; const column = [ @@ -42,29 +41,29 @@ export default class index extends Component { constructor(props) { super(props) this.state = { - dataTable: [], - dataExport: [], - openDialog: false, - openDialogEdit:false, - typeDialog: 'Save', - dataEdit: null, alertDelete: false, - idDelete: 0, + currentDay: 'today', + currentPage: 1, + dataEdit: null, + dataExport: [], dataGs: [], dataIdHo: [], - search: "", + dataMap:"", + dataTable: [], + endDate:moment(moment().format("YYYY-M-D")), + idDelete: 0, + openDialog: false, + openDialogEdit:false, page: 0, rowsPerPage: LENGTH_DATA, - currentPage: 1, - totalPage: 0, - tooltipMap: false, - tooltipDelete: false, - typeClock: "All", + search: "", startDate:moment(moment().format("YYYY-M-D")), - endDate:moment(moment().format("YYYY-M-D")), - currentDay: 'today', - dataMap:"", + tooltipDelete: false, tooltipExport:false, + tooltipMap: false, + totalPage: 0, + typeClock: "All", + typeDialog: 'Save', } } @@ -84,8 +83,6 @@ export default class index extends Component { }; getDataPanicButton = async () => { - // let url = BASE_URL + `panic_button.php?act=get_data&role_name=${roleName}`; - let start = 0; if (this.state.currentPage !== 1) { start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage @@ -131,7 +128,6 @@ export default class index extends Component { .post(PANIC_BUTTON_SEARCH, payload, config) .then(res => res) .catch((error) => error.response); - console.log('test panic button', result); if(result && result.data){ if (result && result.data && result.data.code == 200) { this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord,dataExport:result.data.data_export }); @@ -149,7 +145,7 @@ export default class index extends Component { this.setState({ openDialogEdit: true }) this.showDialogEdit(); } - + } handleCloseDialog = () => { @@ -243,8 +239,6 @@ export default class index extends Component { } updateStatusResponse = async (data) => { - console.log('test data', data) - let url = PANIC_BUTTON_UPDATE(data.id); let payload = { "user_id" : data.user_id, @@ -255,18 +249,10 @@ export default class index extends Component { } - // let url = BASE_URL + `panic_button.php?act=edit&id=${data.id}`; - - // const formData = new FormData(); - // formData.append("lat", data.lat); - // formData.append("lon", data.lon); - // formData.append("status_response", data.status_response); - const result = await axios .put(url, payload, config) .then(res => res) .catch((error) => error.response); - // console.log(result) if(result && result.data){ if (result.data.code == 200) { this.getDataPanicButton() @@ -285,10 +271,6 @@ export default class index extends Component { return ( - {/* this.handleDelete(n.id)}> - this.toggle("delete")}> - Delete - */} this.handleEdit(n)}> @@ -299,13 +281,12 @@ export default class index extends Component { { n.created_date!==null ? moment(n.created_at).format("DD-MM-YYYY HH:mm:ss") : "-" } { n.join_first_name !==null ? n.join_first_name : "-" } { n.status_response!==null ? n.status_response : "-" } - {/* { n.clock_out_time!==null ? moment(n.clock_out_time).format("HH:mm:ss") : "-" } */} ) }) : No Data Available - } + } ) } @@ -314,31 +295,27 @@ export default class index extends Component { const val = e.target.value; this.setState({ currentDay:val }); if(val==="today"){ - console.log("test 1 test",val); this.setState({ startDate:moment(moment().format("YYYY-M-D")), - endDate:moment(moment().format("YYYY-M-D")), + endDate:moment(moment().format("YYYY-M-D")), currentPage: 1 }) }else if(val==="3 day"){ - console.log("test test",val); this.setState({ startDate:moment(moment().subtract(3, "days").format("YYYY-M-D")), - endDate:moment(moment().format("YYYY-M-D")), + endDate:moment(moment().format("YYYY-M-D")), currentPage: 1 }) }else if(val==="7 day"){ - console.log("test test",val); this.setState({ startDate:moment(moment().subtract(7, "days").format("YYYY-M-D")), - endDate:moment(moment().format("YYYY-M-D")), + endDate:moment(moment().format("YYYY-M-D")), currentPage: 1 }) }else{ - console.log("test 2 test",val); this.setState({ startDate:moment(moment().format("YYYY-M-D")), - endDate:moment(moment().format("YYYY-M-D")), + endDate:moment(moment().format("YYYY-M-D")), currentPage: 1 }) } @@ -349,19 +326,6 @@ export default class index extends Component { return (
- {/* this.setState({ alertDelete: false, idDelete: 0 })} - focusCancelBtn - > - Data tipe karyawan akan terhapus!! - */}

Panic Button

- {/* {' '} */} @@ -401,12 +364,10 @@ export default class index extends Component {
- {/* */}
- {/* */} {column.map((i, index) => { return ( diff --git a/src/views/SimproV2/ProjectType/index.js b/src/views/SimproV2/ProjectType/index.js index f46ca51..98fee5a 100644 --- a/src/views/SimproV2/ProjectType/index.js +++ b/src/views/SimproV2/ProjectType/index.js @@ -1,16 +1,15 @@ +import * as XLSX from 'xlsx'; +import DialogForm from './DialogForm'; +import DialogInitialGantt from './DialogInitialGantt'; 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 { DownloadOutlined } from '@ant-design/icons'; -import axios from "../../../const/interceptorApi" -import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import DialogForm from './DialogForm'; import { NotificationContainer, NotificationManager } from 'react-notifications'; +import { PROJECT_TYPE_ADD, PROJECT_TYPE_EDIT, PROJECT_TYPE_DELETE, PROJECT_TYPE_SEARCH } from '../../../const/ApiConst'; import { Pagination, Button, Tooltip, Table} from 'antd'; -import DialogInitialGantt from './DialogInitialGantt'; -import { PROJECT_TYPE_ADD, PROJECT_TYPE_EDIT, PROJECT_TYPE_DELETE, - PROJECT_TYPE_SEARCH } from '../../../const/ApiConst'; -import moment from 'moment' const url = ""; const proyek_id = localStorage.getItem('proyek_id'); @@ -18,412 +17,361 @@ const role_id = localStorage.getItem('role_id'); const format = "DD-MM-YYYY"; const token = window.localStorage.getItem('token'); const config = { - headers: - { - Authorization : `Bearer ${token}`, - "Content-type" : `application/json` - } + headers: + { + Authorization : `Bearer ${token}`, + "Content-type" : `application/json` + } }; const column = [ - { name: "Nama" }, - { name: "Deskripsi" }, + { name: "Nama" }, + { name: "Deskripsi" }, ] const ProjectType = ({params}) => { - const token = localStorage.getItem("token") - const HEADER = { - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${token}` - } - } - const pageName = params.name; - const [search, setSearch] = useState('') - const [currentPage, setCurrentPage] = useState(1) - const [openDialog, setOpenDialog] = useState(false) - const [typeDialog, setTypeDialog] = useState('Save') - const [dataExport, setDataExport] = useState([]) - const [rowsPerPage, setRowsPerPage] = useState(10) - const [dataEdit, setDataEdit] = useState([]) - const [alertDelete, setAlertDelete] = useState(false) - const [idDelete, setIdDelete] = useState(0) - const [dataTable, setDatatable] = useState([]) - const [clickOpenModal, setClickOpenModal] = useState(false) - const [allDataMenu, setAllDataMenu] = useState([]) - const [totalPage, setTotalPage] = useState(0) - const [openDialogIG, setOpenDialogIG] = useState(false) - const [idTypeProject, setIdTypeProject] = useState(0) - - useEffect(() => { - getDataProjectType() - }, [currentPage, rowsPerPage, search]) - - useEffect(() => { - const cekData = dataExport || [] - if (cekData.length > 0) { - exportExcel() - } - }, [dataExport]) - - const getDataProjectType = async () => { - - let start = 0; - - if (currentPage !== 1 && currentPage > 1) { - start = (currentPage * rowsPerPage) - rowsPerPage - } - - const payload = { - "columns": [ - { - "name":"name", - "logic_operator":"like", - "value":search, - "operator":"AND" - } - ], - "orders": { - "ascending": true, - "columns": [ - 'id' - ] - }, - "paging": { - "length": rowsPerPage, - "start": start - } - } - - // console.log("payload ", payload) - const result = await axios - .post(PROJECT_TYPE_SEARCH, payload, config) - .then(res => res) - .catch((error) => error.response); - - - - if(result && result.data && result.data.code == 200){ - console.log("get data ", result.data) - 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 = (type) => { - setOpenDialog(true) - setTypeDialog(type) - } - - const handleExportExcel = async () => { - - let start = 0; - - const payload = { - "paging": { "start": start, "length": -1 }, - "columns": [ - { "name": "name", "logic_operator": "like", "value": search, "operator": "AND" } - ], - "joins": [], - "orders": { "columns": ["id"], "ascending": false } - } - - - - const result = await axios - .post(PROJECT_TYPE_SEARCH, payload) - .then(res => res) - .catch((error) => error.response); - - // console.log(result) - - if (result && result.data && result.data.code == 200) { - let resData = result.data.data; - const excelData = []; - resData.map((val, index) => { - let dataRow = { - "Nama": val.name, - "Deskripsi": val.description, - } - excelData.push(dataRow) - }) - // console.log("cek excel data", excelData) - await setDataExport(excelData); - // exportExcel(); - } 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 handleDelete = async (id) => { - await setAlertDelete(true) - await setIdDelete(id) - } - - const handleCloseDialog = (type, data) => { - if (type === "save") { - saveProjectType(data); - } else if (type === "edit") { - editMaterialR(data); - } - setDataEdit([]) - setOpenDialog(false) - } - - const saveProjectType = async (data) => { - const formData = data - const result = await axios.post(PROJECT_TYPE_ADD, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectType() - // console.log("data material s ", formData) - NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); - } else { - // console.log("data material fail ", formData) - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - } - - const editMaterialR = async (data) => { - - let urlEdit = PROJECT_TYPE_EDIT(data.id) - const formData = data - - console.log("from data edit ", formData) - - const result = await axios.put(urlEdit, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectType(); - NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); - } - } - - const toggleAddDialog = () => { - setOpenDialog(!openDialog) - } - - const handleDialogIg = (id) => { - setIdTypeProject(id) - setOpenDialogIG(true) - } - - const closeDialogIG = () => { - setIdTypeProject(0) - setOpenDialogIG(false) - } - - const toggleDialogIG = () => { - if(openDialogIG){ - setIdTypeProject(0) - } - setOpenDialogIG(!openDialogIG); - } - - const onConfirmDelete = async () => { - let url = PROJECT_TYPE_DELETE(idDelete); - - const result = await axios.delete(url,config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataProjectType() - setIdDelete(0) - setAlertDelete(false) - NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); - } else { - setIdDelete(0) - setAlertDelete(false) - NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); - } - } - - const cancelDelete = () => { - setAlertDelete(false) - setIdDelete(0) - } - - const onShowSizeChange = (current, pageSize) => { - setRowsPerPage(pageSize) - } - - const onPagination = (current, pageSize) => { - setCurrentPage(current) - } - - const dataNotAvailable = () => { - if(dataTable.length===0){ - return ( - - - - ) - } - } - - const renderTable = useMemo(() => { - const columns = [ - { - title: 'Action', - dataIndex: '', - key: 'x', - className:'nowrap', - render: (text, record) => <> - - handleDelete(text.id)}> - - - handleEdit(text)}> - {" "} - - handleDialogIg(text.id)}> - - , - }, - { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, - { title: 'Description', dataIndex: 'description', key: 'description' }, - ]; - return ( -
Actions{i.name}
Tidak ada data project type
- ) - }, [dataTable]) - - - - return ( -
- - cancelDelete()} - focusCancelBtn - > - Delete this data - - toggleAddDialog} - typeDialog={typeDialog} - dataEdit={dataEdit} - clickOpenModal={clickOpenModal} - dataParent={allDataMenu} - /> - - - -

{pageName}

- -
- - - - - - - - - - - - - - {/*
- - - - {column.map((i, index) => { - return ( - - ) - })} - - - - {dataNotAvailable()} - {dataTable.map((n, index) => { - return ( - - - - - - ) - })} - -
Aksi{i.name}
- - - handleDelete(n.id)}> - - - - handleEdit(n)}> - - {n.name}{n.description}
*/} - {renderTable} - - - - - ) - } - - export default ProjectType; \ No newline at end of file + const token = localStorage.getItem("token") + const HEADER = { + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + } + } + const pageName = params.name; + + const [alertDelete, setAlertDelete] = useState(false) + const [allDataMenu, setAllDataMenu] = useState([]) + const [clickOpenModal, setClickOpenModal] = useState(false) + const [currentPage, setCurrentPage] = useState(1) + const [dataEdit, setDataEdit] = useState([]) + const [dataExport, setDataExport] = useState([]) + const [dataTable, setDatatable] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [idTypeProject, setIdTypeProject] = useState(0) + const [openDialog, setOpenDialog] = useState(false) + const [openDialogIG, setOpenDialogIG] = useState(false) + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') + const [totalPage, setTotalPage] = useState(0) + const [typeDialog, setTypeDialog] = useState('Save') + + useEffect(() => { + getDataProjectType() + }, [currentPage, rowsPerPage, search]) + + useEffect(() => { + const cekData = dataExport || [] + if (cekData.length > 0) { + exportExcel() + } + }, [dataExport]) + + const getDataProjectType = async () => { + + let start = 0; + + if (currentPage !== 1 && currentPage > 1) { + start = (currentPage * rowsPerPage) - rowsPerPage + } + + const payload = { + "columns": [ + { + "name":"name", + "logic_operator":"like", + "value":search, + "operator":"AND" + } + ], + "orders": { + "ascending": true, + "columns": [ + 'id' + ] + }, + "paging": { + "length": rowsPerPage, + "start": start + } + } + + const result = await axios + .post(PROJECT_TYPE_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 = (type) => { + setOpenDialog(true) + setTypeDialog(type) + } + + const handleExportExcel = async () => { + let start = 0; + + const payload = { + "paging": { "start": start, "length": -1 }, + "columns": [ + { "name": "name", "logic_operator": "like", "value": search, "operator": "AND" } + ], + "joins": [], + "orders": { "columns": ["id"], "ascending": false } + } + + const result = await axios + .post(PROJECT_TYPE_SEARCH, payload) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + let resData = result.data.data; + const excelData = []; + resData.map((val, index) => { + let dataRow = { + "Nama": val.name, + "Deskripsi": val.description, + } + 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 handleDelete = async (id) => { + await setAlertDelete(true) + await setIdDelete(id) + } + + const handleCloseDialog = (type, data) => { + if (type === "save") { + saveProjectType(data); + } else if (type === "edit") { + editMaterialR(data); + } + setDataEdit([]) + setOpenDialog(false) + } + + const saveProjectType = async (data) => { + const formData = data + const result = await axios.post(PROJECT_TYPE_ADD, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataProjectType() + NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } + + const editMaterialR = async (data) => { + let urlEdit = PROJECT_TYPE_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) { + getDataProjectType(); + NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); + } + } + + const toggleAddDialog = () => { + setOpenDialog(!openDialog) + } + + const handleDialogIg = (id) => { + setIdTypeProject(id) + setOpenDialogIG(true) + } + + const closeDialogIG = () => { + setIdTypeProject(0) + setOpenDialogIG(false) + } + + const toggleDialogIG = () => { + if(openDialogIG){ + setIdTypeProject(0) + } + setOpenDialogIG(!openDialogIG); + } + + const onConfirmDelete = async () => { + let url = PROJECT_TYPE_DELETE(idDelete); + + const result = await axios.delete(url,config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataProjectType() + setIdDelete(0) + setAlertDelete(false) + NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); + } else { + setIdDelete(0) + setAlertDelete(false) + NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); + } + } + + const cancelDelete = () => { + setAlertDelete(false) + setIdDelete(0) + } + + const onShowSizeChange = (current, pageSize) => { + setRowsPerPage(pageSize) + } + + const onPagination = (current, pageSize) => { + setCurrentPage(current) + } + + const dataNotAvailable = () => { + if(dataTable.length===0){ + return ( + + Tidak ada data project type + + ) + } + } + + const renderTable = useMemo(() => { + const columns = [ + { + title: 'Action', + dataIndex: '', + key: 'x', + className:'nowrap', + render: (text, record) => <> + + handleDelete(text.id)}> + + + handleEdit(text)}> + {" "} + + handleDialogIg(text.id)}> + + , + }, + { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, + { title: 'Description', dataIndex: 'description', key: 'description' }, + ]; + return ( + + ) + }, [dataTable]) + + return ( +
+ + cancelDelete()} + focusCancelBtn + > + Delete this data + + toggleAddDialog} + typeDialog={typeDialog} + dataEdit={dataEdit} + clickOpenModal={clickOpenModal} + dataParent={allDataMenu} + /> + + + +

{pageName}

+ +
+ + + + + + + + + + + + + + {renderTable} + + + + + ) +} + +export default ProjectType; diff --git a/src/views/SimproV2/ResourceMaterial/index.js b/src/views/SimproV2/ResourceMaterial/index.js index 4ee54f3..9c45c0f 100644 --- a/src/views/SimproV2/ResourceMaterial/index.js +++ b/src/views/SimproV2/ResourceMaterial/index.js @@ -1,9 +1,11 @@ +import * as XLSX from 'xlsx'; +import DialogForm from './DialogForm'; 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 { DownloadOutlined } from '@ant-design/icons'; -import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import DialogForm from './DialogForm'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Table, Button, Tooltip, Tabs, Collapse } from 'antd'; import { formatRupiah, formatNumber, renderLabelStatus } from '../../../const/CustomFunc' @@ -14,8 +16,6 @@ import { REQUEST_MATERIAL_SEARCH, REQUEST_MATERIAL_EDIT, REQUEST_MATERIAL_UPDATE_WAREHOUSE_SITE } from '../../../const/ApiConst'; -import moment from 'moment' -import axios from "../../../const/interceptorApi" const { TabPane } = Tabs; const { Panel } = Collapse; @@ -26,15 +26,12 @@ const role_id = localStorage.getItem('role_id'); const format = "DD-MM-YYYY"; const groupBy = (array, key) => { - // Return the end result return array.reduce((result, currentValue) => { - // If an array already present for key, push it to the array. Else create an array and push the object (result[currentValue[key]] = result[currentValue[key]] || []).push( currentValue ); - // Return the current iteration `result` value, this will be taken as next iteration `result` value and accumulate return result; - }, {}); // empty object is the initial value for result object + }, {}); }; const Resource = ({ params }) => { @@ -45,22 +42,23 @@ const Resource = ({ params }) => { "Authorization": `Bearer ${token}` } } - const pageName = params.name; - const [search, setSearch] = useState('') + + const [alertDelete, setAlertDelete] = useState(false) + const [allDataMenu, setAllDataMenu] = useState([]) + const [clickOpenModal, setClickOpenModal] = useState(false) const [currentPage, setCurrentPage] = useState(1) - const [openDialog, setOpenDialog] = useState(false) - const [typeDialog, setTypeDialog] = useState('Save') - const [dataExport, setDataExport] = useState([]) - const [rowsPerPage, setRowsPerPage] = useState(10) + const [dataDelvMaterial, setDataDelvMaterial] = useState([]) const [dataEdit, setDataEdit] = useState([]) - const [alertDelete, setAlertDelete] = useState(false) - const [idDelete, setIdDelete] = useState(0) + const [dataExport, setDataExport] = useState([]) + const [dataReqMaterial, setDataReqMaterial] = useState([]) const [dataTable, setDatatable] = useState([]) - const [clickOpenModal, setClickOpenModal] = useState(false) - const [allDataMenu, setAllDataMenu] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [openDialog, setOpenDialog] = useState(false) + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') const [totalPage, setTotalPage] = useState(0) - const [dataReqMaterial, setDataReqMaterial] = useState([]) - const [dataDelvMaterial, setDataDelvMaterial] = useState([]) + const [typeDialog, setTypeDialog] = useState('Save') + const pageName = params.name; useEffect(() => { getDataReqMaterial() @@ -99,16 +97,12 @@ const Resource = ({ params }) => { } } - // console.log("payload ", payload) const result = await axios .post(MATERIAL_RESOURCE_SEARCH, payload, HEADER) .then(res => res) .catch((error) => error.response); - - if (result && result.data && result.data.code == 200) { - console.log("get data ", result.data) setDatatable(result.data.data); setTotalPage(result.data.totalRecord); } else { @@ -120,7 +114,6 @@ const Resource = ({ params }) => { const payload = { "columns": [ { "name": "description", "logic_operator": "like", "value": "", "operator": "AND" }, - // { "name": "proyek_id", "logic_operator": "=", "value": idTask, "operator": "AND" } ], "joins": [ { "name": "m_proyek", "column_join": "proyek_id", "column_results": ["kode_sortname", "nama"] } @@ -133,7 +126,6 @@ const Resource = ({ params }) => { .post(REQUEST_MATERIAL_SEARCH, payload, HEADER) .then(res => res) .catch((error) => error.response); - console.log("result getDataReqMaterial", result) if (result && result.status == 200) { if (result.data.data && result.data.data.length > 0) { @@ -149,9 +141,6 @@ const Resource = ({ params }) => { } }) - // const groupedProject = groupBy(result.data.data, 'proyek_id'); - // console.log('dataReqMaterial', groupedProject); - const groupedProjectReq = groupBy(filtered_matReq, 'proyek_id'); const groupedProjectDelv = groupBy(filtered_matDelv, 'proyek_id'); @@ -178,9 +167,6 @@ const Resource = ({ params }) => { const payload = { "paging": { "start": 0, "length": -1 }, - // "columns": [ - // { "name": "nama", "logic_operator": "like", "value": search, "operator": "AND" } - // ], "joins": [], "orders": { "columns": ["id"], "ascending": false } } @@ -196,18 +182,10 @@ const Resource = ({ params }) => { .then(res => res) .catch((error) => error.response); - // console.log(result) if (result && result.data && result.data.code == 200) { let resData = result.data.data; const excelData = []; - // - // - // - // - // - // - // resData.map((n, index) => { let dataRow = { "Nama Proyek": n.nama, @@ -219,9 +197,7 @@ const Resource = ({ params }) => { } excelData.push(dataRow) }) - // console.log("cek excel data", excelData) await setDataExport(excelData); - // exportExcel(); } else { NotificationManager.error('Gagal Export Data!!', 'Failed'); } @@ -261,23 +237,14 @@ const Resource = ({ params }) => { const saveMaterialResource = async (data) => { const formData = data - // { - // 'name': data.materialName, - // 'description': data.description, - // 'unit_price': parseInt(data.unitPrice), - // 'uom': data.uom - // } - // console.log("data material ", formData) const result = await axios.post(MATERIAL_RESOURCE_ADD, formData, HEADER) .then(res => res) .catch((error) => error.response); if (result && result.data && result.data.code === 200) { getDataMaterialR() - // console.log("data material s ", formData) NotificationManager.success(`Data material resource berhasil ditambah`, 'Success!!'); } else { - // console.log("data material fail ", formData) NotificationManager.error(`${result.data.message}`, 'Failed!!'); } } @@ -287,7 +254,6 @@ const Resource = ({ params }) => { let urlEdit = MATERIAL_RESOURCE_EDIT(data.id) const formData = data - console.log("from data edit ", formData) const result = await axios.put(urlEdit, formData, HEADER) .then(res => res) @@ -305,7 +271,6 @@ const Resource = ({ params }) => { let urlEdit = REQUEST_MATERIAL_EDIT(data.id) const formData = data - console.log("from data edit ", formData) const result = await axios.put(urlEdit, formData, HEADER) .then(res => res) @@ -323,7 +288,6 @@ const Resource = ({ params }) => { let urlEdit = REQUEST_MATERIAL_EDIT(data.id) const formData = data - console.log("from data edit ", formData) const result = await axios.put(urlEdit, formData, HEADER) .then(res => res) @@ -392,10 +356,6 @@ const Resource = ({ params }) => { { title: 'Material Name', dataIndex: 'name', key: 'name' }, { title: 'QTY', dataIndex: 'qty', key: 'qty' }, { title: 'UOM', dataIndex: 'uom', key: 'uom' }, - // { - // title: 'Unit Price', dataIndex: 'unit_price', key: 'unit_price', - // render: (text, record) => { return renderFormatNumber(text, "Rp") } - // }, { title: 'Description', dataIndex: 'description', key: 'description' }, { title: 'Status', dataIndex: 'status', key: 'status' } ]; @@ -417,14 +377,6 @@ const Resource = ({ params }) => { dataIndex: '', key: 'id', className: "nowrap", - // render: (text, record) => <> - - // {text.status=="fom" ? <> - // - // {" "} - // - // : "-"} - // , render: (text, record) => <> @@ -451,9 +403,7 @@ const Resource = ({ params }) => { let componentGroup = []; for (const proyek_id in dataReqMaterial) { - // console.log('proyek_id', proyek_id); const title = `${dataReqMaterial[proyek_id][0]['join_first_kode_sortname']} - ${dataReqMaterial[proyek_id][0]['join_first_nama']}`; - // console.log('title', title); componentGroup.push(
{n.nama}{n.biaya}
{n.jumlah_pekerja}{n.pic}{n.mulai_proyek ? moment(n.mulai_proyek).format("DD-MM-YYYY") : "-"}{n.akhir_proyek ? moment(n.akhir_proyek).format("DD-MM-YYYY") : "-"}
{ ) } - // console.log('componentGroup', componentGroup); return componentGroup.map((item, index) => { return item; }) @@ -507,9 +456,7 @@ const Resource = ({ params }) => { let componentGroup = []; for (const proyek_id in dataDelvMaterial) { - // console.log('proyek_id', proyek_id); const title = `${dataDelvMaterial[proyek_id][0]['join_first_kode_sortname']} - ${dataDelvMaterial[proyek_id][0]['join_first_nama']}`; - // console.log('title', title); componentGroup.push(
{ ) } - // console.log('componentGroup', componentGroup); return componentGroup.map((item, index) => { return item; }) @@ -574,9 +520,6 @@ const Resource = ({ params }) => { - {/* - - */} @@ -602,9 +545,6 @@ const Resource = ({ params }) => { - {/* - - */} @@ -660,4 +600,4 @@ const Resource = ({ params }) => { ) } -export default Resource; \ No newline at end of file +export default Resource; diff --git a/src/views/SimproV2/ResourceTools/index.js b/src/views/SimproV2/ResourceTools/index.js index ee1c2af..201df2a 100644 --- a/src/views/SimproV2/ResourceTools/index.js +++ b/src/views/SimproV2/ResourceTools/index.js @@ -1,20 +1,19 @@ +import * as XLSX from 'xlsx'; +import DialogForm from './DialogForm'; +import DialogTools from './DialogEditReqTools'; import React, { useState, useEffect, useMemo } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import _, { initial } from 'underscore' +import axios from "../../../const/interceptorApi" +import moment from 'moment' import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { DownloadOutlined } from '@ant-design/icons'; -import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import DialogForm from './DialogForm'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Table, Button, Tooltip, Tabs, Collapse } from 'antd'; +import { renderLabelStatus } from '../../../const/CustomFunc'; import { - // AXIOS, TOOLS_RESOURCE_ADD, TOOLS_RESOURCE_SEARCH, REQUEST_TOOLS_SEARCH, TOOLS_RESOURCE_EDIT, TOOLS_RESOURCE_DELETE } from '../../../const/ApiConst'; -import moment from 'moment' -import _, { initial } from 'underscore' -import DialogTools from './DialogEditReqTools'; -import axios from "../../../const/interceptorApi" -import { renderLabelStatus } from '../../../const/CustomFunc'; const { TabPane } = Tabs; const { Panel } = Collapse; @@ -40,24 +39,25 @@ const ResourceWorker = ({ params }) => { "Authorization": `Bearer ${token}` } } - const pageName = params.name; - const [search, setSearch] = useState('') - const [currentPage, setCurrentPage] = useState(1) - const [openDialog, setOpenDialog] = useState(false) - const [typeDialog, setTypeDialog] = useState('Save') - const [dataExport, setDataExport] = useState([]) - const [rowsPerPage, setRowsPerPage] = useState(10) - const [dataEdit, setDataEdit] = useState(null) + const [alertDelete, setAlertDelete] = useState(false) - const [idDelete, setIdDelete] = useState(0) - const [dataTable, setDatatable] = useState([]) const [clickOpenModal, setClickOpenModal] = useState(false) - const [totalPage, setTotalPage] = useState(0) - const [roleList, setRoleList] = useState([]) - const [dataReqTools, setDataReqTools] = useState([]); + const [currentPage, setCurrentPage] = useState(1) const [dataDeliveryTools, setDataDeliveryTools] = useState([]); - const [openDialogFormTools, setOpenDialogFormTools] = useState(false); + const [dataEdit, setDataEdit] = useState(null) + const [dataExport, setDataExport] = useState([]) + const [dataReqTools, setDataReqTools] = useState([]); + const [dataTable, setDatatable] = useState([]) + const [idDelete, setIdDelete] = useState(0) const [idTask, setIdTask] = useState(0); + const [openDialog, setOpenDialog] = useState(false) + const [openDialogFormTools, setOpenDialogFormTools] = 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 pageName = params.name; useEffect(() => { getDataReqTools() @@ -112,7 +112,6 @@ const ResourceWorker = ({ params }) => { .catch((error) => error.response); if (result && result.data && result.data.code == 200) { - console.log(result.data.data) setDatatable(result.data.data); setTotalPage(result.data.totalRecord); } else { @@ -155,12 +154,10 @@ const ResourceWorker = ({ params }) => { .catch((error) => error.response); if (result && result.data && result.data.code == 200) { - // console.log(result.data.data) const group = _.chain(result.data.data) .groupBy("join_first_nama") .map((value, key) => ({ header: key, data: value })) .value() - console.log("req tools", group) setDataReqTools(group); } else { NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); @@ -206,7 +203,6 @@ const ResourceWorker = ({ params }) => { .groupBy("join_first_nama") .map((value, key) => ({ header: key, data: value })) .value() - console.log("delivery tools", group) setDataDeliveryTools(group); } else { NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); @@ -228,9 +224,6 @@ const ResourceWorker = ({ params }) => { const payload = { "paging": { "start": 0, "length": -1 }, - // "columns": [ - // { "name": "nama", "logic_operator": "like", "value": search, "operator": "AND" } - // ], "joins": [], "orders": { "columns": ["id"], "ascending": false } } @@ -245,18 +238,10 @@ const ResourceWorker = ({ params }) => { .then(res => res) .catch((error) => error.response); - // console.log(result) if (result && result.data && result.data.code == 200) { let resData = result.data.data; const excelData = []; - // - // - // - // - // - // - // resData.map((n, index) => { let dataRow = { "Nama Proyek": n.nama, @@ -268,9 +253,7 @@ const ResourceWorker = ({ params }) => { } excelData.push(dataRow) }) - // console.log("cek excel data", excelData) await setDataExport(excelData); - // exportExcel(); } else { NotificationManager.error('Gagal Export Data!!', 'Failed'); } @@ -363,10 +346,7 @@ const ResourceWorker = ({ params }) => { key: 'x', className: 'nowrap', render: (text, record) => <> - {/* - - */} - + @@ -380,7 +360,6 @@ const ResourceWorker = ({ params }) => { { title: 'QTY', dataIndex: 'qty', key: 'qty' }, { title: 'Description', dataIndex: 'description', key: 'description' }, ]; - // console.log("columns", columns) return (
{n.nama}{n.biaya}
{n.jumlah_pekerja}{n.pic}{n.mulai_proyek ? moment(n.mulai_proyek).format("DD-MM-YYYY") : "-"}{n.akhir_proyek ? moment(n.akhir_proyek).format("DD-MM-YYYY") : "-"}
{ { title: 'Asset Type', dataIndex: 'asset_type', key: 'asset_type' }, { title: 'UOM', dataIndex: 'uom', key: 'uom' }, { title: 'QTY', dataIndex: 'qty', key: 'qty' }, - // { title: 'Description', dataIndex: 'description', key: 'description' }, ]; if (type === 'request') { @@ -470,8 +448,6 @@ const ResourceWorker = ({ params }) => { columns.push({ title: 'Ownership Status', dataIndex: 'ownership_status', key: 'ownership_status' }); columns.push({ title: 'Ownership Name', dataIndex: 'ownership_name', key: 'ownership_name' }); - - // console.log("columns", columns) return (
{ - {/* - - */} @@ -524,9 +497,6 @@ const ResourceWorker = ({ params }) => { - {/* - - */} @@ -604,4 +574,4 @@ const ResourceWorker = ({ params }) => { ) } -export default ResourceWorker; \ No newline at end of file +export default ResourceWorker; diff --git a/src/views/SimproV2/ResourceWorker/index.js b/src/views/SimproV2/ResourceWorker/index.js index e53e26a..a2bccd4 100644 --- a/src/views/SimproV2/ResourceWorker/index.js +++ b/src/views/SimproV2/ResourceWorker/index.js @@ -1,17 +1,17 @@ -import React, { useState, useEffect, useMemo } from 'react'; -import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; -import { DownloadOutlined } from '@ant-design/icons'; -import axios from "../../../const/interceptorApi" import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; import DialogForm from './DialogForm'; import DialogFormUserShift from './DialogFormUserShift'; +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 { DownloadOutlined } from '@ant-design/icons'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Table, Button, Tooltip } from 'antd'; import { PROYEK_SEARCH, USER_ADD, USER_SEARCH, USER_EDIT, USER_DELETE, ROLE_SEARCH, DIVISI_SEARCH, USER_SHIFT_ADD } from '../../../const/ApiConst'; -import moment from 'moment' const url = ""; const proyek_id = localStorage.getItem('proyek_id'); @@ -34,24 +34,24 @@ const ResourceWorker = ({ params }) => { "Authorization": `Bearer ${token}` } } - const pageName = params.name; - const [search, setSearch] = useState('') + 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 [typeDialog, setTypeDialog] = useState('Save') - const [typeDialogShift, setTypeDialogShift] = useState('Save') - const [dataExport, setDataExport] = useState([]) + const [roleList, setRoleList] = useState([]) const [rowsPerPage, setRowsPerPage] = useState(10) - const [dataEdit, setDataEdit] = useState([]) - const [alertDelete, setAlertDelete] = useState(false) - const [idDelete, setIdDelete] = useState(0) - const [dataTable, setDatatable] = useState([]) - const [clickOpenModal, setClickOpenModal] = useState(false) - const [clickOpenModalShift, setClickOpenModalShift] = useState(false) + const [search, setSearch] = useState('') const [totalPage, setTotalPage] = useState(0) - const [roleList, setRoleList] = useState([]) - const [divisiList, setDivisiList] = useState([]) + const [typeDialog, setTypeDialog] = useState('Save') + const [typeDialogShift, setTypeDialogShift] = useState('Save') + const pageName = params.name; useEffect(() => { getRoleList() @@ -60,7 +60,6 @@ const ResourceWorker = ({ params }) => { useEffect(() => { getDataUser() - console.log("cek token", token) }, [search, rowsPerPage, currentPage]) const onShowSizeChange = (current, pageSize) => { @@ -81,7 +80,6 @@ const ResourceWorker = ({ params }) => { .post(ROLE_SEARCH, formData, config) .then(res => res) .catch((error) => error.response); - // console.log(result) if (result && result.data && result.data.code == 200) { setRoleList(result.data.data); @@ -100,7 +98,6 @@ const ResourceWorker = ({ params }) => { .post(DIVISI_SEARCH, formData, config) .then(res => res) .catch((error) => error.response); - // console.log(result) if (result && result.data && result.data.code == 200) { setDivisiList(result.data.data); @@ -117,44 +114,6 @@ const ResourceWorker = ({ params }) => { start = (currentPage * rowsPerPage) - rowsPerPage } - // const payload = { - // "paging": { - // "start": start, - // "length": rowsPerPage - // }, - // "columns": [ - // { - // "name": "name", - // "logic_operator": "like", - // "value": search, - // "operator": "AND" - // } - // ], - // "joins": [ - // { - // "name": "m_roles", - // "column_join": "role_id", - // "column_results": [ - // "name", - // "description" - // ] - // }, - // { - // "name": "m_divisi", - // "column_join": "divisi_id", - // "column_results": [ - // "name", - // ] - // } - // ], - // "orders": { - // "columns": [ - // "id" - // ], - // "ascending": false - // } - // } - const payload = { "paging": { "start": start, @@ -240,7 +199,6 @@ const ResourceWorker = ({ params }) => { .catch((error) => error.response); if (result && result.data && result.data.code == 200) { - console.log("cek resource", result.data.data) setDatatable(result.data.data); setTotalPage(result.data.totalRecord); } else { @@ -288,18 +246,9 @@ const ResourceWorker = ({ params }) => { .then(res => res) .catch((error) => error.response); - // console.log(result) - if (result && result.data && result.data.code == 200) { let resData = result.data.data; const excelData = []; - // - // - // - // - // - // - // resData.map((n, index) => { let dataRow = { "Nama Proyek": n.nama, @@ -311,9 +260,7 @@ const ResourceWorker = ({ params }) => { } excelData.push(dataRow) }) - // console.log("cek excel data", excelData) await setDataExport(excelData); - // exportExcel(); } else { NotificationManager.error('Gagal Export Data!!', 'Failed'); } @@ -350,13 +297,9 @@ const ResourceWorker = ({ params }) => { } const handleCloseDialogShift = (type, data) => { - console.log(data) if (type === "save") { saveUserShift(data); } - // else if (type === "edit") { - // editUser(data); - // } setDataEdit([]) setOpenDialogShift(false) } @@ -393,7 +336,6 @@ const ResourceWorker = ({ params }) => { let urlEdit = USER_EDIT(data.id) const formData = data - console.log("cek form data", formData) const result = await axios.put(urlEdit, formData, HEADER) .then(res => res) @@ -446,9 +388,6 @@ const ResourceWorker = ({ params }) => { dataIndex: '', key: 'x', render: (text, record) => <> - {/* - - */} @@ -459,9 +398,6 @@ const ResourceWorker = ({ params }) => { - {/* - - */} , }, @@ -478,20 +414,7 @@ const ResourceWorker = ({ params }) => { { title: 'Phone No.', dataIndex: 'phone_number', key: 'phone_number' }, { title: 'Email', dataIndex: 'email', key: 'email' }, { title: 'Status', dataIndex: 'status_resource', key: 'status_status' } - // { - // title: 'Aktifitas Mulai', - // dataIndex: 'mulai_proyek', - // key: 'mulai_proyek', - // render: (text, record) => <>{moment(text).format(format)}, - // }, - // { - // title: 'Aktifitas Selesai', - // dataIndex: 'akhir_proyek', - // key: 'akhir_proyek', - // render: (text, record) => <>{moment(text).format(format)}, - // }, ]; - // console.log("columns", columns) return (
{n.nama}{n.biaya}
{n.jumlah_pekerja}{n.pic}{n.mulai_proyek ? moment(n.mulai_proyek).format("DD-MM-YYYY") : "-"}{n.akhir_proyek ? moment(n.akhir_proyek).format("DD-MM-YYYY") : "-"}
{ ) } -export default ResourceWorker; \ No newline at end of file +export default ResourceWorker; diff --git a/src/views/SimproV2/Satuan/index.js b/src/views/SimproV2/Satuan/index.js index 63d0cdf..b420f89 100644 --- a/src/views/SimproV2/Satuan/index.js +++ b/src/views/SimproV2/Satuan/index.js @@ -1,361 +1,338 @@ -import React, { useState, useEffect, useMemo } from 'react'; -import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap'; -import axios from "../../../const/interceptorApi" import * as XLSX from 'xlsx'; -import SweetAlert from 'react-bootstrap-sweetalert'; import DialogForm from './DialogForm'; +import React, { useState, useEffect, useMemo } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from "../../../const/interceptorApi" +import { Card, CardBody, CardHeader, Col, Row, Input, Table } from 'reactstrap'; import { NotificationContainer, NotificationManager } from 'react-notifications'; import { Pagination, Button, Tooltip } from 'antd'; -import { - SATUAN_ADD, SATUAN_EDIT, SATUAN_DELETE,SATUAN_SEARCH -} from '../../../const/ApiConst'; +import { SATUAN_ADD, SATUAN_EDIT, SATUAN_DELETE,SATUAN_SEARCH} from '../../../const/ApiConst'; const token = window.localStorage.getItem('token'); const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } + headers: + { + Authorization: `Bearer ${token}`, + "Content-type": `application/json` + } }; const column = [ - { name: "Nama" }, - { name: "Deskripsi" }, + { name: "Nama" }, + { name: "Deskripsi" }, ] const Satuan = ({ params }) => { - const token = localStorage.getItem("token") - const HEADER = { - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${token}` - } - } - const pageName = params.name; - const [search, setSearch] = useState('') - const [currentPage, setCurrentPage] = useState(1) - const [openDialog, setOpenDialog] = useState(false) - const [typeDialog, setTypeDialog] = useState('Save') - const [dataExport, setDataExport] = useState([]) - const [rowsPerPage, setRowsPerPage] = useState(10) - const [dataEdit, setDataEdit] = useState([]) - const [alertDelete, setAlertDelete] = useState(false) - const [idDelete, setIdDelete] = useState(0) - const [dataTable, setDatatable] = useState([]) - const [clickOpenModal, setClickOpenModal] = useState(false) - const [allDataMenu, setAllDataMenu] = useState([]) - const [totalPage, setTotalPage] = useState(0) - - useEffect(() => { - getDataSatuan() - }, [currentPage, rowsPerPage, search]) - - useEffect(() => { - const cekData = dataExport || [] - if (cekData.length > 0) { - exportExcel() - } - }, [dataExport]) - - const getDataSatuan = async () => { - - let start = 0; - - if (currentPage !== 1 && currentPage > 1) { - start = (currentPage * rowsPerPage) - rowsPerPage - } - - const payload = { - "columns": [ - { - "name": "name", - "logic_operator": "like", - "value": search, - "operator": "AND" - } - ], - "orders": { - "ascending": true, - "columns": [ - 'id' - ] - }, - "paging": { - "length": rowsPerPage, - "start": start - } - } - - // console.log("payload ", payload) - const result = await axios - .post(SATUAN_SEARCH, payload, config) - .then(res => res) - .catch((error) => error.response); - - - - if (result && result.data && result.data.code == 200) { - console.log("get data ", result.data) - 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 = (type) => { - setOpenDialog(true) - setTypeDialog(type) - } - - const handleExportExcel = async () => { - console.log("cek cek cek cke") - const payload = { - "paging": { "start": 0, "length": -1 }, - "columns": [ - { "name": "name", "logic_operator": "like", "value": search, "operator": "AND" } - ], - "joins": [], - "orders": { "columns": ["id"], "ascending": false } - } - - - - const result = await axios - .post(SATUAN_SEARCH, payload, config) - .then(res => res) - .catch((error) => error.response); - - // console.log(result) - - if (result && result.data && result.data.code == 200) { - let resData = result.data.data; - const excelData = []; - resData.map((val, index) => { - let dataRow = { - "Nama": val.name, - "Deskripsi": val.description, - } - excelData.push(dataRow) - }) - // console.log("cek excel data", resData) - await setDataExport(excelData); - // exportExcel(); - } else { - NotificationManager.error('Gagal Export Data!!', 'Failed'); - } - } - - const exportExcel = () => { - const dataExcel = dataExport || []; - console.log("cek data excel", dataExcel) - 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 handleDelete = async (id) => { - await setAlertDelete(true) - await setIdDelete(id) - } - - const handleCloseDialog = (type, data) => { - if (type === "save") { - saveSatuan(data); - } else if (type === "edit") { - editMaterialR(data); - } - setDataEdit([]) - setOpenDialog(false) - } - - const saveSatuan = async (data) => { - const formData = data - const result = await axios.post(SATUAN_ADD, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataSatuan() - // console.log("data material s ", formData) - NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); - } else { - // console.log("data material fail ", formData) - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - } - - const editMaterialR = async (data) => { - - let urlEdit = SATUAN_EDIT(data.id) - const formData = data - - console.log("from data edit ", formData) - - const result = await axios.put(urlEdit, formData, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataSatuan(); - NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); - } - } - - const toggleAddDialog = () => { - setOpenDialog(!openDialog) - } - - const onConfirmDelete = async () => { - let url = SATUAN_DELETE(idDelete); - - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - getDataSatuan() - setIdDelete(0) - setAlertDelete(false) - NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); - } else { - setIdDelete(0) - setAlertDelete(false) - NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); - } - } - - const cancelDelete = () => { - setAlertDelete(false) - setIdDelete(0) - } - - const onShowSizeChange = (current, pageSize) => { - setRowsPerPage(pageSize) - } - - const onPagination = (current, pageSize) => { - setCurrentPage(current) - } - - const dataNotAvailable = () => { - if (dataTable.length === 0) { - return ( - - - - ) - } - } - - - - return ( -
- - cancelDelete()} - focusCancelBtn - > - Delete this data - - toggleAddDialog} - typeDialog={typeDialog} - dataEdit={dataEdit} - clickOpenModal={clickOpenModal} - dataParent={allDataMenu} - /> - - -

{pageName}

- -
- - - - - - - - - - - - - -
Tidak ada data project type
- - - - {column.map((i, index) => { - return ( - - ) - })} - - - - {dataNotAvailable()} - {dataTable.map((n, index) => { - return ( - - - - - - ) - })} - -
Aksi{i.name}
- - - handleDelete(n.id)}> - - - - handleEdit(n)}> - - {n.name}{n.description}
- - - - - ) + const token = localStorage.getItem("token") + const HEADER = { + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + } + } + const pageName = params.name; + + const [alertDelete, setAlertDelete] = useState(false) + const [allDataMenu, setAllDataMenu] = useState([]) + const [clickOpenModal, setClickOpenModal] = useState(false) + const [currentPage, setCurrentPage] = useState(1) + const [dataEdit, setDataEdit] = useState([]) + const [dataExport, setDataExport] = useState([]) + const [dataTable, setDatatable] = useState([]) + const [idDelete, setIdDelete] = useState(0) + const [openDialog, setOpenDialog] = useState(false) + const [rowsPerPage, setRowsPerPage] = useState(10) + const [search, setSearch] = useState('') + const [totalPage, setTotalPage] = useState(0) + const [typeDialog, setTypeDialog] = useState('Save') + + useEffect(() => { + getDataSatuan() + }, [currentPage, rowsPerPage, search]) + + useEffect(() => { + const cekData = dataExport || [] + if (cekData.length > 0) { + exportExcel() + } + }, [dataExport]) + + const getDataSatuan = async () => { + + let start = 0; + + if (currentPage !== 1 && currentPage > 1) { + start = (currentPage * rowsPerPage) - rowsPerPage + } + + const payload = { + "columns": [ + { + "name": "name", + "logic_operator": "like", + "value": search, + "operator": "AND" + } + ], + "orders": { + "ascending": true, + "columns": [ + 'id' + ] + }, + "paging": { + "length": rowsPerPage, + "start": start + } + } + + const result = await axios + .post(SATUAN_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 = (type) => { + setOpenDialog(true) + setTypeDialog(type) + } + + const handleExportExcel = async () => { + const payload = { + "paging": { "start": 0, "length": -1 }, + "columns": [ + { "name": "name", "logic_operator": "like", "value": search, "operator": "AND" } + ], + "joins": [], + "orders": { "columns": ["id"], "ascending": false } + } + const result = await axios + .post(SATUAN_SEARCH, payload, config) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.data.code == 200) { + let resData = result.data.data; + const excelData = []; + resData.map((val, index) => { + let dataRow = { + "Nama": val.name, + "Deskripsi": val.description, + } + 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 handleDelete = async (id) => { + await setAlertDelete(true) + await setIdDelete(id) + } + + const handleCloseDialog = (type, data) => { + if (type === "save") { + saveSatuan(data); + } else if (type === "edit") { + editMaterialR(data); + } + setDataEdit([]) + setOpenDialog(false) + } + + const saveSatuan = async (data) => { + const formData = data + const result = await axios.post(SATUAN_ADD, formData, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataSatuan() + NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + } + + const editMaterialR = async (data) => { + let urlEdit = SATUAN_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) { + getDataSatuan(); + NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); + } + } + + const toggleAddDialog = () => { + setOpenDialog(!openDialog) + } + + const onConfirmDelete = async () => { + let url = SATUAN_DELETE(idDelete); + + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + getDataSatuan() + setIdDelete(0) + setAlertDelete(false) + NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); + } else { + setIdDelete(0) + setAlertDelete(false) + NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); + } + } + + const cancelDelete = () => { + setAlertDelete(false) + setIdDelete(0) + } + + const onShowSizeChange = (current, pageSize) => { + setRowsPerPage(pageSize) + } + + const onPagination = (current, pageSize) => { + setCurrentPage(current) + } + + const dataNotAvailable = () => { + if (dataTable.length === 0) { + return ( + + Tidak ada data project type + + ) + } + } + + return ( +
+ + cancelDelete()} + focusCancelBtn + > + Delete this data + + toggleAddDialog} + typeDialog={typeDialog} + dataEdit={dataEdit} + clickOpenModal={clickOpenModal} + dataParent={allDataMenu} + /> + + +

{pageName}

+ + + + + + + + + + + + + +
+ + + + + + {column.map((i, index) => { + return ( + + ) + })} + + + + {dataNotAvailable()} + {dataTable.map((n, index) => { + return ( + + + + + + ) + })} + +
Aksi{i.name}
+ + + handleDelete(n.id)}> + + + + handleEdit(n)}> + + {n.name}{n.description}
+ +
+
+
+ ) } -export default Satuan; \ No newline at end of file +export default Satuan;