fix: Handle login when there are no accounts (#12816)
This commit is contained in:
@@ -10,6 +10,7 @@ import campaignsRoutes from './campaigns/campaigns.routes';
|
||||
import { routes as captainRoutes } from './captain/captain.routes';
|
||||
import AppContainer from './Dashboard.vue';
|
||||
import Suspended from './suspended/Index.vue';
|
||||
import NoAccounts from './noAccounts/Index.vue';
|
||||
|
||||
export default {
|
||||
routes: [
|
||||
@@ -36,5 +37,10 @@ export default {
|
||||
},
|
||||
component: Suspended,
|
||||
},
|
||||
{
|
||||
path: frontendURL('no-accounts'),
|
||||
name: 'no_accounts',
|
||||
component: NoAccounts,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useMapGetter } from 'dashboard/composables/store';
|
||||
import EmptyState from 'dashboard/components/widgets/EmptyState.vue';
|
||||
import NextButton from 'dashboard/components-next/button/Button.vue';
|
||||
import Auth from 'dashboard/api/auth';
|
||||
|
||||
const { t } = useI18n();
|
||||
const isOnChatwootCloud = useMapGetter('globalConfig/isOnChatwootCloud');
|
||||
|
||||
const message = computed(() => {
|
||||
if (isOnChatwootCloud.value) {
|
||||
return t('APP_GLOBAL.NO_ACCOUNTS.MESSAGE_CLOUD');
|
||||
}
|
||||
return t('APP_GLOBAL.NO_ACCOUNTS.MESSAGE_SELF_HOSTED');
|
||||
});
|
||||
|
||||
const handleLogout = () => {
|
||||
Auth.logout();
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="flex flex-col flex-1 items-center justify-center w-full h-full gap-6 bg-n-slate-2"
|
||||
>
|
||||
<EmptyState
|
||||
:title="$t('APP_GLOBAL.NO_ACCOUNTS.TITLE')"
|
||||
:message="message"
|
||||
/>
|
||||
<NextButton
|
||||
variant="smooth"
|
||||
color-scheme="secondary"
|
||||
:label="$t('APP_GLOBAL.NO_ACCOUNTS.LOGOUT')"
|
||||
@click="handleLogout"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -18,8 +18,17 @@ export const validateAuthenticateRoutePermission = (to, next) => {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!to.name) {
|
||||
return next(frontendURL(`accounts/${user.account_id}/dashboard`));
|
||||
const { accounts = [], account_id: accountId } = user;
|
||||
|
||||
if (!accounts.length) {
|
||||
if (to.name === 'no_accounts') {
|
||||
return next();
|
||||
}
|
||||
return next(frontendURL('no-accounts'));
|
||||
}
|
||||
|
||||
if (to.name === 'no_accounts' || !to.name) {
|
||||
return next(frontendURL(`accounts/${accountId}/dashboard`));
|
||||
}
|
||||
|
||||
const nextRoute = validateLoggedInRoutes(to, store.getters.getCurrentUser);
|
||||
|
||||
Reference in New Issue
Block a user