@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.
- package/dist/helpers/ApiHelper.d.ts.map +1 -1
- package/dist/helpers/ApiHelper.js +3 -3
- package/dist/helpers/ApiHelper.js.map +1 -1
- package/dist/helpers/ErrorHelper.d.ts +2 -2
- package/dist/helpers/ErrorHelper.d.ts.map +1 -1
- package/dist/helpers/ErrorHelper.js.map +1 -1
- package/dist/helpers/FileHelper.d.ts +1 -1
- package/dist/helpers/FileHelper.d.ts.map +1 -1
- package/dist/helpers/FileHelper.js +2 -6
- package/dist/helpers/FileHelper.js.map +1 -1
- package/dist/helpers/UserHelper.d.ts +1 -1
- package/dist/helpers/UserHelper.d.ts.map +1 -1
- package/dist/helpers/UserHelper.js +10 -3
- package/dist/helpers/UserHelper.js.map +1 -1
- package/dist/pageComponents/LoginPage.d.ts +1 -0
- package/dist/pageComponents/LoginPage.d.ts.map +1 -1
- package/dist/pageComponents/LoginPage.js +7 -1
- package/dist/pageComponents/LoginPage.js.map +1 -1
- package/dist/pageComponents/LogoutPage.d.ts +1 -0
- package/dist/pageComponents/LogoutPage.d.ts.map +1 -1
- package/dist/pageComponents/LogoutPage.js +7 -1
- package/dist/pageComponents/LogoutPage.js.map +1 -1
- package/dist/pageComponents/components/SelectChurchModal.d.ts +1 -0
- package/dist/pageComponents/components/SelectChurchModal.d.ts.map +1 -1
- package/dist/pageComponents/components/SelectChurchModal.js +9 -1
- package/dist/pageComponents/components/SelectChurchModal.js.map +1 -1
- package/package.json +2 -2
- package/src/helpers/ApiHelper.ts +119 -119
- package/src/helpers/ErrorHelper.ts +2 -2
- package/src/helpers/FileHelper.ts +3 -6
- package/src/helpers/UserHelper.ts +64 -57
- package/src/pageComponents/LoginPage.tsx +223 -217
- package/src/pageComponents/LogoutPage.tsx +23 -18
- 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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
if (props.callbackErrors?.length > 0) {
|
|
67
|
+
setErrors(props.callbackErrors)
|
|
68
|
+
}
|
|
69
|
+
}, [props.callbackErrors])
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
if (props.jwt) {
|
|
101
|
+
const decoded: any = jwt_decode(userJwtBackup)
|
|
102
|
+
selectedChurchId = decoded.churchId
|
|
103
|
+
}
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
const search = new URLSearchParams(location?.search);
|
|
106
|
+
const churchIdInParams = search.get("churchId");
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
118
|
-
|
|
118
|
+
const selectChurchById = async () => {
|
|
119
|
+
await UserHelper.selectChurch(props.context, selectedChurchId, undefined);
|
|
119
120
|
|
|
120
|
-
|
|
121
|
+
setCookie("lastChurchId", selectedChurchId, { path: "/" });
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
219
|
+
const handleLoginErrors = (errors: string[]) => {
|
|
220
|
+
setWelcomeBackName("");
|
|
221
|
+
console.log(errors);
|
|
222
|
+
setErrors([Locale.label("login.validate.invalid")]);
|
|
223
|
+
}
|
|
218
224
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
258
|
+
React.useEffect(init, []); //eslint-disable-line
|
|
253
259
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
10
|
+
const [, , removeCookie] = useCookies(["jwt", "email", "name", "lastChurchId"]);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
removeCookie("jwt");
|
|
13
|
+
removeCookie("email");
|
|
14
|
+
removeCookie("name");
|
|
15
|
+
removeCookie("lastChurchId");
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
+
const [showSearch, setShowSearch] = React.useState(false);
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const handleClose = () => {
|
|
25
|
+
window.location.reload();
|
|
26
|
+
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
};
|