import { useRef, useState } from 'react' import { useLocation } from 'react-router-dom' import { Space, Flex, Card, Modal } from 'antd' 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 ObjectForm from '../../common/ObjectForm' import EditButtons from '../../common/EditButtons' import LockIndicator from '../../common/LockIndicator.jsx' import InfoCircleIcon from '../../../Icons/InfoCircleIcon.jsx' import NoteIcon from '../../../Icons/NoteIcon.jsx' import AuditLogIcon from '../../../Icons/AuditLogIcon.jsx' import ActionHandler from '../../common/ActionHandler.jsx' import ObjectActions from '../../common/ObjectActions.jsx' import ObjectTable from '../../common/ObjectTable.jsx' import InfoCollapsePlaceholder from '../../common/InfoCollapsePlaceholder.jsx' import DocumentPrintButton from '../../common/DocumentPrintButton.jsx' import UserNotifierToggle from '../../common/UserNotifierToggle.jsx' import ScrollBox from '../../common/ScrollBox.jsx' import PartSkuIcon from '../../../Icons/PartSkuIcon.jsx' import NewPartSku from '../PartSkus/NewPartSku' const PartInfo = () => { const location = useLocation() const objectFormRef = useRef(null) const actionHandlerRef = useRef(null) const partId = new URLSearchParams(location.search).get('partId') const [newPartSkuOpen, setNewPartSkuOpen] = useState(false) const partSkusTableRef = useRef() const [collapseState, updateCollapseState] = useCollapseState('PartInfo', { info: true, partSkus: 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 }, newPartSku: () => { setNewPartSkuOpen(true) return true }, 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} /> { setEditFormState((prev) => ({ ...prev, ...state })) }} > {({ loading, isEditing, objectData }) => ( } active={collapseState.info} onToggle={(expanded) => updateCollapseState('info', expanded) } collapseKey='info' > )} } active={collapseState.partSkus} onToggle={(expanded) => updateCollapseState('partSkus', expanded) } collapseKey='partSkus' > {objectFormState.loading ? ( ) : ( )} setNewPartSkuOpen(false)} destroyOnClose > { setNewPartSkuOpen(false) partSkusTableRef.current?.reload?.() }} reset={newPartSkuOpen} defaultValues={{ part: partId ? { _id: partId } : 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 PartInfo