fix toaster upon user settings change (#1802)

Co-authored-by: SleeplessOne1917 <abias1122@gmail.com>
This commit is contained in:
Alec Armbruster 2023-07-04 17:08:32 -04:00 committed by GitHub
parent 26ff0f7e06
commit c3ab9e74f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 8 deletions

View file

@ -175,7 +175,9 @@ export class Login extends Component<any, State> {
} }
case "success": { case "success": {
UserService.Instance.login(loginRes.data); UserService.Instance.login({
res: loginRes.data,
});
const site = await HttpService.client.getSite({ const site = await HttpService.client.getSite({
auth: myAuth(), auth: myAuth(),
}); });

View file

@ -206,7 +206,7 @@ export class Setup extends Component<any, State> {
if (i.state.registerRes.state == "success") { if (i.state.registerRes.state == "success") {
const data = i.state.registerRes.data; const data = i.state.registerRes.data;
UserService.Instance.login(data); UserService.Instance.login({ res: data });
i.setState({ doneRegisteringUser: true }); i.setState({ doneRegisteringUser: true });
} }
} }

View file

@ -469,7 +469,9 @@ export class Signup extends Component<any, State> {
// Only log them in if a jwt was set // Only log them in if a jwt was set
if (data.jwt) { if (data.jwt) {
UserService.Instance.login(data); UserService.Instance.login({
res: data,
});
const site = await HttpService.client.getSite({ auth: myAuth() }); const site = await HttpService.client.getSite({ auth: myAuth() });

View file

@ -135,7 +135,9 @@ export class PasswordChange extends Component<any, State> {
if (i.state.passwordChangeRes.state === "success") { if (i.state.passwordChangeRes.state === "success") {
const data = i.state.passwordChangeRes.data; const data = i.state.passwordChangeRes.data;
UserService.Instance.login(data); UserService.Instance.login({
res: data,
});
const site = await HttpService.client.getSite({ auth: myAuth() }); const site = await HttpService.client.getSite({ auth: myAuth() });
if (site.state === "success") { if (site.state === "success") {

View file

@ -1175,8 +1175,12 @@ export class Settings extends Component<any, SettingsState> {
...i.state.saveUserSettingsForm, ...i.state.saveUserSettingsForm,
auth: myAuthRequired(), auth: myAuthRequired(),
}); });
if (saveRes.state === "success") { if (saveRes.state === "success") {
UserService.Instance.login(saveRes.data); UserService.Instance.login({
res: saveRes.data,
showToast: false,
});
toast(I18NextService.i18n.t("saved")); toast(I18NextService.i18n.t("saved"));
window.scrollTo(0, 0); window.scrollTo(0, 0);
} }
@ -1198,7 +1202,10 @@ export class Settings extends Component<any, SettingsState> {
auth: myAuthRequired(), auth: myAuthRequired(),
}); });
if (changePasswordRes.state === "success") { if (changePasswordRes.state === "success") {
UserService.Instance.login(changePasswordRes.data); UserService.Instance.login({
res: changePasswordRes.data,
showToast: false,
});
window.scrollTo(0, 0); window.scrollTo(0, 0);
toast(I18NextService.i18n.t("password_changed")); toast(I18NextService.i18n.t("password_changed"));
} }

View file

@ -26,12 +26,18 @@ export class UserService {
this.#setJwtInfo(); this.#setJwtInfo();
} }
public login(res: LoginResponse) { public login({
res,
showToast = true,
}: {
res: LoginResponse;
showToast?: boolean;
}) {
const expires = new Date(); const expires = new Date();
expires.setDate(expires.getDate() + 365); expires.setDate(expires.getDate() + 365);
if (isBrowser() && res.jwt) { if (isBrowser() && res.jwt) {
toast(I18NextService.i18n.t("logged_in")); showToast && toast(I18NextService.i18n.t("logged_in"));
setAuthCookie(res.jwt); setAuthCookie(res.jwt);
this.#setJwtInfo(); this.#setJwtInfo();
} }