WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 50e76e6

Browse files
author
Richard Bangay
committed
create a readonly email input component for the iframed signin and register pages
style amends to the iframed pages to make them more like the supporter onboarding designs (more like support-frontend style which is currently the only consumer of the iframed routes)
1 parent 56ed5e3 commit 50e76e6

File tree

9 files changed

+106
-38
lines changed

9 files changed

+106
-38
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Meta } from '@storybook/react';
2+
import React from 'react';
3+
import IframeThemedEmailInput from '@/client/components/IframeThemedEmailInput';
4+
5+
export default {
6+
title: 'Components/IframeThemedEmailInput',
7+
component: IframeThemedEmailInput,
8+
parameters: {
9+
layout: 'padded',
10+
},
11+
} as Meta;
12+
13+
export const Default = () => {
14+
return <IframeThemedEmailInput label="Themed text input" />;
15+
};
16+
Default.storyName = 'default';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import { TextInput, TextInputProps } from '@guardian/source/react-components';
3+
4+
const textInputTheme = {
5+
textLabel: 'var(--color-input-label)',
6+
textUserInput: 'var(--color-input-text)',
7+
border: 'var(--color-input-border)',
8+
backgroundInput: 'var(--color-input-highlight)',
9+
};
10+
11+
const IframeThemedEmailInput = (props: Omit<TextInputProps, 'theme'>) => {
12+
return <TextInput {...props} theme={textInputTheme} />;
13+
};
14+
15+
export default IframeThemedEmailInput;

src/client/layouts/MinimalLayout.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import useClientState from '@/client/lib/hooks/useClientState';
1212
import { SuccessSummary } from '@guardian/source-development-kitchen/react-components';
1313

