refactor: add trial account check
This commit is contained in:
@@ -58,7 +58,6 @@ import SLAPaywall from './components/SLAPaywall.vue';
|
||||
|
||||
import { mapGetters } from 'vuex';
|
||||
import { convertSecondsToTimeUnit } from '@chatwoot/utils';
|
||||
import { differenceInDays } from 'date-fns';
|
||||
import alertMixin from 'shared/mixins/alertMixin';
|
||||
|
||||
export default {
|
||||
@@ -85,7 +84,9 @@ export default {
|
||||
isOnChatwootCloud: 'globalConfig/isOnChatwootCloud',
|
||||
records: 'sla/getSLA',
|
||||
uiFlags: 'sla/getUIFlags',
|
||||
accountId: 'getCurrentAccountId',
|
||||
getAccount: 'accounts/getAccount',
|
||||
isTrialAccount: 'accounts/isTrialAccount',
|
||||
}),
|
||||
deleteConfirmText() {
|
||||
return this.$t('SLA.DELETE.CONFIRM.YES');
|
||||
@@ -101,14 +102,12 @@ export default {
|
||||
return false;
|
||||
}
|
||||
|
||||
const isTrial = this.isTrialAccount();
|
||||
const isTrial = this.isTrialAccount(this.accountId);
|
||||
const currentPlan = this.currentPlan();
|
||||
if (isTrial) return false;
|
||||
if (!currentPlan) return true;
|
||||
|
||||
if (currentPlan === 'Business' || currentPlan === 'Enterprise')
|
||||
return false;
|
||||
return true;
|
||||
return ['Hacker', 'Startup'].includes(currentPlan);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
@@ -118,17 +117,6 @@ export default {
|
||||
openAddPopup() {
|
||||
this.showAddPopup = true;
|
||||
},
|
||||
isTrialAccount() {
|
||||
// check if account is less than 15 days old
|
||||
const account = this.getAccount(this.accountId);
|
||||
if (!account) return false;
|
||||
|
||||
const createdAt = new Date(account.created_at);
|
||||
|
||||
const diffDays = differenceInDays(new Date(), createdAt);
|
||||
|
||||
return diffDays <= 15;
|
||||
},
|
||||
currentPlan() {
|
||||
const account = this.getAccount(this.accountId);
|
||||
if (!account) return '';
|
||||
|
||||
@@ -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,11 +22,18 @@ 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;
|
||||
},
|
||||
isTrialAccount: $state => id => {
|
||||
const account = findRecordById($state, id);
|
||||
const createdAt = new Date(account.created_at);
|
||||
const diffDays = differenceInDays(new Date(), createdAt);
|
||||
|
||||
return diffDays <= TRIAL_PERIOD_DAYS;
|
||||
},
|
||||
isFeatureEnabledonAccount:
|
||||
($state, _, __, rootGetters) => (id, featureName) => {
|
||||
// If a user is SuperAdmin and has access to the account, then they would see all the available features
|
||||
|
||||
Reference in New Issue
Block a user