Browse Source

change notification alert, clean code useState, clean payload

pull/2/head
wahyuun 1 year ago
parent
commit
4e9278d90f
  1. 34
      src/views/SimproV2/Divisi/index.js

34
src/views/SimproV2/Divisi/index.js

@ -47,18 +47,14 @@ const ProjectType = ({ params }) => {
const [idDelete, setIdDelete] = useState(0)
const [openDialog, setOpenDialog] = useState(false)
const [rowsPerPage, setRowsPerPage] = useState(10)
const [search, setSearch] = useState('')
const [search, setSearch] = useState("")
const [totalPage, setTotalPage] = useState(0)
const [typeDialog, setTypeDialog] = useState('Save')
const [dataDivisions, setDataDivisions] = useState([])
const { t } = useTranslation()
useEffect(() => {
getListDivision()
}, [])
useEffect(() => {
getDataProjectType()
getDataProjectType();
}, [currentPage, rowsPerPage, search])
useEffect(() => {
@ -87,15 +83,15 @@ const ProjectType = ({ params }) => {
const getDataProjectType = async () => {
let start = 0;
if (currentPage !== 1 && currentPage > 1) {
start = (currentPage * rowsPerPage) - rowsPerPage
start = currentPage * rowsPerPage - rowsPerPage;
}
const payload = {
"columns": [
columns: [
{
"name": "name",
"logic_operator": "ilike",
"value": search,
"operator": "AND"
name: "name",
logic_operator: "ilike",
value: search,
operator: "AND"
}
],
"orders": {
@ -115,10 +111,8 @@ const ProjectType = ({ params }) => {
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
result.data.data.map((res) => {
res.key = res.id.toString()
});
setDatatable(result.data.data);
let dataRes = result.data.data || [];
setDatatable(dataRes);
setTotalPage(result.data.totalRecord);
} else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
@ -220,9 +214,9 @@ const ProjectType = ({ params }) => {
.catch((error) => error.response);
if (result && result.data && result.data.code === 200) {
getDataProjectType()
NotificationManager.success(`Data berhasil ditambah`, 'Success!!');
NotificationManager.success(`Data berhasil ditambahkan`, 'Success!!');
} else {
NotificationManager.error(`${result.data.message}`, 'Failed!!');
NotificationManager.error(`Data gagal ditambahkan`, 'Failed!!');
}
}
@ -234,9 +228,9 @@ const ProjectType = ({ params }) => {
.catch((error) => error.response);
if (result && result.data && result.data.code === 200) {
getDataProjectType();
NotificationManager.success(`Data berhasil diedit`, 'Success!!');
NotificationManager.success(`Data berhasil diubah`, 'Success!!');
} else {
NotificationManager.error(`Data gagal di edit`, `Failed!!`);
NotificationManager.error(`Data gagal diubah`, `Failed!!`);
}
}

Loading…
Cancel
Save