|
|
|
@ -4,7 +4,7 @@ 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 { BASE_SIMPRO_LUMEN, USER_LIST, ROLE_LIST } from '../../../const/ApiConst'; |
|
|
|
|
import { Transfer } from 'antd'; |
|
|
|
|
import { withTranslation } from 'react-i18next'; |
|
|
|
|
const token = window.localStorage.getItem('token'); |
|
|
|
@ -43,6 +43,7 @@ class DialogDetail extends Component {
|
|
|
|
|
}, () => { |
|
|
|
|
this.getDataDetail(); |
|
|
|
|
this.getDataUsers(); |
|
|
|
|
this.getDataRoles(); |
|
|
|
|
this.setState({ isParentClick: false }); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -61,6 +62,18 @@ class DialogDetail extends Component {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getDataRoles = async () => { |
|
|
|
|
const result = await axios |
|
|
|
|
.get(ROLE_LIST, config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
console.log('Get Data Roles', result) |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.status == 200) { |
|
|
|
|
this.setState({ dataRoles: result.data.data }); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getDataDetail = async () => { |
|
|
|
|
countError++; |
|
|
|
|
let url = BASE_SIMPRO_LUMEN + `/broadcast/search`; |
|
|
|
@ -85,6 +98,7 @@ class DialogDetail extends Component {
|
|
|
|
|
if (countError < 6) { |
|
|
|
|
this.getDataDetail(); |
|
|
|
|
this.getDataUsers(); |
|
|
|
|
this.getDataRoles(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -97,7 +111,10 @@ class DialogDetail extends Component {
|
|
|
|
|
this.props.closeDialog() |
|
|
|
|
} |
|
|
|
|
render() { |
|
|
|
|
const dataListDetail = this.state.dataListDetail || []; |
|
|
|
|
const dataUser = this.state.dataUser || []; |
|
|
|
|
const dataRoles = this.state.dataRoles || []; |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Modal size="xl" isOpen={this.props.openDialog} toggle={this.props.toggleDialog}> |
|
|
|
|
<ModalHeader toggle={this.handleCloseDialog}>{this.props.t('broadcastDetail')}</ModalHeader> |
|
|
|
@ -114,14 +131,42 @@ class DialogDetail extends Component {
|
|
|
|
|
</tr> |
|
|
|
|
</thead> |
|
|
|
|
<tbody> |
|
|
|
|
{this.state.dataListDetail.map((val, index) => { |
|
|
|
|
const matchedUser = dataUser.find(item => item.id == val.send_to_id); |
|
|
|
|
{dataListDetail.map((val, index) => { |
|
|
|
|
const matchedUserNames = []; |
|
|
|
|
const matchedUserNamesNotKoma = []; |
|
|
|
|
const matchRolesName = []; |
|
|
|
|
|
|
|
|
|
if (typeof val.send_to_id === 'string' && val.send_to_id.includes(',')) { |
|
|
|
|
const sendToIds = val.send_to_id.split(',').map(id => parseInt(id, 10)); |
|
|
|
|
matchedUserNames[index] = sendToIds.map(id => { |
|
|
|
|
const matchedUser = dataUser.find(item => item.id === id); |
|
|
|
|
return matchedUser ? <div>{"- " + matchedUser.name}</div> : null; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (typeof val.send_to_id === 'string' && val.send_to_id.indexOf(',') === -1) { |
|
|
|
|
const id = parseInt(val.send_to_id, 10); |
|
|
|
|
const matchedUser = dataUser.find(item => item.id === id); |
|
|
|
|
matchedUserNamesNotKoma[index] = matchedUser ? <div>{matchedUser.name}</div> : null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (val.send_to_type === 'roles') { |
|
|
|
|
const id = parseInt(val.send_to_id, 10); |
|
|
|
|
const matchedRole = dataRoles.find(item => item.id === id); |
|
|
|
|
matchRolesName[index] = matchedRole ? <div><b>Role </b>{matchedRole.name}</div> : null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<tr key={index}> |
|
|
|
|
<td>{val.status_send === "" ? "-" : val.status_send}</td> |
|
|
|
|
<td>{val.created_at === "" ? "-" : moment(val.created_at).format("DD-MM-YYYY HH:mm:ss")}</td> |
|
|
|
|
<td>{val.description === "" ? "-" : val.description}</td> |
|
|
|
|
<td>{ matchedUser ? matchedUser.name : "-" }</td> |
|
|
|
|
<td> |
|
|
|
|
{val.send_to_type === "all" ? "All User" : ""} |
|
|
|
|
{val.send_to_type === "roles" ? matchRolesName[index] : ""} |
|
|
|
|
{typeof val.send_to_id === 'string' && val.send_to_id.indexOf(',') === -1 ? matchedUserNamesNotKoma[index] : ""} |
|
|
|
|
{typeof val.send_to_id === 'string' && val.send_to_id.includes(',') ? matchedUserNames[index] : ""} |
|
|
|
|
</td> |
|
|
|
|
<td>{val.title_notif === "" ? "-" : val.title_notif}</td> |
|
|
|
|
<td>{val.message_notif === "" ? "-" : val.message_notif}</td> |
|
|
|
|
</tr> |
|
|
|
|