Add invoice creation mode support to Shop PO flow
Introduce invoice creation mode feature using invoiceCreationModeApi and DEFAULT_INVOICE_CREATION_MODE. Update confirmation logic to call confirmAndCreateInvoice and show draft invoice messaging in ModeA. Update types and UI in page.tsx and confirm-shop-po-dialog.tsx for consistent behavior.
This commit is contained in:
@@ -24,9 +24,12 @@ import {
|
||||
items as itemsApi,
|
||||
priceLists as priceListsApi,
|
||||
users as usersApi,
|
||||
invoiceCreationMode as invoiceCreationModeApi,
|
||||
DEFAULT_INVOICE_CREATION_MODE,
|
||||
getApiError,
|
||||
getPaginatedItems,
|
||||
} from '@/lib/api/index'
|
||||
import type { InvoiceCreationMode } from '@/lib/api/sys-config'
|
||||
import type { ItemSummaryResponse, ShopPOResponse, UserResponse } from '@/types/api'
|
||||
|
||||
const lineItemSchema = z.object({
|
||||
@@ -56,6 +59,11 @@ export default function EditShopPOPage() {
|
||||
const [usersList, setUsersList] = useState<UserResponse[]>([])
|
||||
const [confirmedByUserId, setConfirmedByUserId] = useState('')
|
||||
const [confirming, setConfirming] = useState(false)
|
||||
const [mode, setMode] = useState<InvoiceCreationMode>(DEFAULT_INVOICE_CREATION_MODE)
|
||||
|
||||
useEffect(() => {
|
||||
invoiceCreationModeApi.get().then(setMode).catch(() => {})
|
||||
}, [])
|
||||
|
||||
const form = useForm<FormValues>({
|
||||
resolver: zodResolver(schema),
|
||||
@@ -98,9 +106,14 @@ export default function EditShopPOPage() {
|
||||
if (!po || !confirmedByUserId) return
|
||||
setConfirming(true)
|
||||
try {
|
||||
const updated = await shopPosApi.confirm(po.id, confirmedByUserId)
|
||||
const updated = mode === 'ModeA'
|
||||
? await shopPosApi.confirmAndCreateInvoice(po.id, confirmedByUserId)
|
||||
: await shopPosApi.confirm(po.id, confirmedByUserId)
|
||||
setPo(updated)
|
||||
toast.add({ title: 'Shop PO confirmed', type: 'success' })
|
||||
toast.add({
|
||||
title: mode === 'ModeA' ? 'Shop PO confirmed and invoice created' : 'Shop PO confirmed',
|
||||
type: 'success',
|
||||
})
|
||||
} catch (err) {
|
||||
toast.add({ title: 'Failed to confirm Shop PO', description: getApiError(err), type: 'error' })
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user