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
@@ -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