Skip to content

Commit

Permalink
Merge branch 'dev' into mobility-profile-routing
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed May 17, 2024
2 parents c60c4e4 + 0eaed51 commit 41e7f79
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 57 deletions.
7 changes: 3 additions & 4 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ api:
persistence:
enabled: true
strategy: localStorage
### This variable hides the "more info" link when accepting the terms of storage.
### If no terms of storage page content is set, this removes an otherwise dead link
### False is default in that if the value isn't set, the link isn't shown
# terms_of_storage: true
### This variable defines the default state of the terms of storage checkbox.
### Possible values: 'visible-unchecked' (default) | 'visible-checked' | 'hidden-unchecked' | 'hidden-checked'
# termsOfStorageDefault: 'visible-unchecked'

### If using the OTP Middleware to store user profiles
### with Auth0 as the authentication mechanism,
Expand Down
116 changes: 67 additions & 49 deletions lib/components/user/terms-of-use-pane.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
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'
import { LinkOpensNewWindow } from '../util/externalLink'
import {
TERMS_OF_SERVICE_PATH,
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 @@ -18,26 +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
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 All @@ -61,52 +77,54 @@ const TermsOfUsePane = ({
/>
</Checkbox>
</FormGroup>
<FormGroup>
<Checkbox
checked={storeTripHistory}
name="storeTripHistory"
onBlur={handleBlur}
onChange={(e) => {
// Show alert when user is unchecking the checkbox
if (storeTripHistory) {
// Do nothing if the user hits cancel
if (
// eslint-disable-next-line no-restricted-globals
!confirm(
intl.formatMessage({
id: 'components.TermsOfUsePane.confirmDeletionPrompt'
})
)
) {
return
{showStorageTerms ? (
<FormGroup>
<Checkbox
checked={storeTripHistory}
name="storeTripHistory"
onBlur={handleBlur}
onChange={(e) => {
// Show alert when user is unchecking the checkbox
if (storeTripHistory) {
// Do nothing if the user hits cancel
if (
// eslint-disable-next-line no-restricted-globals
!confirm(
intl.formatMessage({
id: 'components.TermsOfUsePane.confirmDeletionPrompt'
})
)
) {
return
}
}
}

handleChange(e)
}}
>
<FormattedMessage
id="components.TermsOfUsePane.termsOfStorageStatement"
values={{
termsOfStorageLink: (contents: JSX.Element) => (
<LinkOpensNewWindow
contents={contents}
inline
url={`/#${TERMS_OF_STORAGE_PATH}`}
/>
)
handleChange(e)
}}
/>
</Checkbox>
</FormGroup>
>
<FormattedMessage
id="components.TermsOfUsePane.termsOfStorageStatement"
values={{
termsOfStorageLink: (contents: JSX.Element) => (
<LinkOpensNewWindow
contents={contents}
inline
url={`/#${TERMS_OF_STORAGE_PATH}`}
/>
)
}}
/>
</Checkbox>
</FormGroup>
) : null}
</div>
)
}
const mapStateToProps = (state: AppReduxState) => {
return {
locale: state.otp.ui?.locale,
termsOfServiceLink: state.otp.config.termsOfServiceLink,
termsOfStorageSet: state.otp.config.persistence?.terms_of_storage
termsOfStorageDefault: state.otp.config.persistence?.termsOfStorageDefault
}
}

Expand Down
19 changes: 15 additions & 4 deletions lib/util/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ export interface Auth0Config {
/** Local persistence setting */
export interface LocalPersistenceConfig {
strategy: 'localStorage'
// eslint-disable-next-line camelcase
terms_of_storage?: boolean
}

/** OTP Middleware (Personas) settings */
Expand All @@ -107,14 +105,27 @@ export interface MiddlewarePersistenceConfig {
strategy: 'otp_middleware'
}

/**
* Enum to describe the layout state of checkboxes.
*/
export enum CheckboxDefaultState {
/** Checkbox is hidden and initially checked */
HIDDEN_CHECKED = 'hidden-checked',
/** Checkbox is hidden and initially unchecked */
HIDDEN_UNCHECKED = 'hidden-unchecked',
/** Checkbox is visible and initially checked */
VISIBLE_CHECKED = 'visible-checked',
/** Checkbox is visible and initially unchecked */
VISIBLE_UNCHECKED = 'visible-unchecked'
}

/** General persistence settings */
export type PersistenceConfig = (
| LocalPersistenceConfig
| MiddlewarePersistenceConfig
) & {
enabled?: boolean
// eslint-disable-next-line camelcase
terms_of_storage?: boolean
termsOfStorageDefault?: CheckboxDefaultState
}

/** Popup target settings */
Expand Down

0 comments on commit 41e7f79

Please sign in to comment.