Skip to content

Commit d2cd45c

Browse files
Privacy policy followup (#3924)
* Use early return * Cleanup Privacy toast * Extract showPrivacyPolicyNotification action
1 parent 31ef601 commit d2cd45c

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

packages/app/src/app/overmind/internalActions.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ export const handleError: Action<{
513513
});
514514
};
515515

516-
export const trackCurrentTeams: AsyncAction = async ({ state, effects }) => {
516+
export const trackCurrentTeams: AsyncAction = async ({ effects }) => {
517517
const { me } = await effects.gql.queries.teams({});
518518
if (me) {
519519
effects.analytics.setGroup(
@@ -526,3 +526,33 @@ export const trackCurrentTeams: AsyncAction = async ({ state, effects }) => {
526526
);
527527
}
528528
};
529+
530+
const seenTermsKey = 'ACCEPTED_TERMS_CODESANDBOX';
531+
export const showPrivacyPolicyNotification: Action = ({ effects, state }) => {
532+
if (effects.browser.storage.get(seenTermsKey)) {
533+
return;
534+
}
535+
536+
if (!state.isFirstVisit) {
537+
effects.analytics.track('Saw Privacy Policy Notification');
538+
effects.notificationToast.add({
539+
message:
540+
'Hello, our privacy policy has been updated recently. What’s new? CodeSandbox emails. Please read and reach out.',
541+
title: 'Updated Privacy',
542+
status: NotificationStatus.NOTICE,
543+
sticky: true,
544+
actions: {
545+
primary: [
546+
{
547+
label: 'Open Privacy Policy',
548+
run: () => {
549+
window.open('https://codesandbox.io/legal/privacy', '_blank');
550+
},
551+
},
552+
],
553+
},
554+
});
555+
}
556+
557+
effects.browser.storage.set(seenTermsKey, true);
558+
};

packages/app/src/app/overmind/onInitialize.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { NotificationStatus } from '@codesandbox/notifications';
21
import { OnInitialize } from '.';
32

43
export const onInitialize: OnInitialize = async (
54
{ state, effects, actions },
65
overmindInstance
76
) => {
87
const provideJwtToken = () => state.jwt || effects.jwt.get();
9-
const seenTermsKey = 'ACCEPTED_TERMS_CODESANDBOX';
108

119
state.isFirstVisit = Boolean(
1210
!effects.jwt.get() && !effects.browser.storage.get('hasVisited')
@@ -107,26 +105,5 @@ export const onInitialize: OnInitialize = async (
107105

108106
effects.preview.initialize(overmindInstance.reaction);
109107

110-
// show terms message on first visit since new terms
111-
if (!effects.browser.storage.get(seenTermsKey) && !state.isFirstVisit) {
112-
effects.analytics.track('Saw Privacy Policy Notification');
113-
effects.notificationToast.add({
114-
message:
115-
'Hello, our privacy policy has been updated recently. What’s new? CodeSandbox emails. Please read and reach out.',
116-
title: 'Updated Privacy',
117-
status: NotificationStatus.NOTICE,
118-
sticky: true,
119-
actions: {
120-
primary: [
121-
{
122-
label: 'Open Privacy Policy',
123-
run: () => {
124-
window.open('https://codesandbox.io/legal/privacy', '_blank');
125-
},
126-
},
127-
],
128-
},
129-
});
130-
}
131-
effects.browser.storage.set(seenTermsKey, true);
108+
actions.internal.showPrivacyPolicyNotification();
132109
};

packages/homepage/src/components/Toast/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
/* eslint-disable jsx-a11y/control-has-associated-label */
21
import React, { useState, useEffect } from 'react';
32
import track from '@codesandbox/common/lib/utils/analytics';
43
import { Link } from 'gatsby';
54
import { AnimatePresence } from 'framer-motion';
65

76
import { ToastContainer } from './elements';
87

8+
const key = 'ACCEPTED_TERMS_CODESANDBOX';
99
const Privacy = () => {
10-
const key = 'ACCEPTED_TERMS_CODESANDBOX';
1110
const [show, setShow] = useState(false);
1211

1312
useEffect(() => {
14-
const hasSeen = !!window.localStorage.getItem(key);
13+
const hasSeen = Boolean(window.localStorage.getItem(key));
1514
if (!hasSeen) {
1615
setShow(true);
1716
window.localStorage.setItem(key, true);
@@ -33,7 +32,7 @@ const Privacy = () => {
3332
<Link to="/legal/privacy">Privacy Policy</Link>
3433
<button
3534
type="button"
36-
ariaLabel="Close"
35+
aria-label="Close"
3736
onClick={() => setShow(false)}
3837
/>
3938
</ToastContainer>

0 commit comments

Comments
 (0)