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:
@@ -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;
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user