chore: Ability to change default account (#5393)

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: Tejaswini Chile <tejaswini@chatwoot.com>
This commit is contained in:
Muhsin Keloth
2022-10-06 06:01:12 +05:30
committed by GitHub
parent bd445216e9
commit b668723313
10 changed files with 130 additions and 20 deletions

View File

@@ -6,7 +6,7 @@ export const frontendURL = (path, params) => {
};
const getSSOAccountPath = ({ ssoAccountId, user }) => {
const { accounts = [] } = user || {};
const { accounts = [], account_id = null } = user || {};
const ssoAccount = accounts.find(
account => account.id === Number(ssoAccountId)
);
@@ -14,7 +14,9 @@ const getSSOAccountPath = ({ ssoAccountId, user }) => {
if (ssoAccount) {
accountPath = `accounts/${ssoAccountId}`;
} else if (accounts.length) {
accountPath = `accounts/${accounts[0].id}`;
// If the account id is not found, redirect to the first account
const accountId = account_id || accounts[0].id;
accountPath = `accounts/${accountId}`;
}
return accountPath;
};