diff --git a/src/views/Master/MasterBroadcast/DialogDetail.js b/src/views/Master/MasterBroadcast/DialogDetail.js index 80d73be..0d5165f 100644 --- a/src/views/Master/MasterBroadcast/DialogDetail.js +++ b/src/views/Master/MasterBroadcast/DialogDetail.js @@ -4,10 +4,17 @@ 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_URL_GEOHR_API } from '../../../const/ApiConst'; +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/"; @@ -42,26 +49,23 @@ class DialogDetail extends Component { getDataDetail = async () => { countError++; - let url = BASE_URL_GEOHR_API + `/broadcast-detail/search?broadcastId=${this.state.id}`; + let url = BASE_SIMPRO_LUMEN + `/broadcast/search`; const payload = { "paging": { "start": 0, "length": 25 }, "orders": { "columns": ["id"], "ascending": true }, "columns": [ - { "name": "status_send", "logic_operator": "ilike", "value": "", "operator": "AND" } - ], - "joins": [ - { "name": "m_broadcast", "column_results": ["title_notif", "message_notif", "description", "status_send"], "column_join": "broadcast_id" } + { "name": "id", "logic_operator": "=", "value": this.state.id, "operator": "AND" } ] } const result = await axios - .post(url, payload) + .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.broadcast_details) { - this.setState({ dataListDetail: result.data.data.broadcast_details }) + if (result.data.data && result.data.data) { + this.setState({ dataListDetail: result.data.data }) } } else { if (countError < 6) { @@ -97,11 +101,11 @@ class DialogDetail extends Component { {this.state.dataListDetail.map((val, index) => { return ( - {val.join.status_send === "" ? "-" : val.status_send} - {val.join.created_date === "" ? "-" : moment(val.created_date).format("YYYY-MM-DD HH:mm:ss")} - {val.join.broadcast_description === "" ? "-" : val.join.broadcast_description} - {val.join.broadcast_title_notif === "" ? "-" : val.join.broadcast_title_notif} - {val.join.broadcast_message_notif === "" ? "-" : val.join.broadcast_message_notif} + {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} ) })} diff --git a/src/views/Master/MasterBroadcast/DialogForm.js b/src/views/Master/MasterBroadcast/DialogForm.js index c114a4d..db6298e 100644 --- a/src/views/Master/MasterBroadcast/DialogForm.js +++ b/src/views/Master/MasterBroadcast/DialogForm.js @@ -3,7 +3,7 @@ import React, { Component } from 'react'; import { Button, Form, FormFeedback, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import Select from 'react-select'; import axios from 'axios'; -import { BASE_URL_GEOHR_API2, ROLE_SEARCH, USER_WASPANG } from '../../../const/ApiConst'; +import { BASE_URL_GEOHR_API2, ROLE_SEARCH, USER_WASPANG, USER_LIST } from '../../../const/ApiConst'; import { Transfer } from 'antd'; import { withTranslation } from 'react-i18next'; @@ -137,7 +137,7 @@ class DialogForm extends Component { if (penerima === "all") { idSend = this.state.allEmployeeId; send_to_type = "all"; - } else if (penerima === "division") { + } else if (penerima === "organization") { idSend = this.state.idOrganization; send_to_type = "roles"; } else if (penerima === "karyawan") { @@ -145,9 +145,13 @@ class DialogForm extends Component { send_to_type = "users"; } + if(Array.isArray(idSend)){ idSend = idSend.map(function (e) { return e.toString() }); + } else { + idSend = idSend; + } const data = { title, @@ -186,7 +190,7 @@ class DialogForm extends Component { } setEmployeeOrganization = () => { - let arrEd = this.state.dataEmployee; + let arrEd = this.state.dataEmployee.data; let cek = arrEd.filter(this.filterId) this.setState({ idEmployeeDivision: cek }) @@ -289,14 +293,14 @@ class DialogForm extends Component { "ascending": false } } - + //TODO should use search instead const result = await axios - .post(USER_WASPANG, payload, config) + .get(USER_LIST, config) .then(res => res) .catch((error) => error.response); console.log('test role', result) - if (result && result.data && result.code == "200") { + if (result && result.data && result.status == 200) { this.setState({ dataEmployee: result.data }, () => { this.setDataEmployee(); }); @@ -307,12 +311,12 @@ class DialogForm extends Component { setDataEmployee = () => { const listEmployee = []; const allIdEmployee = []; - this.state.dataEmployee.map((val, index) => { + this.state.dataEmployee.data.map((val, index) => { allIdEmployee.push(val.id); listEmployee.push({ key: val.id, id: val.id, - title: val.join.m_users_name + title: val.name }); }) diff --git a/src/views/Master/MasterBroadcast/index.js b/src/views/Master/MasterBroadcast/index.js index 770be69..36e5193 100644 --- a/src/views/Master/MasterBroadcast/index.js +++ b/src/views/Master/MasterBroadcast/index.js @@ -5,7 +5,7 @@ import React, { Component } from 'react'; import SweetAlert from 'react-bootstrap-sweetalert'; import axios from 'axios'; import moment from 'moment'; -import { API_BROADCAST_SIMPRO, BASE_SIMPRO, BASE_URL_GEOHR_API2 } from '../../../const/ApiConst'; +import { API_BROADCAST_SIMPRO, BASE_SIMPRO, BASE_SIMPRO_LUMEN, BASE_URL_GEOHR_API2 } from '../../../const/ApiConst'; 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'; @@ -85,7 +85,7 @@ class index extends Component { }; getDataBroadcast = async () => { - let url = BASE_SIMPRO + `/broadcast/search`; + let url = BASE_SIMPRO_LUMEN + `/broadcast/search`; const { searchDetail } = this.state let start = 0; @@ -180,7 +180,7 @@ class index extends Component { } saveBroadcast = async (type, data) => { - let url = BASE_SIMPRO + `/broadcast/add`; + let url = BASE_SIMPRO_LUMEN + `/broadcast/add`; const param = { "title_notif": data.title, @@ -205,7 +205,7 @@ class index extends Component { "send_to_type": "users", "message_notif": data.message, "description": data.description, - "send_to_id": data.id.map((id, index) => id) + "send_to_id": data.send_to_type == "users" ? data.id.map((id, index) => id) : null } if (data.send_to_type === "all") {