|
1 | 1 | 'use client'; |
2 | 2 | import PlusIcon from '@rsuite/icons/legacy/Plus'; |
3 | | -import { Table } from 'antd'; |
| 3 | +import { Table, Form } from 'antd'; |
| 4 | +import type { DefaultOptionType } from 'antd/es/select'; |
4 | 5 | import type { ColumnsType } from 'antd/es/table'; |
5 | 6 | import React, { FC } from 'react'; |
6 | 7 | import { FormProvider, Controller } from 'react-hook-form'; |
7 | | -import { Grid, Row, Col, Form, PanelGroup, Panel, IconButton } from 'rsuite'; |
| 8 | +import { Grid, Row, Col, PanelGroup, Panel, IconButton } from 'rsuite'; |
8 | 9 | import { AppLayout } from '@/Layout/App'; |
9 | | -import { useDummy, DataType } from '@/app/dummy_generator/useDummy'; |
10 | | -import { Input } from '@/components/common/Form/Input'; |
| 10 | +import { dataTypeOptions } from '@/app/dummy_generator/facker'; |
| 11 | +import type { DataType } from '@/app/dummy_generator/facker'; |
| 12 | +import { NameOptions } from '@/app/dummy_generator/options/NameOptions'; |
| 13 | +import { useDummy, RecordType } from '@/app/dummy_generator/useDummy'; |
| 14 | +import { FormRow } from '@/components/common/Form/FormRow'; |
| 15 | +import { Select } from '@/components/common/Form/Select'; |
11 | 16 | import { PageTitle } from '@/components/common/PageTitle'; |
12 | 17 | import { PanelHeader } from '@/components/common/PanelHeader'; |
13 | 18 |
|
14 | | -const columns: ColumnsType<DataType> = [ |
| 19 | +const columns: ColumnsType<RecordType> = [ |
15 | 20 | { |
16 | 21 | title: 'ID', |
17 | 22 | key: 'key', |
18 | 23 | dataIndex: 'key', |
| 24 | + width: '5%', |
19 | 25 | }, |
20 | 26 | { |
21 | 27 | title: 'Content', |
22 | 28 | key: 'content', |
23 | 29 | dataIndex: 'content', |
24 | 30 | }, |
25 | 31 | { |
26 | | - title: 'Action', |
| 32 | + title: '削除', |
27 | 33 | key: 'action', |
28 | 34 | dataIndex: 'action', |
| 35 | + width: '15%', |
29 | 36 | }, |
30 | 37 | ]; |
31 | 38 |
|
32 | 39 | export const DummyGenerator: FC = () => { |
33 | 40 | const title = 'ダミー情報の生成'; |
34 | 41 | const { methods, fields, onClickAdd } = useDummy(); |
| 42 | + const { watch, control } = methods; |
35 | 43 |
|
36 | 44 | const source = fields.map((value, index) => { |
37 | 45 | return { |
38 | 46 | key: index, |
39 | | - content: <ConfigRow id={value.id} index={index} control={methods.control} />, |
| 47 | + content: <ConfigRow id={value.id} index={index} control={control} watch={watch} />, |
40 | 48 | action: null, |
41 | 49 | }; |
42 | 50 | }); |
43 | 51 |
|
44 | | - // const source: DataType[] = [ |
45 | | - // { |
46 | | - // key: 1, |
47 | | - // content: '1', |
48 | | - // action: 'a', |
49 | | - // }, |
50 | | - // { |
51 | | - // key: 2, |
52 | | - // content: '2', |
53 | | - // action: 'a', |
54 | | - // } |
55 | | - // ]; |
56 | | - |
57 | 52 | return ( |
58 | 53 | <FormProvider {...methods}> |
59 | 54 | <AppLayout> |
60 | 55 | <Grid fluid> |
61 | 56 | <PageTitle title={title} /> |
62 | 57 | <Row gutter={5}> |
63 | 58 | <Col md={12} xs={24}> |
64 | | - <Form fluid layout="horizontal"> |
| 59 | + <Form layout="horizontal"> |
65 | 60 | <PanelGroup bordered> |
66 | 61 | <Panel bordered header={<PanelHeader title="管理" />}> |
67 | 62 | <IconButton |
@@ -93,13 +88,40 @@ const ConfigRow: FC<{ |
93 | 88 | id: string; |
94 | 89 | index: number; |
95 | 90 | control: any; |
96 | | -}> = ({ id, index, control }) => { |
| 91 | + watch: any; |
| 92 | +}> = ({ id, index, control, watch }) => { |
97 | 93 | return ( |
98 | | - <Controller |
99 | | - key={id} |
100 | | - name={`items.${index}.firstName`} |
101 | | - control={control} |
102 | | - render={({ field: { ref, ...field } }) => <Input {...field} />} |
103 | | - /> |
| 94 | + <FormRow label="形式"> |
| 95 | + <Controller |
| 96 | + key={id} |
| 97 | + name={`items.${index}.dataType`} |
| 98 | + control={control} |
| 99 | + render={({ field: { ref, ...field } }) => ( |
| 100 | + <Select |
| 101 | + style={{ width: 250 }} |
| 102 | + options={dataTypeOptions as unknown as DefaultOptionType[]} |
| 103 | + defaultValue={undefined} |
| 104 | + showSearch |
| 105 | + {...field} |
| 106 | + /> |
| 107 | + )} |
| 108 | + /> |
| 109 | + <Options dataType={watch(`items.${index}.dataType`)} index={index} control={control} /> |
| 110 | + </FormRow> |
104 | 111 | ); |
105 | 112 | }; |
| 113 | + |
| 114 | +const Options: FC<{ dataType: DataType; index: number; control: any }> = ({ |
| 115 | + dataType, |
| 116 | + index, |
| 117 | + control, |
| 118 | +}) => { |
| 119 | + switch (dataType) { |
| 120 | + case 'name': { |
| 121 | + return <NameOptions />; |
| 122 | + } |
| 123 | + default: { |
| 124 | + return null; |
| 125 | + } |
| 126 | + } |
| 127 | +}; |
0 commit comments