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
|
||||||
@ -1,30 +1,43 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { withForm } from '@/app/components/base/form'
|
||||||
|
import type { FormData } from './types'
|
||||||
|
import { useStore } from '@tanstack/react-form'
|
||||||
|
import { useHiddenFieldNames } from './hooks'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { RiArrowRightSLine } from '@remixicon/react'
|
import { RiArrowRightSLine } from '@remixicon/react'
|
||||||
|
|
||||||
type ShowAllSettingsProps = {
|
type ShowAllSettingsProps = {
|
||||||
description: string
|
initialData?: FormData
|
||||||
handleShowAllSettings: () => void
|
handleShowAllSettings: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShowAllSettings = ({
|
const ShowAllSettings = ({
|
||||||
description,
|
initialData,
|
||||||
handleShowAllSettings,
|
handleShowAllSettings,
|
||||||
}: ShowAllSettingsProps) => {
|
}: ShowAllSettingsProps) => withForm({
|
||||||
const { t } = useTranslation()
|
defaultValues: initialData,
|
||||||
|
render: function Render({
|
||||||
|
form,
|
||||||
|
}) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const type = useStore(form.store, state => state.values.type)
|
||||||
|
|
||||||
return (
|
const hiddenFieldNames = useHiddenFieldNames(type)
|
||||||
<div className='flex cursor-pointer items-center gap-x-4' onClick={handleShowAllSettings}>
|
|
||||||
<div className='flex grow flex-col'>
|
return (
|
||||||
<span className='system-sm-medium flex min-h-6 items-center text-text-secondary'>
|
<div className='flex cursor-pointer items-center gap-x-4' onClick={handleShowAllSettings}>
|
||||||
{t('appDebug.variableConfig.showAllSettings')}
|
<div className='flex grow flex-col'>
|
||||||
</span>
|
<span className='system-sm-medium flex min-h-6 items-center text-text-secondary'>
|
||||||
<span className='body-xs-regular pb-0.5 text-text-tertiary first-letter:capitalize'>
|
{t('appDebug.variableConfig.showAllSettings')}
|
||||||
{description}
|
</span>
|
||||||
</span>
|
<span className='body-xs-regular pb-0.5 text-text-tertiary first-letter:capitalize'>
|
||||||
|
{hiddenFieldNames}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<RiArrowRightSLine className='h-4 w-4 shrink-0 text-text-secondary' />
|
||||||
</div>
|
</div>
|
||||||
<RiArrowRightSLine className='h-4 w-4 shrink-0 text-text-secondary' />
|
)
|
||||||
</div>
|
},
|
||||||
)
|
})
|
||||||
}
|
|
||||||
|
|
||||||
export default ShowAllSettings
|
export default ShowAllSettings
|
||||||
|
|||||||
Loading…
Reference in New Issue