import { PlusOutlined } from '@ant-design/icons/lib' import { Button, Form, Space, Tabs } from 'antd' import { FormInstance } from 'antd/lib/form' import { TabPaneProps } from 'antd/lib/tabs' import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' import { FormFieldFragment, FormNotificationFragment, } from '../../../graphql/fragment/form.fragment' import { NotificationCard } from './notification.card' interface Props extends TabPaneProps { form: FormInstance fields: FormFieldFragment[] } export const NotificationsTab: React.FC = (props) => { const { t } = useTranslation() const groups: { [key: string]: FormFieldFragment[] } = {} props.fields.forEach((field) => { if (!groups[field.type]) { groups[field.type] = [] } groups[field.type].push(field) }) const addField = useCallback( (add: (defaults: unknown) => void, index: number) => { return ( ) }, [props.fields] ) return ( {(fields, { add, remove, move }) => { const addAndMove = (index: number) => (defaults) => { add(defaults) move(fields.length, index) } return (
{addField(addAndMove(0), 0)} {fields.map((field, index) => (
{addField(addAndMove(index + 1), index + 1)}
))}
) }}
) }