feat: Enhance form components with hidden fields and popup properties for improved configuration
parent
839fe12087
commit
d1d83f8a2a
@ -0,0 +1,39 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { withForm } from '@/app/components/base/form'
|
||||||
|
import type { FormData } from './types'
|
||||||
|
import InputField from '@/app/components/base/form/form-scenarios/input-field/field'
|
||||||
|
import { useStore } from '@tanstack/react-form'
|
||||||
|
import { useHiddenConfigurations } from './hooks'
|
||||||
|
|
||||||
|
type HiddenFieldsProps = {
|
||||||
|
initialData?: FormData
|
||||||
|
}
|
||||||
|
|
||||||
|
const HiddenFields = ({
|
||||||
|
initialData,
|
||||||
|
}: HiddenFieldsProps) => withForm({
|
||||||
|
defaultValues: initialData,
|
||||||
|
render: function Render({
|
||||||
|
form,
|
||||||
|
}) {
|
||||||
|
const options = useStore(form.store, state => state.values.options)
|
||||||
|
|
||||||
|
const hiddenConfigurations = useHiddenConfigurations({
|
||||||
|
options,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{hiddenConfigurations.map((config, index) => {
|
||||||
|
const FieldComponent = InputField<FormData>({
|
||||||
|
initialData,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
return <FieldComponent key={index} form={form} />
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default HiddenFields
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
import React, { useCallback } from 'react'
|
||||||
|
import { withForm } from '@/app/components/base/form'
|
||||||
|
import type { FormData } from './types'
|
||||||
|
import InputField from '@/app/components/base/form/form-scenarios/input-field/field'
|
||||||
|
import type { DeepKeys } from '@tanstack/react-form'
|
||||||
|
import { useConfigurations } from './hooks'
|
||||||
|
|
||||||
|
type InitialFieldsProps = {
|
||||||
|
initialData?: FormData
|
||||||
|
supportFile: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const InitialFields = ({
|
||||||
|
initialData,
|
||||||
|
supportFile,
|
||||||
|
}: InitialFieldsProps) => withForm({
|
||||||
|
defaultValues: initialData,
|
||||||
|
render: function Render({
|
||||||
|
form,
|
||||||
|
}) {
|
||||||
|
const setFieldValue = useCallback((fieldName: DeepKeys<FormData>, value: any) => {
|
||||||
|
form.setFieldValue(fieldName, value)
|
||||||
|
}, [form])
|
||||||
|
|
||||||
|
const initialConfigurations = useConfigurations({
|
||||||
|
setFieldValue,
|
||||||
|
supportFile,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{initialConfigurations.map((config, index) => {
|
||||||
|
const FieldComponent = InputField<FormData>({
|
||||||
|
initialData,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
return <FieldComponent key={index} form={form} />
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default InitialFields
|
||||||
Loading…
Reference in New Issue