@churchapps/apphelper-login 0.4.13
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/README.md +104 -0
- package/dist/LoginPage.d.ts +25 -0
- package/dist/LoginPage.d.ts.map +1 -0
- package/dist/LoginPage.js +248 -0
- package/dist/LoginPage.js.map +1 -0
- package/dist/LogoutPage.d.ts +9 -0
- package/dist/LogoutPage.d.ts.map +1 -0
- package/dist/LogoutPage.js +33 -0
- package/dist/LogoutPage.js.map +1 -0
- package/dist/components/Forgot.d.ts +8 -0
- package/dist/components/Forgot.d.ts.map +1 -0
- package/dist/components/Forgot.js +127 -0
- package/dist/components/Forgot.js.map +1 -0
- package/dist/components/Login.d.ts +15 -0
- package/dist/components/Login.d.ts.map +1 -0
- package/dist/components/Login.js +126 -0
- package/dist/components/Login.js.map +1 -0
- package/dist/components/LoginSetPassword.d.ts +13 -0
- package/dist/components/LoginSetPassword.d.ts.map +1 -0
- package/dist/components/LoginSetPassword.js +167 -0
- package/dist/components/LoginSetPassword.js.map +1 -0
- package/dist/components/Register.d.ts +12 -0
- package/dist/components/Register.d.ts.map +1 -0
- package/dist/components/Register.js +217 -0
- package/dist/components/Register.js.map +1 -0
- package/dist/components/SelectChurchModal.d.ts +14 -0
- package/dist/components/SelectChurchModal.d.ts.map +1 -0
- package/dist/components/SelectChurchModal.js +39 -0
- package/dist/components/SelectChurchModal.js.map +1 -0
- package/dist/components/SelectChurchRegister.d.ts +11 -0
- package/dist/components/SelectChurchRegister.d.ts.map +1 -0
- package/dist/components/SelectChurchRegister.js +83 -0
- package/dist/components/SelectChurchRegister.js.map +1 -0
- package/dist/components/SelectChurchSearch.d.ts +10 -0
- package/dist/components/SelectChurchSearch.d.ts.map +1 -0
- package/dist/components/SelectChurchSearch.js +61 -0
- package/dist/components/SelectChurchSearch.js.map +1 -0
- package/dist/components/SelectableChurch.d.ts +9 -0
- package/dist/components/SelectableChurch.d.ts.map +1 -0
- package/dist/components/SelectableChurch.js +34 -0
- package/dist/components/SelectableChurch.js.map +1 -0
- package/dist/helpers/AnalyticsHelper.d.ts +7 -0
- package/dist/helpers/AnalyticsHelper.d.ts.map +1 -0
- package/dist/helpers/AnalyticsHelper.js +30 -0
- package/dist/helpers/AnalyticsHelper.js.map +1 -0
- package/dist/helpers/Locale.d.ts +13 -0
- package/dist/helpers/Locale.d.ts.map +1 -0
- package/dist/helpers/Locale.js +200 -0
- package/dist/helpers/Locale.js.map +1 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +3 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
- package/src/LoginPage.tsx +283 -0
- package/src/LogoutPage.tsx +43 -0
- package/src/components/Forgot.tsx +247 -0
- package/src/components/Login.tsx +250 -0
- package/src/components/LoginSetPassword.tsx +298 -0
- package/src/components/Register.tsx +371 -0
- package/src/components/SelectChurchModal.tsx +82 -0
- package/src/components/SelectChurchRegister.tsx +88 -0
- package/src/components/SelectChurchSearch.tsx +85 -0
- package/src/components/SelectableChurch.tsx +72 -0
- package/src/helpers/AnalyticsHelper.ts +32 -0
- package/src/helpers/Locale.ts +233 -0
- package/src/helpers/index.ts +2 -0
- package/src/index.ts +10 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { FormEventHandler } from "react";
|
|
4
|
+
import { LoginResponseInterface, RegisterUserInterface, UserInterface } from "@churchapps/helpers";
|
|
5
|
+
import { ApiHelper } from "@churchapps/helpers";
|
|
6
|
+
import { AnalyticsHelper, Locale } from "../helpers";
|
|
7
|
+
import { TextField, Card, CardContent, Typography, Button } from "@mui/material";
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
appName?: string,
|
|
11
|
+
appUrl?: string,
|
|
12
|
+
updateErrors: (errors: string[]) => void,
|
|
13
|
+
loginCallback?: () => void
|
|
14
|
+
userRegisteredCallback?: (user: UserInterface) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Register: React.FC<Props> = (props) => {
|
|
18
|
+
|
|
19
|
+
const cleanAppUrl = () => {
|
|
20
|
+
if (!props.appUrl) return null;
|
|
21
|
+
else {
|
|
22
|
+
const index = props.appUrl.indexOf("/", 9);
|
|
23
|
+
if (index === -1) return props.appUrl;
|
|
24
|
+
else return props.appUrl.substring(0, index);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const [registered, setRegistered] = React.useState(false);
|
|
29
|
+
const [user, setUser] = React.useState<RegisterUserInterface>({ firstName: "", lastName: "", email: "", appName: props.appName, appUrl: cleanAppUrl() });
|
|
30
|
+
const [errors, setErrors] = React.useState([]);
|
|
31
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
32
|
+
|
|
33
|
+
const handleRegisterErrors = (errors: string[]) => {
|
|
34
|
+
props.updateErrors(errors)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const handleRegisterSuccess = (resp: LoginResponseInterface) => {
|
|
38
|
+
setRegistered(true);
|
|
39
|
+
AnalyticsHelper.logEvent("User", "Register");
|
|
40
|
+
if (props.userRegisteredCallback) props.userRegisteredCallback(resp.user);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const validateEmail = (email: string) => (/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(.\w{2,3})+$/.test(email))
|
|
44
|
+
|
|
45
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
46
|
+
const u = { ...user }
|
|
47
|
+
switch (e.target.name) {
|
|
48
|
+
case "firstName": u.firstName = e.target.value; break;
|
|
49
|
+
case "lastName": u.lastName = e.target.value; break;
|
|
50
|
+
case "email": u.email = e.target.value; break;
|
|
51
|
+
}
|
|
52
|
+
setUser(u);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const validate = () => {
|
|
56
|
+
let errors = [];
|
|
57
|
+
if (!user.email?.trim()) errors.push(Locale.label("login.validate.email"));
|
|
58
|
+
else if (!validateEmail(user.email)) errors.push(Locale.label("login.validate.email"));
|
|
59
|
+
if (!user.firstName?.trim()) errors.push(Locale.label("login.validate.firstName"));
|
|
60
|
+
if (!user.lastName?.trim()) errors.push(Locale.label("login.validate.lastName"));
|
|
61
|
+
setErrors(errors);
|
|
62
|
+
return errors.length === 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const register: FormEventHandler = (e) => {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
props.updateErrors([])
|
|
68
|
+
if (validate()) {
|
|
69
|
+
setIsSubmitting(true);
|
|
70
|
+
ApiHelper.postAnonymous("/users/register", user, "MembershipApi")
|
|
71
|
+
.then((resp: any) => {
|
|
72
|
+
if (resp.errors) handleRegisterErrors(resp.errors);
|
|
73
|
+
else handleRegisterSuccess(resp);
|
|
74
|
+
})
|
|
75
|
+
.catch((e) => { props.updateErrors([e.toString()]); throw e; })
|
|
76
|
+
.finally(() => {
|
|
77
|
+
setIsSubmitting(false)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (registered) {
|
|
83
|
+
return (
|
|
84
|
+
<div style={{ minHeight: '100vh', backgroundColor: 'white', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '16px' }}>
|
|
85
|
+
<Card sx={{
|
|
86
|
+
width: '100%',
|
|
87
|
+
maxWidth: { xs: '400px', sm: '500px' },
|
|
88
|
+
backgroundColor: 'white',
|
|
89
|
+
border: '1px solid #e5e7eb',
|
|
90
|
+
boxShadow: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)'
|
|
91
|
+
}}>
|
|
92
|
+
<CardContent sx={{ textAlign: 'center', padding: '32px' }}>
|
|
93
|
+
<div style={{ marginBottom: '32px' }}>
|
|
94
|
+
<img
|
|
95
|
+
src="/images/logo-login.png"
|
|
96
|
+
alt="Church Logo"
|
|
97
|
+
style={{
|
|
98
|
+
maxWidth: '100%',
|
|
99
|
+
width: 'auto',
|
|
100
|
+
height: 'auto',
|
|
101
|
+
maxHeight: '80px',
|
|
102
|
+
marginBottom: '16px',
|
|
103
|
+
objectFit: 'contain'
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
<Typography
|
|
108
|
+
component="h1"
|
|
109
|
+
sx={{
|
|
110
|
+
fontSize: '24px',
|
|
111
|
+
fontWeight: 'bold',
|
|
112
|
+
color: '#111827',
|
|
113
|
+
marginBottom: '32px'
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
Registration Complete
|
|
117
|
+
</Typography>
|
|
118
|
+
<Typography sx={{ color: '#6b7280', marginBottom: '24px' }}>
|
|
119
|
+
{Locale.label("login.registerThankYou")}
|
|
120
|
+
</Typography>
|
|
121
|
+
<button
|
|
122
|
+
type="button"
|
|
123
|
+
onClick={(e) => { e.preventDefault(); props.loginCallback && props.loginCallback(); }}
|
|
124
|
+
style={{
|
|
125
|
+
background: 'none',
|
|
126
|
+
border: 'none',
|
|
127
|
+
color: '#3b82f6',
|
|
128
|
+
fontSize: '14px',
|
|
129
|
+
cursor: 'pointer',
|
|
130
|
+
textDecoration: 'none'
|
|
131
|
+
}}
|
|
132
|
+
onMouseOver={(e) => e.currentTarget.style.textDecoration = 'underline'}
|
|
133
|
+
onMouseOut={(e) => e.currentTarget.style.textDecoration = 'none'}
|
|
134
|
+
>
|
|
135
|
+
Back to sign in
|
|
136
|
+
</button>
|
|
137
|
+
</CardContent>
|
|
138
|
+
</Card>
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<div style={{ minHeight: '100vh', backgroundColor: 'white', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '16px' }}>
|
|
145
|
+
<Card sx={{
|
|
146
|
+
width: '100%',
|
|
147
|
+
maxWidth: { xs: '400px', sm: '500px' },
|
|
148
|
+
backgroundColor: 'white',
|
|
149
|
+
border: '1px solid #e5e7eb',
|
|
150
|
+
boxShadow: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)'
|
|
151
|
+
}}>
|
|
152
|
+
<CardContent sx={{ textAlign: 'center', padding: '32px' }}>
|
|
153
|
+
<div style={{ marginBottom: '32px' }}>
|
|
154
|
+
<img
|
|
155
|
+
src="/images/logo-login.png"
|
|
156
|
+
alt="Church Logo"
|
|
157
|
+
style={{
|
|
158
|
+
maxWidth: '100%',
|
|
159
|
+
width: 'auto',
|
|
160
|
+
height: 'auto',
|
|
161
|
+
maxHeight: '80px',
|
|
162
|
+
marginBottom: '16px',
|
|
163
|
+
objectFit: 'contain'
|
|
164
|
+
}}
|
|
165
|
+
/>
|
|
166
|
+
</div>
|
|
167
|
+
<Typography
|
|
168
|
+
component="h1"
|
|
169
|
+
sx={{
|
|
170
|
+
fontSize: '24px',
|
|
171
|
+
fontWeight: 'bold',
|
|
172
|
+
color: '#111827',
|
|
173
|
+
marginBottom: '8px'
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
Create Account
|
|
177
|
+
</Typography>
|
|
178
|
+
<Typography
|
|
179
|
+
sx={{
|
|
180
|
+
color: '#6b7280',
|
|
181
|
+
marginBottom: '32px'
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
Create a new account to access your church
|
|
185
|
+
</Typography>
|
|
186
|
+
|
|
187
|
+
<form onSubmit={register} style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
|
|
188
|
+
{errors.length > 0 && (
|
|
189
|
+
<div style={{
|
|
190
|
+
backgroundColor: '#fef2f2',
|
|
191
|
+
border: '1px solid #fecaca',
|
|
192
|
+
borderRadius: '6px',
|
|
193
|
+
padding: '12px',
|
|
194
|
+
textAlign: 'left'
|
|
195
|
+
}}>
|
|
196
|
+
{errors.map((error, index) => (
|
|
197
|
+
<div key={index} style={{ color: '#dc2626', fontSize: '14px' }}>{error}</div>
|
|
198
|
+
))}
|
|
199
|
+
</div>
|
|
200
|
+
)}
|
|
201
|
+
|
|
202
|
+
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '8px' }}>
|
|
203
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
|
|
204
|
+
<label htmlFor="firstName" style={{ fontSize: '14px', fontWeight: 500, color: '#374151', textAlign: 'left' }}>
|
|
205
|
+
First Name
|
|
206
|
+
</label>
|
|
207
|
+
<TextField
|
|
208
|
+
id="firstName"
|
|
209
|
+
name="firstName"
|
|
210
|
+
type="text"
|
|
211
|
+
placeholder="First Name"
|
|
212
|
+
value={user.firstName}
|
|
213
|
+
onChange={handleChange}
|
|
214
|
+
required
|
|
215
|
+
autoComplete="given-name"
|
|
216
|
+
variant="outlined"
|
|
217
|
+
fullWidth
|
|
218
|
+
sx={{
|
|
219
|
+
'& .MuiOutlinedInput-root': {
|
|
220
|
+
backgroundColor: 'white',
|
|
221
|
+
'& fieldset': {
|
|
222
|
+
borderColor: '#d1d5db'
|
|
223
|
+
},
|
|
224
|
+
'&:hover fieldset': {
|
|
225
|
+
borderColor: '#d1d5db'
|
|
226
|
+
},
|
|
227
|
+
'&.Mui-focused fieldset': {
|
|
228
|
+
borderColor: '#3b82f6'
|
|
229
|
+
},
|
|
230
|
+
'& input': {
|
|
231
|
+
color: '#111827',
|
|
232
|
+
fontSize: '16px'
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
'& .MuiInputLabel-root': {
|
|
236
|
+
display: 'none'
|
|
237
|
+
}
|
|
238
|
+
}}
|
|
239
|
+
/>
|
|
240
|
+
</div>
|
|
241
|
+
|
|
242
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
|
|
243
|
+
<label htmlFor="lastName" style={{ fontSize: '14px', fontWeight: 500, color: '#374151', textAlign: 'left' }}>
|
|
244
|
+
Last Name
|
|
245
|
+
</label>
|
|
246
|
+
<TextField
|
|
247
|
+
id="lastName"
|
|
248
|
+
name="lastName"
|
|
249
|
+
type="text"
|
|
250
|
+
placeholder="Last Name"
|
|
251
|
+
value={user.lastName}
|
|
252
|
+
onChange={handleChange}
|
|
253
|
+
required
|
|
254
|
+
autoComplete="family-name"
|
|
255
|
+
variant="outlined"
|
|
256
|
+
fullWidth
|
|
257
|
+
sx={{
|
|
258
|
+
'& .MuiOutlinedInput-root': {
|
|
259
|
+
backgroundColor: 'white',
|
|
260
|
+
'& fieldset': {
|
|
261
|
+
borderColor: '#d1d5db'
|
|
262
|
+
},
|
|
263
|
+
'&:hover fieldset': {
|
|
264
|
+
borderColor: '#d1d5db'
|
|
265
|
+
},
|
|
266
|
+
'&.Mui-focused fieldset': {
|
|
267
|
+
borderColor: '#3b82f6'
|
|
268
|
+
},
|
|
269
|
+
'& input': {
|
|
270
|
+
color: '#111827',
|
|
271
|
+
fontSize: '16px'
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
'& .MuiInputLabel-root': {
|
|
275
|
+
display: 'none'
|
|
276
|
+
}
|
|
277
|
+
}}
|
|
278
|
+
/>
|
|
279
|
+
</div>
|
|
280
|
+
</div>
|
|
281
|
+
|
|
282
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
|
|
283
|
+
<label htmlFor="email" style={{ fontSize: '14px', fontWeight: 500, color: '#374151', textAlign: 'left' }}>
|
|
284
|
+
Email
|
|
285
|
+
</label>
|
|
286
|
+
<TextField
|
|
287
|
+
id="email"
|
|
288
|
+
name="email"
|
|
289
|
+
type="email"
|
|
290
|
+
placeholder="Email"
|
|
291
|
+
value={user.email}
|
|
292
|
+
onChange={handleChange}
|
|
293
|
+
required
|
|
294
|
+
autoComplete="email"
|
|
295
|
+
variant="outlined"
|
|
296
|
+
fullWidth
|
|
297
|
+
sx={{
|
|
298
|
+
'& .MuiOutlinedInput-root': {
|
|
299
|
+
backgroundColor: 'white',
|
|
300
|
+
'& fieldset': {
|
|
301
|
+
borderColor: '#d1d5db'
|
|
302
|
+
},
|
|
303
|
+
'&:hover fieldset': {
|
|
304
|
+
borderColor: '#d1d5db'
|
|
305
|
+
},
|
|
306
|
+
'&.Mui-focused fieldset': {
|
|
307
|
+
borderColor: '#3b82f6'
|
|
308
|
+
},
|
|
309
|
+
'& input': {
|
|
310
|
+
color: '#111827',
|
|
311
|
+
fontSize: '16px'
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
'& .MuiInputLabel-root': {
|
|
315
|
+
display: 'none'
|
|
316
|
+
}
|
|
317
|
+
}}
|
|
318
|
+
/>
|
|
319
|
+
</div>
|
|
320
|
+
|
|
321
|
+
<Button
|
|
322
|
+
type="submit"
|
|
323
|
+
variant="contained"
|
|
324
|
+
fullWidth
|
|
325
|
+
disabled={isSubmitting}
|
|
326
|
+
sx={{
|
|
327
|
+
backgroundColor: 'hsl(218, 85%, 55%)',
|
|
328
|
+
color: 'white',
|
|
329
|
+
padding: '12px',
|
|
330
|
+
textTransform: 'none',
|
|
331
|
+
fontSize: '16px',
|
|
332
|
+
fontWeight: 500,
|
|
333
|
+
borderRadius: '6px',
|
|
334
|
+
'&:hover': {
|
|
335
|
+
backgroundColor: 'hsl(218, 85%, 50%)'
|
|
336
|
+
},
|
|
337
|
+
'&:disabled': {
|
|
338
|
+
backgroundColor: '#9ca3af'
|
|
339
|
+
}
|
|
340
|
+
}}
|
|
341
|
+
>
|
|
342
|
+
{isSubmitting ? "Please wait..." : "Register"}
|
|
343
|
+
</Button>
|
|
344
|
+
|
|
345
|
+
<div style={{ textAlign: 'center' }}>
|
|
346
|
+
<div style={{ fontSize: '14px', color: '#6b7280' }}>
|
|
347
|
+
Already have an account?{' '}
|
|
348
|
+
<button
|
|
349
|
+
type="button"
|
|
350
|
+
onClick={(e) => { e.preventDefault(); props.loginCallback && props.loginCallback(); }}
|
|
351
|
+
style={{
|
|
352
|
+
background: 'none',
|
|
353
|
+
border: 'none',
|
|
354
|
+
color: '#3b82f6',
|
|
355
|
+
fontSize: '14px',
|
|
356
|
+
cursor: 'pointer',
|
|
357
|
+
textDecoration: 'none'
|
|
358
|
+
}}
|
|
359
|
+
onMouseOver={(e) => e.currentTarget.style.textDecoration = 'underline'}
|
|
360
|
+
onMouseOut={(e) => e.currentTarget.style.textDecoration = 'none'}
|
|
361
|
+
>
|
|
362
|
+
Sign in
|
|
363
|
+
</button>
|
|
364
|
+
</div>
|
|
365
|
+
</div>
|
|
366
|
+
</form>
|
|
367
|
+
</CardContent>
|
|
368
|
+
</Card>
|
|
369
|
+
</div>
|
|
370
|
+
);
|
|
371
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { ChurchInterface, LoginUserChurchInterface } from "@churchapps/helpers";
|
|
5
|
+
import { SelectChurchSearch } from "./SelectChurchSearch";
|
|
6
|
+
import { SelectableChurch } from "./SelectableChurch";
|
|
7
|
+
import { ErrorMessages } from "@churchapps/apphelper"
|
|
8
|
+
import { Dialog, DialogContent, DialogTitle, IconButton, Tooltip } from "@mui/material";
|
|
9
|
+
import { Logout } from "@mui/icons-material";
|
|
10
|
+
import { Locale } from "../helpers";
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
appName: string,
|
|
14
|
+
show: boolean,
|
|
15
|
+
userChurches?: LoginUserChurchInterface[],
|
|
16
|
+
selectChurch: (churchId: string) => void,
|
|
17
|
+
registeredChurchCallback?: (church: ChurchInterface) => void,
|
|
18
|
+
errors?: string[],
|
|
19
|
+
handleRedirect?: (url: string) => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const SelectChurchModal: React.FC<Props> = (props) => {
|
|
23
|
+
const [showSearch, setShowSearch] = React.useState(false);
|
|
24
|
+
|
|
25
|
+
const handleClose = () => {
|
|
26
|
+
window.location.reload();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const getContents = () => {
|
|
30
|
+
if (showSearch || props.userChurches?.length === 0) return <SelectChurchSearch selectChurch={props.selectChurch} registeredChurchCallback={props.registeredChurchCallback} appName={props.appName} />
|
|
31
|
+
else return (<>
|
|
32
|
+
{props.userChurches?.map(uc => (<SelectableChurch church={uc.church} selectChurch={props.selectChurch} key={uc.church.id} />))}
|
|
33
|
+
<button
|
|
34
|
+
type="button"
|
|
35
|
+
style={{
|
|
36
|
+
display: "block",
|
|
37
|
+
textAlign: "center",
|
|
38
|
+
background: "none",
|
|
39
|
+
border: "none",
|
|
40
|
+
color: "#3b82f6",
|
|
41
|
+
cursor: "pointer",
|
|
42
|
+
textDecoration: "underline"
|
|
43
|
+
}}
|
|
44
|
+
onClick={(e) => { e.preventDefault(); setShowSearch(true); }}
|
|
45
|
+
>
|
|
46
|
+
{Locale.label("selectChurch.another")}
|
|
47
|
+
</button>
|
|
48
|
+
</>);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Dialog
|
|
53
|
+
open={props.show}
|
|
54
|
+
onClose={handleClose}
|
|
55
|
+
aria-labelledby="select-church-title"
|
|
56
|
+
aria-describedby="select-church-content"
|
|
57
|
+
>
|
|
58
|
+
<DialogTitle id="select-church-title">{Locale.label("selectChurch.selectChurch")}
|
|
59
|
+
</DialogTitle>
|
|
60
|
+
<Tooltip title="Logout" arrow>
|
|
61
|
+
<IconButton
|
|
62
|
+
sx={{ position: "absolute", right: 8, top: 8 }}
|
|
63
|
+
color="error"
|
|
64
|
+
aria-label="Logout"
|
|
65
|
+
onClick={() => {
|
|
66
|
+
// Use handleRedirect function if available, otherwise fallback to window.location
|
|
67
|
+
if (props.handleRedirect) {
|
|
68
|
+
props.handleRedirect("/logout");
|
|
69
|
+
} else {
|
|
70
|
+
window.location.href = "/logout";
|
|
71
|
+
}
|
|
72
|
+
}}>
|
|
73
|
+
<Logout />
|
|
74
|
+
</IconButton>
|
|
75
|
+
</Tooltip>
|
|
76
|
+
<DialogContent id="select-church-content" sx={{ width: 500, maxWidth: "100%" }}>
|
|
77
|
+
<ErrorMessages errors={props.errors} />
|
|
78
|
+
{getContents()}
|
|
79
|
+
</DialogContent>
|
|
80
|
+
</Dialog>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { ApiHelper } from "@churchapps/helpers";
|
|
5
|
+
import { Locale } from "../helpers";
|
|
6
|
+
import { ChurchInterface, RegisterChurchRequestInterface } from "@churchapps/helpers";
|
|
7
|
+
import { ErrorMessages, InputBox } from "@churchapps/apphelper"
|
|
8
|
+
import { Grid, TextField } from "@mui/material";
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
initialChurchName: string,
|
|
12
|
+
registeredChurchCallback?: (church: ChurchInterface) => void,
|
|
13
|
+
selectChurch: (churchId: string) => void,
|
|
14
|
+
appName: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const SelectChurchRegister: React.FC<Props> = (props) => {
|
|
18
|
+
const suggestSubDomain = (name: string) => {
|
|
19
|
+
let result = name.toLowerCase().replaceAll("christian", "").replaceAll("church", "").replaceAll(" ", "");
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const [church, setChurch] = React.useState<RegisterChurchRequestInterface>({ name: props.initialChurchName, appName: props.appName, subDomain: suggestSubDomain(props.initialChurchName) });
|
|
24
|
+
const [errors, setErrors] = React.useState([]);
|
|
25
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
26
|
+
|
|
27
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
28
|
+
const c = { ...church }
|
|
29
|
+
switch (e.target.name) {
|
|
30
|
+
case "churchName": c.name = e.target.value; break;
|
|
31
|
+
case "subDomain": c.subDomain = e.target.value; break;
|
|
32
|
+
case "address1": c.address1 = e.target.value; break;
|
|
33
|
+
case "address2": c.address2 = e.target.value; break;
|
|
34
|
+
case "city": c.city = e.target.value; break;
|
|
35
|
+
case "state": c.state = e.target.value; break;
|
|
36
|
+
case "zip": c.zip = e.target.value; break;
|
|
37
|
+
case "country": c.country = e.target.value; break;
|
|
38
|
+
}
|
|
39
|
+
setChurch(c);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const validate = () => {
|
|
43
|
+
let errors = [];
|
|
44
|
+
if (!church.name?.trim()) errors.push(Locale.label("selectChurch.validate.name"));
|
|
45
|
+
if (!church.address1?.trim()) errors.push(Locale.label("selectChurch.validate.address"));
|
|
46
|
+
if (!church.city?.trim()) errors.push(Locale.label("selectChurch.validate.city"));
|
|
47
|
+
if (!church.state?.trim()) errors.push(Locale.label("selectChurch.validate.state"));
|
|
48
|
+
if (!church.zip?.trim()) errors.push(Locale.label("selectChurch.validate.zip"));
|
|
49
|
+
if (!church.country?.trim()) errors.push(Locale.label("selectChurch.validate.country"));
|
|
50
|
+
setErrors(errors);
|
|
51
|
+
return errors.length === 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const handleSave = () => {
|
|
55
|
+
if (validate()) {
|
|
56
|
+
setIsSubmitting(true);
|
|
57
|
+
const c = { ...church };
|
|
58
|
+
if (!c.subDomain) c.subDomain = suggestSubDomain(c.name);
|
|
59
|
+
ApiHelper.post("/churches/add", church, "MembershipApi").then(async resp => {
|
|
60
|
+
setIsSubmitting(false);
|
|
61
|
+
if (resp.errors !== undefined) setErrors(errors);
|
|
62
|
+
else {
|
|
63
|
+
if (props.registeredChurchCallback) props.registeredChurchCallback(resp);
|
|
64
|
+
props.selectChurch(resp.id);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<InputBox id="churchBox" saveFunction={handleSave} headerText={Locale.label("selectChurch.register")} headerIcon="church" isSubmitting={isSubmitting}>
|
|
72
|
+
<ErrorMessages errors={errors} />
|
|
73
|
+
<TextField required fullWidth name="churchName" label={Locale.label("selectChurch.name")} value={church.name} onChange={handleChange} />
|
|
74
|
+
|
|
75
|
+
<TextField required fullWidth name="address1" label={Locale.label("selectChurch.address1")} value={church.address1} onChange={handleChange} />
|
|
76
|
+
<Grid container spacing={3}>
|
|
77
|
+
<Grid size={6}><TextField fullWidth name="address2" label={Locale.label("selectChurch.address2")} value={church.address2} onChange={handleChange} /></Grid>
|
|
78
|
+
<Grid size={6}><TextField required fullWidth name="city" label={Locale.label("selectChurch.city")} value={church.city} onChange={handleChange} /></Grid>
|
|
79
|
+
</Grid>
|
|
80
|
+
<Grid container spacing={3}>
|
|
81
|
+
<Grid size={6}><TextField required fullWidth name="state" label={Locale.label("selectChurch.state")} value={church.state} onChange={handleChange} /></Grid>
|
|
82
|
+
<Grid size={6}><TextField required fullWidth name="zip" label={Locale.label("selectChurch.zip")} value={church.zip} onChange={handleChange} /></Grid>
|
|
83
|
+
</Grid>
|
|
84
|
+
<TextField required fullWidth name="country" label={Locale.label("selectChurch.country")} value={church.country} onChange={handleChange} />
|
|
85
|
+
</InputBox>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button, TextField } from "@mui/material";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { ApiHelper } from "@churchapps/helpers";
|
|
6
|
+
import { Locale } from "../helpers";
|
|
7
|
+
import { ChurchInterface } from "@churchapps/helpers";
|
|
8
|
+
import { SelectableChurch } from "./SelectableChurch";
|
|
9
|
+
import { SelectChurchRegister } from "./SelectChurchRegister";
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
selectChurch: (churchId: string) => void,
|
|
13
|
+
registeredChurchCallback?: (church: ChurchInterface) => void,
|
|
14
|
+
appName: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const SelectChurchSearch: React.FC<Props> = (props) => {
|
|
18
|
+
const [searchText, setSearchText] = React.useState("");
|
|
19
|
+
const [churches, setChurches] = React.useState<ChurchInterface[]>(null);
|
|
20
|
+
const [showRegister, setShowRegister] = React.useState(false);
|
|
21
|
+
|
|
22
|
+
const handleSubmit = (e: React.MouseEvent) => {
|
|
23
|
+
if (e !== null) e.preventDefault();
|
|
24
|
+
let term = searchText.trim();
|
|
25
|
+
ApiHelper.post("/churches/search", { name: term }, "MembershipApi").then(data => setChurches(data));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => setSearchText(e.currentTarget.value);
|
|
29
|
+
|
|
30
|
+
const handleKeyDown = (e: React.KeyboardEvent<any>) => { if (e.key === "Enter") { e.preventDefault(); handleSubmit(null); } }
|
|
31
|
+
|
|
32
|
+
const handleRegisterClick = (e: React.MouseEvent) => {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
if (window.confirm(Locale.label("selectChurch.confirmRegister"))) {
|
|
35
|
+
setShowRegister(true);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getRegisterLink = () => (
|
|
40
|
+
<div>
|
|
41
|
+
<button
|
|
42
|
+
type="button"
|
|
43
|
+
style={{
|
|
44
|
+
display: "block",
|
|
45
|
+
textAlign: "center",
|
|
46
|
+
background: "none",
|
|
47
|
+
border: "none",
|
|
48
|
+
color: "#3b82f6",
|
|
49
|
+
cursor: "pointer",
|
|
50
|
+
textDecoration: "underline",
|
|
51
|
+
width: "100%"
|
|
52
|
+
}}
|
|
53
|
+
onClick={handleRegisterClick}
|
|
54
|
+
>
|
|
55
|
+
{Locale.label("selectChurch.register")}
|
|
56
|
+
</button>
|
|
57
|
+
</div>
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const getChurches = () => {
|
|
61
|
+
const result: React.ReactElement[] = [];
|
|
62
|
+
churches.forEach(church => {
|
|
63
|
+
result.push(<SelectableChurch church={church} selectChurch={props.selectChurch} />);
|
|
64
|
+
});
|
|
65
|
+
result.push(getRegisterLink());
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const getResults = () => {
|
|
70
|
+
if (churches === null) return;
|
|
71
|
+
else if (churches.length === 0) return <><p>{Locale.label("selectChurch.noMatches")}</p>{getRegisterLink()}</>
|
|
72
|
+
else return getChurches();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (showRegister) return (<SelectChurchRegister selectChurch={props.selectChurch} registeredChurchCallback={props.registeredChurchCallback} appName={props.appName} initialChurchName={searchText} />)
|
|
76
|
+
else return (
|
|
77
|
+
<>
|
|
78
|
+
<TextField fullWidth name="searchText" label="Name" value={searchText} onChange={handleChange} onKeyDown={handleKeyDown}
|
|
79
|
+
InputProps={{ endAdornment: <Button variant="contained" id="searchButton" data-testid="search-button" onClick={handleSubmit}>{Locale.label("common.search")}</Button> }}
|
|
80
|
+
/>
|
|
81
|
+
{getResults()}
|
|
82
|
+
</>
|
|
83
|
+
|
|
84
|
+
);
|
|
85
|
+
};
|