Merge pull request #1545 from appwrite/fix-premium-support

Feat: use premium support from plan attribute
This commit is contained in:
Ernst Mulders
2024-12-18 10:07:41 +01:00
committed by GitHub
7 changed files with 32 additions and 33 deletions
+4 -7
View File
@@ -5,17 +5,14 @@
import SupportWizard from '$routes/(console)/supportWizard.svelte';
import { showSupportModal } from '$routes/(console)/wizard/support/store';
import { isCloud } from '$lib/system';
import { organization } from '$lib/stores/organization';
import { BillingPlan } from '$lib/constants';
import { trackEvent } from '$lib/actions/analytics';
import { localeTimezoneName, utcHourToLocaleHour } from '$lib/helpers/date';
import { upgradeURL } from '$lib/stores/billing';
import { currentPlan } from '$lib/stores/organization';
export let show = false;
$: isPaid =
$organization?.billingPlan === BillingPlan.PRO ||
$organization?.billingPlan === BillingPlan.SCALE;
$: hasPremiumSupport = $currentPlan?.premiumSupport ?? false;
$: supportTimings = `${utcHourToLocaleHour('16:00')} - ${utcHourToLocaleHour('00:00')} ${localeTimezoneName()}`;
</script>
@@ -24,13 +21,13 @@
<section class="drop-section u-grid u-gap-24 u-padding-24">
<div>
<h4 class="eyebrow-heading-3">Premium support</h4>
{#if isPaid}
{#if hasPremiumSupport}
<p class="u-line-height-1-5 u-margin-block-start-8">
Get personalized support from the Appwrite team from <b>{supportTimings}</b>
</p>
{/if}
</div>
{#if $organization?.billingPlan === BillingPlan.FREE}
{#if !hasPremiumSupport}
<Button
fullWidth
href={$upgradeURL}
+1
View File
@@ -281,6 +281,7 @@ export type Plan = {
trialDays: number;
isAvailable: boolean;
selfService: boolean;
premiumSupport: boolean;
};
export type PlansInfo = {
+2
View File
@@ -2,6 +2,7 @@ import { page } from '$app/stores';
import { derived, writable } from 'svelte/store';
import type { Models } from '@appwrite.io/console';
import type { Tier } from './billing';
import type { Plan } from '$lib/sdk/billing';
export type Organization = Models.Team<Record<string, unknown>> & {
billingBudget: number;
@@ -43,4 +44,5 @@ export const organizationList = derived(
);
export const organization = derived(page, ($page) => $page.data?.organization as Organization);
export const currentPlan = derived(page, ($page) => $page.data?.currentPlan as Plan);
export const members = derived(page, ($page) => $page.data.members as Models.MembershipList);
@@ -12,6 +12,7 @@ import { get } from 'svelte/store';
import { preferences } from '$lib/stores/preferences';
import type { Organization } from '$lib/stores/organization';
import { defaultRoles, defaultScopes } from '$lib/constants';
import type { Plan } from '$lib/sdk/billing';
export const load: LayoutLoad = async ({ params, depends }) => {
depends(Dependencies.ORGANIZATION);
@@ -19,12 +20,14 @@ export const load: LayoutLoad = async ({ params, depends }) => {
depends(Dependencies.PAYMENT_METHODS);
let roles = isCloud ? [] : defaultRoles;
let scopes = isCloud ? [] : defaultScopes;
let currentPlan: Plan = null;
try {
if (isCloud) {
const res = await sdk.forConsole.billing.getRoles(params.organization);
roles = res.roles;
scopes = res.scopes;
currentPlan = await sdk.forConsole.billing.getPlan(params.organization);
if (scopes.includes('billing.read')) {
await failedInvoice.load(params.organization);
if (get(failedInvoice)) {
@@ -53,6 +56,7 @@ export const load: LayoutLoad = async ({ params, depends }) => {
header: Header,
breadcrumbs: Breadcrumbs,
organization,
currentPlan,
members,
roles,
scopes
@@ -1,6 +1,6 @@
<script lang="ts">
import { Container } from '$lib/layout';
import { organization } from '$lib/stores/organization';
import { currentPlan, organization } from '$lib/stores/organization';
import BudgetAlert from './budgetAlert.svelte';
import BudgetCap from './budgetCap.svelte';
import PlanSummary from './planSummary.svelte';
@@ -123,7 +123,7 @@
<PlanSummary
creditList={data?.creditList}
members={data?.members}
currentPlan={data?.currentPlan}
currentPlan={$currentPlan}
invoices={data?.invoices.invoices} />
<PaymentHistory />
<PaymentMethods />
@@ -25,33 +25,24 @@ export const load: PageLoad = async ({ parent, depends }) => {
.catch(() => null)
: null;
const [
paymentMethods,
addressList,
aggregationList,
billingAddress,
currentPlan,
creditList,
invoices
] = await Promise.all([
sdk.forConsole.billing.listPaymentMethods(),
sdk.forConsole.billing.listAddresses(),
sdk.forConsole.billing.listAggregation(organization.$id),
billingAddressPromise,
sdk.forConsole.billing.getPlan(organization.$id),
sdk.forConsole.billing.listCredits(organization.$id),
sdk.forConsole.billing.listInvoices(organization.$id, [
Query.limit(1),
Query.equal('from', organization.billingCurrentInvoiceDate)
])
]);
const [paymentMethods, addressList, aggregationList, billingAddress, creditList, invoices] =
await Promise.all([
sdk.forConsole.billing.listPaymentMethods(),
sdk.forConsole.billing.listAddresses(),
sdk.forConsole.billing.listAggregation(organization.$id),
billingAddressPromise,
sdk.forConsole.billing.listCredits(organization.$id),
sdk.forConsole.billing.listInvoices(organization.$id, [
Query.limit(1),
Query.equal('from', organization.billingCurrentInvoiceDate)
])
]);
return {
paymentMethods,
addressList,
aggregationList,
billingAddress,
currentPlan,
creditList,
invoices
};
@@ -32,7 +32,12 @@
import { type Coupon, type PaymentList } from '$lib/sdk/billing';
import { plansInfo, tierToPlan, type Tier } from '$lib/stores/billing';
import { addNotification } from '$lib/stores/notifications';
import { organization, organizationList, type Organization } from '$lib/stores/organization';
import {
currentPlan,
organization,
organizationList,
type Organization
} from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { user } from '$lib/stores/user';
import { VARS } from '$lib/system';
@@ -101,8 +106,7 @@
billingPlan = BillingPlan.PRO;
}
const currentPlan = await sdk.forConsole.billing.getPlan($organization?.$id);
selfService = currentPlan.selfService;
selfService = $currentPlan?.selfService ?? true;
});
async function loadPaymentMethods() {