event.js 3.89 KB
export default [{
        name: 'APP_LOGIN_SUCCESS',
        callback: function(e) {
            this.$router.push({ path: 'dashboard' });
        }
    },
    {
        name: 'APP_LOGOUT',
        callback: function(e) {
            this.snackbar = {
                show: true,
                color: 'green',
                text: 'Logout successfully.'
            };
            // console.log("roteeeeeeeeeeeeeee", this.$store.state.isUserLoggedIn)
            if (this.$store.state.role === "ADMIN") {
                this.$store.dispatch('setToken', null)
                this.$store.dispatch('Id', null)
                this.$store.dispatch('Role', null)
                this.$store.dispatch('setSchoolToken', null)
                this.$store.dispatch('setSchoolRole', null)
                this.$router.replace({ path: '/' });
            } else if (this.$store.state.schoolRole === "SUPERADMIN") {
                this.$store.dispatch('setSchoolToken', null)
                this.$store.dispatch('setSchoolRole', null)
                this.$router.replace({ path: '/' });
            } else if (this.$store.state.role === "TEACHER") {
                this.$store.dispatch('setToken', null)
                this.$store.dispatch('Id', null)
                this.$store.dispatch('Role', null)
                this.$store.dispatch('setSchoolToken', null)
                this.$store.dispatch('setSchoolRole', null)
                this.$router.replace({ path: '/' });
            } else if (this.$store.state.role === "ACCOUNTANT") {
                this.$store.dispatch('setToken', null)
                this.$store.dispatch('Id', null)
                this.$store.dispatch('Role', null)
                this.$store.dispatch('setSchoolToken', null)
                this.$store.dispatch('setSchoolRole', null)
                this.$router.replace({ path: '/' });
            } else if (this.$store.state.role === "LIBRARIAN") {
                this.$store.dispatch('setToken', null)
                this.$store.dispatch('Id', null)
                this.$store.dispatch('Role', null)
                this.$store.dispatch('setSchoolToken', null)
                this.$store.dispatch('setSchoolRole', null)
                this.$router.replace({ path: '/' });
            } else if (this.$store.state.role === "PARENT") {
                this.$store.dispatch('setToken', null)
                this.$store.dispatch('Id', null)
                this.$store.dispatch('Role', null)
                this.$store.dispatch('setSchoolToken', null)
                this.$store.dispatch('setSchoolRole', null)
                this.$router.replace({ path: '/' });
            }
        }
    },
    {
        name: 'APP_CHANGE',
        callback: function(e) {
            this.snackbar = {
                show: true,
                color: 'green',
                text: 'Logout successfully.'
            };
            this.$router.replace({
                path: '/'
            });
        }
    },
    {
        name: 'APP_PAGE_LOADED',
        callback: function(e) {}
    },
    {
        name: 'APP_AUTH_FAILED',
        callback: function(e) {
            this.$router.push('/login');
            this.$message.error('Token has expired');
        }
    },
    {
        name: 'APP_BAD_REQUEST',
        // @error api response data
        callback: function(msg) {
            this.$message.error(msg);
        }
    },
    {
        name: 'APP_ACCESS_DENIED',
        // @error api response data
        callback: function(msg) {
            this.$message.error(msg);
            this.$router.push('/forbidden');
        }
    },
    {
        name: 'APP_RESOURCE_DELETED',
        // @error api response data
        callback: function(msg) {
            this.$message.success(msg);
        }
    },
    {
        name: 'APP_RESOURCE_UPDATED',
        // @error api response data
        callback: function(msg) {
            this.$message.success(msg);
        }
    },

];