import { useContext, useRef, useState } from 'react'
import { Button, Dropdown, Flex, Modal, Space } from 'antd'
import NewPrinterProfile, {
EditPrinterProfile
} from './PrinterProfiles/NewPrinterProfile'
import ColumnViewButton from '../common/ColumnViewButton'
import ExportListButton from '../common/ExportListButton'
import FilterSidebarButton from '../common/FilterSidebarButton'
import ObjectTable from '../common/ObjectTable'
import ObjectTableViewButton from '../common/ObjectTableViewButton'
import { ApiServerContext } from '../context/ApiServerContext'
import PlusIcon from '../../Icons/PlusIcon'
import ReloadIcon from '../../Icons/ReloadIcon'
import useColumnVisibility from '../hooks/useColumnVisibility'
import useFilterSidebarVisibility from '../hooks/useFilterSidebarVisibility'
import useViewMode from '../hooks/useViewMode'
const PrinterProfiles = () => {
const { deleteObject } = useContext(ApiServerContext)
const [profileModal, setProfileModal] = useState({
open: false,
profileId: null
})
const tableRef = useRef()
const [viewMode, setViewMode] = useViewMode('PrinterProfiles')
const [columnVisibility, setColumnVisibility] =
useColumnVisibility('printerProfile')
const [showFilterSidebar, setShowFilterSidebar] =
useFilterSidebarVisibility('PrinterProfiles')
const actionItems = {
items: [
{
label: 'New Printer Profile',
key: 'newPrinterProfile',
icon:
},
{ type: 'divider' },
{
label: 'Reload List',
key: 'reloadList',
icon:
}
],
onClick: ({ key }) => {
if (key === 'reloadList') {
tableRef.current?.reload()
} else if (key === 'newPrinterProfile') {
setProfileModal({ open: true, profileId: null })
}
}
}
const handleRowAction = (action, profile) => {
if (action.name === 'edit') {
setProfileModal({ open: true, profileId: profile._id })
return true
}
if (action.name === 'delete') {
Modal.confirm({
title: 'Delete printer profile?',
content: `This will permanently delete ${profile.name || profile._reference}.`,
okText: 'Delete',
okType: 'danger',
onOk: async () => {
await deleteObject(profile._id, 'printerProfile')
await tableRef.current?.reload()
}
})
return true
}
return false
}
return (
<>
setShowFilterSidebar(!showFilterSidebar)}
/>
setProfileModal({ open: false, profileId: null })}
destroyOnHidden
>
{profileModal.open &&
(profileModal.profileId ? (
{
setProfileModal({ open: false, profileId: null })
tableRef.current?.reload()
}}
/>
) : (
{
setProfileModal({ open: false, profileId: null })
tableRef.current?.reload()
}}
/>
))}
>
)
}
export default PrinterProfiles