@churchapps/apphelper 0.3.42 → 0.3.45

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.
Files changed (34) hide show
  1. package/dist/helpers/ApiHelper.d.ts.map +1 -1
  2. package/dist/helpers/ApiHelper.js +3 -3
  3. package/dist/helpers/ApiHelper.js.map +1 -1
  4. package/dist/helpers/ErrorHelper.d.ts +2 -2
  5. package/dist/helpers/ErrorHelper.d.ts.map +1 -1
  6. package/dist/helpers/ErrorHelper.js.map +1 -1
  7. package/dist/helpers/FileHelper.d.ts +1 -1
  8. package/dist/helpers/FileHelper.d.ts.map +1 -1
  9. package/dist/helpers/FileHelper.js +2 -6
  10. package/dist/helpers/FileHelper.js.map +1 -1
  11. package/dist/helpers/UserHelper.d.ts +1 -1
  12. package/dist/helpers/UserHelper.d.ts.map +1 -1
  13. package/dist/helpers/UserHelper.js +10 -3
  14. package/dist/helpers/UserHelper.js.map +1 -1
  15. package/dist/pageComponents/LoginPage.d.ts +1 -0
  16. package/dist/pageComponents/LoginPage.d.ts.map +1 -1
  17. package/dist/pageComponents/LoginPage.js +7 -1
  18. package/dist/pageComponents/LoginPage.js.map +1 -1
  19. package/dist/pageComponents/LogoutPage.d.ts +1 -0
  20. package/dist/pageComponents/LogoutPage.d.ts.map +1 -1
  21. package/dist/pageComponents/LogoutPage.js +7 -1
  22. package/dist/pageComponents/LogoutPage.js.map +1 -1
  23. package/dist/pageComponents/components/SelectChurchModal.d.ts +1 -0
  24. package/dist/pageComponents/components/SelectChurchModal.d.ts.map +1 -1
  25. package/dist/pageComponents/components/SelectChurchModal.js +9 -1
  26. package/dist/pageComponents/components/SelectChurchModal.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/helpers/ApiHelper.ts +119 -119
  29. package/src/helpers/ErrorHelper.ts +2 -2
  30. package/src/helpers/FileHelper.ts +3 -6
  31. package/src/helpers/UserHelper.ts +64 -57
  32. package/src/pageComponents/LoginPage.tsx +223 -217
  33. package/src/pageComponents/LogoutPage.tsx +23 -18
  34. package/src/pageComponents/components/SelectChurchModal.tsx +40 -32
@@ -16,251 +16,257 @@ import { CommonEnvironmentHelper } from "../helpers/CommonEnvironmentHelper";
16
16
  import ga4 from "react-ga4";
17
17
 
18
18
  interface Props {
19
- context: UserContextInterface,
20
- jwt: string,
21
- auth: string,
22
- keyName?: string,
23
- logo?: string,
24
- appName?: string,
25
- appUrl?: string,
26
- returnUrl?: string,
27
- loginSuccessOverride?: () => void,
28
- userRegisteredCallback?: (user: UserInterface) => Promise<void>;
29
- churchRegisteredCallback?: (church: ChurchInterface) => Promise<void>;
30
- callbackErrors?: string[];
31
- showLogo?: boolean;
32
- loginContainerCssProps?: PaperProps;
33
- defaultEmail?: string;
34
- defaultPassword?: string;
19
+ context: UserContextInterface,
20
+ jwt: string,
21
+ auth: string,
22
+ keyName?: string,
23
+ logo?: string,
24
+ appName?: string,
25
+ appUrl?: string,
26
+ returnUrl?: string,
27
+ loginSuccessOverride?: () => void,
28
+ userRegisteredCallback?: (user: UserInterface) => Promise<void>;
29
+ churchRegisteredCallback?: (church: ChurchInterface) => Promise<void>;
30
+ callbackErrors?: string[];
31
+ showLogo?: boolean;
32
+ loginContainerCssProps?: PaperProps;
33
+ defaultEmail?: string;
34
+ defaultPassword?: string;
35
+ handleRedirect?: (url: string) => void; // Function to handle redirects from parent component
35
36
  }
36
37
 
