Skip to content

Commit

Permalink
refactor(fe): ⚡ make switch more easy to use with rhf & antd
Browse files Browse the repository at this point in the history
  • Loading branch information
lehuygiang28 committed Aug 21, 2024
1 parent aa9d69b commit 8ceb445
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions apps/fe/src/components/form/task-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ export function TaskForm({ mode, defaultValues, onSubmit, formProps }: TaskFormP
dispatchCronValues({ type: 'set_values', value: String(value) });
break;
}
case 'isEnable': {
setValue(key, value === 'true' || value === true);
break;
}
default: {
if (key in taskForm) {
setValue(key, String(value));
Expand Down Expand Up @@ -230,18 +226,13 @@ export function TaskForm({ mode, defaultValues, onSubmit, formProps }: TaskFormP
<Controller<TaskFormValues>
name={'isEnable'}
control={control}
render={({ field: { onChange, value } }) => (
<Item<TaskFormValues>
name={'isEnable'}
label={'Enable'}
validateStatus={errors?.isEnable ? 'error' : 'validating'}
help={<>{errors?.isEnable?.message}</>}
>
render={({ field }) => (
<Item<TaskFormValues> name={'isEnable'} label={'Enable'}>
<Switch
checked={value == 'true' || value == true}
onChange={onChange}
checkedChildren={true}
unCheckedChildren={false}
{...field}
value={field?.value === 'true' || field?.value === true}
checked={field?.value == 'true' || field?.value == true}
onChange={field.onChange}
/>
</Item>
)}
Expand Down Expand Up @@ -465,6 +456,23 @@ export function TaskForm({ mode, defaultValues, onSubmit, formProps }: TaskFormP
</Item>
)}
/>
<Controller<TaskFormValues>
name={'options.saveResponse'}
control={control}
render={({ field }) => (
<Item noStyle>
<Space>
<Switch
{...field}
value={field?.value === 'true' || field?.value === true}
checked={field?.value === 'true' || field?.value === true}
onChange={field.onChange}
/>
Save response in log history
</Space>
</Item>
)}
/>
</Space>
<Divider orientation="left">Notify me when</Divider>
<Space direction="vertical">
Expand Down

0 comments on commit 8ceb445

Please sign in to comment.