1414
import locations from '@/shared/lib/locations';
15-
import { DarkTheme, LightTheme, Theme } from '@/client/styles/Theme';
15+
import { IframeLightTheme, Theme } from '@/client/styles/Theme';
1616
import {
1717
mainSectionStyles,
1818
successMessageStyles,
@@ -40,7 +40,7 @@ interface MinimalLayoutProps {
4040
errorContext?: React.ReactNode;
4141
showErrorReportUrl?: boolean;
4242
shortRequestId?: string;
43-
overrideTheme?: 'light' | 'dark';
43+
overrideTheme?: 'iframe-light';
4444
}
4545

4646
const mainStyles = (wide: boolean) => css`
@@ -91,11 +91,8 @@ export const MinimalLayout = ({
9191
const errorMessage = errorOverride || error;
9292

9393
const getTheme = () => {
94-
if (overrideTheme === 'light') {
95-
return <LightTheme />;
96-
}
97-
if (overrideTheme === 'dark') {
98-
return <DarkTheme />;
94+
if (overrideTheme === 'iframe-light') {
95+
return <IframeLightTheme />;
9996
}
10097
return <Theme />;
10198
};

src/client/pages/IframedPasscodeEmailSent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export const IframedPasscodeEmailSent = ({
172172
shortRequestId={shortRequestId}
173173
showGuardianHeader={false}
174174
subduedHeadingStyle={true}
175-
overrideTheme="light"
175+
overrideTheme="iframe-light"
176176
>
177177
{email ? (
178178
<MainBodyText>

src/client/pages/IframedRegisterWithEmail.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import ThemedLink from '@/client/components/ThemedLink';
1010
import locations from '@/shared/lib/locations';
1111
import { SUPPORT_EMAIL } from '@/shared/model/Configuration';
1212
import { PasscodeErrors } from '@/shared/model/Errors';
13+
import IframeThemedEmailInput from '../components/IframeThemedEmailInput';
14+
import { disableAutofillBackground } from '../styles/Shared';
1315

1416
type RegisterWithEmailProps = RegistrationProps & {
1517
shortRequestId?: string;
@@ -58,7 +60,7 @@ export const IframedRegisterWithEmail = ({
5860
errorOverride={pageError}
5961
showGuardianHeader={false}
6062
subduedHeadingStyle={true}
61-
overrideTheme="light"
63+
overrideTheme="iframe-light"
6264
>
6365
<MainForm
6466
formAction={buildUrlWithQueryParams('/register', {}, queryParams)}
@@ -75,11 +77,24 @@ export const IframedRegisterWithEmail = ({
7577
primaryTermsPosition={false}
7678
shortRequestId={shortRequestId}
7779
>
78-
<EmailInput
79-
label="Email address"
80-
defaultValue={email}
81-
autoComplete="off"
82-
/>
80+
{email ? (
81+
<IframeThemedEmailInput
82+
label="Email address"
83+
name="email"
84+
type="email"
85+
autoComplete="email"
86+
defaultValue={email}
87+
cssOverrides={disableAutofillBackground}
88+
readOnly
89+
aria-readonly
90+
/>
91+
) : (
92+
<EmailInput
93+
label="Email address"
94+
defaultValue={email}
95+
autoComplete="off"
96+
/>
97+
)}
8398
</MainForm>
8499
</MinimalLayout>
85100
);

src/client/pages/IframedSignIn.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import locations from '@/shared/lib/locations';
2121
import { SUPPORT_EMAIL } from '@/shared/model/Configuration';
2222
import { MinimalLayout } from '@/client/layouts/MinimalLayout';
2323
import ThemedLink from '@/client/components/ThemedLink';
24+
import IframeThemedEmailInput from '../components/IframeThemedEmailInput';
25+
import { disableAutofillBackground } from '../styles/Shared';
2426

2527
export type IframedSignInProps = {
2628
queryParams: QueryParams;
@@ -158,7 +160,7 @@ export const IframedSignIn = ({
158160
shortRequestId={shortRequestId}
159161
showGuardianHeader={false}
160162
subduedHeadingStyle={true}
161-
overrideTheme="light"
163+
overrideTheme="iframe-light"
162164
>
163165
{/* AuthProviderButtons component with show boolean */}
164166
{!hideSocialButtons &&
@@ -191,7 +193,21 @@ export const IframedSignIn = ({
191193
name="isCombinedSigninAndRegisterFlow"
192194
value="combined"
193195
/>
194-
<EmailInput label="Email address" defaultValue={email} />
196+
{email ? (
197+
<IframeThemedEmailInput
198+
label="Email address"
199+
name="email"
200+
type="email"
201+
autoComplete="email"
202+
defaultValue={email}
203+
cssOverrides={disableAutofillBackground}
204+
readOnly
205+
aria-readonly
206+
/>
207+
) : (
208+
<EmailInput label="Email address" defaultValue={email} />
209+
)}
210+
195211
<input type="hidden" name="passcode" value="passcode" />
196212
</MainForm>
197213
</MinimalLayout>

src/client/styles/Theme.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ const darkTheme = css`
7272
--color-alert-success: ${palette.success[500]};
7373
`;
7474

75+
const iframeLightTheme = css`
76+
${lightTheme}
77+
--color-heading: ${palette.neutral[7]};
78+
--color-input-text: ${palette.neutral[7]};
79+
--color-input-label: ${palette.neutral[7]};
80+
`;
81+
7582
export const Theme = () => {
7683
return (
7784
<Global
@@ -101,28 +108,12 @@ export const Theme = () => {
101108
);
102109
};
103110

104-
export const LightTheme = () => {
105-
return (
106-
<Global
107-
styles={css`
108-
:root {
109-
${lightTheme}
110-
}
111-
112-
body {
113-
background: var(--color-background);
114-
}
115-
`}
116-
/>
117-
);
118-
};
119-
120-
export const DarkTheme = () => {
111+
export const IframeLightTheme = () => {
121112
return (
122113
<Global
123114
styles={css`
124115
:root {
125-
${darkTheme}
116+
${iframeLightTheme}
126117
}
127118
128119
body {

src/server/routes/register.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ router.get(
112112
const handleRegisterByPasscode = (
113113
req: Request,
114114
res: ResponseWithRequestState,
115+
overrideEmailAddress?: string | null,
115116
): string => {
116117
const state = res.locals;
117118
const { error, error_description } = state.queryParams;
@@ -121,7 +122,7 @@ const handleRegisterByPasscode = (
121122
pageTitle: 'Register With Email',
122123
requestState: mergeRequestState(state, {
123124
pageData: {
124-
email: readEmailCookie(req),
125+
email: overrideEmailAddress || readEmailCookie(req),
125126
},
126127
globalMessage: {
127128
error: getErrorMessageFromQueryParams(error, error_description),
@@ -143,7 +144,15 @@ router.get(
143144
'/iframed/register/email',
144145
redirectIfLoggedIn,
145146
(req: Request, res: ResponseWithRequestState) => {
146-
const html = handleRegisterByPasscode(req, res);
147+
const params = new URLSearchParams(
148+
req.url.substring(req.url.indexOf('?'), req.url.length),
149+
);
150+
const prepopulatedEmailParamEncoded = params.get('prepopulateEmail');
151+
const prepopulatedEmail = prepopulatedEmailParamEncoded
152+
? decodeURIComponent(prepopulatedEmailParamEncoded)
153+
: null;
154+
155+
const html = handleRegisterByPasscode(req, res, prepopulatedEmail);
147156
res.type('html').send(html);
148157
},
149158
);

src/server/routes/signIn.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const getErrorMessageFromQueryParams = (
9898
const handleSigninRender = async (
9999
req: Request,
100100
res: ResponseWithRequestState,
101+
overrideEmailAddress?: string | null,
101102
): Promise<string> => {
102103
const state = res.locals;
103104
const { encryptedEmail, error, error_description, signInEmail } =
@@ -115,7 +116,7 @@ const handleSigninRender = async (
115116
const html = renderer(getPath, {
116117
requestState: mergeRequestState(state, {
117118
pageData: {
118-
email,
119+
email: overrideEmailAddress || email,
119120
focusPasswordField: !!email,
120121
},
121122
globalMessage: {
@@ -140,7 +141,15 @@ router.get(
140141
'/iframed/signin',
141142
redirectIfLoggedIn,
142143
handleAsyncErrors(async (req: Request, res: ResponseWithRequestState) => {
143-
const html = await handleSigninRender(req, res);
144+
const params = new URLSearchParams(
145+
req.url.substring(req.url.indexOf('?'), req.url.length),
146+
);
147+
const prepopulatedEmailParamEncoded = params.get('prepopulateEmail');
148+
const prepopulatedEmail = prepopulatedEmailParamEncoded
149+
? decodeURIComponent(prepopulatedEmailParamEncoded)
150+
: null;
151+
152+
const html = await handleSigninRender(req, res, prepopulatedEmail);
144153
return res.type('html').send(html);
145154
}),
146155
);

0 commit comments

Comments
 (0)