feat: add vendor optional fields and configuration hooks
- Implemented VendorOptionalFields component to handle optional vendor details (mobile, email, address) with validation. - Created useCustomerConfig hook to load optional customer field settings from Sales configuration. - Developed useProcurementConfig hook to manage Procurement configuration flags. - Introduced accessConfigApi for managing access configuration settings. - Added openingBalancesApi for handling opening balances operations. - Created procurementConfigApi for managing procurement configuration settings. - Implemented nav-routes for permission-based routing. - Developed PDF generation for purchase orders with dynamic vendor and item details. - Added purchase-order tax helpers for tax calculations and formatting. - Defined types for opening balances and related operations.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import { salesConfigApi } from "@/lib/api/sales-config"
|
||||
|
||||
/** Which optional customer fields Settings -> Sales Configuration has switched on. */
|
||||
export interface CustomerFieldConfig {
|
||||
phone: boolean
|
||||
email: boolean
|
||||
address: boolean
|
||||
city: boolean
|
||||
country: boolean
|
||||
creditLimit: boolean
|
||||
creditDays: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Everything on — the default before this became configurable, and what a screen shows until the real switches arrive
|
||||
* (or if they can't be read). The server refuses a value for a field that is off, so a wrong guess is caught there.
|
||||
*/
|
||||
export const CUSTOMER_FIELDS_ON: CustomerFieldConfig = {
|
||||
phone: true,
|
||||
email: true,
|
||||
address: true,
|
||||
city: true,
|
||||
country: true,
|
||||
creditLimit: true,
|
||||
creditDays: true,
|
||||
}
|
||||
|
||||
/** Loads the optional-customer-field switches from the Sales configuration. */
|
||||
export function useCustomerConfig(): { fields: CustomerFieldConfig; loaded: boolean } {
|
||||
const [fields, setFields] = useState<CustomerFieldConfig>(CUSTOMER_FIELDS_ON)
|
||||
const [loaded, setLoaded] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
let active = true
|
||||
salesConfigApi
|
||||
.get()
|
||||
.then(({ data }) => {
|
||||
if (!active) return
|
||||
setFields({
|
||||
phone: data.customerPhoneEnabled,
|
||||
email: data.customerEmailEnabled,
|
||||
address: data.customerAddressEnabled,
|
||||
city: data.customerCityEnabled,
|
||||
country: data.customerCountryEnabled,
|
||||
creditLimit: data.customerCreditLimitEnabled,
|
||||
creditDays: data.customerCreditDaysEnabled,
|
||||
})
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
if (active) setLoaded(true)
|
||||
})
|
||||
return () => {
|
||||
active = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
return { fields, loaded }
|
||||
}
|
||||
Reference in New Issue
Block a user