Refactor form components to accept defaultValues prop for enhanced flexibility
- Updated NewFilamentStock, NewPartStock, NewPurchaseOrder, NewStockAudit, NewCourierService, NewCourier, NewDocumentPrinter, NewDocumentSize, NewDocumentTemplate, NewPart, NewProduct, NewTaxRate, NewTaxRecord, NewVendor, NewGCodeFile, NewJob, and NewPrinter components to accept a defaultValues prop. - Merged defaultValues with existing default values in each component to allow for more customizable form initialization.
This commit is contained in:
parent
dbb6be8654
commit
2f323181f5
@ -3,12 +3,12 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewFilamentStock = ({ onOk, reset }) => {
|
||||
const NewFilamentStock = ({ onOk, reset, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'filamentStock'}
|
||||
reset={reset}
|
||||
defaultValues={{ state: { type: 'unconsumed' } }}
|
||||
defaultValues={{ state: { type: 'unconsumed' }, ...defaultValues }}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
@ -64,7 +64,8 @@ const NewFilamentStock = ({ onOk, reset }) => {
|
||||
|
||||
NewFilamentStock.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewFilamentStock
|
||||
|
||||
@ -3,12 +3,12 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewPartStock = ({ onOk, reset }) => {
|
||||
const NewPartStock = ({ onOk, reset, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'partStock'}
|
||||
reset={reset}
|
||||
defaultValues={{ state: { type: 'new' } }}
|
||||
defaultValues={{ state: { type: 'new' }, ...defaultValues }}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
@ -64,7 +64,8 @@ const NewPartStock = ({ onOk, reset }) => {
|
||||
|
||||
NewPartStock.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewPartStock
|
||||
|
||||
@ -5,12 +5,12 @@ import WizardView from '../../common/WizardView'
|
||||
import { getModelProperty } from '../../../../database/ObjectModels.js'
|
||||
import ObjectProperty from '../../common/ObjectProperty.jsx'
|
||||
|
||||
const NewPurchaseOrder = ({ onOk, reset }) => {
|
||||
const NewPurchaseOrder = ({ onOk, reset, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'purchaseOrder'}
|
||||
reset={reset}
|
||||
defaultValues={{ state: { type: 'new' } }}
|
||||
defaultValues={{ state: { type: 'new' }, ...defaultValues }}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
@ -83,7 +83,8 @@ const NewPurchaseOrder = ({ onOk, reset }) => {
|
||||
|
||||
NewPurchaseOrder.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewPurchaseOrder
|
||||
|
||||
@ -3,12 +3,12 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewStockAudit = ({ onOk, reset }) => {
|
||||
const NewStockAudit = ({ onOk, reset, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'stockAudit'}
|
||||
reset={reset}
|
||||
defaultValues={{ state: { type: 'new' } }}
|
||||
defaultValues={{ state: { type: 'new' }, ...defaultValues }}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
@ -64,7 +64,8 @@ const NewStockAudit = ({ onOk, reset }) => {
|
||||
|
||||
NewStockAudit.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewStockAudit
|
||||
|
||||
@ -3,13 +3,14 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewCourierService = ({ onOk }) => {
|
||||
const NewCourierService = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'courierService'}
|
||||
defaultValues={{
|
||||
active: true,
|
||||
tracked: false
|
||||
tracked: false,
|
||||
...defaultValues
|
||||
}}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
@ -80,7 +81,8 @@ const NewCourierService = ({ onOk }) => {
|
||||
|
||||
NewCourierService.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewCourierService
|
||||
|
||||
@ -3,9 +3,9 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewCourier = ({ onOk }) => {
|
||||
const NewCourier = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm type={'courier'}>
|
||||
<NewObjectForm type={'courier'} defaultValues={{ ...defaultValues }}>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
{
|
||||
@ -74,7 +74,8 @@ const NewCourier = ({ onOk }) => {
|
||||
|
||||
NewCourier.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewCourier
|
||||
|
||||
@ -3,11 +3,11 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewDocumentPrinter = ({ onOk }) => {
|
||||
const NewDocumentPrinter = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'documentPrinter'}
|
||||
defaultValues={{ active: true, global: false }}
|
||||
defaultValues={{ active: true, global: false, ...defaultValues }}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
@ -79,7 +79,8 @@ const NewDocumentPrinter = ({ onOk }) => {
|
||||
|
||||
NewDocumentPrinter.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewDocumentPrinter
|
||||
|
||||
@ -3,9 +3,9 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewDocumentSize = ({ onOk }) => {
|
||||
const NewDocumentSize = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm type={'documentSize'}>
|
||||
<NewObjectForm type={'documentSize'} defaultValues={{ ...defaultValues }}>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
{
|
||||
@ -60,7 +60,8 @@ const NewDocumentSize = ({ onOk }) => {
|
||||
|
||||
NewDocumentSize.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewDocumentSize
|
||||
|
||||
@ -3,11 +3,11 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewDocumentTemplate = ({ onOk }) => {
|
||||
const NewDocumentTemplate = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'documentTemplate'}
|
||||
defaultValues={{ active: true, global: false }}
|
||||
defaultValues={{ active: true, global: false, ...defaultValues }}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
@ -79,7 +79,8 @@ const NewDocumentTemplate = ({ onOk }) => {
|
||||
|
||||
NewDocumentTemplate.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewDocumentTemplate
|
||||
|
||||
@ -3,11 +3,15 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewPart = ({ onOk }) => {
|
||||
const NewPart = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'part'}
|
||||
defaultValues={{ priceMode: 'margin', globalPricing: true }}
|
||||
defaultValues={{
|
||||
priceMode: 'margin',
|
||||
globalPricing: true,
|
||||
...defaultValues
|
||||
}}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
@ -112,7 +116,8 @@ const NewPart = ({ onOk }) => {
|
||||
|
||||
NewPart.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewPart
|
||||
|
||||
@ -3,9 +3,12 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewProduct = ({ onOk }) => {
|
||||
const NewProduct = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm type={'product'} defaultValues={{ priceMode: 'margin' }}>
|
||||
<NewObjectForm
|
||||
type={'product'}
|
||||
defaultValues={{ priceMode: 'margin', ...defaultValues }}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
{
|
||||
@ -98,7 +101,8 @@ const NewProduct = ({ onOk }) => {
|
||||
|
||||
NewProduct.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewProduct
|
||||
|
||||
@ -3,9 +3,9 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewTaxRate = ({ onOk }) => {
|
||||
const NewTaxRate = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm type={'taxRate'}>
|
||||
<NewObjectForm type={'taxRate'} defaultValues={{ ...defaultValues }}>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
{
|
||||
@ -74,7 +74,8 @@ const NewTaxRate = ({ onOk }) => {
|
||||
|
||||
NewTaxRate.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewTaxRate
|
||||
|
||||
@ -3,9 +3,9 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewTaxRecord = ({ onOk }) => {
|
||||
const NewTaxRecord = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm type={'taxRecord'}>
|
||||
<NewObjectForm type={'taxRecord'} defaultValues={{ ...defaultValues }}>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
{
|
||||
@ -74,7 +74,8 @@ const NewTaxRecord = ({ onOk }) => {
|
||||
|
||||
NewTaxRecord.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewTaxRecord
|
||||
|
||||
@ -3,9 +3,12 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewVendor = ({ onOk }) => {
|
||||
const NewVendor = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm type={'vendor'} defaultValues={{ active: true }}>
|
||||
<NewObjectForm
|
||||
type={'vendor'}
|
||||
defaultValues={{ active: true, ...defaultValues }}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
const steps = [
|
||||
{
|
||||
@ -74,7 +77,8 @@ const NewVendor = ({ onOk }) => {
|
||||
|
||||
NewVendor.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewVendor
|
||||
|
||||
@ -3,12 +3,13 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewGCodeFile = ({ onOk }) => {
|
||||
const NewGCodeFile = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'gcodeFile'}
|
||||
defaultValues={{
|
||||
state: { type: 'draft' }
|
||||
state: { type: 'draft' },
|
||||
...defaultValues
|
||||
}}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
@ -83,7 +84,8 @@ const NewGCodeFile = ({ onOk }) => {
|
||||
|
||||
NewGCodeFile.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewGCodeFile
|
||||
|
||||
@ -3,12 +3,13 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewJob = ({ onOk }) => {
|
||||
const NewJob = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'job'}
|
||||
defaultValues={{
|
||||
state: { type: 'draft' }
|
||||
state: { type: 'draft' },
|
||||
...defaultValues
|
||||
}}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
@ -66,7 +67,8 @@ const NewJob = ({ onOk }) => {
|
||||
|
||||
NewJob.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewJob
|
||||
|
||||
@ -3,7 +3,7 @@ import ObjectInfo from '../../common/ObjectInfo'
|
||||
import NewObjectForm from '../../common/NewObjectForm'
|
||||
import WizardView from '../../common/WizardView'
|
||||
|
||||
const NewPrinter = ({ onOk }) => {
|
||||
const NewPrinter = ({ onOk, defaultValues }) => {
|
||||
return (
|
||||
<NewObjectForm
|
||||
type={'printer'}
|
||||
@ -12,7 +12,8 @@ const NewPrinter = ({ onOk }) => {
|
||||
port: 7125,
|
||||
protocol: 'ws'
|
||||
},
|
||||
active: true
|
||||
active: true,
|
||||
...defaultValues
|
||||
}}
|
||||
>
|
||||
{({ handleSubmit, submitLoading, objectData, formValid }) => {
|
||||
@ -103,7 +104,8 @@ const NewPrinter = ({ onOk }) => {
|
||||
|
||||
NewPrinter.propTypes = {
|
||||
onOk: PropTypes.func.isRequired,
|
||||
reset: PropTypes.bool
|
||||
reset: PropTypes.bool,
|
||||
defaultValues: PropTypes.object
|
||||
}
|
||||
|
||||
export default NewPrinter
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user