// src/partStocks.js import React, { useState, useContext, useRef } from 'react' import { useNavigate } from 'react-router-dom' import { Button, Flex, Space, Modal, message, Dropdown, Typography } from 'antd' import { AuthContext } from '../context/AuthContext' import NewPartStock from './PartStocks/NewPartStock' import IdDisplay from '../common/IdDisplay' import PartStockIcon from '../../Icons/PartStockIcon' import InfoCircleIcon from '../../Icons/InfoCircleIcon' import PlusIcon from '../../Icons/PlusIcon' import ReloadIcon from '../../Icons/ReloadIcon' import PartStockState from '../common/PartStockState' import TimeDisplay from '../common/TimeDisplay' import ObjectTable from '../common/ObjectTable' import config from '../../../config' const { Text } = Typography const PartStocks = () => { const [messageApi, contextHolder] = message.useMessage() const navigate = useNavigate() const tableRef = useRef() const [newPartStockOpen, setNewPartStockOpen] = useState(false) const { authenticated } = useContext(AuthContext) const getPartStockActionItems = (id) => { return { items: [ { label: 'Info', key: 'info', icon: } ], onClick: ({ key }) => { if (key === 'info') { navigate(`/dashboard/inventory/partstocks/info?partStockId=${id}`) } } } } // Column definitions const columns = [ { title: '', dataIndex: '', key: 'icon', width: 40, fixed: 'left', render: () => }, { title: 'Part Name', dataIndex: 'part', key: 'name', width: 200, fixed: 'left', render: (part) => {part.name} }, { title: 'ID', dataIndex: '_id', key: 'id', width: 180, render: (text) => ( ) }, { title: 'State', key: 'state', width: 350, render: (record) => }, { title: 'Current Quantity', dataIndex: 'currentQuantity', key: 'currentQuantity', width: 160, render: (currentQuantity) => {currentQuantity} }, { title: 'Starting Quantity', dataIndex: 'startingQuantity', key: 'startingQuantity', width: 160, render: (startingQuantity) => {startingQuantity} }, { title: 'Created At', dataIndex: 'createdAt', key: 'createdAt', width: 180, render: (createdAt) => { if (createdAt) { return } else { return 'n/a' } } }, { title: 'Updated At', dataIndex: 'updatedAt', key: 'updatedAt', width: 180, render: (updatedAt) => { if (updatedAt) { return } else { return 'n/a' } } }, { title: 'Actions', key: 'actions', fixed: 'right', width: 150, render: (text, record) => { return ( ) } } ] const actionItems = { items: [ { label: 'New Part Stock', key: 'newPartStock', icon: }, { type: 'divider' }, { label: 'Reload List', key: 'reloadList', icon: } ], onClick: ({ key }) => { if (key === 'reloadList') { tableRef.current?.reload() } else if (key === 'newPartStock') { setNewPartStockOpen(true) } } } return ( <> {contextHolder} { setNewPartStockOpen(false) }} destroyOnHidden={true} > { setNewPartStockOpen(false) messageApi.success('New part stock created successfully.') tableRef.current?.reload() }} reset={newPartStockOpen} /> ) } export default PartStocks