37
38
  export const LoginPage: React.FC<Props> = ({ showLogo = true, loginContainerCssProps, ...props }) => {
38
- const [welcomeBackName, setWelcomeBackName] = React.useState("");
39
- const [pendingAutoLogin, setPendingAutoLogin] = React.useState(false);
40
- const [errors, setErrors] = React.useState([]);
41
- const [cookies, setCookie] = useCookies(["jwt", "name", "email", "lastChurchId"]);
42
- const [showForgot, setShowForgot] = React.useState(false);
43
- const [showRegister, setShowRegister] = React.useState(false);
44
- const [showSelectModal, setShowSelectModal] = React.useState(false);
45
- const [loginResponse, setLoginResponse] = React.useState<LoginResponseInterface>(null)
46
- const [userJwt, setUserJwt] = React.useState("");
47
- const [isSubmitting, setIsSubmitting] = React.useState(false);
39
+ const [welcomeBackName, setWelcomeBackName] = React.useState("");
40
+ const [pendingAutoLogin, setPendingAutoLogin] = React.useState(false);
41
+ const [errors, setErrors] = React.useState([]);
42
+ const [cookies, setCookie] = useCookies(["jwt", "name", "email", "lastChurchId"]);
43
+ const [showForgot, setShowForgot] = React.useState(false);
44
+ const [showRegister, setShowRegister] = React.useState(false);
45
+ const [showSelectModal, setShowSelectModal] = React.useState(false);
46
+ const [loginResponse, setLoginResponse] = React.useState<LoginResponseInterface>(null)
47
+ const [userJwt, setUserJwt] = React.useState("");
48
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
48
49
 
49
- const loginFormRef = React.useRef(null);
50
- const location = typeof window !== "undefined" && window.location;
51
- let selectedChurchId = "";
52
- let registeredChurch: ChurchInterface = null;
53
- let userJwtBackup = ""; //use state copy for storing between page updates. This copy for instant availability.
50
+ const loginFormRef = React.useRef(null);
51
+ const location = typeof window !== "undefined" && window.location;
52
+ let selectedChurchId = "";
53
+ let registeredChurch: ChurchInterface = null;
54
+ let userJwtBackup = ""; //use state copy for storing between page updates. This copy for instant availability.
54
55
 
55
- const cleanAppUrl = () => {
56
- if (!props.appUrl) return null;
57
- else {
58
- const index = props.appUrl.indexOf("/", 9);
59
- if (index === -1) return props.appUrl;
60
- else return props.appUrl.substring(0, index);
61
- }
62
- }
56
+ const cleanAppUrl = () => {
57
+ if (!props.appUrl) return null;
58
+ else {
59
+ const index = props.appUrl.indexOf("/", 9);
60
+ if (index === -1) return props.appUrl;
61
+ else return props.appUrl.substring(0, index);
62
+ }
63
+ }
63
64
 
64
- React.useEffect(() => {
65
- if (props.callbackErrors?.length > 0) {
66
- setErrors(props.callbackErrors)
67
- }
68
- }, [props.callbackErrors])
65
+ React.useEffect(() => {
66
+ if (props.callbackErrors?.length > 0) {
67
+ setErrors(props.callbackErrors)
68
+ }
69
+ }, [props.callbackErrors])
69
70
 
70
- const init = () => {
71
- const search = new URLSearchParams(location?.search);
72
- const action = search.get("action");
73
- if (action === "forgot") setShowForgot(true);
74
- else if (action === "register") setShowRegister(true);
75
- else {
76
- if (!props.auth && props.jwt) {
77
- console.log("JWT IS", props.jwt)
78
- setWelcomeBackName(cookies.name);
79
- login({ jwt: props.jwt });
80
- setPendingAutoLogin(true);
81
- } else {
82
- setPendingAutoLogin(false);
83
- }
84
- }
85
- };
71
+ const init = () => {
72
+ const search = new URLSearchParams(location?.search);
73
+ const action = search.get("action");
74
+ if (action === "forgot") setShowForgot(true);
75
+ else if (action === "register") setShowRegister(true);
76
+ else {
77
+ if (!props.auth && props.jwt) {
78
+ console.log("JWT IS", props.jwt)
79
+ setWelcomeBackName(cookies.name);
80
+ login({ jwt: props.jwt });
81
+ setPendingAutoLogin(true);
82
+ } else {
83
+ setPendingAutoLogin(false);
84
+ }
85
+ }
86
+ };
86
87
 
87
- const handleLoginSuccess = async (resp: LoginResponseInterface) => {
88
- userJwtBackup = resp.user.jwt;
89
- setUserJwt(userJwtBackup);
90
- ApiHelper.setDefaultPermissions(resp.user.jwt);
91
- setLoginResponse(resp)
92
- resp.userChurches.forEach(uc => { if (!uc.apis) uc.apis = []; });
93
- UserHelper.userChurches = resp.userChurches;
88
+ const handleLoginSuccess = async (resp: LoginResponseInterface) => {
89
+ userJwtBackup = resp.user.jwt;
90
+ setUserJwt(userJwtBackup);
91
+ ApiHelper.setDefaultPermissions(resp.user.jwt);
92
+ setLoginResponse(resp)
93
+ resp.userChurches.forEach(uc => { if (!uc.apis) uc.apis = []; });
94
+ UserHelper.userChurches = resp.userChurches;
94
95
 
95
- setCookie("name", `${resp.user.firstName} ${resp.user.lastName}`, { path: "/" });
96
- setCookie("email", resp.user.email, { path: "/" });
97
- UserHelper.user = resp.user;
96
+ setCookie("name", `${resp.user.firstName} ${resp.user.lastName}`, { path: "/" });
97
+ setCookie("email", resp.user.email, { path: "/" });
98
+ UserHelper.user = resp.user;
98
99
 
99
- if (props.jwt) {
100
- const decoded: any = jwt_decode(userJwtBackup)
101
- selectedChurchId = decoded.churchId
102
- }
100
+ if (props.jwt) {
101
+ const decoded: any = jwt_decode(userJwtBackup)
102
+ selectedChurchId = decoded.churchId
103
+ }
103
104
 
104
- const search = new URLSearchParams(location?.search);
105
- const churchIdInParams = search.get("churchId");
105
+ const search = new URLSearchParams(location?.search);
106
+ const churchIdInParams = search.get("churchId");
106
107
 
107
- if (props.keyName) selectChurchByKeyName();
108
- else if (selectedChurchId) selectChurchById();
109
- else if (churchIdInParams) selectChurch(churchIdInParams);
110
- else if (props.jwt && cookies.lastChurchId && ArrayHelper.getOne(resp.userChurches, "church.id", cookies.lastChurchId)) {
111
- selectedChurchId = cookies.lastChurchId;
112
- selectChurchById();
113
- }
114
- else setShowSelectModal(true);
115
- }
108
+ if (props.keyName) selectChurchByKeyName();
109
+ else if (selectedChurchId) selectChurchById();
110
+ else if (churchIdInParams) selectChurch(churchIdInParams);
111
+ else if (props.jwt && cookies.lastChurchId && ArrayHelper.getOne(resp.userChurches, "church.id", cookies.lastChurchId)) {
112
+ selectedChurchId = cookies.lastChurchId;
113
+ selectChurchById();
114
+ }
115
+ else setShowSelectModal(true);
116
+ }
116
117
 
117
- const selectChurchById = async () => {
118
- await UserHelper.selectChurch(props.context, selectedChurchId, undefined);
118
+ const selectChurchById = async () => {
119
+ await UserHelper.selectChurch(props.context, selectedChurchId, undefined);
119
120
 
120
- setCookie("lastChurchId", selectedChurchId, { path: "/" });
121
+ setCookie("lastChurchId", selectedChurchId, { path: "/" });
121
122
 
122
- if (registeredChurch) {
123
- AnalyticsHelper.logEvent("Church", "Register", UserHelper.currentUserChurch.church.name);
124
- try {
125
- if (CommonEnvironmentHelper.GoogleAnalyticsTag && typeof (window) !== "undefined") {
126
- ga4.gtag("event", "conversion", { send_to: "AW-427967381/Ba2qCLrXgJoYEJWHicwB" });
127
- }
128
- } catch { }
129
- }
130
- else AnalyticsHelper.logEvent("Church", "Select", UserHelper.currentUserChurch.church.name);
123
+ if (registeredChurch) {
124
+ AnalyticsHelper.logEvent("Church", "Register", UserHelper.currentUserChurch.church.name);
125
+ try {
126
+ if (CommonEnvironmentHelper.GoogleAnalyticsTag && typeof (window) !== "undefined") {
127
+ ga4.gtag("event", "conversion", { send_to: "AW-427967381/Ba2qCLrXgJoYEJWHicwB" });
128
+ }
129
+ } catch { }
130
+ }
131
+ else AnalyticsHelper.logEvent("Church", "Select", UserHelper.currentUserChurch.church.name);
131
132
 
132
- if (props.churchRegisteredCallback && registeredChurch) {
133
- await props.churchRegisteredCallback(registeredChurch)
134
- registeredChurch = null;
135
- login({ jwt: userJwt || userJwtBackup });
136
- } else await continueLoginProcess();
137
- }
133
+ if (props.churchRegisteredCallback && registeredChurch) {
134
+ await props.churchRegisteredCallback(registeredChurch)
135
+ registeredChurch = null;
136
+ login({ jwt: userJwt || userJwtBackup });
137
+ } else await continueLoginProcess();
138
+ }
138
139
 
139
- const selectChurchByKeyName = async () => {
140
- if (!ArrayHelper.getOne(UserHelper.userChurches, "church.subDomain", props.keyName)) {
141
- const userChurch: LoginUserChurchInterface = await ApiHelper.post("/churches/select", { subDomain: props.keyName }, "MembershipApi");
142
- UserHelper.setupApiHelper(userChurch);
143
- setCookie("lastChurchId", userChurch.church.id, { path: "/" });
144
- //create/claim the person record and relogin
145
- await ApiHelper.get("/people/claim/" + userChurch.church.id, "MembershipApi");
146
- login({ jwt: userJwt || userJwtBackup });
147
- return;
148
- }
149
- await UserHelper.selectChurch(props.context, undefined, props.keyName);
150
- const selectedChurch = ArrayHelper.getOne(UserHelper.userChurches, "church.subDomain", props.keyName);
151
- if (selectedChurch) setCookie("lastChurchId", selectedChurch.church.id, { path: "/" });
152
- await continueLoginProcess()
153
- return;
154
- }
140
+ const selectChurchByKeyName = async () => {
141
+ if (!ArrayHelper.getOne(UserHelper.userChurches, "church.subDomain", props.keyName)) {
142
+ const userChurch: LoginUserChurchInterface = await ApiHelper.post("/churches/select", { subDomain: props.keyName }, "MembershipApi");
143
+ UserHelper.setupApiHelper(userChurch);
144
+ setCookie("lastChurchId", userChurch.church.id, { path: "/" });
145
+ //create/claim the person record and relogin
146
+ await ApiHelper.get("/people/claim/" + userChurch.church.id, "MembershipApi");
147
+ login({ jwt: userJwt || userJwtBackup });
148
+ return;
149
+ }
150
+ await UserHelper.selectChurch(props.context, undefined, props.keyName);
151
+ const selectedChurch = ArrayHelper.getOne(UserHelper.userChurches, "church.subDomain", props.keyName);
152
+ if (selectedChurch) setCookie("lastChurchId", selectedChurch.church.id, { path: "/" });
153
+ await continueLoginProcess()
154
+ return;
155
+ }
155
156
 
156
- async function continueLoginProcess() {
157
- if (UserHelper.currentUserChurch) {
158
- UserHelper.currentUserChurch.apis.forEach(api => {
159
- if (api.keyName === "MembershipApi") setCookie("jwt", api.jwt, { path: "/" });
160
- })
161
- try {
162
- if (UserHelper.currentUserChurch.church.id) ApiHelper.patch(`/userChurch/${UserHelper.user.id}`, { churchId: UserHelper.currentUserChurch.church.id, appName: props.appName, lastAccessed: new Date() }, "MembershipApi")
163
- } catch (e) {
164
- console.log("Could not update user church accessed date")
165
- }
166
- }
157
+ async function continueLoginProcess() {
158
+ if (UserHelper.currentUserChurch) {
159
+ UserHelper.currentUserChurch.apis.forEach(api => {
160
+ if (api.keyName === "MembershipApi") setCookie("jwt", api.jwt, { path: "/" });
161
+ })
162
+ try {
163
+ if (UserHelper.currentUserChurch.church.id) ApiHelper.patch(`/userChurch/${UserHelper.user.id}`, { churchId: UserHelper.currentUserChurch.church.id, appName: props.appName, lastAccessed: new Date() }, "MembershipApi")
164
+ } catch (e) {
165
+ console.log("Could not update user church accessed date")
166
+ }
167
+ }
167
168
 
168
- if (props.loginSuccessOverride !== undefined) props.loginSuccessOverride();
169
- else {
170
- props.context.setUser(UserHelper.user);
171
- props.context.setUserChurches(UserHelper.userChurches)
172
- props.context.setUserChurch(UserHelper.currentUserChurch)
173
- try {
174
- const p = await ApiHelper.get(`/people/${UserHelper.currentUserChurch.person?.id}`, "MembershipApi");
175
- if (p) props.context.setPerson(p);
176
- } catch {
177
- console.log("claiming person");
178
- const personClaim = await ApiHelper.get("/people/claim/" + UserHelper.currentUserChurch.church.id, "MembershipApi");
179
- props.context.setPerson(personClaim);
180
- }
169
+ if (props.loginSuccessOverride !== undefined) props.loginSuccessOverride();
170
+ else {
171
+ props.context.setUser(UserHelper.user);
172
+ props.context.setUserChurches(UserHelper.userChurches)
173
+ props.context.setUserChurch(UserHelper.currentUserChurch)
174
+ try {
175
+ const p = await ApiHelper.get(`/people/${UserHelper.currentUserChurch.person?.id}`, "MembershipApi");
176
+ if (p) props.context.setPerson(p);
177
+ } catch {
178
+ console.log("claiming person");
179
+ const personClaim = await ApiHelper.get("/people/claim/" + UserHelper.currentUserChurch.church.id, "MembershipApi");
180
+ props.context.setPerson(personClaim);
181
+ }
181
182
 
182
- const search = new URLSearchParams(location?.search);
183
- const returnUrl = search.get("returnUrl") || props.returnUrl;
184
- if (returnUrl && typeof window !== "undefined") {
185
- window.location.href = returnUrl;
186
- }
187
- }
188
- }
183
+ const search = new URLSearchParams(location?.search);
184
+ const returnUrl = search.get("returnUrl") || props.returnUrl;
185
+ if (returnUrl && typeof window !== "undefined") {
186
+ // Use handleRedirect function if available, otherwise fallback to window.location
187
+ if (props.handleRedirect) {
188
+ props.handleRedirect(returnUrl);
189
+ } else {
190
+ window.location.href = returnUrl;
191
+ }
192
+ }
193
+ }
194
+ }
189
195
 
190
- async function selectChurch(churchId: string) {
191
- try {
192
- setErrors([])
193
- selectedChurchId = churchId;
194
- setCookie("lastChurchId", churchId, { path: "/" });
195
- if (!ArrayHelper.getOne(UserHelper.userChurches, "church.id", churchId)) {
196
- const userChurch: LoginUserChurchInterface = await ApiHelper.post("/churches/select", { churchId: churchId }, "MembershipApi");
197
- UserHelper.setupApiHelper(userChurch);
196
+ async function selectChurch(churchId: string) {
197
+ try {
198
+ setErrors([])
199
+ selectedChurchId = churchId;
200
+ setCookie("lastChurchId", churchId, { path: "/" });
201
+ if (!ArrayHelper.getOne(UserHelper.userChurches, "church.id", churchId)) {
202
+ const userChurch: LoginUserChurchInterface = await ApiHelper.post("/churches/select", { churchId: churchId }, "MembershipApi");
203
+ UserHelper.setupApiHelper(userChurch);
198
204
 
199
- //create/claim the person record and relogin
200
- await ApiHelper.get("/people/claim/" + churchId, "MembershipApi");
201
- login({ jwt: userJwt || userJwtBackup });
202
- return;
203
- }
204
- UserHelper.selectChurch(props.context, churchId, null).then(() => { continueLoginProcess() });
205
- } catch (err) {
206
- console.log("Error in selecting church: ", err)
207
- setErrors([Locale.label("login.validate.selectingChurch")])
208
- loginFormRef?.current?.setSubmitting(false);
209
- }
205
+ //create/claim the person record and relogin
206
+ await ApiHelper.get("/people/claim/" + churchId, "MembershipApi");
207
+ login({ jwt: userJwt || userJwtBackup });
208
+ return;
209
+ }
210
+ UserHelper.selectChurch(props.context, churchId, null).then(() => { continueLoginProcess() });
211
+ } catch (err) {
212
+ console.log("Error in selecting church: ", err)
213
+ setErrors([Locale.label("login.validate.selectingChurch")])
214
+ loginFormRef?.current?.setSubmitting(false);
215
+ }
210
216
 
211
- }
217
+ }
212
218
 
213
- const handleLoginErrors = (errors: string[]) => {
214
- setWelcomeBackName("");
215
- console.log(errors);
216
- setErrors([Locale.label("login.validate.invalid")]);
217
- }
219
+ const handleLoginErrors = (errors: string[]) => {
220
+ setWelcomeBackName("");
221
+ console.log(errors);
222
+ setErrors([Locale.label("login.validate.invalid")]);
223
+ }
218
224
 
219
- const login = async (data: any) => {
220
- setErrors([])
221
- setIsSubmitting(true);
222
- try {
223
- const resp: LoginResponseInterface = await ApiHelper.postAnonymous("/users/login", data, "MembershipApi");
224
- setIsSubmitting(false);
225
- handleLoginSuccess(resp);
226
- } catch (e: any) {
227
- setPendingAutoLogin(false);
228
- if (!data.jwt) handleLoginErrors([e.toString()]);
229
- else setWelcomeBackName("");
230
- setIsSubmitting(false);
231
- }
232
- };
225
+ const login = async (data: any) => {
226
+ setErrors([])
227
+ setIsSubmitting(true);
228
+ try {
229
+ const resp: LoginResponseInterface = await ApiHelper.postAnonymous("/users/login", data, "MembershipApi");
230
+ setIsSubmitting(false);
231
+ handleLoginSuccess(resp);
232
+ } catch (e: any) {
233
+ setPendingAutoLogin(false);
234
+ if (!data.jwt) handleLoginErrors([e.toString()]);
235
+ else setWelcomeBackName("");
236
+ setIsSubmitting(false);
237
+ }
238
+ };
233
239
 
234
- const getWelcomeBack = () => { if (welcomeBackName !== "") return (<><Alert severity="info"><div dangerouslySetInnerHTML={{ __html: Locale.label("login.welcomeName")?.replace("{}", welcomeBackName) }} /></Alert><Loading /></>); }
235
- const getCheckEmail = () => { if (new URLSearchParams(location?.search).get("checkEmail") === "1") return <Alert severity="info">{Locale.label("login.registerThankYou")}</Alert> }
236
- const handleRegisterCallback = () => { setShowForgot(false); setShowRegister(true); }
237
- const handleLoginCallback = () => { setShowForgot(false); setShowRegister(false); }
238
- const handleChurchRegistered = (church: ChurchInterface) => { registeredChurch = church; setShowRegister(false); console.log("Updated VERSION********") }
240
+ const getWelcomeBack = () => { if (welcomeBackName !== "") return (<><Alert severity="info"><div dangerouslySetInnerHTML={{ __html: Locale.label("login.welcomeName")?.replace("{}", welcomeBackName) }} /></Alert><Loading /></>); }
241
+ const getCheckEmail = () => { if (new URLSearchParams(location?.search).get("checkEmail") === "1") return <Alert severity="info">{Locale.label("login.registerThankYou")}</Alert> }
242
+ const handleRegisterCallback = () => { setShowForgot(false); setShowRegister(true); }
243
+ const handleLoginCallback = () => { setShowForgot(false); setShowRegister(false); }
244
+ const handleChurchRegistered = (church: ChurchInterface) => { registeredChurch = church; setShowRegister(false); console.log("Updated VERSION********") }
239
245
 
240
- const getInputBox = () => {
241
- if (showRegister) return (
242
- <Box id="loginBox" sx={{ backgroundColor: "#FFF", border: "1px solid #CCC", borderRadius: "5px", padding: "20px" }}>
243
- <Typography component="h2" sx={{ fontSize: "32px", fontWeight: 500, lineHeight: 1.2, margin: "0 0 8px 0" }}>{Locale.label("login.createAccount")}</Typography>
244
- <Register updateErrors={setErrors} appName={props.appName} appUrl={cleanAppUrl()} loginCallback={handleLoginCallback} userRegisteredCallback={props.userRegisteredCallback} />
245
- </Box>
246
- );
247
- else if (showForgot) return (<Forgot registerCallback={handleRegisterCallback} loginCallback={handleLoginCallback} />);
248
- else if (props.auth) return (<LoginSetPassword setErrors={setErrors} setShowForgot={setShowForgot} isSubmitting={isSubmitting} auth={props.auth} login={login} appName={props.appName} appUrl={cleanAppUrl()} />)
249
- else return <Login setShowRegister={setShowRegister} setShowForgot={setShowForgot} setErrors={setErrors} isSubmitting={isSubmitting} login={login} mainContainerCssProps={loginContainerCssProps} defaultEmail={props.defaultEmail} defaultPassword={props.defaultPassword} />;
250
- }
246
+ const getInputBox = () => {
247
+ if (showRegister) return (
248
+ <Box id="loginBox" sx={{ backgroundColor: "#FFF", border: "1px solid #CCC", borderRadius: "5px", padding: "20px" }}>
249
+ <Typography component="h2" sx={{ fontSize: "32px", fontWeight: 500, lineHeight: 1.2, margin: "0 0 8px 0" }}>{Locale.label("login.createAccount")}</Typography>
250
+ <Register updateErrors={setErrors} appName={props.appName} appUrl={cleanAppUrl()} loginCallback={handleLoginCallback} userRegisteredCallback={props.userRegisteredCallback} />
251
+ </Box>
252
+ );
253
+ else if (showForgot) return (<Forgot registerCallback={handleRegisterCallback} loginCallback={handleLoginCallback} />);
254
+ else if (props.auth) return (<LoginSetPassword setErrors={setErrors} setShowForgot={setShowForgot} isSubmitting={isSubmitting} auth={props.auth} login={login} appName={props.appName} appUrl={cleanAppUrl()} />)
255
+ else return <Login setShowRegister={setShowRegister} setShowForgot={setShowForgot} setErrors={setErrors} isSubmitting={isSubmitting} login={login} mainContainerCssProps={loginContainerCssProps} defaultEmail={props.defaultEmail} defaultPassword={props.defaultPassword} />;
256
+ }
251
257
 
252
- React.useEffect(init, []); //eslint-disable-line
258
+ React.useEffect(init, []); //eslint-disable-line
253
259
 
254
- return (
255
- <Box sx={{ maxWidth: "382px" }} px="16px" mx="auto">
256
- {showLogo && <img src={props.logo || "/images/logo-login.png"} alt="logo" style={{ width: "100%", marginTop: 100, marginBottom: 60 }} />}
257
- <ErrorMessages errors={errors} />
258
- {getWelcomeBack()}
259
- {getCheckEmail()}
260
- {!pendingAutoLogin && getInputBox()}
261
- <SelectChurchModal show={showSelectModal} userChurches={loginResponse?.userChurches} selectChurch={selectChurch} registeredChurchCallback={handleChurchRegistered} errors={errors} appName={props.appName} />
262
- <FloatingSupport appName={props.appName} />
263
- </Box>
264
- );
260
+ return (
261
+ <Box sx={{ maxWidth: "382px" }} px="16px" mx="auto">
262
+ {showLogo && <img src={props.logo || "/images/logo-login.png"} alt="logo" style={{ width: "100%", marginTop: 100, marginBottom: 60 }} />}
263
+ <ErrorMessages errors={errors} />
264
+ {getWelcomeBack()}
265
+ {getCheckEmail()}
266
+ {!pendingAutoLogin && getInputBox()}
267
+ <SelectChurchModal show={showSelectModal} userChurches={loginResponse?.userChurches} selectChurch={selectChurch} registeredChurchCallback={handleChurchRegistered} errors={errors} appName={props.appName} />
268
+ <FloatingSupport appName={props.appName} />
269
+ </Box>
270
+ );
265
271
 
266
272
  };
