wahyuun
1 year ago
4 changed files with 298 additions and 276 deletions
@ -1,99 +1,99 @@
|
||||
import React, { useEffect, useState } from 'react' |
||||
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; |
||||
import { Button, Form, FormGroup, Label, Input, Col, Row } from 'reactstrap'; |
||||
import { Select } from 'antd'; |
||||
import moment from 'moment'; |
||||
import 'antd/dist/antd.css'; |
||||
|
||||
const { Option } = Select |
||||
|
||||
const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, dataMenu}) => { |
||||
const [id, setId] = useState(0) |
||||
const [name, setName] = useState('') |
||||
const [descripton, setDescription] = useState('') |
||||
const [status, setStatus] = useState('') |
||||
|
||||
|
||||
useEffect(()=> { |
||||
if(typeDialog==="Edit"){ |
||||
console.log("data edit", dataEdit) |
||||
setId(dataEdit.id) |
||||
setName(dataEdit.nama) |
||||
setDescription(dataEdit.keterangan) |
||||
setStatus(dataEdit.status) |
||||
}else{ |
||||
setId(0) |
||||
setName('') |
||||
setDescription('') |
||||
setStatus('') |
||||
} |
||||
},[dataEdit,openDialog]) |
||||
|
||||
const handleSave = () => { |
||||
let data = ''; |
||||
if(typeDialog==="Save"){ |
||||
data = { |
||||
nama:name, |
||||
keterangan:descripton, |
||||
status |
||||
} |
||||
|
||||
closeDialog('save', data); |
||||
}else{ |
||||
data = { |
||||
id, |
||||
nama:name, |
||||
keterangan:descripton, |
||||
status |
||||
} |
||||
|
||||
|
||||
closeDialog('edit', data); |
||||
} |
||||
} |
||||
|
||||
const handleCancel = () => { |
||||
closeDialog('cancel', 'none') |
||||
setId(0) |
||||
setName('') |
||||
setDescription('') |
||||
setStatus('') |
||||
} |
||||
|
||||
|
||||
const renderForm = () => { |
||||
return( |
||||
<Form> |
||||
<FormGroup> |
||||
<Label className="capitalize">Nama Alert</Label> |
||||
<Input type="text" value={name} onChange={(e)=> setName(e.target.value)} placeholder={`Waspang tidak sesuai target..`}/> |
||||
</FormGroup> |
||||
<FormGroup> |
||||
<Label className="capitalize">Keterangan</Label> |
||||
<Input type="text" value={descripton} onChange={(e)=> setDescription(e.target.value)} placeholder={`Rencana vs actual tidak sesuai..`} /> |
||||
</FormGroup> |
||||
<FormGroup> |
||||
<Label className="capitalize">Status</Label> |
||||
<Input type="text" value={status} onChange={(e)=> setStatus(e.target.value)} placeholder={`Warning..`} /> |
||||
</FormGroup> |
||||
</Form> |
||||
) |
||||
} |
||||
|
||||
|
||||
return ( |
||||
<Modal size="lg" isOpen={openDialog} toggle={toggleDialog}> |
||||
<ModalHeader className="capitalize" toggle={closeDialog}>{typeDialog=="Save" ? `Tambah` : "Edit"} Config Alert</ModalHeader> |
||||
<ModalBody> |
||||
{renderForm()} |
||||
</ModalBody> |
||||
<ModalFooter> |
||||
<Button color="primary" onClick={() => handleSave()}>{typeDialog}</Button>{' '} |
||||
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Batal</Button> |
||||
</ModalFooter> |
||||
</Modal> |
||||
) |
||||
|
||||
} |
||||
|
||||
export default DialogForm; |
||||
import React, { useEffect, useState } from 'react' |
||||
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; |
||||
import { Button, Form, FormGroup, Label, Input, Col, Row } from 'reactstrap'; |
||||
import { Select } from 'antd'; |
||||
import moment from 'moment'; |
||||
import 'antd/dist/antd.css'; |
||||
|
||||
const { Option } = Select |
||||
|
||||
const DialogForm = ({openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, dataMenu}) => { |
||||
const [id, setId] = useState(0) |
||||
const [name, setName] = useState('') |
||||
const [descripton, setDescription] = useState('') |
||||
const [status, setStatus] = useState('') |
||||
|
||||
|
||||
useEffect(()=> { |
||||
if(typeDialog==="Edit"){ |
||||
console.log("data edit", dataEdit) |
||||
setId(dataEdit.id) |
||||
setName(dataEdit.nama) |
||||
setDescription(dataEdit.keterangan) |
||||
setStatus(dataEdit.status) |
||||
}else{ |
||||
setId(0) |
||||
setName('') |
||||
setDescription('') |
||||
setStatus('') |
||||
} |
||||
},[dataEdit,openDialog]) |
||||
|
||||
const handleSave = () => { |
||||
let data = ''; |
||||
if(typeDialog==="Save"){ |
||||
data = { |
||||
nama:name, |
||||
keterangan:descripton, |
||||
status |
||||
} |
||||
|
||||
closeDialog('save', data); |
||||
}else{ |
||||
data = { |
||||
id, |
||||
nama:name, |
||||
keterangan:descripton, |
||||
status |
||||
} |
||||
|
||||
|
||||
closeDialog('edit', data); |
||||
} |
||||
} |
||||
|
||||
const handleCancel = () => { |
||||
closeDialog('cancel', 'none') |
||||
setId(0) |
||||
setName('') |
||||
setDescription('') |
||||
setStatus('') |
||||
} |
||||
|
||||
|
||||
const renderForm = () => { |
||||
return( |
||||
<Form> |
||||
<FormGroup> |
||||
<Label className="capitalize">Nama Alert</Label> |
||||
<Input type="text" value={name} onChange={(e)=> setName(e.target.value)} placeholder={`Waspang tidak sesuai target..`}/> |
||||
</FormGroup> |
||||
<FormGroup> |
||||
<Label className="capitalize">Keterangan</Label> |
||||
<Input type="text" value={descripton} onChange={(e)=> setDescription(e.target.value)} placeholder={`Rencana vs actual tidak sesuai..`} /> |
||||
</FormGroup> |
||||
<FormGroup> |
||||
<Label className="capitalize">Status</Label> |
||||
<Input type="text" value={status} onChange={(e)=> setStatus(e.target.value)} placeholder={`Warning..`} /> |
||||
</FormGroup> |
||||
</Form> |
||||
) |
||||
} |
||||
|
||||
|
||||
return ( |
||||
<Modal size="lg" isOpen={openDialog} toggle={toggleDialog}> |
||||
<ModalHeader className="capitalize" toggle={closeDialog}>{typeDialog=="Save" ? `Tambah` : "Edit"} Config Alert</ModalHeader> |
||||
<ModalBody> |
||||
{renderForm()} |
||||
</ModalBody> |
||||
<ModalFooter> |
||||
<Button color="primary" onClick={() => handleSave()}>{typeDialog}</Button>{' '} |
||||
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Batal</Button> |
||||
</ModalFooter> |
||||
</Modal> |
||||
) |
||||
|
||||
} |
||||
|
||||
export default DialogForm; |
||||
|
@ -1,172 +1,172 @@
|
||||
import Bell from '@iconify/icons-ion/notifications-outline'; |
||||
import BellOff from '@iconify/icons-ion/notifications-off-outline'; |
||||
import React, { useState, useEffect } from 'react'; |
||||
import axios from 'axios'; |
||||
import { CALERTUSER_SEARCH,CONFIGALERT_SEARCH,CALERTUSER_DELETE, CALERTUSER_ADD } from '../../../const/ApiConst.js'; |
||||
import { Card as ACard,Row, Col, Switch } from 'antd'; |
||||
import { Card, CardBody, CardHeader, Input } from 'reactstrap'; |
||||
import { Icon } from '@iconify/react'; |
||||
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
||||
|
||||
const token = window.localStorage.getItem('token'); |
||||
const userID = window.localStorage.getItem('user_id'); |
||||
|
||||
const Index = ({params}) => { |
||||
|
||||
const [alertUser, setAlertUser] = useState([]) |
||||
const [checked, setChecked] = useState({}) |
||||
const [dataTable, setDatatable] = useState([]) |
||||
const [onSetSwitch, setOnSetSwitch] = useState(false) |
||||
const pageName = params.name; |
||||
|
||||
const config = { |
||||
headers: |
||||
{ |
||||
Authorization : `Bearer ${token}`, |
||||
"Content-type" : `application/json` |
||||
} |
||||
}; |
||||
|
||||
useEffect(()=> { |
||||
getDataConfigAlert(); |
||||
},[]) |
||||
|
||||
useEffect(() => { |
||||
getDataConfigAlertUser(); |
||||
},[dataTable]) |
||||
|
||||
const getDataConfigAlert = async () => { |
||||
const payload = { |
||||
"paging": {"start": 0, "length": -1}, |
||||
"columns": [ |
||||
{"name": "nama", "logic_operator": "ilike", "value": "", "operator": "AND"} |
||||
], |
||||
"joins": [], |
||||
"orders": {"columns": ["id"], "ascending": false} |
||||
} |
||||
|
||||
const result = await axios |
||||
.post(CONFIGALERT_SEARCH, payload, config) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if(result && result.data && result.data.code == 200){ |
||||
let resData = result.data.data |
||||
let checkedAlert = {} |
||||
resData.map((val, index) => { |
||||
checkedAlert[val.id] = false |
||||
}); |
||||
setChecked(checkedAlert); |
||||
setDatatable(resData); |
||||
}else{ |
||||
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const getDataConfigAlertUser = async () => { |
||||
const payload = { |
||||
"paging": {"start": 0, "length": -1}, |
||||
"columns": [ |
||||
{"name": "user_id", "logic_operator": "=", "value": localStorage.getItem('user_id'), "operator": "AND"} |
||||
], |
||||
"joins": [], |
||||
"orders": {"columns": ["id"], "ascending": false} |
||||
} |
||||
|
||||
const result = await axios |
||||
.post(CALERTUSER_SEARCH, payload, config) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if(result && result.data && result.data.code == 200){ |
||||
let resData = result.data.data |
||||
let configAlert = []; |
||||
resData.map((val, index) => { |
||||
configAlert.push(val.config_alert_id); |
||||
let indexRes = dataTable.findIndex(x => x.id === val.config_alert_id); |
||||
if(indexRes >= 0){ |
||||
let id = dataTable[indexRes].id; |
||||
let tempChecked = checked; |
||||
tempChecked[id] = true; |
||||
setChecked(tempChecked); |
||||
} |
||||
}); |
||||
window.localStorage.setItem('userConfigAlert', configAlert.join()); |
||||
setOnSetSwitch(false) |
||||
setAlertUser(result.data.data); |
||||
}else{ |
||||
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const onChange = (checked, id) => { |
||||
setOnSetSwitch(true) |
||||
if(checked){ |
||||
addConfigAlertUser(id); |
||||
}else{ |
||||
setDeleteConfigAlertUser(id) |
||||
} |
||||
} |
||||
|
||||
const addConfigAlertUser = async (id) => { |
||||
const formData = { |
||||
"user_id":parseInt(localStorage.getItem('user_id')), |
||||
"config_alert_id":id |
||||
} |
||||
|
||||
const result = await axios.post(CALERTUSER_ADD, formData, config) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if(result && result.data && result.data.code===200){ |
||||
getDataConfigAlertUser(); |
||||
} |
||||
} |
||||
|
||||
const setDeleteConfigAlertUser = async (id) => { |
||||
let indexCek = alertUser.findIndex(x => x.user_id === parseInt(localStorage.getItem('user_id')) && x.config_alert_id === id); |
||||
if(indexCek >= 0){ |
||||
let idAlert = alertUser[indexCek].id |
||||
deleteConfigAlertUser(idAlert) |
||||
} |
||||
} |
||||
|
||||
const deleteConfigAlertUser = async (id) => { |
||||
const url = CALERTUSER_DELETE(id) |
||||
const result = await axios.delete(url, config) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
if (result && result.data && result.data.code === 200) { |
||||
getDataConfigAlert(); |
||||
} |
||||
} |
||||
|
||||
return ( |
||||
<div> |
||||
<NotificationContainer /> |
||||
<Card> |
||||
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> |
||||
<h4 className="capitalize">{pageName}</h4> |
||||
</CardHeader> |
||||
<CardBody> |
||||
<Row gutter={16}> |
||||
{dataTable.map((val, index) => ( |
||||
<Col key={index} md={{span:5,offset:1}} xs={{span:11,offset:1}}> |
||||
<ACard style={{height:"100%"}} actions={[ |
||||
<Switch checked={checked[val.id] ? true : false} onChange={(checked) => onChange(checked, val.id)} disabled={onSetSwitch} />, |
||||
]}> |
||||
<div style={{height:'100%',width:'100%',display:'flex',justifyContent:'center', alignItems:'center', textAlign:'center', flexDirection:'column'}}> |
||||
<i style={{marginBottom:"25px"}}><Icon icon={checked[val.id] ? Bell : BellOff} color="black" width="100" height="100" /></i> |
||||
<p style={{marginBottom:"0"}}>{val.nama}</p> |
||||
</div> |
||||
</ACard> |
||||
</Col> |
||||
))} |
||||
</Row> |
||||
</CardBody> |
||||
</Card> |
||||
</div> |
||||
) |
||||
} |
||||
|
||||
export default Index; |
||||
import Bell from '@iconify/icons-ion/notifications-outline'; |
||||
import BellOff from '@iconify/icons-ion/notifications-off-outline'; |
||||
import React, { useState, useEffect } from 'react'; |
||||
import axios from 'axios'; |
||||
import { CALERTUSER_SEARCH,CONFIGALERT_SEARCH,CALERTUSER_DELETE, CALERTUSER_ADD } from '../../../const/ApiConst.js'; |
||||
import { Card as ACard,Row, Col, Switch } from 'antd'; |
||||
import { Card, CardBody, CardHeader, Input } from 'reactstrap'; |
||||
import { Icon } from '@iconify/react'; |
||||
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
||||
|
||||
const token = window.localStorage.getItem('token'); |
||||
const userID = window.localStorage.getItem('user_id'); |
||||
|
||||
const Index = ({params}) => { |
||||
|
||||
const [alertUser, setAlertUser] = useState([]) |
||||
const [checked, setChecked] = useState({}) |
||||
const [dataTable, setDatatable] = useState([]) |
||||
const [onSetSwitch, setOnSetSwitch] = useState(false) |
||||
const pageName = params.name; |
||||
|
||||
const config = { |
||||
headers: |
||||
{ |
||||
Authorization : `Bearer ${token}`, |
||||
"Content-type" : `application/json` |
||||
} |
||||
}; |
||||
|
||||
useEffect(()=> { |
||||
getDataConfigAlert(); |
||||
},[]) |
||||
|
||||
useEffect(() => { |
||||
getDataConfigAlertUser(); |
||||
},[dataTable]) |
||||
|
||||
const getDataConfigAlert = async () => { |
||||
const payload = { |
||||
"paging": {"start": 0, "length": -1}, |
||||
"columns": [ |
||||
{"name": "nama", "logic_operator": "ilike", "value": "", "operator": "AND"} |
||||
], |
||||
"joins": [], |
||||
"orders": {"columns": ["id"], "ascending": false} |
||||
} |
||||
|
||||
const result = await axios |
||||
.post(CONFIGALERT_SEARCH, payload, config) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if(result && result.data && result.data.code == 200){ |
||||
let resData = result.data.data |
||||
let checkedAlert = {} |
||||
resData.map((val, index) => { |
||||
checkedAlert[val.id] = false |
||||
}); |
||||
setChecked(checkedAlert); |
||||
setDatatable(resData); |
||||
}else{ |
||||
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const getDataConfigAlertUser = async () => { |
||||
const payload = { |
||||
"paging": {"start": 0, "length": -1}, |
||||
"columns": [ |
||||
{"name": "user_id", "logic_operator": "=", "value": localStorage.getItem('user_id'), "operator": "AND"} |
||||
], |
||||
"joins": [], |
||||
"orders": {"columns": ["id"], "ascending": false} |
||||
} |
||||
|
||||
const result = await axios |
||||
.post(CALERTUSER_SEARCH, payload, config) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if(result && result.data && result.data.code == 200){ |
||||
let resData = result.data.data |
||||
let configAlert = []; |
||||
resData.map((val, index) => { |
||||
configAlert.push(val.config_alert_id); |
||||
let indexRes = dataTable.findIndex(x => x.id === val.config_alert_id); |
||||
if(indexRes >= 0){ |
||||
let id = dataTable[indexRes].id; |
||||
let tempChecked = checked; |
||||
tempChecked[id] = true; |
||||
setChecked(tempChecked); |
||||
} |
||||
}); |
||||
window.localStorage.setItem('userConfigAlert', configAlert.join()); |
||||
setOnSetSwitch(false) |
||||
setAlertUser(result.data.data); |
||||
}else{ |
||||
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const onChange = (checked, id) => { |
||||
setOnSetSwitch(true) |
||||
if(checked){ |
||||
addConfigAlertUser(id); |
||||
}else{ |
||||
setDeleteConfigAlertUser(id) |
||||
} |
||||
} |
||||
|
||||
const addConfigAlertUser = async (id) => { |
||||
const formData = { |
||||
"user_id":parseInt(localStorage.getItem('user_id')), |
||||
"config_alert_id":id |
||||
} |
||||
|
||||
const result = await axios.post(CALERTUSER_ADD, formData, config) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if(result && result.data && result.data.code===200){ |
||||
getDataConfigAlertUser(); |
||||
} |
||||
} |
||||
|
||||
const setDeleteConfigAlertUser = async (id) => { |
||||
let indexCek = alertUser.findIndex(x => x.user_id === parseInt(localStorage.getItem('user_id')) && x.config_alert_id === id); |
||||
if(indexCek >= 0){ |
||||
let idAlert = alertUser[indexCek].id |
||||
deleteConfigAlertUser(idAlert) |
||||
} |
||||
} |
||||
|
||||
const deleteConfigAlertUser = async (id) => { |
||||
const url = CALERTUSER_DELETE(id) |
||||
const result = await axios.delete(url, config) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
if (result && result.data && result.data.code === 200) { |
||||
getDataConfigAlert(); |
||||
} |
||||
} |
||||
|
||||
return ( |
||||
<div> |
||||
<NotificationContainer /> |
||||
<Card> |
||||
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> |
||||
<h4 className="capitalize">{pageName}</h4> |
||||
</CardHeader> |
||||
<CardBody> |
||||
<Row gutter={16}> |
||||
{dataTable.map((val, index) => ( |
||||
<Col key={index} md={{span:5,offset:1}} xs={{span:11,offset:1}}> |
||||
<ACard style={{height:"100%"}} actions={[ |
||||
<Switch checked={checked[val.id] ? true : false} onChange={(checked) => onChange(checked, val.id)} disabled={onSetSwitch} />, |
||||
]}> |
||||
<div style={{height:'100%',width:'100%',display:'flex',justifyContent:'center', alignItems:'center', textAlign:'center', flexDirection:'column'}}> |
||||
<i style={{marginBottom:"25px"}}><Icon icon={checked[val.id] ? Bell : BellOff} color="black" width="100" height="100" /></i> |
||||
<p style={{marginBottom:"0"}}>{val.nama}</p> |
||||
</div> |
||||
</ACard> |
||||
</Col> |
||||
))} |
||||
</Row> |
||||
</CardBody> |
||||
</Card> |
||||
</div> |
||||
) |
||||
} |
||||
|
||||
export default Index; |
||||
|
Loading…
Reference in new issue