import { DatatablePrime } from '@/components/Datatables' import { DialogDelete } from '@/components/Dialog' import FormUnitKerja from '@/components/Form/UnitKerja' import { Belakang } from '@/components/Layouts' import { Judul } from '@/components/TextCustom' import { UnitKerjaDelete, UnitKerjaGetOne, UnitKerjaList } from '@/services/referensi/unitKerja-service' import Head from 'next/head' import { Button } from 'primereact/button' import { Column } from 'primereact/column' import { Toast } from 'primereact/toast' import { useEffect, useRef, useState } from 'react' export default function UnitKerja() { const toast = useRef(null) const [data, setData] = useState([]) const [dialogForm, setDialogForm] = useState(false) const [dataEdit, setDataEdit] = useState([]) const [refresh, setRefresh] = useState(0) const [search, setSearch] = useState('') const [dialogDelete, setDialogDelete] = useState({}) useEffect(() => { let params = { draw: 0 } if (search !== null && search !== '') { params.search = search } else { params.search = '' } UnitKerjaList(params).then((res) => setData(res.data)) }, [search, refresh]) const editUnitKerja = (data) => { UnitKerjaGetOne({ ref_id: data.ref_id }).then((res) => { if (res.status === 'ok') { setDataEdit(res.data) setDialogForm(true) } else { console.log(res.message) } }) } const deleteUnitKerja = () => { UnitKerjaDelete({ ref_id: dialogDelete.ref_id }).then((res) => { if (res.status === 'success') { setRefresh(Math.random) setDialogDelete({ visible: false }) toast.current.show({ severity: 'success', detail: res.message, closable: false, }) } else { setDialogDelete({ visible: false }) toast.current.show({ severity: 'error', detail: res.message, closable: false, }) } }) } const actionBodyTemplate = (rowData) => { return (
) } return ( <> Unit Kerja Unit Kerja {dialogDelete.visible === true && ( )} ) }