@@ -4,27 +4,32 @@ import React from "react";
4
4
  import { useCookies } from "react-cookie"
5
5
  import { ApiHelper, UserContextInterface } from "../helpers";
6
6
 
7
- interface Props { context?: UserContextInterface, }
7
+ interface Props { context?: UserContextInterface, handleRedirect?: (url: string) => void }
8
8
 
9
9
  export const LogoutPage: React.FC<Props> = (props) => {
10
- const [, , removeCookie] = useCookies(["jwt", "email", "name", "lastChurchId"]);
10
+ const [, , removeCookie] = useCookies(["jwt", "email", "name", "lastChurchId"]);
11
11
 
12
- removeCookie("jwt");
13
- removeCookie("email");
14
- removeCookie("name");
15
- removeCookie("lastChurchId");
12
+ removeCookie("jwt");
13
+ removeCookie("email");
14
+ removeCookie("name");
15
+ removeCookie("lastChurchId");
16
16
 
17
- ApiHelper.clearPermissions();
18
- props.context?.setUser(null);
19
- props.context?.setPerson(null);
20
- props.context?.setUserChurches(null);
21
- props.context?.setUserChurch(null);
17
+ ApiHelper.clearPermissions();
18
+ props.context?.setUser(null);
19
+ props.context?.setPerson(null);
20
+ props.context?.setUserChurches(null);
21
+ props.context?.setUserChurch(null);
22
22
 
23
- setTimeout(() => {
24
- // a must check for Nextjs
25
- if (typeof window !== "undefined") {
26
- window.location.href = "/";
27
- }
28
- }, 300);
29
- return null;
23
+ setTimeout(() => {
24
+ // a must check for Nextjs
25
+ if (typeof window !== "undefined") {
26
+ // Use handleRedirect function if available, otherwise fallback to window.location
27
+ if (props.handleRedirect) {
28
+ props.handleRedirect("/");
29
+ } else {
30
+ window.location.href = "/";
31
+ }
32
+ }
33
+ }, 300);
34
+ return null;
30
35
  }
