Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: code by adding loader when logging out(#60) #94

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createAnimation, IonApp, IonRouterOutlet, loadingController } from '@io
import { useAuthStore } from "@/store/auth";
import { useRouter } from "vue-router";
import { defineComponent } from 'vue';
import { initialise } from '@/adapter';
import { initialise, resetConfig } from '@/adapter';
import emitter from "@/event-bus"

export default defineComponent({
Expand All @@ -25,13 +25,16 @@ export default defineComponent({
}
},
methods: {
async presentLoader() {
async presentLoader(options = { message: '', backdropDismiss: true } as any) {
// When having a custom message remove already existing loader
if(options.message && this.loader) this.dismissLoader();

if (!this.loader) {
this.loader = await loadingController
.create({
message: this.$t("Click the backdrop to dismiss."),
message: options.message ? this.$t(options.message) : this.$t("Click the backdrop to dismiss."),
translucent: true,
backdropDismiss: true
backdropDismiss: options.backdropDismiss
});
}
this.loader.present();
Expand Down Expand Up @@ -87,6 +90,21 @@ export default defineComponent({
}
})
},
async mounted() {
this.loader = await loadingController
.create({
message: this.$t("Click the backdrop to dismiss."),
translucent: true,
backdropDismiss: true
});
emitter.on('presentLoader', this.presentLoader);
emitter.on('dismissLoader', this.dismissLoader);
},
unmounted() {
emitter.off('presentLoader', this.presentLoader);
emitter.off('dismissLoader', this.dismissLoader);
resetConfig()
},
setup () {
const router = useRouter();
const authStore = useAuthStore();
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Launch Pad": "Launch Pad",
"Login": "Login",
"Logout": "Logout",
"Logging out...": "Logging out...",
"Next": "Next",
"OMS": "OMS",
"Password": "Password",
Expand Down
3 changes: 3 additions & 0 deletions src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { hasError, logout, updateInstanceUrl, updateToken } from '@/adapter';
import { showToast } from '@/util';
import { translate } from '@/i18n'
import emitter from "@/event-bus";

export const useAuthStore = defineStore('authStore', {
state: () => ({
Expand Down Expand Up @@ -45,7 +46,7 @@
const resp = await UserService.login(username, password);
if (hasError(resp)) {
showToast(translate('Sorry, your username or password is incorrect. Please try again.'));
console.error("error", resp.data._ERROR_MESSAGE_);

Check warning on line 49 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 49 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
return Promise.reject(new Error(resp.data._ERROR_MESSAGE_));
}

Expand All @@ -65,7 +66,7 @@
// If any of the API call in try block has status code other than 2xx it will be handled in common catch block.
// TODO Check if handling of specific status codes is required.
showToast(translate('Something went wrong while login. Please contact administrator.'));
console.error("error: ", error);

Check warning on line 69 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 69 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
return Promise.reject(new Error(error))
}
},
Expand All @@ -82,7 +83,7 @@
// If any of the API call in try block has status code other than 2xx it will be handled in common catch block.
// TODO Check if handling of specific status codes is required.
showToast(translate('Something went wrong while login. Please contact administrator.'));
console.error("error: ", error);

Check warning on line 86 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 86 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
return Promise.reject(new Error(error))
}
},
Expand All @@ -90,6 +91,7 @@
// Calling the logout api to flag the user as logged out, only when user is authorised
// if the user is already unauthorised then not calling the logout api as it returns 401 again that results in a loop, thus there is no need to call logout api if the user is unauthorised
if(!payload?.isUserUnauthorised) {
emitter.emit("presentLoader",{ message: "Logging out...", backdropDismiss: false });
await logout();
}

Expand All @@ -102,6 +104,7 @@
}
this.redirectUrl = ''
updateToken('');
emitter.emit('dismissLoader')
},
async setToken(token: any, expirationTime: any) {
this.token = {
Expand Down
Loading