wahyuun
1 year ago
1 changed files with 141 additions and 123 deletions
@ -1,123 +1,141 @@ |
|||||||
import 'antd/dist/antd.css'; |
import 'antd/dist/antd.css'; |
||||||
import React, { Component } from 'react'; |
import React, { Component } from 'react'; |
||||||
import moment from 'moment'; |
import moment from 'moment'; |
||||||
import { Button, Table, FormFeedback, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; |
import { Button, Table, FormFeedback, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; |
||||||
import Select from 'react-select'; |
import Select from 'react-select'; |
||||||
import axios from 'axios'; |
import axios from 'axios'; |
||||||
import { BASE_SIMPRO_LUMEN, BASE_URL_GEOHR_API } from '../../../const/ApiConst'; |
import { BASE_SIMPRO_LUMEN, USER_LIST } from '../../../const/ApiConst'; |
||||||
import { Transfer } from 'antd'; |
import { Transfer } from 'antd'; |
||||||
import { withTranslation } from 'react-i18next'; |
import { withTranslation } from 'react-i18next'; |
||||||
const token = window.localStorage.getItem('token'); |
const token = window.localStorage.getItem('token'); |
||||||
const config = { |
const config = { |
||||||
headers: |
headers: |
||||||
{ |
{ |
||||||
Authorization: `Bearer ${token}`, |
Authorization: `Bearer ${token}`, |
||||||
"Content-type": `application/json` |
"Content-type": `application/json` |
||||||
} |
} |
||||||
}; |
}; |
||||||
const ERROR_TITLE = "judul is required!" |
const ERROR_TITLE = "judul is required!" |
||||||
const ERROR_MESSAGE = "message is required!" |
const ERROR_MESSAGE = "message is required!" |
||||||
const BASE_URL = "https://oslog.id/geohr-api/"; |
const BASE_URL = "https://oslog.id/geohr-api/"; |
||||||
let countError = 0; |
let countError = 0; |
||||||
class DialogDetail extends Component { |
class DialogDetail extends Component { |
||||||
constructor(props) { |
constructor(props) { |
||||||
super(props) |
super(props) |
||||||
this.state = { |
this.state = { |
||||||
openDialog: false, |
openDialog: false, |
||||||
isParentClick: false, |
isParentClick: false, |
||||||
dataListDetail: [], |
dataListDetail: [], |
||||||
id: 0, |
id: 0, |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
async componentDidMount() { |
async componentDidMount() { |
||||||
this.props.showDialog(this.showDialog); |
this.props.showDialog(this.showDialog); |
||||||
} |
} |
||||||
|
|
||||||
async componentDidUpdate() { |
async componentDidUpdate() { |
||||||
if (this.state.isParentClick === true) { |
if (this.state.isParentClick === true) { |
||||||
const { dataDetail } = this.props |
const { dataDetail } = this.props |
||||||
console.log("cek data detail", dataDetail) |
console.log("cek data detail", dataDetail) |
||||||
this.setState({ |
this.setState({ |
||||||
id: dataDetail.id |
id: dataDetail.id |
||||||
}, () => { |
}, () => { |
||||||
this.getDataDetail(); |
this.getDataDetail(); |
||||||
this.setState({ isParentClick: false }); |
this.getDataUsers(); |
||||||
}); |
this.setState({ isParentClick: false }); |
||||||
} |
}); |
||||||
} |
} |
||||||
|
} |
||||||
getDataDetail = async () => { |
|
||||||
countError++; |
getDataUsers = async () => { |
||||||
let url = BASE_SIMPRO_LUMEN + `/broadcast/search`; |
const result = await axios |
||||||
const payload = { |
.get(USER_LIST, config) |
||||||
"paging": { "start": 0, "length": 25 }, |
.then(res => res) |
||||||
"orders": { "columns": ["id"], "ascending": true }, |
.catch((error) => error.response); |
||||||
"columns": [ |
console.log('Get Data User', result) |
||||||
{ "name": "id", "logic_operator": "=", "value": this.state.id, "operator": "AND" } |
|
||||||
] |
if (result && result.data && result.status == 200) { |
||||||
} |
this.setState({ dataUser: result.data.data }, () => { |
||||||
const result = await axios |
}); |
||||||
.post(url, payload, config) |
} |
||||||
.then(res => res) |
} |
||||||
.catch((error) => error.response); |
|
||||||
console.log('cek data detail', result.data) |
getDataDetail = async () => { |
||||||
|
countError++; |
||||||
if (result && result.data && result.data.code === 200) { |
let url = BASE_SIMPRO_LUMEN + `/broadcast/search`; |
||||||
if (result.data.data && result.data.data) { |
const payload = { |
||||||
this.setState({ dataListDetail: result.data.data }) |
"paging": { "start": 0, "length": 25 }, |
||||||
} |
"orders": { "columns": ["id"], "ascending": true }, |
||||||
} else { |
"columns": [ |
||||||
if (countError < 6) { |
{ "name": "id", "logic_operator": "=", "value": this.state.id, "operator": "AND" } |
||||||
this.getDataDetail(); |
] |
||||||
} |
} |
||||||
} |
const result = await axios |
||||||
} |
.post(url, payload, config) |
||||||
|
.then(res => res) |
||||||
showDialog = () => { |
.catch((error) => error.response); |
||||||
this.setState({ isParentClick: true }); |
console.log('cek data detail', result.data) |
||||||
} |
|
||||||
|
if (result && result.data && result.data.code === 200) { |
||||||
handleCloseDialog = () => { |
if (result.data.data && result.data.data) { |
||||||
this.props.closeDialog() |
this.setState({ dataListDetail: result.data.data }) |
||||||
} |
} |
||||||
|
} else { |
||||||
render() { |
if (countError < 6) { |
||||||
return ( |
this.getDataDetail(); |
||||||
<Modal size="xl" isOpen={this.props.openDialog} toggle={this.props.toggleDialog}> |
this.getDataUsers(); |
||||||
<ModalHeader toggle={this.handleCloseDialog}>{this.props.t('broadcastDetail')}</ModalHeader> |
} |
||||||
<ModalBody> |
} |
||||||
<Table> |
} |
||||||
<thead> |
|
||||||
<tr> |
showDialog = () => { |
||||||
<th>{this.props.t('statusSend')}</th> |
this.setState({ isParentClick: true }); |
||||||
<th>{this.props.t('dateSend')}</th> |
} |
||||||
<th>{this.props.t('description')}</th> |
|
||||||
<th>{this.props.t('titleNotification')}</th> |
handleCloseDialog = () => { |
||||||
<th>{this.props.t('messageNotification')}</th> |
this.props.closeDialog() |
||||||
</tr> |
} |
||||||
</thead> |
render() { |
||||||
<tbody> |
const dataUser = this.state.dataUser || []; |
||||||
{this.state.dataListDetail.map((val, index) => { |
return ( |
||||||
return ( |
<Modal size="xl" isOpen={this.props.openDialog} toggle={this.props.toggleDialog}> |
||||||
<tr key={index}> |
<ModalHeader toggle={this.handleCloseDialog}>{this.props.t('broadcastDetail')}</ModalHeader> |
||||||
<td>{val.status_send === "" ? "-" : val.status_send}</td> |
<ModalBody> |
||||||
<td>{val.created_at === "" ? "-" : moment(val.created_date).format("DD-MM-YYYY HH:mm:ss")}</td> |
<Table> |
||||||
<td>{val.description === "" ? "-" : val.description}</td> |
<thead> |
||||||
<td>{val.title_notif === "" ? "-" : val.title_notif}</td> |
<tr> |
||||||
<td>{val.message_notif === "" ? "-" : val.message_notif}</td> |
<th>{this.props.t('statusSend')}</th> |
||||||
</tr> |
<th>{this.props.t('dateSend')}</th> |
||||||
) |
<th>{this.props.t('description')}</th> |
||||||
})} |
<th>{this.props.t('receiver')}</th> |
||||||
</tbody> |
<th>{this.props.t('titleNotification')}</th> |
||||||
</Table> |
<th>{this.props.t('messageNotification')}</th> |
||||||
|
</tr> |
||||||
</ModalBody> |
</thead> |
||||||
<ModalFooter> |
<tbody> |
||||||
<Button color="secondary" onClick={this.handleCloseDialog}>{this.props.t('close')}</Button> |
{this.state.dataListDetail.map((val, index) => { |
||||||
</ModalFooter> |
const matchedUser = dataUser.find(item => item.id == val.send_to_id); |
||||||
</Modal> |
return ( |
||||||
) |
<tr key={index}> |
||||||
} |
<td>{val.status_send === "" ? "-" : val.status_send}</td> |
||||||
} |
<td>{val.created_at === "" ? "-" : moment(val.created_date).format("DD-MM-YYYY HH:mm:ss")}</td> |
||||||
export default withTranslation()(DialogDetail); |
<td>{val.description === "" ? "-" : val.description}</td> |
||||||
|
<td>{ matchedUser ? matchedUser.name : "-" }</td> |
||||||
|
<td>{val.title_notif === "" ? "-" : val.title_notif}</td> |
||||||
|
<td>{val.message_notif === "" ? "-" : val.message_notif}</td> |
||||||
|
</tr> |
||||||
|
) |
||||||
|
})} |
||||||
|
</tbody> |
||||||
|
</Table> |
||||||
|
|
||||||
|
</ModalBody> |
||||||
|
<ModalFooter> |
||||||
|
<Button color="secondary" onClick={this.handleCloseDialog}>{this.props.t('close')}</Button> |
||||||
|
</ModalFooter> |
||||||
|
</Modal> |
||||||
|
) |
||||||
|
} |
||||||
|
} |
||||||
|
export default withTranslation()(DialogDetail); |
||||||
|
Loading…
Reference in new issue