Skip to content

Commit

Permalink
improvement(TermsOfUsePane): Precheck terms of storage if so configured.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed May 14, 2024
1 parent c3e2936 commit be20928
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions lib/components/user/terms-of-use-pane.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Checkbox, ControlLabel, FormGroup } from 'react-bootstrap'
import { connect } from 'react-redux'
import { FormattedMessage, useIntl } from 'react-intl'
import React, { FormEventHandler } from 'react'
import { FormikProps } from 'formik'
import React, { useEffect } from 'react'

import { AppReduxState } from '../../util/state-types'
import { CheckboxDefaultState } from '../../util/config-types'
Expand All @@ -11,6 +12,15 @@ import {
TERMS_OF_STORAGE_PATH
} from '../../util/constants'

import { EditedUser } from './types'

interface Props extends FormikProps<EditedUser> {
disableCheckTerms: boolean
locale: string
termsOfServiceLink?: string
termsOfStorageDefault?: CheckboxDefaultState
}

/**
* User terms of use pane.
*/
Expand All @@ -19,30 +29,31 @@ const TermsOfUsePane = ({
handleBlur,
handleChange,
locale,
setFieldValue,
termsOfServiceLink,
termsOfStorageDefault = CheckboxDefaultState.VISIBLE_UNCHECKED,
values: userData
}: {
disableCheckTerms: boolean
handleBlur: () => void
handleChange: FormEventHandler<Checkbox>
locale: string
termsOfServiceLink?: string
termsOfStorageDefault?: CheckboxDefaultState
values: {
hasConsentedToTerms: boolean
storeTripHistory: boolean
}
}) => {
}: Props) => {
const intl = useIntl()
const { hasConsentedToTerms, storeTripHistory } = userData
const { hasConsentedToTerms, id, storeTripHistory } = userData

const TOSLinkWithI18n = termsOfServiceLink?.replace('{locale}', locale)

const termsURL = TOSLinkWithI18n || `/#${TERMS_OF_SERVICE_PATH}`

const showStorageTerms = termsOfStorageDefault.startsWith('visible-')

useEffect(() => {
// When creating a new account, pre-check the storage field per defaults.
if (
!id &&
(termsOfStorageDefault === CheckboxDefaultState.HIDDEN_CHECKED ||
termsOfStorageDefault === CheckboxDefaultState.VISIBLE_CHECKED)
) {
setFieldValue('storeTripHistory', true)
}
}, [id, setFieldValue, termsOfStorageDefault])

return (
<div>
<ControlLabel>
Expand Down

0 comments on commit be20928

Please sign in to comment.