Tom Butcher 291d5e438c Add PostFilamentStock Component and Update FilamentStock Model
- Introduced the PostFilamentStock component to handle posting filament stock with confirmation dialog and loading state management.
- Updated NewFilamentStock component to change the default state from 'unconsumed' to 'draft'.
- Enhanced FilamentStock model by adding 'postedAt' field and integrating the PostFilamentStock component into the actions for posting filament stocks.
- Improved visibility and disabled state logic for editing and posting actions based on filament stock state.
2026-09-01 17:26:15 +01:00

47 lines
1.3 KiB
JavaScript

import { useState, useContext } from 'react'
import PropTypes from 'prop-types'
import { ApiServerContext } from '../../context/ApiServerContext'
import { message } from 'antd'
import MessageDialogView from '../../common/MessageDialogView.jsx'
const PostFilamentStock = ({ onOk, objectData }) => {
const [postLoading, setPostLoading] = useState(false)
const { sendObjectFunction } = useContext(ApiServerContext)
const handlePost = async () => {
setPostLoading(true)
try {
const result = await sendObjectFunction(
objectData._id,
'FilamentStock',
'post'
)
if (result) {
message.success('Filament stock posted successfully')
onOk(result)
}
} catch (error) {
console.error('Error posting filament stock:', error)
} finally {
setPostLoading(false)
}
}
return (
<MessageDialogView
title={'Are you sure you want to post this filament stock?'}
description={`Posting filament stock ${objectData?.name || objectData?._reference || objectData?._id} will finalize it and make it read-only.`}
onOk={handlePost}
okText='Post'
okLoading={postLoading}
/>
)
}
PostFilamentStock.propTypes = {
onOk: PropTypes.func.isRequired,
objectData: PropTypes.object
}
export default PostFilamentStock