Commit f8c59e38 authored by Riri Novita's avatar Riri Novita

Binding Maintenance Mode

parent a0e81ca0
......@@ -488,6 +488,11 @@ const create = (type = "") => {
const getMonitoringOLPA = (body) => api.get(`transaction/monitoring/outlook/${body.year}`)
const getMonitoringCafrm = (body) => api.get(`transaction/monitoring/cafrm/${body.year}/${body.month}/${body.status}`)
// Maintenance
const getDetailMaintenanceMode = () => api.get('maintenance/mode/get_maintenance_mode')
const createMaintenanceMode = (body) => api.post('maintenance/mode/create_maintenance_mode', body)
const updateMaintenanceMode = (body) => api.post('maintenance/mode/update_maintenance_mode', body)
// Superadmin Approve
const getListApprover = (report, monthlyReportId) => api.get(`transaction/${report}/get_approver/${monthlyReportId}`)
const getIdToken = (userId) => api.get(`transaction/get_token/${userId}`)
......@@ -844,7 +849,10 @@ const create = (type = "") => {
getMonitoringCafrm,
getListApprover,
getIdToken,
triggerHistoricalRatio
triggerHistoricalRatio,
getDetailMaintenanceMode,
createMaintenanceMode,
updateMaintenanceMode
}
}
......
......@@ -75,29 +75,202 @@ class MaintenanceMode extends Component {
this.editorRefEmail = React.createRef();
// this.handleChange = this.handleChange.bind(this)
this.state = {
isModeNonActive: true,
isModeActive: false,
isModeActiveNo: true,
isModeActiveYes: false,
isModeNonActiveNo: true,
isModeNonActiveYes: false,
contentMode: "",
contentEmail: "",
checkedB: true
load: false,
loading: false,
mailcontentModeActive: "",
mailcontentModeNonActive: "",
checkedB: true,
headline: '',
maintenanceContent: '',
subjectMailActive: '',
subjectMailNonActive: '',
maintenanceID: null,
maintenanceStatus: 0,
mailStatusActive: 0,
mailStatusNonActive: 0,
}
}
componentDidMount() {
this.getDetailMaintenanceMode()
}
getDetailMaintenanceMode() {
this.setState({ loading: true })
api.create().getDetailMaintenanceMode().then((response) => {
console.log(response);
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
let data = response.data.data
console.log(data.maintenance_mail.length);
let dataModeActive = data.maintenance_mail.length > 0 ? data.maintenance_mail.[0].[0] : null
let dataModeNonActive = data.maintenance_mail.length > 0 ? data.maintenance_mail.[0].[1] : null
this.setState({
maintenanceID: data.maintenance_id,
headline: data.maintenance_headline,
maintenanceContent: data.maintenance_content,
maintenanceStatus: data.maintenance_status === null ? 0 : data.maintenance_status,
mailStatusActive: dataModeActive === null ? 0 : dataModeActive.status,
subjectMailActive: dataModeActive === null ? null : dataModeActive.mailSubject,
mailcontentModeActive: dataModeActive === null ? null : dataModeActive.mailBody,
mailStatusNonActive: dataModeNonActive === null ? 0 : dataModeNonActive.status,
subjectMailNonActive: dataModeNonActive === null ? null : dataModeNonActive.mailSubject,
mailcontentModeNonActive: dataModeNonActive === null ? null : dataModeNonActive.mailBody,
}, () => {
setTimeout(() => {
this.setState({ loading: false })
}, 2000);
})
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
handleChange(e, type) {
let data = this.state
let isDate = type !== '' ? true : false
if (isDate && type === 'start_date') {
this.setState({
...data, startDate: format(e, 'yyyy-MM-dd'), endDate: null
})
} else if (isDate && type === 'end_date') {
this.setState({
...data, endDate: format(e, 'yyyy-MM-dd')
})
} else {
this.setState({
...data, [e.target.name]: e.target.value
})
}
}
handleCreate() {
let payload = {
"maintenance_headline": this.state.headline,
"maintenance_content": this.state.maintenanceContent,
"maintenance_status": this.state.maintenanceStatus,
"maintenance_mail": [
{
"mail_type": "MAINTENANCE_MODE_ACTIVE",
"mail_subject": this.state.subjectMailActive,
"mail_body": this.state.mailcontentModeActive,
"mail_status": this.state.mailStatusActive
},
{
"mail_type": "MAINTENANCE_MODE_INACTIVE",
"mail_subject": this.state.subjectMailNonActive,
"mail_body": this.state.mailcontentModeNonActive,
"mail_status": this.state.mailStatusNonActive
}
]
}
console.log(payload);
api.create().createMaintenanceMode(payload).then((response) => {
console.log(response)
this.setState({ loading: true })
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success', loading: false }, () => this.getDetailMaintenanceMode())
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
// this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
alert(response.problem)
this.setState({ loading: false })
}
})
}
handleEdit() {
let payload = {
"maintenance_id": this.state.maintenanceID,
"maintenance_headline": this.state.headline,
"maintenance_content": this.state.maintenanceContent,
"maintenance_status": this.state.maintenanceStatus,
"maintenance_mail": [
{
"mail_type": "MAINTENANCE_MODE_ACTIVE",
"mail_subject": this.state.subjectMailActive,
"mail_body": this.state.mailcontentModeActive,
"mail_status": this.state.mailStatusActive
},
{
"mail_type": "MAINTENANCE_MODE_INACTIVE",
"mail_subject": this.state.subjectMailNonActive,
"mail_body": this.state.mailcontentModeNonActive,
"mail_status": this.state.mailStatusNonActive
}
]
}
console.log(payload);
api.create().updateMaintenanceMode(payload).then((response) => {
console.log(response)
this.setState({ loading: true })
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success', loading: false }, () => this.getDetailMaintenanceMode())
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
// this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
alert(response.problem)
this.setState({ loading: false })
}
})
}
closeAlert() {
this.setState({ alert: false })
}
handleChange(event) {
this.setState({ ...this.state.checkedB, [event.target.name]: event.target.checked });
};
// handleChange(event) {
// this.setState({ ...this.state.checkedB, [event.target.name]: event.target.checked });
// };
handleImageUploadBefore(files, info, uploadHandler) {
// uploadHandler is a function
......@@ -117,8 +290,8 @@ class MaintenanceMode extends Component {
}
handleEditorChange(value) {
console.log(value);
this.setState({ contentMode: value })
// console.log(value);
this.setState({ mailcontentModeActive: value })
// setContent(value)
}
......@@ -199,8 +372,8 @@ class MaintenanceMode extends Component {
}
handleEditorChangeEmail(value) {
console.log(value);
this.setState({ contentEmail: value })
// console.log(value);
this.setState({ mailcontentModeNonActive: value })
// setContent(value)
}
......@@ -266,7 +439,7 @@ class MaintenanceMode extends Component {
render() {
const loadingComponent = (
<div style={{ position: 'fixed', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
<div style={{ position: 'absolute', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
<PropagateLoader
// css={override}
size={20}
......@@ -283,8 +456,8 @@ class MaintenanceMode extends Component {
{this.state.messageAlert}
</Alert>
</Snackbar>
this.state.load && (
<div>
{this.state.loading && loadingComponent}
<div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
<Typography style={{ fontSize: '16px', color: 'white' }}>Maintenance Mode</Typography>
</div>
......@@ -295,7 +468,7 @@ class MaintenanceMode extends Component {
<Typography style={{ fontSize: '17px', color: '#4b4b4b', margin: 10 }}>General Setting - Maintenance Mode</Typography>
</div>
<div style={{ marginTop: 5, marginRight: 30 }}>
<button
{/* <button
type="button"
style={{ background: 'white' }}
onClick={() => Alert('Coming Soon !')}
......@@ -303,10 +476,10 @@ class MaintenanceMode extends Component {
<div style={{ width: 102, height: 30, backgroundColor: '#fff', border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center', marginRight: 15 }}>
<span style={{ color: '#354960', fontSize: 11 }}>Batal</span>
</div>
</button>
</button> */}
<button
type="button"
onClick={() => Alert('Coming Soon !')}
onClick={() => this.state.maintenanceID === null ? this.handleCreate() : this.handleEdit()}
>
<div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#fff', fontSize: 11 }}>Simpan</span>
......@@ -324,18 +497,18 @@ class MaintenanceMode extends Component {
<button
type="button"
style={{ background: '#fff', marginRight: 15 }}
onClick={() => this.setState({ isModeNonActive: true, isModeActive: false })}
onClick={() => this.setState({ maintenanceStatus: 0 })}
>
<div style={{ width: 102, height: 30, backgroundColor: this.state.isModeNonActive ? 'green' : '#fff', border: this.state.isModeNonActive ? 'none' : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.isModeNonActive ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Non Active</span>
<div style={{ width: 102, height: 30, backgroundColor: this.state.maintenanceStatus === 0 ? 'green' : '#fff', border: this.state.maintenanceStatus === 0 ? 'none' : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.maintenanceStatus === 0 ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Non Active</span>
</div>
</button>
<button
type="button"
onClick={() => this.setState({ isModeActive: true, isModeNonActive: false })}
onClick={() => this.setState({ maintenanceStatus: 1 })}
>
<div style={{ width: 102, height: 30, backgroundColor: this.state.isModeActive ? 'red' : '#fff', border: this.state.isModeActive ? null : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.isModeActive ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Active</span>
<div style={{ width: 102, height: 30, backgroundColor: this.state.maintenanceStatus === 1 ? 'red' : '#fff', border: this.state.maintenanceStatus === 1 ? null : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.maintenanceStatus === 1 ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Active</span>
</div>
</button>
</div>
......@@ -349,6 +522,10 @@ class MaintenanceMode extends Component {
<div>
<TextField
variant="outlined"
id="headline"
name="headline"
value={this.state.headline}
onChange={(e) => this.handleChange(e, '')}
style={{ width: '80%' }}
inputProps={{ style: { color: '#656565', height: 0 } }}
/>
......@@ -361,9 +538,13 @@ class MaintenanceMode extends Component {
<div>
<TextField
variant="outlined"
id="maintenanceContent"
name="maintenanceContent"
onChange={(e) => this.handleChange(e, '')}
value={this.state.maintenanceContent}
style={{ width: '80%' }}
multiline
maxRows={6}
maxRows={4}
inputProps={{ style: { color: '#656565' } }}
/>
</div>
......@@ -377,18 +558,18 @@ class MaintenanceMode extends Component {
<button
type="button"
style={{ background: '#fff', marginRight: 15 }}
onClick={() => this.setState({ isModeActiveNo: true, isModeActiveYes: false })}
onClick={() => this.setState({ mailStatusActive: 0 })}
>
<div style={{ width: 102, height: 30, backgroundColor: this.state.isModeActiveNo ? 'red' : '#fff', border: this.state.isModeActiveNo ? 'none' : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.isModeActiveNo ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Tidak</span>
<div style={{ width: 102, height: 30, backgroundColor: this.state.mailStatusActive === 0 ? 'red' : '#fff', border: this.state.mailStatusActive === 0 ? 'none' : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.mailStatusActive === 0 ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Tidak</span>
</div>
</button>
<button
type="button"
onClick={() => this.setState({ isModeActiveYes: true, isModeActiveNo: false })}
onClick={() => this.setState({ mailStatusActive: 1 })}
>
<div style={{ width: 102, height: 30, backgroundColor: this.state.isModeActiveYes ? 'green' : '#fff', border: this.state.isModeActiveYes ? null : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.isModeActiveYes ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Ya</span>
<div style={{ width: 102, height: 30, backgroundColor: this.state.mailStatusActive === 1 ? 'green' : '#fff', border: this.state.mailStatusActive === 1 ? null : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.mailStatusActive === 1 ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Ya</span>
</div>
</button>
</div>
......@@ -400,6 +581,10 @@ class MaintenanceMode extends Component {
<div>
<TextField
variant="outlined"
id="subjectMailActive"
name="subjectMailActive"
onChange={(e) => this.handleChange(e, '')}
value={this.state.subjectMailActive}
style={{ width: '80%' }}
inputProps={{ style: { color: '#656565', height: 0 } }}
/>
......@@ -432,7 +617,7 @@ class MaintenanceMode extends Component {
// Other option
}}
onChange={this.handleEditorChange.bind(this)}
setContents={this.state.contentMode}
setContents={this.state.mailcontentModeActive}
onDrop={this.handleDrop.bind(this)}
imageUploadHandler={this.imageUploadHandler.bind(this)}
onBlur={this.handleBlur.bind(this)}
......@@ -451,18 +636,18 @@ class MaintenanceMode extends Component {
<button
type="button"
style={{ background: '#fff', marginRight: 15 }}
onClick={() => this.setState({ isModeNonActiveNo: true, isModeNonActiveYes: false })}
onClick={() => this.setState({ mailStatusNonActive: 0 })}
>
<div style={{ width: 102, height: 30, backgroundColor: this.state.isModeNonActiveNo ? 'red' : '#fff', border: this.state.isModeNonActiveNo ? 'none' : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.isModeNonActiveNo ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Tidak</span>
<div style={{ width: 102, height: 30, backgroundColor: this.state.mailStatusNonActive === 0 ? 'red' : '#fff', border: this.state.mailStatusNonActive === 0 ? 'none' : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.mailStatusNonActive === 0 ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Tidak</span>
</div>
</button>
<button
type="button"
onClick={() => this.setState({ isModeNonActiveYes: true, isModeNonActiveNo: false })}
onClick={() => this.setState({ mailStatusNonActive: 1 })}
>
<div style={{ width: 102, height: 30, backgroundColor: this.state.isModeNonActiveYes ? 'green' : '#fff', border: this.state.isModeNonActiveYes ? null : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.isModeNonActiveYes ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Ya</span>
<div style={{ width: 102, height: 30, backgroundColor: this.state.mailStatusNonActive === 1 ? 'green' : '#fff', border: this.state.mailStatusNonActive === 1 ? null : 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: this.state.mailStatusNonActive === 1 ? 'white' : '#354960', fontSize: 11, fontWeight: 'bold' }}>Ya</span>
</div>
</button>
</div>
......@@ -474,6 +659,10 @@ class MaintenanceMode extends Component {
<div>
<TextField
variant="outlined"
id="subjectMailNonActive"
name="subjectMailNonActive"
onChange={(e) => this.handleChange(e, '')}
value={this.state.subjectMailNonActive}
style={{ width: '80%' }}
inputProps={{ style: { color: '#656565', height: 0 } }}
/>
......@@ -506,7 +695,7 @@ class MaintenanceMode extends Component {
// Other option
}}
onChange={this.handleEditorChangeEmail.bind(this)}
setContents={this.state.contentEmail}
setContents={this.state.mailcontentModeNonActive}
onDrop={this.handleDropEmail.bind(this)}
imageUploadHandler={this.imageUploadHandlerEmail.bind(this)}
onBlur={this.handleBlurEmail.bind(this)}
......@@ -521,7 +710,6 @@ class MaintenanceMode extends Component {
</Paper>
</div>
</div>
)
</div>
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment