import { useRef, useState } from 'react' import { useLocation } from 'react-router-dom' import { Space, Flex, Card, Modal } from 'antd' import { LoadingOutlined } from '@ant-design/icons' import loglevel from 'loglevel' import config from '../../../../config' import useCollapseState from '../../hooks/useCollapseState' import NotesPanel from '../../common/NotesPanel' import InfoCollapse from '../../common/InfoCollapse' import ObjectInfo from '../../common/ObjectInfo' import ViewButton from '../../common/ViewButton' import InfoCircleIcon from '../../../Icons/InfoCircleIcon.jsx' import NoteIcon from '../../../Icons/NoteIcon.jsx' import AuditLogIcon from '../../../Icons/AuditLogIcon.jsx' import ObjectForm from '../../common/ObjectForm' import EditButtons from '../../common/EditButtons' import LockIndicator from '../../common/LockIndicator.jsx' import ActionHandler from '../../common/ActionHandler' import ObjectActions from '../../common/ObjectActions.jsx' import ObjectTable from '../../common/ObjectTable.jsx' import InfoCollapsePlaceholder from '../../common/InfoCollapsePlaceholder.jsx' import FilamentIcon from '../../../Icons/FilamentIcon.jsx' import FilamentSkuIcon from '../../../Icons/FilamentSkuIcon.jsx' import DocumentPrintButton from '../../common/DocumentPrintButton.jsx' import ScrollBox from '../../common/ScrollBox.jsx' import UserNotifierToggle from '../../common/UserNotifierToggle.jsx' import NewFilamentSku from '../FilamentSkus/NewFilamentSku' const log = loglevel.getLogger('FilamentInfo') log.setLevel(config.logLevel) const FilamentInfo = () => { const location = useLocation() const objectFormRef = useRef(null) const actionHandlerRef = useRef(null) const filamentId = new URLSearchParams(location.search).get('filamentId') const [newFilamentSkuOpen, setNewFilamentSkuOpen] = useState(false) const filamentSkusTableRef = useRef() const [collapseState, updateCollapseState] = useCollapseState( 'FilamentInfo', { info: true, filamentSkus: true, stocks: true, notes: true, auditLogs: true } ) const [objectFormState, setEditFormState] = useState({ isEditing: false, editLoading: false, formValid: false, lock: null, loading: false, objectData: {} }) const actions = { reload: () => { objectFormRef?.current?.fetchObject?.() return true }, newFilamentSku: () => { setNewFilamentSkuOpen(true) return false }, edit: () => { objectFormRef?.current?.startEditing?.() return false }, cancelEdit: () => { objectFormRef?.current?.cancelEditing?.() return true }, finishEdit: () => { objectFormRef?.current?.handleUpdate?.() return true } } return ( <> { actionHandlerRef.current.callAction('finishEdit') }} cancelEditing={() => { actionHandlerRef.current.callAction('cancelEdit') }} startEditing={() => { actionHandlerRef.current.callAction('edit') }} editLoading={objectFormState.editLoading} formValid={objectFormState.formValid} disabled={objectFormState.lock?.locked || objectFormState.loading} loading={objectFormState.editLoading} /> } active={collapseState.info} onToggle={(expanded) => updateCollapseState('info', expanded)} collapseKey='info' > { setEditFormState((prev) => ({ ...prev, ...state })) }} > {({ loading, isEditing, objectData }) => { return ( } isEditing={isEditing} type='filament' objectData={objectData} /> ) }} } active={collapseState.filamentSkus} onToggle={(expanded) => updateCollapseState('filamentSkus', expanded) } collapseKey='filamentSkus' > {objectFormState.loading ? ( ) : ( )} } active={collapseState.stocks} onToggle={(expanded) => updateCollapseState('stocks', expanded)} collapseKey='stocks' > {objectFormState.loading ? ( ) : ( )} setNewFilamentSkuOpen(false)} destroyOnClose > { setNewFilamentSkuOpen(false) filamentSkusTableRef.current?.reload?.() }} reset={newFilamentSkuOpen} defaultValues={{ filament: filamentId ? { _id: filamentId } : undefined }} /> } active={collapseState.notes} onToggle={(expanded) => updateCollapseState('notes', expanded)} collapseKey='notes' > } active={collapseState.auditLogs} onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } collapseKey='auditLogs' > {objectFormState.loading ? ( ) : ( )} ) } export default FilamentInfo