@@ -9,42 +9,50 @@ import { Dialog, DialogContent, DialogTitle, Icon, IconButton, Tooltip } from "@
9
9
  import { Locale } from "../../helpers";
10
10
 
11
11
  interface Props {
12
- appName: string,
13
- show: boolean,
14
- userChurches?: LoginUserChurchInterface[],
15
- selectChurch: (churchId: string) => void,
16
- registeredChurchCallback?: (church: ChurchInterface) => void,
17
- errors?: string[]
12
+ appName: string,
13
+ show: boolean,
14
+ userChurches?: LoginUserChurchInterface[],
15
+ selectChurch: (churchId: string) => void,
16
+ registeredChurchCallback?: (church: ChurchInterface) => void,
17
+ errors?: string[],
18
+ handleRedirect?: (url: string) => void
18
19
  }
19
20
 
20
21
  export const SelectChurchModal: React.FC<Props> = (props) => {
21
- const [showSearch, setShowSearch] = React.useState(false);
22
+ const [showSearch, setShowSearch] = React.useState(false);
22
23
 
23
- const handleClose = () => {
24
- window.location.reload();
25
- }
24
+ const handleClose = () => {
25
+ window.location.reload();
26
+ }
26
27
 
27
- const getContents = () => {
28
- if (showSearch || props.userChurches?.length === 0) return <SelectChurchSearch selectChurch={props.selectChurch} registeredChurchCallback={props.registeredChurchCallback} appName={props.appName} />
29
- else return (<>
30
- {props.userChurches?.map(uc => (<SelectableChurch church={uc.church} selectChurch={props.selectChurch} key={uc.church.id} />))}
31
- <a href="about:blank" style={{ display: "block", textAlign: "center" }} onClick={(e) => { e.preventDefault(); setShowSearch(true); }}>{Locale.label("selectChurch.another")}</a>
32
- </>);
33
- }
28
+ const getContents = () => {
29
+ if (showSearch || props.userChurches?.length === 0) return <SelectChurchSearch selectChurch={props.selectChurch} registeredChurchCallback={props.registeredChurchCallback} appName={props.appName} />
30
+ else return (<>
31
+ {props.userChurches?.map(uc => (<SelectableChurch church={uc.church} selectChurch={props.selectChurch} key={uc.church.id} />))}
32
+ <a href="about:blank" style={{ display: "block", textAlign: "center" }} onClick={(e) => { e.preventDefault(); setShowSearch(true); }}>{Locale.label("selectChurch.another")}</a>
33
+ </>);
34
+ }
34
35
 
35
- return (
36
- <Dialog open={props.show} onClose={handleClose}>
37
- <DialogTitle>{Locale.label("selectChurch.selectChurch")}
38
- </DialogTitle>
39
- <Tooltip title="Logout" arrow>
40
- <IconButton sx={{ position: "absolute", right: 8, top: 8 }} color="error" onClick={() => { window.location.href = "/logout" }}>
41
- <Icon>logout</Icon>
42
- </IconButton>
43
- </Tooltip>
44
- <DialogContent sx={{ width: 500, maxWidth: "100%" }}>
45
- <ErrorMessages errors={props.errors} />
46
- {getContents()}
47
- </DialogContent>
48
- </Dialog>
49
- );
36
+ return (
37
+ <Dialog open={props.show} onClose={handleClose}>
38
+ <DialogTitle>{Locale.label("selectChurch.selectChurch")}
39
+ </DialogTitle>
40
+ <Tooltip title="Logout" arrow>
41
+ <IconButton sx={{ position: "absolute", right: 8, top: 8 }} color="error" onClick={() => {
42
+ // Use handleRedirect function if available, otherwise fallback to window.location
43
+ if (props.handleRedirect) {
44
+ props.handleRedirect("/logout");
45
+ } else {
46
+ window.location.href = "/logout";
47
+ }
48
+ }}>
49
+ <Icon>logout</Icon>
50
+ </IconButton>
51
+ </Tooltip>
52
+ <DialogContent sx={{ width: 500, maxWidth: "100%" }}>
53
+ <ErrorMessages errors={props.errors} />
54
+ {getContents()}
55
+ </DialogContent>
56
+ </Dialog>
57
+ );
50
58
  };