payload-plugin-newsletter 0.3.2 → 0.4.5
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.
- package/CHANGELOG.md +44 -1
- package/CLAUDE.md +31 -19
- package/dist/client.cjs +899 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +52 -0
- package/dist/client.d.ts +52 -0
- package/dist/client.js +867 -0
- package/dist/client.js.map +1 -0
- package/dist/components.cjs +899 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +4 -0
- package/dist/components.d.ts +4 -0
- package/dist/components.js +867 -0
- package/dist/components.js.map +1 -0
- package/dist/index.cjs +2004 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +1967 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types/index.d.ts → types.d.cts} +19 -17
- package/dist/types.d.ts +350 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -25
- package/dist/.tsbuildinfo +0 -1
- package/dist/collections/NewsletterSettings.d.ts +0 -4
- package/dist/collections/NewsletterSettings.d.ts.map +0 -1
- package/dist/collections/Subscribers.d.ts +0 -4
- package/dist/collections/Subscribers.d.ts.map +0 -1
- package/dist/components/MagicLinkVerify.d.ts +0 -27
- package/dist/components/MagicLinkVerify.d.ts.map +0 -1
- package/dist/components/NewsletterForm.d.ts +0 -5
- package/dist/components/NewsletterForm.d.ts.map +0 -1
- package/dist/components/PreferencesForm.d.ts +0 -5
- package/dist/components/PreferencesForm.d.ts.map +0 -1
- package/dist/components/index.d.ts +0 -5
- package/dist/components/index.d.ts.map +0 -1
- package/dist/endpoints/index.d.ts +0 -4
- package/dist/endpoints/index.d.ts.map +0 -1
- package/dist/endpoints/preferences.d.ts +0 -5
- package/dist/endpoints/preferences.d.ts.map +0 -1
- package/dist/endpoints/subscribe.d.ts +0 -4
- package/dist/endpoints/subscribe.d.ts.map +0 -1
- package/dist/endpoints/unsubscribe.d.ts +0 -4
- package/dist/endpoints/unsubscribe.d.ts.map +0 -1
- package/dist/endpoints/verify-magic-link.d.ts +0 -4
- package/dist/endpoints/verify-magic-link.d.ts.map +0 -1
- package/dist/exports/client.d.ts +0 -6
- package/dist/exports/client.d.ts.map +0 -1
- package/dist/exports/components.d.ts +0 -2
- package/dist/exports/components.d.ts.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/fields/newsletterScheduling.d.ts +0 -4
- package/dist/fields/newsletterScheduling.d.ts.map +0 -1
- package/dist/hooks/useNewsletterAuth.d.ts +0 -16
- package/dist/hooks/useNewsletterAuth.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/providers/broadcast.d.ts +0 -19
- package/dist/providers/broadcast.d.ts.map +0 -1
- package/dist/providers/index.d.ts +0 -23
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/resend.d.ts +0 -20
- package/dist/providers/resend.d.ts.map +0 -1
- package/dist/providers/types.d.ts +0 -46
- package/dist/providers/types.d.ts.map +0 -1
- package/dist/src/__tests__/fixtures/newsletter-settings.js +0 -41
- package/dist/src/__tests__/fixtures/newsletter-settings.js.map +0 -1
- package/dist/src/__tests__/fixtures/subscribers.js +0 -70
- package/dist/src/__tests__/fixtures/subscribers.js.map +0 -1
- package/dist/src/__tests__/integration/collections/subscriber-hooks.test.js +0 -356
- package/dist/src/__tests__/integration/collections/subscriber-hooks.test.js.map +0 -1
- package/dist/src/__tests__/integration/endpoints/preferences.test.js +0 -266
- package/dist/src/__tests__/integration/endpoints/preferences.test.js.map +0 -1
- package/dist/src/__tests__/integration/endpoints/subscribe.test.js +0 -280
- package/dist/src/__tests__/integration/endpoints/subscribe.test.js.map +0 -1
- package/dist/src/__tests__/integration/endpoints/unsubscribe.test.js +0 -187
- package/dist/src/__tests__/integration/endpoints/unsubscribe.test.js.map +0 -1
- package/dist/src/__tests__/integration/endpoints/verify-magic-link.test.js +0 -188
- package/dist/src/__tests__/integration/endpoints/verify-magic-link.test.js.map +0 -1
- package/dist/src/__tests__/mocks/email-providers.js +0 -153
- package/dist/src/__tests__/mocks/email-providers.js.map +0 -1
- package/dist/src/__tests__/mocks/payload.js +0 -244
- package/dist/src/__tests__/mocks/payload.js.map +0 -1
- package/dist/src/__tests__/security/csrf-protection.test.js +0 -309
- package/dist/src/__tests__/security/csrf-protection.test.js.map +0 -1
- package/dist/src/__tests__/security/settings-access.test.js +0 -204
- package/dist/src/__tests__/security/settings-access.test.js.map +0 -1
- package/dist/src/__tests__/security/subscriber-access.test.js +0 -210
- package/dist/src/__tests__/security/subscriber-access.test.js.map +0 -1
- package/dist/src/__tests__/security/xss-prevention.test.js +0 -305
- package/dist/src/__tests__/security/xss-prevention.test.js.map +0 -1
- package/dist/src/__tests__/setup/integration.setup.js +0 -38
- package/dist/src/__tests__/setup/integration.setup.js.map +0 -1
- package/dist/src/__tests__/setup/unit.setup.js +0 -41
- package/dist/src/__tests__/setup/unit.setup.js.map +0 -1
- package/dist/src/__tests__/unit/utils/access.test.js +0 -116
- package/dist/src/__tests__/unit/utils/access.test.js.map +0 -1
- package/dist/src/__tests__/unit/utils/jwt.test.js +0 -238
- package/dist/src/__tests__/unit/utils/jwt.test.js.map +0 -1
- package/dist/src/collections/NewsletterSettings.js +0 -390
- package/dist/src/collections/NewsletterSettings.js.map +0 -1
- package/dist/src/collections/Subscribers.js +0 -309
- package/dist/src/collections/Subscribers.js.map +0 -1
- package/dist/src/components/MagicLinkVerify.js +0 -180
- package/dist/src/components/MagicLinkVerify.js.map +0 -1
- package/dist/src/components/NewsletterForm.js +0 -326
- package/dist/src/components/NewsletterForm.js.map +0 -1
- package/dist/src/components/PreferencesForm.js +0 -524
- package/dist/src/components/PreferencesForm.js.map +0 -1
- package/dist/src/components/index.js +0 -5
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/endpoints/index.js +0 -17
- package/dist/src/endpoints/index.js.map +0 -1
- package/dist/src/endpoints/preferences.js +0 -136
- package/dist/src/endpoints/preferences.js.map +0 -1
- package/dist/src/endpoints/subscribe.js +0 -151
- package/dist/src/endpoints/subscribe.js.map +0 -1
- package/dist/src/endpoints/unsubscribe.js +0 -105
- package/dist/src/endpoints/unsubscribe.js.map +0 -1
- package/dist/src/endpoints/verify-magic-link.js +0 -103
- package/dist/src/endpoints/verify-magic-link.js.map +0 -1
- package/dist/src/exports/client.js +0 -7
- package/dist/src/exports/client.js.map +0 -1
- package/dist/src/exports/components.js +0 -6
- package/dist/src/exports/components.js.map +0 -1
- package/dist/src/exports/types.js +0 -3
- package/dist/src/exports/types.js.map +0 -1
- package/dist/src/fields/newsletterScheduling.js +0 -195
- package/dist/src/fields/newsletterScheduling.js.map +0 -1
- package/dist/src/hooks/useNewsletterAuth.js +0 -112
- package/dist/src/hooks/useNewsletterAuth.js.map +0 -1
- package/dist/src/index.js +0 -130
- package/dist/src/index.js.map +0 -1
- package/dist/src/providers/broadcast.js +0 -158
- package/dist/src/providers/broadcast.js.map +0 -1
- package/dist/src/providers/index.js +0 -63
- package/dist/src/providers/index.js.map +0 -1
- package/dist/src/providers/resend.js +0 -122
- package/dist/src/providers/resend.js.map +0 -1
- package/dist/src/providers/types.js +0 -12
- package/dist/src/providers/types.js.map +0 -1
- package/dist/src/templates/BaseTemplate.js +0 -105
- package/dist/src/templates/BaseTemplate.js.map +0 -1
- package/dist/src/templates/MagicLinkTemplate.js +0 -178
- package/dist/src/templates/MagicLinkTemplate.js.map +0 -1
- package/dist/src/templates/NewsletterTemplate.js +0 -150
- package/dist/src/templates/NewsletterTemplate.js.map +0 -1
- package/dist/src/templates/WelcomeTemplate.js +0 -192
- package/dist/src/templates/WelcomeTemplate.js.map +0 -1
- package/dist/src/templates/index.js +0 -6
- package/dist/src/templates/index.js.map +0 -1
- package/dist/src/types/index.js +0 -3
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/utils/access.js +0 -80
- package/dist/src/utils/access.js.map +0 -1
- package/dist/src/utils/jwt.js +0 -91
- package/dist/src/utils/jwt.js.map +0 -1
- package/dist/src/utils/validation.js +0 -74
- package/dist/src/utils/validation.js.map +0 -1
- package/dist/templates/BaseTemplate.d.ts +0 -45
- package/dist/templates/BaseTemplate.d.ts.map +0 -1
- package/dist/templates/MagicLinkTemplate.d.ts +0 -67
- package/dist/templates/MagicLinkTemplate.d.ts.map +0 -1
- package/dist/templates/NewsletterTemplate.d.ts +0 -112
- package/dist/templates/NewsletterTemplate.d.ts.map +0 -1
- package/dist/templates/WelcomeTemplate.d.ts +0 -55
- package/dist/templates/WelcomeTemplate.d.ts.map +0 -1
- package/dist/templates/index.d.ts +0 -7
- package/dist/templates/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/utils/access.d.ts +0 -15
- package/dist/utils/access.d.ts.map +0 -1
- package/dist/utils/jwt.d.ts +0 -32
- package/dist/utils/jwt.d.ts.map +0 -1
- package/dist/utils/validation.d.ts +0 -25
- package/dist/utils/validation.d.ts.map +0 -1
|
@@ -1,524 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import React, { useState, useEffect } from 'react';
|
|
4
|
-
const defaultStyles = {
|
|
5
|
-
container: {
|
|
6
|
-
maxWidth: '600px',
|
|
7
|
-
margin: '0 auto',
|
|
8
|
-
padding: '2rem'
|
|
9
|
-
},
|
|
10
|
-
heading: {
|
|
11
|
-
fontSize: '1.5rem',
|
|
12
|
-
fontWeight: '600',
|
|
13
|
-
marginBottom: '1.5rem',
|
|
14
|
-
color: '#111827'
|
|
15
|
-
},
|
|
16
|
-
form: {
|
|
17
|
-
display: 'flex',
|
|
18
|
-
flexDirection: 'column',
|
|
19
|
-
gap: '1.5rem'
|
|
20
|
-
},
|
|
21
|
-
section: {
|
|
22
|
-
padding: '1.5rem',
|
|
23
|
-
backgroundColor: '#f9fafb',
|
|
24
|
-
borderRadius: '0.5rem',
|
|
25
|
-
border: '1px solid #e5e7eb'
|
|
26
|
-
},
|
|
27
|
-
sectionTitle: {
|
|
28
|
-
fontSize: '1.125rem',
|
|
29
|
-
fontWeight: '500',
|
|
30
|
-
marginBottom: '1rem',
|
|
31
|
-
color: '#111827'
|
|
32
|
-
},
|
|
33
|
-
inputGroup: {
|
|
34
|
-
display: 'flex',
|
|
35
|
-
flexDirection: 'column',
|
|
36
|
-
gap: '0.5rem'
|
|
37
|
-
},
|
|
38
|
-
label: {
|
|
39
|
-
fontSize: '0.875rem',
|
|
40
|
-
fontWeight: '500',
|
|
41
|
-
color: '#374151'
|
|
42
|
-
},
|
|
43
|
-
input: {
|
|
44
|
-
padding: '0.5rem 0.75rem',
|
|
45
|
-
fontSize: '1rem',
|
|
46
|
-
border: '1px solid #e5e7eb',
|
|
47
|
-
borderRadius: '0.375rem',
|
|
48
|
-
outline: 'none',
|
|
49
|
-
transition: 'border-color 0.2s'
|
|
50
|
-
},
|
|
51
|
-
select: {
|
|
52
|
-
padding: '0.5rem 0.75rem',
|
|
53
|
-
fontSize: '1rem',
|
|
54
|
-
border: '1px solid #e5e7eb',
|
|
55
|
-
borderRadius: '0.375rem',
|
|
56
|
-
outline: 'none',
|
|
57
|
-
backgroundColor: '#ffffff'
|
|
58
|
-
},
|
|
59
|
-
checkbox: {
|
|
60
|
-
display: 'flex',
|
|
61
|
-
alignItems: 'center',
|
|
62
|
-
gap: '0.5rem',
|
|
63
|
-
marginBottom: '0.5rem'
|
|
64
|
-
},
|
|
65
|
-
checkboxInput: {
|
|
66
|
-
width: '1rem',
|
|
67
|
-
height: '1rem'
|
|
68
|
-
},
|
|
69
|
-
checkboxLabel: {
|
|
70
|
-
fontSize: '0.875rem',
|
|
71
|
-
color: '#374151'
|
|
72
|
-
},
|
|
73
|
-
buttonGroup: {
|
|
74
|
-
display: 'flex',
|
|
75
|
-
gap: '1rem',
|
|
76
|
-
marginTop: '1rem'
|
|
77
|
-
},
|
|
78
|
-
button: {
|
|
79
|
-
padding: '0.75rem 1.5rem',
|
|
80
|
-
fontSize: '1rem',
|
|
81
|
-
fontWeight: '500',
|
|
82
|
-
borderRadius: '0.375rem',
|
|
83
|
-
cursor: 'pointer',
|
|
84
|
-
transition: 'all 0.2s',
|
|
85
|
-
border: 'none'
|
|
86
|
-
},
|
|
87
|
-
primaryButton: {
|
|
88
|
-
color: '#ffffff',
|
|
89
|
-
backgroundColor: '#3b82f6'
|
|
90
|
-
},
|
|
91
|
-
secondaryButton: {
|
|
92
|
-
color: '#374151',
|
|
93
|
-
backgroundColor: '#ffffff',
|
|
94
|
-
border: '1px solid #e5e7eb'
|
|
95
|
-
},
|
|
96
|
-
dangerButton: {
|
|
97
|
-
color: '#ffffff',
|
|
98
|
-
backgroundColor: '#ef4444'
|
|
99
|
-
},
|
|
100
|
-
error: {
|
|
101
|
-
fontSize: '0.875rem',
|
|
102
|
-
color: '#ef4444',
|
|
103
|
-
marginTop: '0.5rem'
|
|
104
|
-
},
|
|
105
|
-
success: {
|
|
106
|
-
fontSize: '0.875rem',
|
|
107
|
-
color: '#10b981',
|
|
108
|
-
marginTop: '0.5rem'
|
|
109
|
-
},
|
|
110
|
-
info: {
|
|
111
|
-
fontSize: '0.875rem',
|
|
112
|
-
color: '#6b7280',
|
|
113
|
-
marginTop: '0.5rem'
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
export const PreferencesForm = ({ subscriber: initialSubscriber, onSuccess, onError, className, styles: customStyles = {}, sessionToken, apiEndpoint = '/api/newsletter/preferences', showUnsubscribe = true, locales = [
|
|
117
|
-
'en'
|
|
118
|
-
], labels = {
|
|
119
|
-
title: 'Newsletter Preferences',
|
|
120
|
-
personalInfo: 'Personal Information',
|
|
121
|
-
emailPreferences: 'Email Preferences',
|
|
122
|
-
name: 'Name',
|
|
123
|
-
language: 'Preferred Language',
|
|
124
|
-
newsletter: 'Newsletter updates',
|
|
125
|
-
announcements: 'Product announcements',
|
|
126
|
-
saveButton: 'Save Preferences',
|
|
127
|
-
unsubscribeButton: 'Unsubscribe',
|
|
128
|
-
saving: 'Saving...',
|
|
129
|
-
saved: 'Preferences saved successfully!',
|
|
130
|
-
unsubscribeConfirm: 'Are you sure you want to unsubscribe? This cannot be undone.'
|
|
131
|
-
} })=>{
|
|
132
|
-
const [subscriber, setSubscriber] = useState(initialSubscriber || {});
|
|
133
|
-
const [loading, setLoading] = useState(false);
|
|
134
|
-
const [loadingData, setLoadingData] = useState(!initialSubscriber);
|
|
135
|
-
const [error, setError] = useState(null);
|
|
136
|
-
const [success, setSuccess] = useState(false);
|
|
137
|
-
const styles = {
|
|
138
|
-
container: {
|
|
139
|
-
...defaultStyles.container,
|
|
140
|
-
...customStyles.container
|
|
141
|
-
},
|
|
142
|
-
heading: {
|
|
143
|
-
...defaultStyles.heading,
|
|
144
|
-
...customStyles.heading
|
|
145
|
-
},
|
|
146
|
-
form: {
|
|
147
|
-
...defaultStyles.form,
|
|
148
|
-
...customStyles.form
|
|
149
|
-
},
|
|
150
|
-
section: {
|
|
151
|
-
...defaultStyles.section,
|
|
152
|
-
...customStyles.section
|
|
153
|
-
},
|
|
154
|
-
sectionTitle: {
|
|
155
|
-
...defaultStyles.sectionTitle,
|
|
156
|
-
...customStyles.sectionTitle
|
|
157
|
-
},
|
|
158
|
-
inputGroup: {
|
|
159
|
-
...defaultStyles.inputGroup,
|
|
160
|
-
...customStyles.inputGroup
|
|
161
|
-
},
|
|
162
|
-
label: {
|
|
163
|
-
...defaultStyles.label,
|
|
164
|
-
...customStyles.label
|
|
165
|
-
},
|
|
166
|
-
input: {
|
|
167
|
-
...defaultStyles.input,
|
|
168
|
-
...customStyles.input
|
|
169
|
-
},
|
|
170
|
-
select: {
|
|
171
|
-
...defaultStyles.select,
|
|
172
|
-
...customStyles.select
|
|
173
|
-
},
|
|
174
|
-
checkbox: {
|
|
175
|
-
...defaultStyles.checkbox,
|
|
176
|
-
...customStyles.checkbox
|
|
177
|
-
},
|
|
178
|
-
checkboxInput: {
|
|
179
|
-
...defaultStyles.checkboxInput,
|
|
180
|
-
...customStyles.checkboxInput
|
|
181
|
-
},
|
|
182
|
-
checkboxLabel: {
|
|
183
|
-
...defaultStyles.checkboxLabel,
|
|
184
|
-
...customStyles.checkboxLabel
|
|
185
|
-
},
|
|
186
|
-
buttonGroup: {
|
|
187
|
-
...defaultStyles.buttonGroup,
|
|
188
|
-
...customStyles.buttonGroup
|
|
189
|
-
},
|
|
190
|
-
button: {
|
|
191
|
-
...defaultStyles.button,
|
|
192
|
-
...customStyles.button
|
|
193
|
-
},
|
|
194
|
-
primaryButton: {
|
|
195
|
-
...defaultStyles.primaryButton,
|
|
196
|
-
...customStyles.primaryButton
|
|
197
|
-
},
|
|
198
|
-
secondaryButton: {
|
|
199
|
-
...defaultStyles.secondaryButton,
|
|
200
|
-
...customStyles.secondaryButton
|
|
201
|
-
},
|
|
202
|
-
dangerButton: {
|
|
203
|
-
...defaultStyles.dangerButton,
|
|
204
|
-
...customStyles.dangerButton
|
|
205
|
-
},
|
|
206
|
-
error: {
|
|
207
|
-
...defaultStyles.error,
|
|
208
|
-
...customStyles.error
|
|
209
|
-
},
|
|
210
|
-
success: {
|
|
211
|
-
...defaultStyles.success,
|
|
212
|
-
...customStyles.success
|
|
213
|
-
},
|
|
214
|
-
info: {
|
|
215
|
-
...defaultStyles.info,
|
|
216
|
-
...customStyles.info
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
// Fetch current preferences if not provided
|
|
220
|
-
useEffect(()=>{
|
|
221
|
-
if (!initialSubscriber && sessionToken) {
|
|
222
|
-
fetchPreferences();
|
|
223
|
-
}
|
|
224
|
-
}, []);
|
|
225
|
-
const fetchPreferences = async ()=>{
|
|
226
|
-
try {
|
|
227
|
-
const response = await fetch(apiEndpoint, {
|
|
228
|
-
headers: {
|
|
229
|
-
'Authorization': `Bearer ${sessionToken}`
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
if (!response.ok) {
|
|
233
|
-
throw new Error('Failed to load preferences');
|
|
234
|
-
}
|
|
235
|
-
const data = await response.json();
|
|
236
|
-
setSubscriber(data.subscriber);
|
|
237
|
-
} catch (err) {
|
|
238
|
-
setError(err instanceof Error ? err.message : 'Failed to load preferences');
|
|
239
|
-
if (onError) {
|
|
240
|
-
onError(err instanceof Error ? err : new Error('Failed to load preferences'));
|
|
241
|
-
}
|
|
242
|
-
} finally{
|
|
243
|
-
setLoadingData(false);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
const handleSave = async (e)=>{
|
|
247
|
-
e.preventDefault();
|
|
248
|
-
setError(null);
|
|
249
|
-
setSuccess(false);
|
|
250
|
-
setLoading(true);
|
|
251
|
-
try {
|
|
252
|
-
const response = await fetch(apiEndpoint, {
|
|
253
|
-
method: 'POST',
|
|
254
|
-
headers: {
|
|
255
|
-
'Content-Type': 'application/json',
|
|
256
|
-
'Authorization': `Bearer ${sessionToken}`
|
|
257
|
-
},
|
|
258
|
-
body: JSON.stringify({
|
|
259
|
-
name: subscriber.name,
|
|
260
|
-
locale: subscriber.locale,
|
|
261
|
-
emailPreferences: subscriber.emailPreferences
|
|
262
|
-
})
|
|
263
|
-
});
|
|
264
|
-
const data = await response.json();
|
|
265
|
-
if (!response.ok) {
|
|
266
|
-
throw new Error(data.error || 'Failed to save preferences');
|
|
267
|
-
}
|
|
268
|
-
setSubscriber(data.subscriber);
|
|
269
|
-
setSuccess(true);
|
|
270
|
-
if (onSuccess) {
|
|
271
|
-
onSuccess(data.subscriber);
|
|
272
|
-
}
|
|
273
|
-
} catch (err) {
|
|
274
|
-
const errorMessage = err instanceof Error ? err.message : 'An error occurred';
|
|
275
|
-
setError(errorMessage);
|
|
276
|
-
if (onError) {
|
|
277
|
-
onError(new Error(errorMessage));
|
|
278
|
-
}
|
|
279
|
-
} finally{
|
|
280
|
-
setLoading(false);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
const handleUnsubscribe = async ()=>{
|
|
284
|
-
if (!window.confirm(labels.unsubscribeConfirm)) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
setLoading(true);
|
|
288
|
-
setError(null);
|
|
289
|
-
try {
|
|
290
|
-
const response = await fetch('/api/newsletter/unsubscribe', {
|
|
291
|
-
method: 'POST',
|
|
292
|
-
headers: {
|
|
293
|
-
'Content-Type': 'application/json',
|
|
294
|
-
'Authorization': `Bearer ${sessionToken}`
|
|
295
|
-
},
|
|
296
|
-
body: JSON.stringify({
|
|
297
|
-
email: subscriber.email
|
|
298
|
-
})
|
|
299
|
-
});
|
|
300
|
-
if (!response.ok) {
|
|
301
|
-
throw new Error('Failed to unsubscribe');
|
|
302
|
-
}
|
|
303
|
-
setSubscriber({
|
|
304
|
-
...subscriber,
|
|
305
|
-
subscriptionStatus: 'unsubscribed'
|
|
306
|
-
});
|
|
307
|
-
if (onSuccess) {
|
|
308
|
-
onSuccess({
|
|
309
|
-
...subscriber,
|
|
310
|
-
subscriptionStatus: 'unsubscribed'
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
} catch (err) {
|
|
314
|
-
setError('Failed to unsubscribe. Please try again.');
|
|
315
|
-
if (onError) {
|
|
316
|
-
onError(err instanceof Error ? err : new Error('Failed to unsubscribe'));
|
|
317
|
-
}
|
|
318
|
-
} finally{
|
|
319
|
-
setLoading(false);
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
if (loadingData) {
|
|
323
|
-
return /*#__PURE__*/ _jsx("div", {
|
|
324
|
-
className: className,
|
|
325
|
-
style: styles.container,
|
|
326
|
-
children: /*#__PURE__*/ _jsx("p", {
|
|
327
|
-
style: styles.info,
|
|
328
|
-
children: "Loading preferences..."
|
|
329
|
-
})
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
if (subscriber.subscriptionStatus === 'unsubscribed') {
|
|
333
|
-
return /*#__PURE__*/ _jsxs("div", {
|
|
334
|
-
className: className,
|
|
335
|
-
style: styles.container,
|
|
336
|
-
children: [
|
|
337
|
-
/*#__PURE__*/ _jsx("h2", {
|
|
338
|
-
style: styles.heading,
|
|
339
|
-
children: "Unsubscribed"
|
|
340
|
-
}),
|
|
341
|
-
/*#__PURE__*/ _jsx("p", {
|
|
342
|
-
style: styles.info,
|
|
343
|
-
children: "You have been unsubscribed from all emails. To resubscribe, please sign up again."
|
|
344
|
-
})
|
|
345
|
-
]
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
return /*#__PURE__*/ _jsxs("div", {
|
|
349
|
-
className: className,
|
|
350
|
-
style: styles.container,
|
|
351
|
-
children: [
|
|
352
|
-
/*#__PURE__*/ _jsx("h2", {
|
|
353
|
-
style: styles.heading,
|
|
354
|
-
children: labels.title
|
|
355
|
-
}),
|
|
356
|
-
/*#__PURE__*/ _jsxs("form", {
|
|
357
|
-
onSubmit: handleSave,
|
|
358
|
-
style: styles.form,
|
|
359
|
-
children: [
|
|
360
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
361
|
-
style: styles.section,
|
|
362
|
-
children: [
|
|
363
|
-
/*#__PURE__*/ _jsx("h3", {
|
|
364
|
-
style: styles.sectionTitle,
|
|
365
|
-
children: labels.personalInfo
|
|
366
|
-
}),
|
|
367
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
368
|
-
style: styles.inputGroup,
|
|
369
|
-
children: [
|
|
370
|
-
/*#__PURE__*/ _jsx("label", {
|
|
371
|
-
htmlFor: "name",
|
|
372
|
-
style: styles.label,
|
|
373
|
-
children: labels.name
|
|
374
|
-
}),
|
|
375
|
-
/*#__PURE__*/ _jsx("input", {
|
|
376
|
-
id: "name",
|
|
377
|
-
type: "text",
|
|
378
|
-
value: subscriber.name || '',
|
|
379
|
-
onChange: (e)=>setSubscriber({
|
|
380
|
-
...subscriber,
|
|
381
|
-
name: e.target.value
|
|
382
|
-
}),
|
|
383
|
-
disabled: loading,
|
|
384
|
-
style: styles.input
|
|
385
|
-
})
|
|
386
|
-
]
|
|
387
|
-
}),
|
|
388
|
-
locales.length > 1 && /*#__PURE__*/ _jsxs("div", {
|
|
389
|
-
style: styles.inputGroup,
|
|
390
|
-
children: [
|
|
391
|
-
/*#__PURE__*/ _jsx("label", {
|
|
392
|
-
htmlFor: "locale",
|
|
393
|
-
style: styles.label,
|
|
394
|
-
children: labels.language
|
|
395
|
-
}),
|
|
396
|
-
/*#__PURE__*/ _jsx("select", {
|
|
397
|
-
id: "locale",
|
|
398
|
-
value: subscriber.locale || locales[0],
|
|
399
|
-
onChange: (e)=>setSubscriber({
|
|
400
|
-
...subscriber,
|
|
401
|
-
locale: e.target.value
|
|
402
|
-
}),
|
|
403
|
-
disabled: loading,
|
|
404
|
-
style: styles.select,
|
|
405
|
-
children: locales.map((locale)=>/*#__PURE__*/ _jsx("option", {
|
|
406
|
-
value: locale,
|
|
407
|
-
children: locale.toUpperCase()
|
|
408
|
-
}, locale))
|
|
409
|
-
})
|
|
410
|
-
]
|
|
411
|
-
})
|
|
412
|
-
]
|
|
413
|
-
}),
|
|
414
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
415
|
-
style: styles.section,
|
|
416
|
-
children: [
|
|
417
|
-
/*#__PURE__*/ _jsx("h3", {
|
|
418
|
-
style: styles.sectionTitle,
|
|
419
|
-
children: labels.emailPreferences
|
|
420
|
-
}),
|
|
421
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
422
|
-
style: styles.checkbox,
|
|
423
|
-
children: [
|
|
424
|
-
/*#__PURE__*/ _jsx("input", {
|
|
425
|
-
id: "pref-newsletter",
|
|
426
|
-
type: "checkbox",
|
|
427
|
-
checked: subscriber.emailPreferences?.newsletter ?? true,
|
|
428
|
-
onChange: (e)=>setSubscriber({
|
|
429
|
-
...subscriber,
|
|
430
|
-
emailPreferences: {
|
|
431
|
-
...subscriber.emailPreferences,
|
|
432
|
-
newsletter: e.target.checked
|
|
433
|
-
}
|
|
434
|
-
}),
|
|
435
|
-
disabled: loading,
|
|
436
|
-
style: styles.checkboxInput
|
|
437
|
-
}),
|
|
438
|
-
/*#__PURE__*/ _jsx("label", {
|
|
439
|
-
htmlFor: "pref-newsletter",
|
|
440
|
-
style: styles.checkboxLabel,
|
|
441
|
-
children: labels.newsletter
|
|
442
|
-
})
|
|
443
|
-
]
|
|
444
|
-
}),
|
|
445
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
446
|
-
style: styles.checkbox,
|
|
447
|
-
children: [
|
|
448
|
-
/*#__PURE__*/ _jsx("input", {
|
|
449
|
-
id: "pref-announcements",
|
|
450
|
-
type: "checkbox",
|
|
451
|
-
checked: subscriber.emailPreferences?.announcements ?? true,
|
|
452
|
-
onChange: (e)=>setSubscriber({
|
|
453
|
-
...subscriber,
|
|
454
|
-
emailPreferences: {
|
|
455
|
-
...subscriber.emailPreferences,
|
|
456
|
-
announcements: e.target.checked
|
|
457
|
-
}
|
|
458
|
-
}),
|
|
459
|
-
disabled: loading,
|
|
460
|
-
style: styles.checkboxInput
|
|
461
|
-
}),
|
|
462
|
-
/*#__PURE__*/ _jsx("label", {
|
|
463
|
-
htmlFor: "pref-announcements",
|
|
464
|
-
style: styles.checkboxLabel,
|
|
465
|
-
children: labels.announcements
|
|
466
|
-
})
|
|
467
|
-
]
|
|
468
|
-
})
|
|
469
|
-
]
|
|
470
|
-
}),
|
|
471
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
472
|
-
style: styles.buttonGroup,
|
|
473
|
-
children: [
|
|
474
|
-
/*#__PURE__*/ _jsx("button", {
|
|
475
|
-
type: "submit",
|
|
476
|
-
disabled: loading,
|
|
477
|
-
style: {
|
|
478
|
-
...styles.button,
|
|
479
|
-
...styles.primaryButton,
|
|
480
|
-
...loading && {
|
|
481
|
-
opacity: 0.5,
|
|
482
|
-
cursor: 'not-allowed'
|
|
483
|
-
}
|
|
484
|
-
},
|
|
485
|
-
children: loading ? labels.saving : labels.saveButton
|
|
486
|
-
}),
|
|
487
|
-
showUnsubscribe && /*#__PURE__*/ _jsx("button", {
|
|
488
|
-
type: "button",
|
|
489
|
-
onClick: handleUnsubscribe,
|
|
490
|
-
disabled: loading,
|
|
491
|
-
style: {
|
|
492
|
-
...styles.button,
|
|
493
|
-
...styles.dangerButton,
|
|
494
|
-
...loading && {
|
|
495
|
-
opacity: 0.5,
|
|
496
|
-
cursor: 'not-allowed'
|
|
497
|
-
}
|
|
498
|
-
},
|
|
499
|
-
children: labels.unsubscribeButton
|
|
500
|
-
})
|
|
501
|
-
]
|
|
502
|
-
}),
|
|
503
|
-
error && /*#__PURE__*/ _jsx("p", {
|
|
504
|
-
style: styles.error,
|
|
505
|
-
children: error
|
|
506
|
-
}),
|
|
507
|
-
success && /*#__PURE__*/ _jsx("p", {
|
|
508
|
-
style: styles.success,
|
|
509
|
-
children: labels.saved
|
|
510
|
-
})
|
|
511
|
-
]
|
|
512
|
-
})
|
|
513
|
-
]
|
|
514
|
-
});
|
|
515
|
-
};
|
|
516
|
-
// Factory function for creating custom preferences forms
|
|
517
|
-
export function createPreferencesForm(defaultProps) {
|
|
518
|
-
return (props)=>/*#__PURE__*/ _jsx(PreferencesForm, {
|
|
519
|
-
...defaultProps,
|
|
520
|
-
...props
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
//# sourceMappingURL=PreferencesForm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PreferencesForm.tsx"],"sourcesContent":["'use client'\n\nimport React, { useState, useEffect, FormEvent } from 'react'\nimport type { PreferencesFormProps, Subscriber } from '../types'\n\nconst defaultStyles = {\n container: {\n maxWidth: '600px',\n margin: '0 auto',\n padding: '2rem',\n },\n heading: {\n fontSize: '1.5rem',\n fontWeight: '600',\n marginBottom: '1.5rem',\n color: '#111827',\n },\n form: {\n display: 'flex',\n flexDirection: 'column' as const,\n gap: '1.5rem',\n },\n section: {\n padding: '1.5rem',\n backgroundColor: '#f9fafb',\n borderRadius: '0.5rem',\n border: '1px solid #e5e7eb',\n },\n sectionTitle: {\n fontSize: '1.125rem',\n fontWeight: '500',\n marginBottom: '1rem',\n color: '#111827',\n },\n inputGroup: {\n display: 'flex',\n flexDirection: 'column' as const,\n gap: '0.5rem',\n },\n label: {\n fontSize: '0.875rem',\n fontWeight: '500',\n color: '#374151',\n },\n input: {\n padding: '0.5rem 0.75rem',\n fontSize: '1rem',\n border: '1px solid #e5e7eb',\n borderRadius: '0.375rem',\n outline: 'none',\n transition: 'border-color 0.2s',\n },\n select: {\n padding: '0.5rem 0.75rem',\n fontSize: '1rem',\n border: '1px solid #e5e7eb',\n borderRadius: '0.375rem',\n outline: 'none',\n backgroundColor: '#ffffff',\n },\n checkbox: {\n display: 'flex',\n alignItems: 'center',\n gap: '0.5rem',\n marginBottom: '0.5rem',\n },\n checkboxInput: {\n width: '1rem',\n height: '1rem',\n },\n checkboxLabel: {\n fontSize: '0.875rem',\n color: '#374151',\n },\n buttonGroup: {\n display: 'flex',\n gap: '1rem',\n marginTop: '1rem',\n },\n button: {\n padding: '0.75rem 1.5rem',\n fontSize: '1rem',\n fontWeight: '500',\n borderRadius: '0.375rem',\n cursor: 'pointer',\n transition: 'all 0.2s',\n border: 'none',\n },\n primaryButton: {\n color: '#ffffff',\n backgroundColor: '#3b82f6',\n },\n secondaryButton: {\n color: '#374151',\n backgroundColor: '#ffffff',\n border: '1px solid #e5e7eb',\n },\n dangerButton: {\n color: '#ffffff',\n backgroundColor: '#ef4444',\n },\n error: {\n fontSize: '0.875rem',\n color: '#ef4444',\n marginTop: '0.5rem',\n },\n success: {\n fontSize: '0.875rem',\n color: '#10b981',\n marginTop: '0.5rem',\n },\n info: {\n fontSize: '0.875rem',\n color: '#6b7280',\n marginTop: '0.5rem',\n },\n}\n\nexport const PreferencesForm: React.FC<PreferencesFormProps> = ({\n subscriber: initialSubscriber,\n onSuccess,\n onError,\n className,\n styles: customStyles = {},\n sessionToken,\n apiEndpoint = '/api/newsletter/preferences',\n showUnsubscribe = true,\n locales = ['en'],\n labels = {\n title: 'Newsletter Preferences',\n personalInfo: 'Personal Information',\n emailPreferences: 'Email Preferences',\n name: 'Name',\n language: 'Preferred Language',\n newsletter: 'Newsletter updates',\n announcements: 'Product announcements',\n saveButton: 'Save Preferences',\n unsubscribeButton: 'Unsubscribe',\n saving: 'Saving...',\n saved: 'Preferences saved successfully!',\n unsubscribeConfirm: 'Are you sure you want to unsubscribe? This cannot be undone.',\n },\n}) => {\n const [subscriber, setSubscriber] = useState<Partial<Subscriber>>(initialSubscriber || {})\n const [loading, setLoading] = useState(false)\n const [loadingData, setLoadingData] = useState(!initialSubscriber)\n const [error, setError] = useState<string | null>(null)\n const [success, setSuccess] = useState(false)\n\n const styles = {\n container: { ...defaultStyles.container, ...customStyles.container },\n heading: { ...defaultStyles.heading, ...customStyles.heading },\n form: { ...defaultStyles.form, ...customStyles.form },\n section: { ...defaultStyles.section, ...customStyles.section },\n sectionTitle: { ...defaultStyles.sectionTitle, ...customStyles.sectionTitle },\n inputGroup: { ...defaultStyles.inputGroup, ...customStyles.inputGroup },\n label: { ...defaultStyles.label, ...customStyles.label },\n input: { ...defaultStyles.input, ...customStyles.input },\n select: { ...defaultStyles.select, ...customStyles.select },\n checkbox: { ...defaultStyles.checkbox, ...customStyles.checkbox },\n checkboxInput: { ...defaultStyles.checkboxInput, ...customStyles.checkboxInput },\n checkboxLabel: { ...defaultStyles.checkboxLabel, ...customStyles.checkboxLabel },\n buttonGroup: { ...defaultStyles.buttonGroup, ...customStyles.buttonGroup },\n button: { ...defaultStyles.button, ...customStyles.button },\n primaryButton: { ...defaultStyles.primaryButton, ...customStyles.primaryButton },\n secondaryButton: { ...defaultStyles.secondaryButton, ...customStyles.secondaryButton },\n dangerButton: { ...defaultStyles.dangerButton, ...customStyles.dangerButton },\n error: { ...defaultStyles.error, ...customStyles.error },\n success: { ...defaultStyles.success, ...customStyles.success },\n info: { ...defaultStyles.info, ...customStyles.info },\n }\n\n // Fetch current preferences if not provided\n useEffect(() => {\n if (!initialSubscriber && sessionToken) {\n fetchPreferences()\n }\n }, [])\n\n const fetchPreferences = async () => {\n try {\n const response = await fetch(apiEndpoint, {\n headers: {\n 'Authorization': `Bearer ${sessionToken}`,\n },\n })\n\n if (!response.ok) {\n throw new Error('Failed to load preferences')\n }\n\n const data = await response.json()\n setSubscriber(data.subscriber)\n } catch (err) {\n setError(err instanceof Error ? err.message : 'Failed to load preferences')\n if (onError) {\n onError(err instanceof Error ? err : new Error('Failed to load preferences'))\n }\n } finally {\n setLoadingData(false)\n }\n }\n\n const handleSave = async (e: FormEvent) => {\n e.preventDefault()\n setError(null)\n setSuccess(false)\n setLoading(true)\n\n try {\n const response = await fetch(apiEndpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${sessionToken}`,\n },\n body: JSON.stringify({\n name: subscriber.name,\n locale: subscriber.locale,\n emailPreferences: subscriber.emailPreferences,\n }),\n })\n\n const data = await response.json()\n\n if (!response.ok) {\n throw new Error(data.error || 'Failed to save preferences')\n }\n\n setSubscriber(data.subscriber)\n setSuccess(true)\n if (onSuccess) {\n onSuccess(data.subscriber)\n }\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'An error occurred'\n setError(errorMessage)\n if (onError) {\n onError(new Error(errorMessage))\n }\n } finally {\n setLoading(false)\n }\n }\n\n const handleUnsubscribe = async () => {\n if (!window.confirm(labels.unsubscribeConfirm)) {\n return\n }\n\n setLoading(true)\n setError(null)\n\n try {\n const response = await fetch('/api/newsletter/unsubscribe', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${sessionToken}`,\n },\n body: JSON.stringify({\n email: subscriber.email,\n }),\n })\n\n if (!response.ok) {\n throw new Error('Failed to unsubscribe')\n }\n\n setSubscriber({ ...subscriber, subscriptionStatus: 'unsubscribed' })\n if (onSuccess) {\n onSuccess({ ...subscriber, subscriptionStatus: 'unsubscribed' } as Subscriber)\n }\n } catch (err) {\n setError('Failed to unsubscribe. Please try again.')\n if (onError) {\n onError(err instanceof Error ? err : new Error('Failed to unsubscribe'))\n }\n } finally {\n setLoading(false)\n }\n }\n\n if (loadingData) {\n return (\n <div className={className} style={styles.container}>\n <p style={styles.info}>Loading preferences...</p>\n </div>\n )\n }\n\n if (subscriber.subscriptionStatus === 'unsubscribed') {\n return (\n <div className={className} style={styles.container}>\n <h2 style={styles.heading}>Unsubscribed</h2>\n <p style={styles.info}>\n You have been unsubscribed from all emails. \n To resubscribe, please sign up again.\n </p>\n </div>\n )\n }\n\n return (\n <div className={className} style={styles.container}>\n <h2 style={styles.heading}>{labels.title}</h2>\n \n <form onSubmit={handleSave} style={styles.form}>\n <div style={styles.section}>\n <h3 style={styles.sectionTitle}>{labels.personalInfo}</h3>\n \n <div style={styles.inputGroup}>\n <label htmlFor=\"name\" style={styles.label}>\n {labels.name}\n </label>\n <input\n id=\"name\"\n type=\"text\"\n value={subscriber.name || ''}\n onChange={(e) => setSubscriber({ ...subscriber, name: e.target.value })}\n disabled={loading}\n style={styles.input}\n />\n </div>\n\n {locales.length > 1 && (\n <div style={styles.inputGroup}>\n <label htmlFor=\"locale\" style={styles.label}>\n {labels.language}\n </label>\n <select\n id=\"locale\"\n value={subscriber.locale || locales[0]}\n onChange={(e) => setSubscriber({ ...subscriber, locale: e.target.value })}\n disabled={loading}\n style={styles.select}\n >\n {locales.map(locale => (\n <option key={locale} value={locale}>\n {locale.toUpperCase()}\n </option>\n ))}\n </select>\n </div>\n )}\n </div>\n\n <div style={styles.section}>\n <h3 style={styles.sectionTitle}>{labels.emailPreferences}</h3>\n \n <div style={styles.checkbox}>\n <input\n id=\"pref-newsletter\"\n type=\"checkbox\"\n checked={subscriber.emailPreferences?.newsletter ?? true}\n onChange={(e) =>\n setSubscriber({\n ...subscriber,\n emailPreferences: {\n ...subscriber.emailPreferences,\n newsletter: e.target.checked,\n },\n })\n }\n disabled={loading}\n style={styles.checkboxInput}\n />\n <label htmlFor=\"pref-newsletter\" style={styles.checkboxLabel}>\n {labels.newsletter}\n </label>\n </div>\n\n <div style={styles.checkbox}>\n <input\n id=\"pref-announcements\"\n type=\"checkbox\"\n checked={subscriber.emailPreferences?.announcements ?? true}\n onChange={(e) =>\n setSubscriber({\n ...subscriber,\n emailPreferences: {\n ...subscriber.emailPreferences,\n announcements: e.target.checked,\n },\n })\n }\n disabled={loading}\n style={styles.checkboxInput}\n />\n <label htmlFor=\"pref-announcements\" style={styles.checkboxLabel}>\n {labels.announcements}\n </label>\n </div>\n </div>\n\n <div style={styles.buttonGroup}>\n <button\n type=\"submit\"\n disabled={loading}\n style={{\n ...styles.button,\n ...styles.primaryButton,\n ...(loading && { opacity: 0.5, cursor: 'not-allowed' }),\n }}\n >\n {loading ? labels.saving : labels.saveButton}\n </button>\n\n {showUnsubscribe && (\n <button\n type=\"button\"\n onClick={handleUnsubscribe}\n disabled={loading}\n style={{\n ...styles.button,\n ...styles.dangerButton,\n ...(loading && { opacity: 0.5, cursor: 'not-allowed' }),\n }}\n >\n {labels.unsubscribeButton}\n </button>\n )}\n </div>\n\n {error && <p style={styles.error}>{error}</p>}\n {success && <p style={styles.success}>{labels.saved}</p>}\n </form>\n </div>\n )\n}\n\n// Factory function for creating custom preferences forms\nexport function createPreferencesForm(\n defaultProps: Partial<PreferencesFormProps>\n): React.FC<PreferencesFormProps> {\n return (props: PreferencesFormProps) => (\n <PreferencesForm {...defaultProps} {...props} />\n )\n}"],"names":["React","useState","useEffect","defaultStyles","container","maxWidth","margin","padding","heading","fontSize","fontWeight","marginBottom","color","form","display","flexDirection","gap","section","backgroundColor","borderRadius","border","sectionTitle","inputGroup","label","input","outline","transition","select","checkbox","alignItems","checkboxInput","width","height","checkboxLabel","buttonGroup","marginTop","button","cursor","primaryButton","secondaryButton","dangerButton","error","success","info","PreferencesForm","subscriber","initialSubscriber","onSuccess","onError","className","styles","customStyles","sessionToken","apiEndpoint","showUnsubscribe","locales","labels","title","personalInfo","emailPreferences","name","language","newsletter","announcements","saveButton","unsubscribeButton","saving","saved","unsubscribeConfirm","setSubscriber","loading","setLoading","loadingData","setLoadingData","setError","setSuccess","fetchPreferences","response","fetch","headers","ok","Error","data","json","err","message","handleSave","e","preventDefault","method","body","JSON","stringify","locale","errorMessage","handleUnsubscribe","window","confirm","email","subscriptionStatus","div","style","p","h2","onSubmit","h3","htmlFor","id","type","value","onChange","target","disabled","length","map","option","toUpperCase","checked","opacity","onClick","createPreferencesForm","defaultProps","props"],"mappings":"AAAA;;AAEA,OAAOA,SAASC,QAAQ,EAAEC,SAAS,QAAmB,QAAO;AAG7D,MAAMC,gBAAgB;IACpBC,WAAW;QACTC,UAAU;QACVC,QAAQ;QACRC,SAAS;IACX;IACAC,SAAS;QACPC,UAAU;QACVC,YAAY;QACZC,cAAc;QACdC,OAAO;IACT;IACAC,MAAM;QACJC,SAAS;QACTC,eAAe;QACfC,KAAK;IACP;IACAC,SAAS;QACPV,SAAS;QACTW,iBAAiB;QACjBC,cAAc;QACdC,QAAQ;IACV;IACAC,cAAc;QACZZ,UAAU;QACVC,YAAY;QACZC,cAAc;QACdC,OAAO;IACT;IACAU,YAAY;QACVR,SAAS;QACTC,eAAe;QACfC,KAAK;IACP;IACAO,OAAO;QACLd,UAAU;QACVC,YAAY;QACZE,OAAO;IACT;IACAY,OAAO;QACLjB,SAAS;QACTE,UAAU;QACVW,QAAQ;QACRD,cAAc;QACdM,SAAS;QACTC,YAAY;IACd;IACAC,QAAQ;QACNpB,SAAS;QACTE,UAAU;QACVW,QAAQ;QACRD,cAAc;QACdM,SAAS;QACTP,iBAAiB;IACnB;IACAU,UAAU;QACRd,SAAS;QACTe,YAAY;QACZb,KAAK;QACLL,cAAc;IAChB;IACAmB,eAAe;QACbC,OAAO;QACPC,QAAQ;IACV;IACAC,eAAe;QACbxB,UAAU;QACVG,OAAO;IACT;IACAsB,aAAa;QACXpB,SAAS;QACTE,KAAK;QACLmB,WAAW;IACb;IACAC,QAAQ;QACN7B,SAAS;QACTE,UAAU;QACVC,YAAY;QACZS,cAAc;QACdkB,QAAQ;QACRX,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,SAAS;wCAAKjF,QAAQ;oCAAc,CAAC;gCACxD;0CAECiC,UAAUd,OAAOU,MAAM,GAAGV,OAAOQ,UAAU;;4BAG7CV,iCACC,KAAClB;gCACCwE,MAAK;gCACLW,SAASxB;gCACTiB,UAAU1C;gCACV+B,OAAO;oCACL,GAAGnD,OAAOd,MAAM;oCAChB,GAAGc,OAAOV,YAAY;oCACtB,GAAI8B,WAAW;wCAAEgD,SAAS;wCAAKjF,QAAQ;oCAAc,CAAC;gCACxD;0CAECmB,OAAOS,iBAAiB;;;;oBAK9BxB,uBAAS,KAAC6D;wBAAED,OAAOnD,OAAOT,KAAK;kCAAGA;;oBAClCC,yBAAW,KAAC4D;wBAAED,OAAOnD,OAAOR,OAAO;kCAAGc,OAAOW,KAAK;;;;;;AAI3D,EAAC;AAED,yDAAyD;AACzD,OAAO,SAASqD,sBACdC,YAA2C;IAE3C,OAAO,CAACC,sBACN,KAAC9E;YAAiB,GAAG6E,YAAY;YAAG,GAAGC,KAAK;;AAEhD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/index.ts"],"sourcesContent":["export { NewsletterForm, createNewsletterForm } from './NewsletterForm'\nexport { PreferencesForm, createPreferencesForm } from './PreferencesForm'\nexport { MagicLinkVerify, createMagicLinkVerify } from './MagicLinkVerify'\n\nexport type { MagicLinkVerifyProps } from './MagicLinkVerify'"],"names":["NewsletterForm","createNewsletterForm","PreferencesForm","createPreferencesForm","MagicLinkVerify","createMagicLinkVerify"],"mappings":"AAAA,SAASA,cAAc,EAAEC,oBAAoB,QAAQ,mBAAkB;AACvE,SAASC,eAAe,EAAEC,qBAAqB,QAAQ,oBAAmB;AAC1E,SAASC,eAAe,EAAEC,qBAAqB,QAAQ,oBAAmB"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createSubscribeEndpoint } from './subscribe';
|
|
2
|
-
import { createVerifyMagicLinkEndpoint } from './verify-magic-link';
|
|
3
|
-
import { createPreferencesEndpoint, createUpdatePreferencesEndpoint } from './preferences';
|
|
4
|
-
import { createUnsubscribeEndpoint } from './unsubscribe';
|
|
5
|
-
export function createNewsletterEndpoints(config) {
|
|
6
|
-
const endpoints = [
|
|
7
|
-
createSubscribeEndpoint(config),
|
|
8
|
-
createUnsubscribeEndpoint(config)
|
|
9
|
-
];
|
|
10
|
-
// Add auth endpoints if enabled
|
|
11
|
-
if (config.auth?.enabled !== false) {
|
|
12
|
-
endpoints.push(createVerifyMagicLinkEndpoint(config), createPreferencesEndpoint(config), createUpdatePreferencesEndpoint(config));
|
|
13
|
-
}
|
|
14
|
-
return endpoints;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/endpoints/index.ts"],"sourcesContent":["import type { Endpoint } from 'payload'\nimport type { NewsletterPluginConfig } from '../types'\nimport { createSubscribeEndpoint } from './subscribe'\nimport { createVerifyMagicLinkEndpoint } from './verify-magic-link'\nimport { createPreferencesEndpoint, createUpdatePreferencesEndpoint } from './preferences'\nimport { createUnsubscribeEndpoint } from './unsubscribe'\n\nexport function createNewsletterEndpoints(\n config: NewsletterPluginConfig\n): Endpoint[] {\n const endpoints: Endpoint[] = [\n createSubscribeEndpoint(config),\n createUnsubscribeEndpoint(config),\n ]\n\n // Add auth endpoints if enabled\n if (config.auth?.enabled !== false) {\n endpoints.push(\n createVerifyMagicLinkEndpoint(config),\n createPreferencesEndpoint(config),\n createUpdatePreferencesEndpoint(config)\n )\n }\n\n return endpoints\n}"],"names":["createSubscribeEndpoint","createVerifyMagicLinkEndpoint","createPreferencesEndpoint","createUpdatePreferencesEndpoint","createUnsubscribeEndpoint","createNewsletterEndpoints","config","endpoints","auth","enabled","push"],"mappings":"AAEA,SAASA,uBAAuB,QAAQ,cAAa;AACrD,SAASC,6BAA6B,QAAQ,sBAAqB;AACnE,SAASC,yBAAyB,EAAEC,+BAA+B,QAAQ,gBAAe;AAC1F,SAASC,yBAAyB,QAAQ,gBAAe;AAEzD,OAAO,SAASC,0BACdC,MAA8B;IAE9B,MAAMC,YAAwB;QAC5BP,wBAAwBM;QACxBF,0BAA0BE;KAC3B;IAED,gCAAgC;IAChC,IAAIA,OAAOE,IAAI,EAAEC,YAAY,OAAO;QAClCF,UAAUG,IAAI,CACZT,8BAA8BK,SAC9BJ,0BAA0BI,SAC1BH,gCAAgCG;IAEpC;IAEA,OAAOC;AACT"}
|