authscape 1.0.708 → 1.0.710

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,238 +0,0 @@
1
- import React, { useState, useEffect } from "react";
2
- import {
3
- Box,
4
- Button,
5
- Checkbox,
6
- FormControlLabel,
7
- Typography,
8
- Paper,
9
- Collapse,
10
- } from "@mui/material";
11
-
12
- export const GDPRConsentDialog = ({
13
- onAccept,
14
- onReject,
15
- enableAnalytics = true,
16
- enableMarketing = true,
17
- additionalPrivacyFeatures = []
18
- }) => {
19
- const initialPreferences = {
20
- necessary: true,
21
- analytics: enableAnalytics,
22
- marketing: enableMarketing,
23
- ...Object.fromEntries(
24
- additionalPrivacyFeatures.map((item) => [item.id, item.checked ?? false])
25
- ),
26
- };
27
-
28
- const [open, setOpen] = useState(false);
29
- const [customize, setCustomize] = useState(false);
30
- const [preferences, setPreferences] = useState(initialPreferences);
31
-
32
- useEffect(() => {
33
- const savedConsent = localStorage.getItem("gdpr-consent");
34
- if (!savedConsent) {
35
- setOpen(true);
36
- }
37
- }, []);
38
-
39
- const saveConsentAndClose = (prefs) => {
40
- localStorage.setItem("gdpr-consent", JSON.stringify(prefs));
41
- if (onAccept) onAccept(prefs);
42
- setOpen(false);
43
- };
44
-
45
- const handleAcceptAll = () => {
46
- const allPrefs = {
47
- necessary: true,
48
- analytics: enableAnalytics,
49
- marketing: enableMarketing,
50
- ...Object.fromEntries(
51
- additionalPrivacyFeatures.map((item) => [item.id, true])
52
- ),
53
- };
54
- saveConsentAndClose(allPrefs);
55
- };
56
-
57
- const handleRejectAll = () => {
58
- const rejectedPrefs = {
59
- necessary: true,
60
- analytics: false,
61
- marketing: false,
62
- ...Object.fromEntries(
63
- additionalPrivacyFeatures.map((item) => [item.id, false])
64
- ),
65
- };
66
- localStorage.setItem("gdpr-consent", JSON.stringify(rejectedPrefs));
67
- if (onReject) onReject();
68
- setOpen(false);
69
- };
70
-
71
- const handleAcceptSelected = () => {
72
- saveConsentAndClose(preferences);
73
- };
74
-
75
- const handleCheckboxChange = (key) => (event) => {
76
- setPreferences((prev) => ({
77
- ...prev,
78
- [key]: event.target.checked,
79
- }));
80
- };
81
-
82
- if (!open) return null;
83
-
84
- return (
85
- <Paper
86
- elevation={4}
87
- sx={{
88
- position: "fixed",
89
- bottom: 0,
90
- left: 0,
91
- right: 0,
92
- p: 2,
93
- zIndex: 1300,
94
- backgroundColor: "#fff",
95
- borderTop: "1px solid #ccc",
96
- }}
97
- >
98
- <Box
99
- display="flex"
100
- flexDirection="column"
101
- alignItems="flex-start"
102
- gap={2}
103
- >
104
- <Box>
105
- <Typography variant="subtitle1" fontWeight="bold">
106
- We value your privacy
107
- </Typography>
108
- <Typography variant="body2">
109
- We use cookies to enhance your experience, for analytics and
110
- marketing. You can accept all, reject all, or customize your
111
- preferences.
112
- </Typography>
113
- </Box>
114
-
115
- <Collapse in={customize}>
116
- <Box mb={2}>
117
- <Box mb={1}>
118
- <FormControlLabel
119
- control={<Checkbox checked disabled />}
120
- label="Necessary (always required)"
121
- />
122
- <br/>
123
- <Typography variant="caption" color="textSecondary" sx={{ ml: 4 }}>
124
- Required to enable core site functionality such as security,
125
- authentication, and accessibility.
126
- </Typography>
127
- </Box>
128
-
129
- {enableAnalytics && (
130
- <Box mb={1}>
131
- <FormControlLabel
132
- control={
133
- <Checkbox
134
- checked={preferences.analytics}
135
- onChange={handleCheckboxChange("analytics")}
136
- />
137
- }
138
- label="Analytics"
139
- />
140
- <br/>
141
- <Typography
142
- variant="caption"
143
- color="textSecondary"
144
- sx={{ ml: 4 }}
145
- >
146
- Helps us understand how you use our site so we can improve it.
147
- For example, tracking page visits or feature usage.
148
- </Typography>
149
- </Box>
150
- )}
151
-
152
- {enableMarketing && (
153
- <Box mb={1}>
154
- <FormControlLabel
155
- control={
156
- <Checkbox
157
- checked={preferences.marketing}
158
- onChange={handleCheckboxChange("marketing")}
159
- />
160
- }
161
- label="Marketing"
162
- />
163
- <br/>
164
- <Typography
165
- variant="caption"
166
- color="textSecondary"
167
- sx={{ ml: 4 }}
168
- >
169
- Allows us to show personalized ads and promotions based on your
170
- behavior and interactions.
171
- </Typography>
172
- </Box>
173
- )}
174
-
175
- {additionalPrivacyFeatures.map((feature) => (
176
- <Box key={feature.id} mb={1}>
177
- <FormControlLabel
178
- control={
179
- <Checkbox
180
- checked={preferences[feature.id] || false}
181
- onChange={handleCheckboxChange(feature.id)}
182
- />
183
- }
184
- label={feature.title}
185
- />
186
- <br/>
187
- <Typography
188
- variant="caption"
189
- color="textSecondary"
190
- sx={{ ml: 4 }}
191
- >
192
- {feature.description}
193
- </Typography>
194
- </Box>
195
- ))}
196
- </Box>
197
- </Collapse>
198
-
199
- <Box display="flex" gap={1} flexWrap="wrap">
200
- {!customize ? (
201
- <>
202
- <Button
203
- variant="contained"
204
- color="primary"
205
- onClick={handleAcceptAll}
206
- >
207
- Accept All
208
- </Button>
209
- <Button
210
- variant="outlined"
211
- color="error"
212
- onClick={handleRejectAll}
213
- >
214
- Reject All
215
- </Button>
216
- <Button variant="text" onClick={() => setCustomize(true)}>
217
- Customize Preferences
218
- </Button>
219
- </>
220
- ) : (
221
- <>
222
- <Button
223
- variant="contained"
224
- color="primary"
225
- onClick={handleAcceptSelected}
226
- >
227
- Save Preferences
228
- </Button>
229
- <Button variant="text" onClick={() => setCustomize(false)}>
230
- Cancel
231
- </Button>
232
- </>
233
- )}
234
- </Box>
235
- </Box>
236
- </Paper>
237
- );
238
- }