From cb9e1928154230827a83e47edd85806a08a6c762 Mon Sep 17 00:00:00 2001 From: wahyuun Date: Mon, 18 Sep 2023 10:43:19 +0700 Subject: [PATCH] add USER_LIST variabel apiConst --- .../Master/MasterBroadcast/DialogDetail.js | 264 ++++++++++-------- 1 file changed, 141 insertions(+), 123 deletions(-) diff --git a/src/views/Master/MasterBroadcast/DialogDetail.js b/src/views/Master/MasterBroadcast/DialogDetail.js index 0d5165f..b4b96cc 100644 --- a/src/views/Master/MasterBroadcast/DialogDetail.js +++ b/src/views/Master/MasterBroadcast/DialogDetail.js @@ -1,123 +1,141 @@ -import 'antd/dist/antd.css'; -import React, { Component } from 'react'; -import moment from 'moment'; -import { Button, Table, FormFeedback, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; -import Select from 'react-select'; -import axios from 'axios'; -import { BASE_SIMPRO_LUMEN, BASE_URL_GEOHR_API } from '../../../const/ApiConst'; -import { Transfer } from 'antd'; -import { withTranslation } from 'react-i18next'; -const token = window.localStorage.getItem('token'); -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } -}; -const ERROR_TITLE = "judul is required!" -const ERROR_MESSAGE = "message is required!" -const BASE_URL = "https://oslog.id/geohr-api/"; -let countError = 0; -class DialogDetail extends Component { - constructor(props) { - super(props) - this.state = { - openDialog: false, - isParentClick: false, - dataListDetail: [], - id: 0, - } - } - - async componentDidMount() { - this.props.showDialog(this.showDialog); - } - - async componentDidUpdate() { - if (this.state.isParentClick === true) { - const { dataDetail } = this.props - console.log("cek data detail", dataDetail) - this.setState({ - id: dataDetail.id - }, () => { - this.getDataDetail(); - this.setState({ isParentClick: false }); - }); - } - } - - getDataDetail = async () => { - countError++; - let url = BASE_SIMPRO_LUMEN + `/broadcast/search`; - const payload = { - "paging": { "start": 0, "length": 25 }, - "orders": { "columns": ["id"], "ascending": true }, - "columns": [ - { "name": "id", "logic_operator": "=", "value": this.state.id, "operator": "AND" } - ] - } - const result = await axios - .post(url, payload, config) - .then(res => res) - .catch((error) => error.response); - console.log('cek data detail', result.data) - - if (result && result.data && result.data.code === 200) { - if (result.data.data && result.data.data) { - this.setState({ dataListDetail: result.data.data }) - } - } else { - if (countError < 6) { - this.getDataDetail(); - } - } - } - - showDialog = () => { - this.setState({ isParentClick: true }); - } - - handleCloseDialog = () => { - this.props.closeDialog() - } - - render() { - return ( - - {this.props.t('broadcastDetail')} - - - - - - - - - - - - - {this.state.dataListDetail.map((val, index) => { - return ( - - - - - - - - ) - })} - -
{this.props.t('statusSend')}{this.props.t('dateSend')}{this.props.t('description')}{this.props.t('titleNotification')}{this.props.t('messageNotification')}
{val.status_send === "" ? "-" : val.status_send}{val.created_at === "" ? "-" : moment(val.created_date).format("DD-MM-YYYY HH:mm:ss")}{val.description === "" ? "-" : val.description}{val.title_notif === "" ? "-" : val.title_notif}{val.message_notif === "" ? "-" : val.message_notif}
- -
- - - -
- ) - } -} -export default withTranslation()(DialogDetail); \ No newline at end of file +import 'antd/dist/antd.css'; +import React, { Component } from 'react'; +import moment from 'moment'; +import { Button, Table, FormFeedback, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; +import Select from 'react-select'; +import axios from 'axios'; +import { BASE_SIMPRO_LUMEN, USER_LIST } from '../../../const/ApiConst'; +import { Transfer } from 'antd'; +import { withTranslation } from 'react-i18next'; +const token = window.localStorage.getItem('token'); +const config = { + headers: + { + Authorization: `Bearer ${token}`, + "Content-type": `application/json` + } +}; +const ERROR_TITLE = "judul is required!" +const ERROR_MESSAGE = "message is required!" +const BASE_URL = "https://oslog.id/geohr-api/"; +let countError = 0; +class DialogDetail extends Component { + constructor(props) { + super(props) + this.state = { + openDialog: false, + isParentClick: false, + dataListDetail: [], + id: 0, + } + } + + async componentDidMount() { + this.props.showDialog(this.showDialog); + } + + async componentDidUpdate() { + if (this.state.isParentClick === true) { + const { dataDetail } = this.props + console.log("cek data detail", dataDetail) + this.setState({ + id: dataDetail.id + }, () => { + this.getDataDetail(); + this.getDataUsers(); + this.setState({ isParentClick: false }); + }); + } + } + + getDataUsers = async () => { + const result = await axios + .get(USER_LIST, config) + .then(res => res) + .catch((error) => error.response); + console.log('Get Data User', result) + + if (result && result.data && result.status == 200) { + this.setState({ dataUser: result.data.data }, () => { + }); + } + } + + getDataDetail = async () => { + countError++; + let url = BASE_SIMPRO_LUMEN + `/broadcast/search`; + const payload = { + "paging": { "start": 0, "length": 25 }, + "orders": { "columns": ["id"], "ascending": true }, + "columns": [ + { "name": "id", "logic_operator": "=", "value": this.state.id, "operator": "AND" } + ] + } + const result = await axios + .post(url, payload, config) + .then(res => res) + .catch((error) => error.response); + console.log('cek data detail', result.data) + + if (result && result.data && result.data.code === 200) { + if (result.data.data && result.data.data) { + this.setState({ dataListDetail: result.data.data }) + } + } else { + if (countError < 6) { + this.getDataDetail(); + this.getDataUsers(); + } + } + } + + showDialog = () => { + this.setState({ isParentClick: true }); + } + + handleCloseDialog = () => { + this.props.closeDialog() + } + render() { + const dataUser = this.state.dataUser || []; + return ( + + {this.props.t('broadcastDetail')} + + + + + + + + + + + + + + {this.state.dataListDetail.map((val, index) => { + const matchedUser = dataUser.find(item => item.id == val.send_to_id); + return ( + + + + + + + + + ) + })} + +
{this.props.t('statusSend')}{this.props.t('dateSend')}{this.props.t('description')}{this.props.t('receiver')}{this.props.t('titleNotification')}{this.props.t('messageNotification')}
{val.status_send === "" ? "-" : val.status_send}{val.created_at === "" ? "-" : moment(val.created_date).format("DD-MM-YYYY HH:mm:ss")}{val.description === "" ? "-" : val.description}{ matchedUser ? matchedUser.name : "-" }{val.title_notif === "" ? "-" : val.title_notif}{val.message_notif === "" ? "-" : val.message_notif}
+ +
+ + + +
+ ) + } +} +export default withTranslation()(DialogDetail);