-
Notifications
You must be signed in to change notification settings - Fork 210
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
feat(react): Convert third party auth 'Set password' page to React #18044
Open
LZoog
wants to merge
2
commits into
main
Choose a base branch
from
FXA-6651
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ import SignupConfirmed from '../../pages/Signup/SignupConfirmed'; | |
import WebChannelExample from '../../pages/WebChannelExample'; | ||
import SignoutSync from '../Settings/SignoutSync'; | ||
import InlineRecoveryKeySetupContainer from '../../pages/InlineRecoveryKeySetup/container'; | ||
import SetPasswordContainer from '../../pages/PostVerify/SetPassword/container'; | ||
|
||
const Settings = lazy(() => import('../Settings')); | ||
|
||
|
@@ -318,6 +319,10 @@ const AuthAndAccountSetupRoutes = ({ | |
path="/post_verify/third_party_auth/callback/*" | ||
{...{ flowQueryParams }} | ||
/> | ||
<SetPasswordContainer | ||
path="/post_verify/finish_account_setup/set_password/*" | ||
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. Should this be |
||
{...{ flowQueryParams, integration }} | ||
/> | ||
|
||
{/* Reset password */} | ||
<ResetPasswordContainer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
139 changes: 139 additions & 0 deletions
139
packages/fxa-settings/src/components/FormSetupAccount/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import React from 'react'; | ||
import { FtlMsg } from 'fxa-react/lib/utils'; | ||
import FormPasswordWithBalloons from '../FormPasswordWithBalloons'; | ||
import InputText from '../InputText'; | ||
import LinkExternal from 'fxa-react/components/LinkExternal'; | ||
import GleanMetrics from '../../lib/glean'; | ||
import ChooseNewsletters from '../ChooseNewsletters'; | ||
import ChooseWhatToSync from '../ChooseWhatToSync'; | ||
import LoadingSpinner from 'fxa-react/components/LoadingSpinner'; | ||
import { FormSetupAccountProps } from './interfaces'; | ||
import { newsletters } from '../ChooseNewsletters/newsletters'; | ||
|
||
export const FormSetupAccount = ({ | ||
formState, | ||
errors, | ||
trigger, | ||
register, | ||
getValues, | ||
onFocus, | ||
email, | ||
onFocusMetricsEvent, | ||
onSubmit, | ||
loading, | ||
isSync, | ||
offeredSyncEngineConfigs, | ||
setDeclinedSyncEngines, | ||
isDesktopRelay, | ||
setSelectedNewsletterSlugs, | ||
ageCheckErrorText, | ||
setAgeCheckErrorText, | ||
onFocusAgeInput, | ||
onBlurAgeInput, | ||
submitButtonGleanId | ||
}: FormSetupAccountProps) => { | ||
const showCWTS = () => { | ||
if (isSync) { | ||
if (offeredSyncEngineConfigs) { | ||
return ( | ||
<ChooseWhatToSync | ||
{...{ | ||
offeredSyncEngineConfigs, | ||
setDeclinedSyncEngines, | ||
}} | ||
/> | ||
); | ||
} else { | ||
// Waiting to receive webchannel message from browser | ||
return <LoadingSpinner className="flex justify-center mb-4" />; | ||
} | ||
} else { | ||
// Display nothing if Sync flow that does not support webchannels | ||
// or if CWTS is disabled | ||
return <></>; | ||
} | ||
}; | ||
|
||
return ( | ||
<FormPasswordWithBalloons | ||
{...{ | ||
formState, | ||
errors, | ||
trigger, | ||
register, | ||
getValues, | ||
email, | ||
onFocusMetricsEvent, | ||
disableButtonUntilValid: true, | ||
onSubmit, | ||
loading, | ||
submitButtonGleanId | ||
}} | ||
passwordFormType="signup" | ||
> | ||
{setAgeCheckErrorText && | ||
setAgeCheckErrorText && | ||
onFocusAgeInput && | ||
onBlurAgeInput && ( | ||
<> | ||
{/* TODO: original component had a SR-only label that is not straightforward to implement with existing InputText component | ||
SR-only text: "How old are you? To learn why we ask for your age, follow the “why do we ask” link below. */} | ||
<FtlMsg id="signup-age-check-label" attrs={{ label: true }}> | ||
<InputText | ||
name="age" | ||
label="How old are you?" | ||
inputMode="numeric" | ||
className="mb-4" | ||
pattern="[0-9]*" | ||
maxLength={3} | ||
onChange={() => { | ||
// clear error tooltip if user types in the field | ||
if (ageCheckErrorText) { | ||
setAgeCheckErrorText(''); | ||
} | ||
}} | ||
inputRef={register({ | ||
pattern: /^[0-9]*$/, | ||
maxLength: 3, | ||
required: true, | ||
})} | ||
onFocusCb={onFocusAgeInput} | ||
onBlurCb={onBlurAgeInput} | ||
errorText={ageCheckErrorText} | ||
tooltipPosition="bottom" | ||
anchorPosition="end" | ||
prefixDataTestId="age" | ||
/> | ||
</FtlMsg> | ||
<FtlMsg id="signup-coppa-check-explanation-link"> | ||
<LinkExternal | ||
href="https://www.ftc.gov/business-guidance/resources/childrens-online-privacy-protection-rule-not-just-kids-sites" | ||
className={`link-blue text-sm py-1 -mt-2 self-start ${ | ||
isDesktopRelay ? 'mb-8' : 'mb-4' | ||
}`} | ||
onClick={() => GleanMetrics.registration.whyWeAsk()} | ||
> | ||
Why do we ask? | ||
</LinkExternal> | ||
</FtlMsg> | ||
</> | ||
)} | ||
|
||
{isSync | ||
? showCWTS() | ||
: !isDesktopRelay && | ||
setSelectedNewsletterSlugs && ( | ||
<ChooseNewsletters | ||
{...{ | ||
newsletters, | ||
setSelectedNewsletterSlugs, | ||
}} | ||
/> | ||
)} | ||
</FormPasswordWithBalloons> | ||
); | ||
}; |
34 changes: 34 additions & 0 deletions
34
packages/fxa-settings/src/components/FormSetupAccount/interfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { UseFormMethods } from 'react-hook-form'; | ||
import { SetPasswordFormData } from '../../pages/PostVerify/SetPassword/interfaces'; | ||
import { SignupFormData } from '../../pages/Signup/interfaces'; | ||
import { syncEngineConfigs } from '../ChooseWhatToSync/sync-engines'; | ||
|
||
export type FormSetupAccountData = SignupFormData | SetPasswordFormData; | ||
|
||
export type FormSetupAccountProps = { | ||
formState: UseFormMethods['formState']; | ||
errors: UseFormMethods['errors']; | ||
trigger: UseFormMethods['trigger']; | ||
register: UseFormMethods['register']; | ||
getValues: UseFormMethods['getValues']; | ||
onFocus?: () => void; | ||
email: string; | ||
onFocusMetricsEvent?: () => void; | ||
onSubmit: (e?: React.BaseSyntheticEvent) => Promise<void>; | ||
loading: boolean; | ||
isSync: boolean; | ||
offeredSyncEngineConfigs?: typeof syncEngineConfigs; | ||
setDeclinedSyncEngines: React.Dispatch<React.SetStateAction<string[]>>; | ||
isDesktopRelay: boolean; | ||
setSelectedNewsletterSlugs?: React.Dispatch<React.SetStateAction<string[]>>; | ||
// Age check props, if not provided it will not be rendered | ||
ageCheckErrorText?: string; | ||
setAgeCheckErrorText?: React.Dispatch<React.SetStateAction<string>>; | ||
onFocusAgeInput?: () => void; | ||
onBlurAgeInput?: () => void; | ||
submitButtonGleanId?: string; | ||
}; |
118 changes: 118 additions & 0 deletions
118
packages/fxa-settings/src/lib/hooks/useSyncEngines/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { useEffect, useMemo, useState } from 'react'; | ||
import { | ||
Integration, | ||
isOAuthIntegration, | ||
isSyncDesktopV3Integration, | ||
} from '../../../models'; | ||
import { | ||
defaultDesktopV3SyncEngineConfigs, | ||
getSyncEngineIds, | ||
syncEngineConfigs, | ||
webChannelDesktopV3EngineConfigs, | ||
} from '../../../components/ChooseWhatToSync/sync-engines'; | ||
import firefox from '../../channels/firefox'; | ||
import { Constants } from '../../constants'; | ||
|
||
type SyncEnginesIntegration = Pick<Integration, 'type' | 'isSync'>; | ||
|
||
export function useSyncEngines(integration: SyncEnginesIntegration) { | ||
const isSyncOAuth = isOAuthIntegration(integration) && integration.isSync(); | ||
const isSyncDesktopV3 = isSyncDesktopV3Integration(integration); | ||
const isSync = integration.isSync(); | ||
|
||
const [webChannelEngines, setWebChannelEngines] = useState< | ||
string[] | undefined | ||
>(); | ||
const [offeredSyncEngineConfigs, setOfferedSyncEngineConfigs] = useState< | ||
typeof syncEngineConfigs | undefined | ||
>(); | ||
const [declinedSyncEngines, setDeclinedSyncEngines] = useState<string[]>([]); | ||
|
||
useEffect(() => { | ||
// This sends a web channel message to the browser to prompt a response | ||
// that we listen for. | ||
// TODO: In content-server, we send this on app-start for all integration types. | ||
// Do we want to move this somewhere else once the index page is Reactified? | ||
if (isSync) { | ||
(async () => { | ||
const status = await firefox.fxaStatus({ | ||
// TODO: Improve getting 'context', probably set this on the integration | ||
context: isSyncDesktopV3 | ||
? Constants.FX_DESKTOP_V3_CONTEXT | ||
: Constants.OAUTH_CONTEXT, | ||
isPairing: false, | ||
service: Constants.SYNC_SERVICE, | ||
}); | ||
if (!webChannelEngines && status.capabilities.engines) { | ||
// choose_what_to_sync may be disabled for mobile sync, see: | ||
// https://github.com/mozilla/application-services/issues/1761 | ||
// Desktop OAuth Sync will always provide this capability too | ||
// for consistency. | ||
if ( | ||
isSyncDesktopV3 || | ||
(isSyncOAuth && status.capabilities.choose_what_to_sync) | ||
) { | ||
setWebChannelEngines(status.capabilities.engines); | ||
} | ||
} | ||
})(); | ||
} | ||
}, [isSync, isSyncDesktopV3, isSyncOAuth, webChannelEngines]); | ||
|
||
useEffect(() => { | ||
if (webChannelEngines) { | ||
LZoog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (isSyncDesktopV3) { | ||
// Desktop v3 web channel message sends additional engines | ||
setOfferedSyncEngineConfigs([ | ||
...defaultDesktopV3SyncEngineConfigs, | ||
...webChannelDesktopV3EngineConfigs.filter((engine) => | ||
webChannelEngines.includes(engine.id) | ||
), | ||
]); | ||
} else if (isSyncOAuth) { | ||
// OAuth Webchannel context sends all engines | ||
setOfferedSyncEngineConfigs( | ||
syncEngineConfigs.filter((engine) => | ||
webChannelEngines.includes(engine.id) | ||
) | ||
); | ||
} | ||
} | ||
}, [isSyncDesktopV3, isSyncOAuth, webChannelEngines]); | ||
|
||
useEffect(() => { | ||
if (offeredSyncEngineConfigs) { | ||
const defaultDeclinedSyncEngines = offeredSyncEngineConfigs | ||
.filter((engineConfig) => !engineConfig.defaultChecked) | ||
.map((engineConfig) => engineConfig.id); | ||
setDeclinedSyncEngines(defaultDeclinedSyncEngines); | ||
} | ||
}, [offeredSyncEngineConfigs, setDeclinedSyncEngines]); | ||
|
||
const offeredSyncEngines = getSyncEngineIds(offeredSyncEngineConfigs || []); | ||
|
||
const selectedEngines = useMemo(() => { | ||
if (isSync) { | ||
return offeredSyncEngines.reduce((acc, syncEngId) => { | ||
acc[syncEngId] = !declinedSyncEngines.includes(syncEngId); | ||
return acc; | ||
}, {} as Record<string, boolean>); | ||
} | ||
return {}; | ||
}, [isSync, declinedSyncEngines, offeredSyncEngines]); | ||
|
||
return { | ||
offeredSyncEngines, | ||
offeredSyncEngineConfigs, | ||
declinedSyncEngines, | ||
setDeclinedSyncEngines, | ||
// for metrics | ||
selectedEngines, | ||
}; | ||
} | ||
|
||
export default useSyncEngines; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This won't roll out until we also turn the feature flag on. I'll double check that's set up properly.
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.
PR on SRE side: https://github.com/mozilla-it/webservices-infra/pull/3382