import { useRef, useState } from 'react' import { useLocation } from 'react-router-dom' import { Space, Flex, Modal } from 'antd' 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.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 PublishListingVarient from './PublishListingVarient.jsx' import UnpublishListingVarient from './UnpublishListingVarient.jsx' import { Card } from 'antd' const log = loglevel.getLogger('ListingVarientInfo') log.setLevel(config.logLevel) const ListingVarientInfo = () => { const location = useLocation() const objectFormRef = useRef(null) const actionHandlerRef = useRef(null) const listingVarientId = new URLSearchParams(location.search).get( 'listingVarientId' ) const [publishOpen, setPublishOpen] = useState(false) const [unpublishOpen, setUnpublishOpen] = useState(false) const [collapseState, updateCollapseState] = useCollapseState( 'ListingVarientInfo', { info: 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?.handleFetchObject?.() return true }, edit: () => { objectFormRef?.current?.startEditing?.() return false }, cancelEdit: () => { objectFormRef?.current?.cancelEditing?.() return true }, finishEdit: () => { objectFormRef?.current?.handleUpdate?.() return true }, delete: () => { objectFormRef?.current?.handleDelete?.() return true }, publish: () => { setPublishOpen(true) return true }, unpublish: () => { setUnpublishOpen(true) 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.notes} onToggle={(expanded) => updateCollapseState('notes', expanded)} collapseKey='notes' > } active={collapseState.auditLogs} onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } collapseKey='auditLogs' > {objectFormState.loading ? ( ) : ( )} setPublishOpen(false)} width={515} footer={null} destroyOnHidden={true} centered={true} > { setPublishOpen(false) actions.reload() }} /> setUnpublishOpen(false)} width={515} footer={null} destroyOnHidden={true} centered={true} > { setUnpublishOpen(false) actions.reload() }} /> ) } export default ListingVarientInfo