Add Acknowledge, Cancel, and Post Purchase Order components
- Introduced AcknowledgePurchaseOrder, CancelPurchaseOrder, and PostPurchaseOrder components for managing purchase order actions. - Each component includes a confirmation dialog and integrates with the ApiServerContext for handling respective operations. - Added loading states and success messages for user feedback upon successful actions.
This commit is contained in:
parent
f83069a7fb
commit
1b6137fe77
@ -0,0 +1,46 @@
|
|||||||
|
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 AcknowledgePurchaseOrder = ({ onOk, objectData }) => {
|
||||||
|
const [acknowledgeLoading, setAcknowledgeLoading] = useState(false)
|
||||||
|
const { sendObjectFunction } = useContext(ApiServerContext)
|
||||||
|
|
||||||
|
const handleAcknowledge = async () => {
|
||||||
|
setAcknowledgeLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await sendObjectFunction(
|
||||||
|
objectData._id,
|
||||||
|
'PurchaseOrder',
|
||||||
|
'acknowledge'
|
||||||
|
)
|
||||||
|
if (result) {
|
||||||
|
message.success('Purchase order acknowledged successfully')
|
||||||
|
onOk(result)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error acknowledging purchase order:', error)
|
||||||
|
} finally {
|
||||||
|
setAcknowledgeLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MessageDialogView
|
||||||
|
title={'Are you sure you want to acknowledge this purchase order?'}
|
||||||
|
description={`Acknowledging purchase order ${objectData?.name || objectData?._reference || objectData?._id} will update its status to acknowledged.`}
|
||||||
|
onOk={handleAcknowledge}
|
||||||
|
okText='Acknowledge'
|
||||||
|
okLoading={acknowledgeLoading}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
AcknowledgePurchaseOrder.propTypes = {
|
||||||
|
onOk: PropTypes.func.isRequired,
|
||||||
|
objectData: PropTypes.object
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AcknowledgePurchaseOrder
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
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 CancelPurchaseOrder = ({ onOk, objectData }) => {
|
||||||
|
const [cancelLoading, setCancelLoading] = useState(false)
|
||||||
|
const { sendObjectFunction } = useContext(ApiServerContext)
|
||||||
|
|
||||||
|
const handleCancel = async () => {
|
||||||
|
setCancelLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await sendObjectFunction(
|
||||||
|
objectData._id,
|
||||||
|
'PurchaseOrder',
|
||||||
|
'cancel'
|
||||||
|
)
|
||||||
|
if (result) {
|
||||||
|
message.success('Purchase order cancelled successfully')
|
||||||
|
onOk(result)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error cancelling purchase order:', error)
|
||||||
|
} finally {
|
||||||
|
setCancelLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MessageDialogView
|
||||||
|
title={'Are you sure you want to cancel this purchase order?'}
|
||||||
|
description={`Cancelling purchase order ${objectData?.name || objectData?._reference || objectData?._id} will update its status to cancelled.`}
|
||||||
|
onOk={handleCancel}
|
||||||
|
okText='Cancel'
|
||||||
|
okLoading={cancelLoading}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
CancelPurchaseOrder.propTypes = {
|
||||||
|
onOk: PropTypes.func.isRequired,
|
||||||
|
objectData: PropTypes.object
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CancelPurchaseOrder
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
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 PostPurchaseOrder = ({ onOk, objectData }) => {
|
||||||
|
const [postLoading, setPostLoading] = useState(false)
|
||||||
|
const { sendObjectFunction } = useContext(ApiServerContext)
|
||||||
|
|
||||||
|
const handlePost = async () => {
|
||||||
|
setPostLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await sendObjectFunction(
|
||||||
|
objectData._id,
|
||||||
|
'PurchaseOrder',
|
||||||
|
'post'
|
||||||
|
)
|
||||||
|
if (result) {
|
||||||
|
message.success('Purchase order posted successfully')
|
||||||
|
onOk(result)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error posting purchase order:', error)
|
||||||
|
} finally {
|
||||||
|
setPostLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MessageDialogView
|
||||||
|
title={'Are you sure you want to post this purchase order?'}
|
||||||
|
description={`Posting purchase order ${objectData?.name || objectData?._reference || objectData?._id} will finalize it and update inventory levels where applicable.`}
|
||||||
|
onOk={handlePost}
|
||||||
|
okText='Post'
|
||||||
|
okLoading={postLoading}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
PostPurchaseOrder.propTypes = {
|
||||||
|
onOk: PropTypes.func.isRequired,
|
||||||
|
objectData: PropTypes.object
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PostPurchaseOrder
|
||||||
Loading…
x
Reference in New Issue
Block a user