Merge pull request #990 from appwrite/chore-trial-feature-flag

chore: trial changes
This commit is contained in:
Damodar Lohani authored and GitHub committed 2024-04-25 08:48:01 +05:45
commit d7d851ff7c
12 files changed
+64 -48

No files matched your search

+1
View File
@@ -261,6 +261,7 @@ export type Plan = {
storage: AdditionalResource;
users: AdditionalResource;
};
trialDays: number;
};
export type PlansInfo = {
+5 -2
View File
@@ -21,7 +21,8 @@
paymentExpired,
checkForMarkedForDeletion,
checkForMandate,
checkForMissingPaymentMethod
checkForMissingPaymentMethod,
plansInfo
} from '$lib/stores/billing';
import { goto } from '$app/navigation';
import { CommandCenter, registerCommands, registerSearchers } from '$lib/commandCenter';
@@ -269,10 +270,12 @@
await checkForUsageLimit(org);
checkForMarkedForDeletion(org);
if (org?.billingPlan !== BillingPlan.STARTER) {
calculateTrialDay(org);
await paymentExpired(org);
await checkPaymentAuthorizationRequired(org);
await checkForMandate(org);
if ($plansInfo.get(org.billingPlan)?.trialDays) {
calculateTrialDay(org);
}
}
$activeHeaderAlert = headerAlert.get();
}
@@ -17,7 +17,7 @@
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}
{#if organization?.billingTrialStartDate && $daysLeftInTrial > 0 && organization.billingPlan !== BillingPlan.STARTER && $plansInfo.get(organization.billingPlan)?.trialDays}
<div
class="u-flex u-cross-center"
use:tooltip={{
@@ -29,7 +29,9 @@
$: currentPlan = $plansInfo?.get($organization?.billingPlan);
$: extraUsage = currentInvoice?.amount - currentPlan?.price;
$: isTrial = new Date($organization?.billingStartDate).getTime() - today.getTime() > 0;
$: isTrial =
new Date($organization?.billingStartDate).getTime() - today.getTime() > 0 &&
$plansInfo.get($organization.billingPlan)?.trialDays;
</script>
{#if $organization}
@@ -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,
@@ -94,7 +100,7 @@
{#if isCloud && $organization?.billingPlan === BillingPlan.STARTER}
<Pill>FREE</Pill>
{/if}
{#if isCloud && $organization?.billingTrialStartDate && $daysLeftInTrial > 0 && $organization.billingPlan !== BillingPlan.STARTER}
{#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,6 +9,7 @@
import type { Coupon } from '$lib/sdk/billing';
import { plansInfo } from '$lib/stores/billing';
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { createOrganization, createOrganizationFinalAction } from './store';
const plan = $plansInfo?.get($createOrganization.billingPlan);
@@ -18,6 +19,8 @@
const today = new Date();
const billingPayDate = new Date(today.getTime() + 44 * 24 * 60 * 60 * 1000);
onMount(() => {});
let coupon: string = null;
let couponData: Partial<Coupon> = {
code: null,
@@ -48,12 +51,18 @@
$: if ($createOrganization.billingPlan === BillingPlan.STARTER) {
$createOrganizationFinalAction = 'Create organization';
}
$: if (plan?.trialDays) {
$createOrganizationFinalAction = 'Start trial';
}
</script>
<WizardStep beforeSubmit={handleBefore}>
<svelte:fragment slot="title">Confirm your details</svelte:fragment>
<svelte:fragment slot="subtitle">
Confirm the details of your new organization and start your free trial.
Confirm the details of your new organization{!plan.trialDays
? '.'
: ' and start your free trial.'}
</svelte:fragment>
<p class="body-text-1 u-bold">Organization name</p>
@@ -123,9 +132,9 @@
{#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 after your trial period ends on <b
>{toLocaleDate(billingPayDate.toString())}</b
>.
billing cycle{!plan.trialDays
? ''
: ` after your trial period ends on ${toLocaleDate(billingPayDate.toString())}`}.
</p>
{/if}
</Box>
@@ -108,7 +108,9 @@
{tierPro.description}
</p>
</div>
<Pill>14 DAY FREE TRIAL</Pill>
{#if proPlan?.trialDays}
<Pill>14 DAY FREE TRIAL</Pill>
{/if}
</svelte:fragment>
</LabelCard>
</li>
@@ -131,7 +133,6 @@
</p>
</div>
<div class:u-opacity-50={disabled}>
<!-- <Pill>14 DAY FREE TRIAL</Pill> -->
<Pill disabled>COMING SOON</Pill>
</div>
</svelte:fragment>
@@ -10,7 +10,7 @@
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';
const today = new Date();
@@ -74,9 +74,11 @@
<WizardStep beforeSubmit={handleSubmit}>
<svelte:fragment slot="title">Payment details</svelte:fragment>
<svelte:fragment slot="subtitle">
Add a payment method to your organization. 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>
<FormList class="u-margin-block-start-8">
@@ -1,10 +1,10 @@
import { BillingPlan } from '$lib/constants';
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
import type { Tier } from '$lib/stores/billing';
import { type Tier } from '$lib/stores/billing';
import { writable } from 'svelte/store';
export const createOrgSteps = writable<WizardStepsType>(new Map());
export const createOrganizationFinalAction = writable<string>('Start trial');
export const createOrganizationFinalAction = writable<string>('Create');
export const createOrganization = writable<{
id?: string;
@@ -161,8 +161,8 @@
<div class:u-opacity-50={disabled}>
{#if $organization.billingPlan === BillingPlan.PRO}
<Pill disabled>CURRENT PLAN</Pill>
{:else}
<Pill>14 DAY FREE TRIAL</Pill>
{:else if proPlan?.trialDays}
<Pill>{proPlan?.trialDays} DAY FREE TRIAL</Pill>
{/if}
</div>
</svelte:fragment>
@@ -1,5 +1,5 @@
<script lang="ts">
import { Alert, Box, CreditCardBrandImage } from '$lib/components';
import { Box, CreditCardBrandImage } from '$lib/components';
import { CouponInput } from '$lib/components/billing';
import { BillingPlan } from '$lib/constants';
import { FormList, InputSelect, InputTextarea } from '$lib/elements/forms';
@@ -7,7 +7,7 @@
import { formatCurrency } from '$lib/helpers/numbers';
import { WizardStep } from '$lib/layout';
import type { Coupon } from '$lib/sdk/billing';
import { plansInfo, tierToPlan } from '$lib/stores/billing';
import { plansInfo } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import {
@@ -49,6 +49,10 @@
$: if (!$isUpgrade) {
$changeOrganizationFinalAction = 'Confirm plan change';
}
$: if (plan?.trialDays) {
$changeOrganizationFinalAction = 'Start trial';
}
</script>
{#if downgradeToStarter}
@@ -58,33 +62,17 @@
Your feedback is important to us and helps us improve the services Appwrite offers.
Please let us know if there is a specific reason for changing your plan.
</svelte:fragment>
<Alert>
<svelte:fragment slot="title"
>Your {tierToPlan($organization.billingPlan).name} plan subscription will end on {toLocaleDate(
$organization.billingNextInvoiceDate
)}</svelte:fragment>
<p class="text">
Following the payment of your final invoice on {toLocaleDate(
$organization.billingNextInvoiceDate
)}, your organization will switch to the {tierToPlan(
$changeOrganizationTier.billingPlan
).name} plan. Until then, you can continue to use the resources available to the {tierToPlan(
$organization.billingPlan
).name} plan.
</p>
</Alert>
<FormList class="u-margin-block-start-24">
<FormList>
<InputSelect
id="reason"
label="Reason for plan change"
label="What made you decide to change your plan?*"
placeholder="Select one"
required
options={feedbackDowngradeOptions}
bind:value={$changeOrganizationTier.feedbackDowngradeReason} />
<InputTextarea
id="comment"
label="If you would like to elaborate, please do so here"
label="Your feedback here"
placeholder="Enter feedback"
bind:value={$changeOrganizationTier.feedbackMessage} />
</FormList>
@@ -93,7 +81,11 @@
<WizardStep>
<svelte:fragment slot="title">Confirm your details</svelte:fragment>
<svelte:fragment slot="subtitle">
Confirm the details of your new organization and start your free trial.
Confirm the details of your new organization{!$plansInfo.get(
$changeOrganizationTier.billingPlan
)?.trialDays
? '.'
: ' and start your free trial.'}
</svelte:fragment>
<p class="body-text-1 u-bold">Organization name</p>
@@ -160,9 +152,9 @@
<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 after your trial period ends on <b
>{toLocaleDate(billingPayDate.toString())}</b
>.
billing cycle{!$plansInfo.get($changeOrganizationTier.billingPlan)?.trialDays
? ''
: ` after your trial period ends on ${toLocaleDate(billingPayDate.toString())}`}.
</p>
</Box>
</WizardStep>
@@ -1,11 +1,11 @@
import { BillingPlan } from '$lib/constants';
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
import type { Tier } from '$lib/stores/billing';
import { type Tier } from '$lib/stores/billing';
import { writable } from 'svelte/store';
export const changeTierSteps = writable<WizardStepsType>(new Map());
export const isUpgrade = writable<boolean>(false);
export const changeOrganizationFinalAction = writable<string>('Start trial');
export const changeOrganizationFinalAction = writable<string>('Create');
export const changeOrganizationTier = writable<{
billingPlan: Tier;