feat: add upgrade banner for SLA feature (#9240)

- Add an upgrade CTA for the SLA feature

-------------------

Co-authored-by: Sojan Jose <sojan@pepalo.com>
Co-authored-by: Pranav <pranav@chatwoot.com>
This commit is contained in:
Shivam Mishra
2024-04-17 05:29:39 +05:30
committed by GitHub
parent d12c38c344
commit 2cde42c7ec
11 changed files with 233 additions and 81 deletions

View File

@@ -1,12 +1,15 @@
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
import * as types from '../mutation-types';
import AccountAPI from '../../api/account';
import { differenceInDays } from 'date-fns';
import EnterpriseAccountAPI from '../../api/enterprise/account';
import { throwErrorMessage } from '../utils/api';
const findRecordById = ($state, id) =>
$state.records.find(record => record.id === Number(id)) || {};
const TRIAL_PERIOD_DAYS = 15;
const state = {
records: [],
uiFlags: {
@@ -19,26 +22,19 @@ const state = {
export const getters = {
getAccount: $state => id => {
return $state.records.find(record => record.id === Number(id)) || {};
return findRecordById($state, id);
},
getUIFlags($state) {
return $state.uiFlags;
},
isFeatureEnabledonAccount:
($state, _, __, rootGetters) => (id, featureName) => {
// If a user is SuperAdmin and has access to the account, then they would see all the available features
const isUserASuperAdmin =
rootGetters.getCurrentUser?.type === 'SuperAdmin';
if (isUserASuperAdmin) {
return true;
}
isTrialAccount: $state => id => {
const account = findRecordById($state, id);
const createdAt = new Date(account.created_at);
const diffDays = differenceInDays(new Date(), createdAt);
const { features = {} } = findRecordById($state, id);
return features[featureName] || false;
},
// There are some features which can be enabled/disabled globally
isFeatureEnabledGlobally: $state => (id, featureName) => {
return diffDays <= TRIAL_PERIOD_DAYS;
},
isFeatureEnabledonAccount: $state => (id, featureName) => {
const { features = {} } = findRecordById($state, id);
return features[featureName] || false;
},

View File

@@ -52,13 +52,4 @@ describe('#getters', () => {
)(1, 'auto_resolve_conversations')
).toEqual(true);
});
it('isFeatureEnabledGlobally', () => {
const state = {
records: [accountData],
};
expect(
getters.isFeatureEnabledGlobally(state)(1, 'auto_resolve_conversations')
).toEqual(false);
});
});