-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: ♻️ migrated code to TS #45
Changes from 4 commits
78c3b9f
067e4a7
8c6103b
60d5901
149d91f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { Checkbox } from '@deriv/components'; | ||
import { FieldInputProps } from 'formik'; | ||
|
||
type TCheckboxFieldProps = { | ||
field: FieldInputProps<boolean>; | ||
id: string; | ||
className: string; | ||
label: string; | ||
}; | ||
|
||
/** | ||
* This component is used with Formik's Field component. | ||
* @param {FieldInputProps<boolean>} field - Formik's field props | ||
* @param {string} id - Checkbox id | ||
* @param {string} className - Class name for styling | ||
* @param {string} label - Checkbox label | ||
* @param {object} props - Other props | ||
* @returns {React.ReactNode} - React node | ||
*/ | ||
const CheckboxField = ({ field: { name, value, onChange }, id, label, className, ...props }: TCheckboxFieldProps) => { | ||
return ( | ||
<div className={className}> | ||
<Checkbox value={value} name={name} label={label} onChange={onChange} {...props} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CheckboxField; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import TermsOfUse from './terms-of-use'; | ||
|
||
export default TermsOfUse; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
flex-grow: 1; | ||
margin: 0 8rem !important; | ||
width: 84% !important; | ||
padding-bottom: unset; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we set the |
||
|
||
@include mobile { | ||
margin: unset !important; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,45 @@ import { | |
} from '@deriv/components'; | ||
import { isDesktop, isMobile, PlatformContext } from '@deriv/shared'; | ||
import { localize, Localize } from '@deriv/translations'; | ||
import CheckboxField from './checkbox-field.jsx'; | ||
import { SharedMessage, BrokerSpecificMessage, Hr } from './terms-of-use-messages.jsx'; | ||
import { TBrokerCodes } from 'Types'; | ||
import CheckboxField from './checkbox-field'; | ||
import { SharedMessage, BrokerSpecificMessage, Hr } from './terms-of-use-messages'; | ||
import './terms-of-use.scss'; | ||
|
||
type TTermsOfUseFormProps = { | ||
agreed_tos: boolean; | ||
agreed_tnc: boolean; | ||
}; | ||
|
||
type TTermsOfUseProps = { | ||
getCurrentStep: () => number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the list is not huge but anyway, wouldn’t it be better to sort all fields alphabetically? :) |
||
onCancel: (current_step: number, goToPreviousStep: () => void) => void; | ||
goToPreviousStep: () => void; | ||
goToNextStep: () => void; | ||
onSubmit: ( | ||
current_step: number | null, | ||
values: TTermsOfUseFormProps, | ||
action: (isSubmitting: boolean) => void, | ||
next_step: () => void | ||
) => void; | ||
value: TTermsOfUseFormProps; | ||
real_account_signup_target: TBrokerCodes; | ||
form_error?: string; | ||
}; | ||
|
||
/** | ||
* Terms of use component for account signup | ||
* @param {Function} getCurrentStep - function to get current step | ||
* @param {Function} onCancel - function to cancel account signup | ||
* @param {Function} goToPreviousStep - function to go to previous step | ||
* @param {Function} goToNextStep - function to go to next step | ||
* @param {Function} onSubmit - function to submit form | ||
* @param {object} value - form values | ||
* @param {string} real_account_signup_target - broker code | ||
* @param {string} form_error - form error | ||
* @param {object} props - other props | ||
* @returns {React.ReactNode} - React node | ||
*/ | ||
const TermsOfUse = ({ | ||
getCurrentStep, | ||
onCancel, | ||
|
@@ -24,7 +59,7 @@ const TermsOfUse = ({ | |
value, | ||
real_account_signup_target, | ||
...props | ||
}) => { | ||
}: TTermsOfUseProps) => { | ||
const { is_appstore } = React.useContext(PlatformContext); | ||
|
||
const handleCancel = () => { | ||
|
@@ -43,7 +78,7 @@ const TermsOfUse = ({ | |
<Formik | ||
initialValues={value} | ||
onSubmit={(values, actions) => { | ||
onSubmit(getCurrentStep() - 1, {}, actions.setSubmitting, goToNextStep); | ||
onSubmit(getCurrentStep() - 1, values, actions.setSubmitting, goToNextStep); | ||
}} | ||
> | ||
{({ handleSubmit, values, isSubmitting }) => ( | ||
|
@@ -56,10 +91,7 @@ const TermsOfUse = ({ | |
is_disabled={isDesktop()} | ||
> | ||
<ThemedScrollbars> | ||
<div | ||
className={cn('details-form__elements', 'terms-of-use')} | ||
style={{ paddingBottom: isDesktop() ? 'unset' : null }} | ||
> | ||
<div className={cn('details-form__elements', 'terms-of-use')}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we set the padding-bottom at the top level, isn't it available on mobile as well as there's no override? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unset or null does the same as there is no override available There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we change this classnames import to commonly used in our app? :) |
||
<BrokerSpecificMessage target={real_account_signup_target} /> | ||
<Hr /> | ||
<SharedMessage /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this component is being used with formik
Field
component, can we try wrapping this withField
directly and we'll be able to remove this field prop?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can u please elaborate?
Checkbox field is passed as a component to Field
<Field component={CheckboxField}