diff --git a/src/containers/DefaultLayout/DefaultLayout.js b/src/containers/DefaultLayout/DefaultLayout.js index b4d20cd..3cbce9e 100644 --- a/src/containers/DefaultLayout/DefaultLayout.js +++ b/src/containers/DefaultLayout/DefaultLayout.js @@ -152,7 +152,7 @@ class DefaultLayout extends Component { } if (countErr) { if (parseInt(countErr) > 2) { - this.signOut(); + // this.signOut(); } else { window.location.reload(); } diff --git a/src/services/base.js b/src/services/base.js new file mode 100644 index 0000000..8166693 --- /dev/null +++ b/src/services/base.js @@ -0,0 +1,41 @@ +import axios from 'axios'; +export default class RequestApi { + // constructor() { + // this.Request = this.Request.bind(this); + // } + + static Request() { + // axios.interceptors.request.use(function (config) { + // const token = localStorage.getItem('token') + // config.headers.Authorization = token; + + // return config; + // }); + const token = localStorage.getItem('token') + + let instance = axios.create({ + headers: { + 'Content-Type': 'application/json', + "Authorization": `Bearer ${token}` + } + }) + + instance.interceptors.response.use( + (response) => response, + async (error) => { + // const originalRequest = error.config; + if (error.response.status === 307 || error.response.status === 403) { + console.log(error.response); + } + + return Promise.reject(error); + } + ); + + return instance; + } + + static getToken() { } +} +export const AXIOS = RequestApi.Request(); + diff --git a/src/views/Map/Map_16.js b/src/views/Map/Map_16.js index 1030c72..0319101 100644 --- a/src/views/Map/Map_16.js +++ b/src/views/Map/Map_16.js @@ -123,6 +123,7 @@ import * as lodash from 'lodash'; import { Pie, Line, Bar } from 'react-chartjs-2'; import numeral from 'numeral'; import { NotificationContainer, NotificationManager } from 'react-notifications'; +import { AXIOS } from '../../services/base' import 'chartjs-plugin-zoom'; const HEADER = { @@ -547,14 +548,14 @@ const optionsChartKurvaS = { enabled: true, mode: 'xy', limits: { - y: {min: 0, max: 100} + y: { min: 0, max: 100 } } }, pan: { enabled: true, mode: 'xy', limits: { - y: {min: 0, max: 100} + y: { min: 0, max: 100 } } } } @@ -779,7 +780,7 @@ class SiopasMap extends Component { this.mapOnClick(evt); }); this.setState({ mapProjection: this.olmap.getView().getProjection() }, () => console.log('mapProjection', this.state.mapProjection)); - + // // set default to check all project // if (this.state.projectTree && this.state.projectTree.length > 0) { // let checked = []; @@ -787,7 +788,7 @@ class SiopasMap extends Component { // console.log('checked', checked); // this.setState({checkedKeysProjectTree: checked}); // } - + } componentDidUpdate = (prevProps, prevState) => { @@ -1089,23 +1090,23 @@ class SiopasMap extends Component { let dateStart = moment(this.state.startDate).format("YYYY-MM-DD 00:00:00"); let dateEnd = moment(this.state.endDate).format("YYYY-MM-DD 23:59:59"); - const payload = { - "paging": {"start": 0, "length": -1}, + const payload = { + "paging": { "start": 0, "length": -1 }, "columns": [ // {"name": "name", "logic_operator": "like", "value": search, "table_name": "m_users"}, - {"name": "clock_in", "logic_operator": "range", "value": dateStart, "value1": dateEnd}, + { "name": "clock_in", "logic_operator": "range", "value": dateStart, "value1": dateEnd }, ], "joins": [{ - "name":"m_users", - "column_join":"user_id", - "column_results":[ - "name", - "ktp_number" - ] - }], - "orders": {"columns": ["id"], "ascending": false} + "name": "m_users", + "column_join": "user_id", + "column_results": [ + "name", + "ktp_number" + ] + }], + "orders": { "columns": ["id"], "ascending": false } } - + const result = await axios .post(PRESENCE_SEARCH, payload, HEADER) .then(res => res) @@ -1113,10 +1114,10 @@ class SiopasMap extends Component { // console.log(result) - if(result && result.data && result.data.code == 200) { + if (result && result.data && result.data.code == 200) { let dataRes = result.data.data || [] this.setState({ presensiData: dataRes }, () => this.getPresensiFeatures()) - }else{ + } else { NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); } } @@ -1308,7 +1309,7 @@ class SiopasMap extends Component { // }; // console.log("dataRes2", dataRes2); // this.setState({ dataPersentaseProyek: dataRes2 }); - this.setState({dataCurvaS: dataRes2}); + this.setState({ dataCurvaS: dataRes2 }); console.log('dataRes2-----------', dataRes2); // set status proyek for adw @@ -1321,7 +1322,7 @@ class SiopasMap extends Component { budgetControl.push(item.data.budget_control); }); } - this.setState({dataStatusProyekAdw: budgetControl}); + this.setState({ dataStatusProyekAdw: budgetControl }); } } else { @@ -2145,7 +2146,7 @@ class SiopasMap extends Component { console.log('checkedKeysProjectTree', checkedKeysProjectTree); // first remove projectLayer and its features - + // this.removeLayerByName('routeLayer'); // this.removeLayerByName('projectLayer'); // this.removeLayerByName('waspangLayer'); @@ -2654,7 +2655,7 @@ class SiopasMap extends Component { "coordinates": [] } - for (let i=0; i < userRoute.features.length; i++) { + for (let i = 0; i < userRoute.features.length; i++) { polyline.coordinates.push(userRoute.features[i].geometry.coordinates); } @@ -2868,10 +2869,10 @@ class SiopasMap extends Component { const { kurvaSWindowMode } = this.state; console.log('toggleKurvaSWindowMode', kurvaSWindowMode); if (kurvaSWindowMode === 'default') { - this.setState({kurvaSWindowMode: 'maximize'}, () => this.renderCarouselKurvaS()) + this.setState({ kurvaSWindowMode: 'maximize' }, () => this.renderCarouselKurvaS()) } else { - this.setState({kurvaSWindowMode: 'default'}, () => this.renderCarouselKurvaS()); + this.setState({ kurvaSWindowMode: 'default' }, () => this.renderCarouselKurvaS()); } } @@ -2907,7 +2908,7 @@ class SiopasMap extends Component { body: JSON.stringify(payload) // body data type must match "Content-Type" header } try { - const result = await fetch(url, config).then(response => response.json()).then(res => res); + const result = await AXIOS.post(url, payload).then(response => response.json()).then(res => res); return result.data || [] } catch (e) { @@ -3133,11 +3134,11 @@ class SiopasMap extends Component { if (animating) return; if ((APP_MODE === 'ADW')) { const nextIndex = activeIndex === dataStatusProyekAdw.length - 1 ? 0 : activeIndex + 1; - this.setState({activeIndex: nextIndex}); + this.setState({ activeIndex: nextIndex }); } else { const nextIndex = activeIndex === dataStatusProyek.length - 1 ? 0 : activeIndex + 1; - this.setState({activeIndex: nextIndex}); + this.setState({ activeIndex: nextIndex }); } } @@ -3145,14 +3146,14 @@ class SiopasMap extends Component { const { animating2, activeIndex2, dataPersentaseProyek } = this.state; if (animating2) return; const nextIndex = activeIndex2 === dataPersentaseProyek.length - 1 ? 0 : activeIndex2 + 1; - this.setState({activeIndex2: nextIndex}); + this.setState({ activeIndex2: nextIndex }); } next3 = () => { const { animating3, activeIndex3, dataCostProyek } = this.state; if (animating3) return; const nextIndex = activeIndex3 === dataCostProyek.length - 1 ? 0 : activeIndex3 + 1; - this.setState({activeIndex3: nextIndex}); + this.setState({ activeIndex3: nextIndex }); } previous = () => { @@ -3160,11 +3161,11 @@ class SiopasMap extends Component { if (animating) return; if ((APP_MODE === 'ADW')) { const nextIndex = activeIndex === 0 ? dataStatusProyekAdw.length - 1 : activeIndex - 1; - this.setState({activeIndex: nextIndex}); + this.setState({ activeIndex: nextIndex }); } else { const nextIndex = activeIndex === 0 ? dataStatusProyek.length - 1 : activeIndex - 1; - this.setState({activeIndex: nextIndex}); + this.setState({ activeIndex: nextIndex }); } } @@ -3172,47 +3173,47 @@ class SiopasMap extends Component { const { animating2, activeIndex2, dataPersentaseProyek } = this.state; if (animating2) return; const nextIndex = activeIndex2 === 0 ? dataPersentaseProyek.length - 1 : activeIndex2 - 1; - this.setState({activeIndex2: nextIndex}); + this.setState({ activeIndex2: nextIndex }); } previous3 = () => { const { animating3, activeIndex3, dataCostProyek } = this.state; if (animating3) return; const nextIndex = activeIndex3 === 0 ? dataCostProyek.length - 1 : activeIndex3 - 1; - this.setState({activeIndex3: nextIndex}); + this.setState({ activeIndex3: nextIndex }); } goToIndex = (newIndex) => { const { animating } = this.state; if (animating) return; - this.setState({activeIndex: newIndex}) + this.setState({ activeIndex: newIndex }) } goToIndex2 = (newIndex) => { const { animating2 } = this.state; if (animating2) return; - this.setState({activeIndex2: newIndex}) + this.setState({ activeIndex2: newIndex }) } goToIndex3 = (newIndex) => { const { animating3 } = this.state; if (animating3) return; - this.setState({activeIndex3: newIndex}) + this.setState({ activeIndex3: newIndex }) } renderRemainingDays = (item) => { - const {day_left, percentage} = item; + const { day_left, percentage } = item; if (day_left > 0 && day_left < 8) { - return