From 01fd5fa010c0c3f7af1e4b87c79c0d2343f9e9fd Mon Sep 17 00:00:00 2001 From: Cuong Vu Date: Thu, 16 Jul 2020 15:01:05 +0700 Subject: [PATCH] fix: #2067 wip remove hoc --- .../forms/contact-information-form.tsx | 139 +++++++++--------- 1 file changed, 66 insertions(+), 73 deletions(-) diff --git a/packages/developer-portal/src/components/pages/settings/forms/contact-information-form.tsx b/packages/developer-portal/src/components/pages/settings/forms/contact-information-form.tsx index d7b68f39b8..b6238b23bf 100644 --- a/packages/developer-portal/src/components/pages/settings/forms/contact-information-form.tsx +++ b/packages/developer-portal/src/components/pages/settings/forms/contact-information-form.tsx @@ -1,5 +1,4 @@ import React from 'react' -import { compose } from 'redux' import { FormSection, FormHeading, @@ -7,57 +6,78 @@ import { Input, Button, Form, - withFormik, - FormikProps, FormikBag, LevelRight, Grid, GridItem, + Formik, } from '@reapit/elements' import { DeveloperModel } from '@reapit/foundations-ts-definitions' import { validate } from '@/utils/form/settings-contact-information' -export type ContactInformationFormProps = FormikProps - +export type ContactInformationFormProps = { + developerInformation: DeveloperModel | null + updateDeveloperInformation: (values: ContactInformationValues) => void +} export const ContactInformationForm: React.FC = ({ - isSubmitting, - isValidating, - isValid, + developerInformation, + updateDeveloperInformation, }) => { return ( - -
- Contact Information - Please use the fields below to edit your contact information - - - - - - - - - - - - - - - - - - - -
-
+ + {({ isSubmitting, isValidating, isValid }) => { + return ( + +
+ Contact Information + Please use the fields below to edit your contact information + + + + + + + + + + + + + + + + + + + +
+
+ ) + }} +
) } @@ -68,38 +88,11 @@ export type ContactInformationValues = { telephone: string } -export const mapPropsContactInformation = ({ developerInformation }: EnhanceContactInformationProps) => { - return { - jobTitle: developerInformation?.jobTitle || '', - telephone: developerInformation?.telephone || '', - companyName: developerInformation?.company || '', - name: developerInformation?.name || '', - } -} - -export type EnhanceContactInformationProps = { - developerInformation: DeveloperModel | null - updateDeveloperInformation: (values: ContactInformationValues) => void -} - -export const handleSubmitContactInformation = async ( - values: ContactInformationValues, - { setSubmitting, props }: FormikBag, -) => { +export const handleSubmitContactInformation = ( + updateDeveloperInformation: (values: ContactInformationValues) => void, +) => (values: ContactInformationValues, { setSubmitting }: FormikBag) => { setSubmitting(true) - props.updateDeveloperInformation(values) + updateDeveloperInformation(values) } -export const withContactInformationForm = withFormik({ - displayName: 'WithContactInformationForm', - mapPropsToValues: mapPropsContactInformation, - handleSubmit: handleSubmitContactInformation, - validate, -}) - -const EnhanceContactInformation = compose>(withContactInformationForm)( - ContactInformationForm, -) -EnhanceContactInformation.displayName = 'EnhanceContactInformation' - -export default EnhanceContactInformation +export default ContactInformationForm