mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
refactor: remove global variable and use backend data
This commit is contained in:
@@ -261,6 +261,7 @@ export type Plan = {
|
||||
storage: AdditionalResource;
|
||||
users: AdditionalResource;
|
||||
};
|
||||
trialDays: number;
|
||||
};
|
||||
|
||||
export type PlansInfo = {
|
||||
|
||||
@@ -10,7 +10,7 @@ import type {
|
||||
PlansMap,
|
||||
PaymentMethodData
|
||||
} from '$lib/sdk/billing';
|
||||
import { IS_TRIAL_DISABLED, isCloud } from '$lib/system';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import { headerAlert } from './headerAlert';
|
||||
@@ -169,7 +169,6 @@ export function isServiceLimited(serviceId: PlanServices, plan: Tier, total: num
|
||||
}
|
||||
|
||||
export function calculateTrialDay(org: Organization) {
|
||||
if (IS_TRIAL_DISABLED) return;
|
||||
if (org?.billingPlan === BillingPlan.STARTER) return false;
|
||||
const endDate = new Date(org?.billingStartDate);
|
||||
const today = new Date();
|
||||
|
||||
@@ -24,4 +24,3 @@ export const isCloud = MODE === Mode.CLOUD;
|
||||
export const isSelfHosted = MODE !== Mode.CLOUD;
|
||||
export const hasStripePublicKey = !!VARS.STRIPE_PUBLIC_KEY;
|
||||
export const GRACE_PERIOD_OVERRIDE = false;
|
||||
export const IS_TRIAL_DISABLED = true;
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
import CreateOrganization from '../../createOrganization.svelte';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import type { PageData } from './$types';
|
||||
import { IS_TRIAL_DISABLED, isCloud } from '$lib/system';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { Pill } from '$lib/elements';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import type { Organization } from '$lib/stores/organization';
|
||||
import { daysLeftInTrial } from '$lib/stores/billing';
|
||||
import { daysLeftInTrial, plansInfo } from '$lib/stores/billing';
|
||||
import { tooltip } from '$lib/actions/tooltip';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
@@ -82,7 +82,7 @@
|
||||
<Pill>FREE</Pill>
|
||||
</div>
|
||||
{/if}
|
||||
{#if organization?.billingTrialStartDate && $daysLeftInTrial > 0 && organization.billingPlan !== BillingPlan.STARTER && !IS_TRIAL_DISABLED}
|
||||
{#if organization?.billingTrialStartDate && $daysLeftInTrial > 0 && organization.billingPlan !== BillingPlan.STARTER && $plansInfo.get(organization.billingPlan)?.trialDays}
|
||||
<div
|
||||
class="u-flex u-cross-center"
|
||||
use:tooltip={{
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
import { humanFileSize } from '$lib/helpers/sizeConvertion';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { trackEvent } from '$lib/actions/analytics';
|
||||
import { IS_TRIAL_DISABLED } from '$lib/system';
|
||||
|
||||
let currentInvoice: Invoice;
|
||||
const today = new Date();
|
||||
@@ -32,7 +31,7 @@
|
||||
$: extraUsage = currentInvoice?.amount - currentPlan?.price;
|
||||
$: isTrial =
|
||||
new Date($organization?.billingStartDate).getTime() - today.getTime() > 0 &&
|
||||
!IS_TRIAL_DISABLED;
|
||||
$plansInfo.get($organization.billingPlan)?.trialDays;
|
||||
</script>
|
||||
|
||||
{#if $organization}
|
||||
@@ -56,7 +55,7 @@
|
||||
<h6 class="body-text-1 u-bold u-trim-1">
|
||||
{tierToPlan($organization?.billingPlan)?.name} plan
|
||||
</h6>
|
||||
{#if $organization?.billingPlan !== BillingPlan.STARTER && isTrial && !IS_TRIAL_DISABLED}
|
||||
{#if $organization?.billingPlan !== BillingPlan.STARTER && isTrial}
|
||||
<Pill>TRIAL</Pill>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,13 @@
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { isTabSelected } from '$lib/helpers/load';
|
||||
import { Cover } from '$lib/layout';
|
||||
import { daysLeftInTrial, getServiceLimit, readOnly, tierToPlan } from '$lib/stores/billing';
|
||||
import {
|
||||
daysLeftInTrial,
|
||||
getServiceLimit,
|
||||
plansInfo,
|
||||
readOnly,
|
||||
tierToPlan
|
||||
} from '$lib/stores/billing';
|
||||
import {
|
||||
members,
|
||||
newMemberModal,
|
||||
@@ -18,7 +24,7 @@
|
||||
organizationList
|
||||
} from '$lib/stores/organization';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
import { GRACE_PERIOD_OVERRIDE, IS_TRIAL_DISABLED, isCloud } from '$lib/system';
|
||||
import { GRACE_PERIOD_OVERRIDE, isCloud } from '$lib/system';
|
||||
import CreateOrganizationCloud from '../createOrganizationCloud.svelte';
|
||||
|
||||
let areMembersLimited: boolean;
|
||||
@@ -94,7 +100,7 @@
|
||||
{#if isCloud && $organization?.billingPlan === BillingPlan.STARTER}
|
||||
<Pill>FREE</Pill>
|
||||
{/if}
|
||||
{#if isCloud && $organization?.billingTrialStartDate && $daysLeftInTrial > 0 && $organization.billingPlan !== BillingPlan.STARTER && !IS_TRIAL_DISABLED}
|
||||
{#if isCloud && $organization?.billingTrialStartDate && $daysLeftInTrial > 0 && $organization.billingPlan !== BillingPlan.STARTER && $plansInfo.get($organization.billingPlan)?.trialDays}
|
||||
<div
|
||||
class="u-flex u-cross-center"
|
||||
use:tooltip={{
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
import type { Coupon } from '$lib/sdk/billing';
|
||||
import { plansInfo } from '$lib/stores/billing';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { IS_TRIAL_DISABLED } from '$lib/system';
|
||||
import { createOrganization, createOrganizationFinalAction } from './store';
|
||||
|
||||
const plan = $plansInfo?.get($createOrganization.billingPlan);
|
||||
@@ -54,7 +53,7 @@
|
||||
<WizardStep beforeSubmit={handleBefore}>
|
||||
<svelte:fragment slot="title">Confirm your details</svelte:fragment>
|
||||
<svelte:fragment slot="subtitle">
|
||||
Confirm the details of your new organization{IS_TRIAL_DISABLED
|
||||
Confirm the details of your new organization{!plan.trialDays
|
||||
? '.'
|
||||
: ' and start your free trial.'}
|
||||
</svelte:fragment>
|
||||
@@ -126,7 +125,7 @@
|
||||
{#if $createOrganization.billingPlan !== BillingPlan.STARTER}
|
||||
<p class="text u-margin-block-start-16">
|
||||
This amount, and any additional usage fees, will be charged on a recurring 30-day
|
||||
billing cycle{IS_TRIAL_DISABLED
|
||||
billing cycle{!plan.trialDays
|
||||
? ''
|
||||
: ` after your trial period ends on ${toLocaleDate(billingPayDate.toString())}`}.
|
||||
</p>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
import { plansInfo, tierFree, tierPro, tierScale } from '$lib/stores/billing';
|
||||
import { organizationList, type Organization } from '$lib/stores/organization';
|
||||
import { updateStepStatus } from '$lib/stores/wizard';
|
||||
import { IS_TRIAL_DISABLED } from '$lib/system';
|
||||
import { createOrganization, createOrgSteps } from './store';
|
||||
|
||||
let showCustomId = false;
|
||||
@@ -109,7 +108,7 @@
|
||||
{tierPro.description}
|
||||
</p>
|
||||
</div>
|
||||
{#if !IS_TRIAL_DISABLED}
|
||||
{#if proPlan?.trialDays}
|
||||
<Pill>14 DAY FREE TRIAL</Pill>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
import { initializeStripe, isStripeInitialized, submitStripeCard } from '$lib/stores/stripe';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { showUsageRatesModal } from '$lib/stores/billing';
|
||||
import { plansInfo, showUsageRatesModal } from '$lib/stores/billing';
|
||||
import { PaymentBoxes } from '$lib/components/billing';
|
||||
import { IS_TRIAL_DISABLED } from '$lib/system';
|
||||
|
||||
const today = new Date();
|
||||
const billingPayDate = new Date(today.getTime() + 44 * 24 * 60 * 60 * 1000);
|
||||
@@ -75,8 +74,10 @@
|
||||
<WizardStep beforeSubmit={handleSubmit}>
|
||||
<svelte:fragment slot="title">Payment details</svelte:fragment>
|
||||
<svelte:fragment slot="subtitle">
|
||||
Add a payment method to your organization. {#if !IS_TRIAL_DISABLED}You will not be charged
|
||||
until your trial ends on <b>{toLocaleDate(billingPayDate.toString())}</b>.
|
||||
Add a payment method to your organization. {#if $plansInfo.get($createOrganization.billingPlan)?.trialDays}You
|
||||
will not be charged until your trial ends on <b
|
||||
>{toLocaleDate(billingPayDate.toString())}</b
|
||||
>.
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
|
||||
import type { Tier } from '$lib/stores/billing';
|
||||
import { IS_TRIAL_DISABLED } from '$lib/system';
|
||||
import { writable } from 'svelte/store';
|
||||
import { plansInfo, type Tier } from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { get, writable } from 'svelte/store';
|
||||
|
||||
export const createOrgSteps = writable<WizardStepsType>(new Map());
|
||||
export const createOrganizationFinalAction = writable<string>(
|
||||
IS_TRIAL_DISABLED ? 'Create' : 'Start trial'
|
||||
get(plansInfo)?.get(get(organization)?.billingPlan)?.trialDays ? 'Start trial' : 'Create'
|
||||
);
|
||||
|
||||
export const createOrganization = writable<{
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
import { Pill } from '$lib/elements';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { formatCurrency } from '$lib/helpers/numbers';
|
||||
import { IS_TRIAL_DISABLED } from '$lib/system';
|
||||
|
||||
let usage: OrganizationUsage = null;
|
||||
let members: Models.MembershipList = null;
|
||||
@@ -162,8 +161,8 @@
|
||||
<div class:u-opacity-50={disabled}>
|
||||
{#if $organization.billingPlan === BillingPlan.PRO}
|
||||
<Pill disabled>CURRENT PLAN</Pill>
|
||||
{:else if !IS_TRIAL_DISABLED}
|
||||
<Pill>14 DAY FREE TRIAL</Pill>
|
||||
{:else if proPlan?.trialDays}
|
||||
<Pill>{proPlan?.trialDays} DAY FREE TRIAL</Pill>
|
||||
{/if}
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
feedbackDowngradeOptions,
|
||||
isUpgrade
|
||||
} from './store';
|
||||
import { IS_TRIAL_DISABLED } from '$lib/system';
|
||||
|
||||
const plan = $plansInfo.get($changeOrganizationTier.billingPlan);
|
||||
const collaboratorPrice = plan?.addons.member?.price ?? 0;
|
||||
@@ -78,7 +77,9 @@
|
||||
<WizardStep>
|
||||
<svelte:fragment slot="title">Confirm your details</svelte:fragment>
|
||||
<svelte:fragment slot="subtitle">
|
||||
Confirm the details of your new organization{IS_TRIAL_DISABLED
|
||||
Confirm the details of your new organization{!$plansInfo.get(
|
||||
$changeOrganizationTier.billingPlan
|
||||
)?.trialDays
|
||||
? '.'
|
||||
: ' and start your free trial.'}
|
||||
</svelte:fragment>
|
||||
@@ -147,7 +148,7 @@
|
||||
|
||||
<p class="text u-margin-block-start-16">
|
||||
This amount, and any additional usage fees, will be charged on a recurring 30-day
|
||||
billing cycle{IS_TRIAL_DISABLED
|
||||
billing cycle{!$plansInfo.get($changeOrganizationTier.billingPlan)?.trialDays
|
||||
? ''
|
||||
: ` after your trial period ends on ${toLocaleDate(billingPayDate.toString())}`}.
|
||||
</p>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
|
||||
import type { Tier } from '$lib/stores/billing';
|
||||
import { IS_TRIAL_DISABLED } from '$lib/system';
|
||||
import { writable } from 'svelte/store';
|
||||
import { plansInfo, type Tier } from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { get, writable } from 'svelte/store';
|
||||
|
||||
export const changeTierSteps = writable<WizardStepsType>(new Map());
|
||||
export const isUpgrade = writable<boolean>(false);
|
||||
export const changeOrganizationFinalAction = writable<string>(
|
||||
IS_TRIAL_DISABLED ? 'Create' : 'Start trial'
|
||||
get(plansInfo)?.get(get(organization)?.billingPlan)?.trialDays ? 'Start trial' : 'Create'
|
||||
);
|
||||
|
||||
export const changeOrganizationTier = writable<{
|
||||
|
||||
Reference in New Issue
Block a user