refactor: add trial account check

This commit is contained in:
Shivam Mishra
2024-04-11 20:56:38 +05:30
parent 50ee09a883
commit dcf188f156
2 changed files with 15 additions and 17 deletions
@@ -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