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