|
| 1 | +import React from 'react'; |
| 2 | +import { Form, validate, FieldProps, renderFields } from '@tpr/forms'; |
| 3 | +import { useInsurerContext } from '../../context'; |
| 4 | +import { Footer } from '../../../components/card'; |
| 5 | +import { Content } from '../../../components/content'; |
| 6 | +import { ArrowButton } from '../../../../buttons/buttons'; |
| 7 | +import { InsurerI18nProps } from '../../i18n'; |
| 8 | +import { RecursivePartial } from '../../context'; |
| 9 | + |
| 10 | +const getFields = ( |
| 11 | + fields: RecursivePartial<InsurerI18nProps['reference']['fields']>, |
| 12 | +): FieldProps[] => [ |
| 13 | + { |
| 14 | + type: 'text', |
| 15 | + name: 'insurerCompanyReference', |
| 16 | + label: fields.insurerCompanyReference.label, |
| 17 | + inputWidth: 5, |
| 18 | + error: fields.insurerCompanyReference.error, |
| 19 | + cfg: { mb: 3 }, |
| 20 | + }, |
| 21 | +]; |
| 22 | + |
| 23 | +export const Reference: React.FC = () => { |
| 24 | + const { current, send, i18n } = useInsurerContext(); |
| 25 | + const { insurer } = current.context; |
| 26 | + const fields = getFields(i18n?.reference?.fields); |
| 27 | + |
| 28 | + const onSubmit = (values) => { |
| 29 | + send('SAVE', { values }); |
| 30 | + }; |
| 31 | + |
| 32 | + return ( |
| 33 | + <Content |
| 34 | + type="insurer" |
| 35 | + title={i18n.reference.title} |
| 36 | + subtitle={i18n.reference.subtitle} |
| 37 | + loading={false} |
| 38 | + > |
| 39 | + <Form |
| 40 | + onSubmit={onSubmit} |
| 41 | + initialValues={{ |
| 42 | + insurerCompanyReference: insurer.insurerCompanyReference, |
| 43 | + }} |
| 44 | + validate={validate(fields)} |
| 45 | + > |
| 46 | + {({ handleSubmit }) => ( |
| 47 | + <form onSubmit={handleSubmit}> |
| 48 | + {renderFields(fields)} |
| 49 | + <Footer> |
| 50 | + <ArrowButton |
| 51 | + intent="special" |
| 52 | + pointsTo="up" |
| 53 | + iconSide="right" |
| 54 | + type="submit" |
| 55 | + title="Save and close" |
| 56 | + disabled={false} |
| 57 | + /> |
| 58 | + </Footer> |
| 59 | + </form> |
| 60 | + )} |
| 61 | + </Form> |
| 62 | + </Content> |
| 63 | + ); |
| 64 | +}; |
0 commit comments