Skip to content

Commit e283430

Browse files
committed
feat: Hide First Edition newsletter when reader is signing in to Guardian Jobs with an existing account
1 parent a615089 commit e283430

File tree

8 files changed

+41
-23
lines changed

8 files changed

+41
-23
lines changed

src/client/components/RegistrationConsents.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ interface RegistrationConsentsProps {
99
geolocation?: GeoLocation;
1010
appName?: AppName;
1111
isJobs?: boolean;
12+
hideRegistrationNewsletter?: boolean;
1213
onChange?: (id: string, checked: boolean) => void;
1314
}
1415

1516
export const RegistrationConsents = ({
1617
geolocation,
1718
appName,
1819
isJobs,
20+
hideRegistrationNewsletter,
1921
}: RegistrationConsentsProps) => {
20-
const consentList = getRegistrationConsentsList(
21-
isJobs ?? false,
22+
const consentList = getRegistrationConsentsList({
23+
isJobs: isJobs ?? false,
2224
geolocation,
2325
appName,
24-
);
26+
hideRegistrationNewsletter,
27+
});
2528
return (
2629
<ToggleSwitchList>
2730
{consentList.map((consentItem) => (

src/client/pages/NewAccountConsents.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type NewAccountConsentsProps = RegistrationProps & {
2020
appName?: AppName;
2121
shortRequestId?: string;
2222
pageError?: string;
23+
hideRegistrationNewsletter?: boolean;
2324
};
2425

2526
const getErrorContext = (pageError?: string) => {
@@ -52,6 +53,7 @@ export const NewAccountConsents = ({
5253
appName,
5354
shortRequestId,
5455
pageError,
56+
hideRegistrationNewsletter,
5557
}: NewAccountConsentsProps) => {
5658
const formTrackingName = 'register';
5759

@@ -96,6 +98,7 @@ export const NewAccountConsents = ({
9698
geolocation={geolocation}
9799
appName={appName}
98100
isJobs={isJobs}
101+
hideRegistrationNewsletter={hideRegistrationNewsletter}
99102
/>
100103
</MainForm>
101104
</MinimalLayout>

src/client/pages/NewAccountConsentsPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const NewAccountConsentsPage = () => {
1111
shortRequestId,
1212
globalMessage = {},
1313
} = clientState;
14-
const { email, formError } = pageData;
14+
const { email, formError, signInOrRegister } = pageData;
1515
const { recaptchaSiteKey } = recaptchaConfig;
1616
const { error: pageError } = globalMessage;
1717

@@ -25,6 +25,7 @@ export const NewAccountConsentsPage = () => {
2525
appName={pageData.appName}
2626
shortRequestId={shortRequestId}
2727
pageError={pageError}
28+
hideRegistrationNewsletter={signInOrRegister === 'REGISTER'}
2829
/>
2930
);
3031
};

src/server/routes/agree.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { loginMiddlewareOAuth } from '@/server/lib/middleware/login';
1212
import { deleteOAuthTokenCookie } from '@/server/lib/okta/tokens';
1313
import { requestStateHasOAuthTokens } from '../lib/middleware/requestState';
1414
import { JOBS_TOS_URI } from '@/shared/model/Configuration';
15+
import { buildUrlWithQueryParams } from '@/shared/lib/routeUtils';
1516

1617
const { defaultReturnUri, signInPageUrl } = getConfiguration();
1718

@@ -92,16 +93,16 @@ router.post(
9293
loginMiddlewareOAuth,
9394
async (req: Request, res: ResponseWithRequestState) => {
9495
const state = res.locals;
96+
const { queryParams } = state;
97+
const { firstName, secondName } = req.body;
98+
9599
if (!requestStateHasOAuthTokens(state)) {
96100
return res.redirect(
97101
303,
98-
addQueryParamsToUntypedPath(signInPageUrl, state.queryParams),
102+
addQueryParamsToUntypedPath(signInPageUrl, queryParams),
99103
);
100104
}
101105

102-
const { returnUrl, fromURI } = state.queryParams;
103-
const { firstName, secondName } = req.body;
104-
105106
try {
106107
await setupJobsUserInOkta(
107108
firstName,
@@ -121,17 +122,12 @@ router.post(
121122
error,
122123
);
123124
trackMetric('JobsGRSGroupAgree::Failure');
124-
} finally {
125-
// complete the oauth flow if coming from the okta sign in page
126-
// through the oauth flow initiated by the jobs site
127-
if (fromURI) {
128-
// eslint-disable-next-line no-unsafe-finally -- we want to redirect and return regardless of any throws
129-
return res.redirect(303, fromURI);
130-
}
131-
// otherwise try going to the return url
132-
// eslint-disable-next-line no-unsafe-finally -- we want to redirect and return regardless of any throws
133-
return res.redirect(303, returnUrl);
134125
}
126+
127+
return res.redirect(
128+
303,
129+
buildUrlWithQueryParams('/welcome/complete-account', {}, queryParams),
130+
);
135131
},
136132
);
137133

src/server/routes/welcome.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ router.get(
233233
requestState: mergeRequestState(state, {
234234
pageData: {
235235
email: encrypedCookieState?.email,
236+
signInOrRegister: encrypedCookieState?.signInOrRegister,
236237
},
237238
}),
238239
});

src/shared/model/ClientState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface PageData {
5555
consents?: Consent[];
5656
page?: ConsentPath;
5757
previousPage?: ConsentPath;
58+
signInOrRegister?: 'SIGNIN' | 'REGISTER';
5859

5960
// reset password token specific
6061
timeUntilTokenExpiry?: number;

src/shared/model/Consent.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,22 @@ interface RegistrationConsentsList {
4444
consentOrNewsletter: 'CONSENT' | 'NEWSLETTER';
4545
}
4646

47-
export const getRegistrationConsentsList = (
48-
isJobs: boolean,
49-
geolocation?: GeoLocation,
50-
appName?: AppName,
51-
): Array<RegistrationConsentsList> => {
47+
export const getRegistrationConsentsList = ({
48+
isJobs,
49+
geolocation,
50+
appName,
51+
hideRegistrationNewsletter,
52+
}: {
53+
isJobs: boolean;
54+
geolocation?: GeoLocation;
55+
appName?: AppName;
56+
hideRegistrationNewsletter?: boolean;
57+
}): Array<RegistrationConsentsList> => {
5258
const registrationNewsletter = chooseNewsletter({
5359
geolocation,
5460
appName,
5561
isJobs,
62+
hideRegistrationNewsletter,
5663
});
5764
const showMarketingConsent = !isJobs;
5865

src/shared/model/Newsletter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,19 @@ export const chooseNewsletter = ({
136136
geolocation,
137137
appName,
138138
isJobs,
139+
hideRegistrationNewsletter,
139140
}: {
140141
geolocation: GeoLocation | undefined;
141142
appName: AppName | undefined;
142143
isJobs?: boolean;
144+
hideRegistrationNewsletter?: boolean;
143145
}): RegistrationNewsletterFormFields | undefined => {
144146
const isFeast = appName === 'Feast';
145147

148+
if (hideRegistrationNewsletter && isJobs) {
149+
return undefined;
150+
}
151+
146152
if (isFeast) {
147153
return RegistrationNewslettersFormFieldsMap.feast;
148154
}

0 commit comments

Comments
 (0)