-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathpromo.tsx
126 lines (109 loc) · 2.85 KB
/
promo.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React, { FC, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import styled from "styled-components";
import { Close } from "@/components/misc/close";
import { State, WorkshopsState } from "@/state";
import { hidePromo, showPromo } from "@/state/common";
import { Dialog, DialogContainer, DialogLinkButton } from "./dialog";
export const Promo: FC = () => {
const showCookieConsent = useSelector<State, boolean>(
(state) => state.common.showCookieConsent
);
const show = useSelector<State, boolean>((state) => state.common.showPromo);
const workshop = useSelector<State, WorkshopsState[number] | undefined>(
(state) => state.workshops.find(({ banner, active }) => banner && active)
);
const dispatch = useDispatch();
const storageKey = workshop && `banner:workshop-${workshop.id}`;
const handleDismiss = () => {
if (storageKey) {
localStorage.setItem(storageKey, "true");
dispatch(hidePromo());
}
};
useEffect(() => {
if (storageKey) {
const dismissed = localStorage.getItem(storageKey);
if (dismissed !== "true") {
dispatch(showPromo());
}
}
}, []);
if (!workshop) {
return null;
}
return (
<Dialog
role="dialog"
aria-live="polite"
aria-label="promo"
aria-describedby="promo:desc"
show={!showCookieConsent && show}
>
{!showCookieConsent && show && (
<Boundary>
<Container>
<Message id="promo:desc">
<Title>{workshop.title}</Title>
<Description>{workshop.teaser}</Description>
</Message>
<Actions>
<DialogLinkButton to={workshop.url}>
Check it out!
</DialogLinkButton>
<Dismiss
aria-label="dismiss promo message"
onClick={handleDismiss}
/>
</Actions>
</Container>
</Boundary>
)}
</Dialog>
);
};
const Boundary = styled.div`
position: relative;
max-width: 1000px;
margin: auto;
`;
const Container = styled(DialogContainer)`
@media only screen and (min-width: 600px) {
flex-direction: row;
align-items: flex-end;
gap: 20px;
}
`;
const Message = styled.div`
flex: 1 1 auto;
font-size: 16px;
@media only screen and (min-width: 600px) {
font-size: 18px;
}
`;
const Title = styled.h5`
color: #0b0722;
`;
const Description = styled.p`
line-height: 1.667em;
color: #0b0722;
`;
const Actions = styled.div`
flex: 0 0 auto;
display: flex;
flex-direction: column-reverse;
align-items: flex-end;
@media only screen and (min-width: 600px) {
${DialogLinkButton} {
align-self: flex-end;
margin-right: 10px;
width: 140px;
}
}
`;
const Dismiss = styled(Close)`
position: absolute;
top: 10px;
right: 10px;
padding: 10px;
`;