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

Loading…
Cancel
Save