|
| 1 | +'use client'; |
| 2 | +import PlusIcon from '@rsuite/icons/legacy/Plus'; |
| 3 | +import { Table } from 'antd'; |
| 4 | +import type { ColumnsType } from 'antd/es/table'; |
| 5 | +import React, { FC } from 'react'; |
| 6 | +import { FormProvider, Controller } from 'react-hook-form'; |
| 7 | +import { Grid, Row, Col, Form, PanelGroup, Panel, IconButton } from 'rsuite'; |
| 8 | +import { AppLayout } from '@/Layout/App'; |
| 9 | +import { useDummy, DataType } from '@/app/dummy_generator/useDummy'; |
| 10 | +import { Input } from '@/components/common/Form/Input'; |
| 11 | +import { PageTitle } from '@/components/common/PageTitle'; |
| 12 | +import { PanelHeader } from '@/components/common/PanelHeader'; |
| 13 | + |
| 14 | +const columns: ColumnsType<DataType> = [ |
| 15 | + { |
| 16 | + title: 'ID', |
| 17 | + key: 'key', |
| 18 | + dataIndex: 'key', |
| 19 | + }, |
| 20 | + { |
| 21 | + title: 'Content', |
| 22 | + key: 'content', |
| 23 | + dataIndex: 'content', |
| 24 | + }, |
| 25 | + { |
| 26 | + title: 'Action', |
| 27 | + key: 'action', |
| 28 | + dataIndex: 'action', |
| 29 | + }, |
| 30 | +]; |
| 31 | + |
| 32 | +export const DummyGenerator: FC = () => { |
| 33 | + const title = 'ダミー情報の生成'; |
| 34 | + const { methods, fields, onClickAdd } = useDummy(); |
| 35 | + |
| 36 | + const source = fields.map((value, index) => { |
| 37 | + return { |
| 38 | + key: index, |
| 39 | + content: <ConfigRow id={value.id} index={index} control={methods.control} />, |
| 40 | + action: null, |
| 41 | + }; |
| 42 | + }); |
| 43 | + |
| 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 | + return ( |
| 58 | + <FormProvider {...methods}> |
| 59 | + <AppLayout> |
| 60 | + <Grid fluid> |
| 61 | + <PageTitle title={title} /> |
| 62 | + <Row gutter={5}> |
| 63 | + <Col md={12} xs={24}> |
| 64 | + <Form fluid layout="horizontal"> |
| 65 | + <PanelGroup bordered> |
| 66 | + <Panel bordered header={<PanelHeader title="管理" />}> |
| 67 | + <IconButton |
| 68 | + icon={<PlusIcon />} |
| 69 | + placement="right" |
| 70 | + size="xs" |
| 71 | + onClick={onClickAdd} |
| 72 | + > |
| 73 | + 追加 |
| 74 | + </IconButton> |
| 75 | + </Panel> |
| 76 | + <Panel bordered header={<PanelHeader title="設定" />}> |
| 77 | + <Table columns={columns} dataSource={source} /> |
| 78 | + </Panel> |
| 79 | + </PanelGroup> |
| 80 | + </Form> |
| 81 | + </Col> |
| 82 | + <Col md={12} xs={24}> |
| 83 | + <Panel bordered header={<PanelHeader title="UUID" />}></Panel> |
| 84 | + </Col> |
| 85 | + </Row> |
| 86 | + </Grid> |
| 87 | + </AppLayout> |
| 88 | + </FormProvider> |
| 89 | + ); |
| 90 | +}; |
| 91 | + |
| 92 | +const ConfigRow: FC<{ |
| 93 | + id: string; |
| 94 | + index: number; |
| 95 | + control: any; |
| 96 | +}> = ({ id, index, control }) => { |
| 97 | + return ( |
| 98 | + <Controller |
| 99 | + key={id} |
| 100 | + name={`items.${index}.firstName`} |
| 101 | + control={control} |
| 102 | + render={({ field: { ref, ...field } }) => <Input {...field} />} |
| 103 | + /> |
| 104 | + ); |
| 105 | +}; |
0 commit comments