Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/components/billing/paymentBoxes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { FormList, InputText } from '$lib/elements/forms';
import { onDestroy, onMount } from 'svelte';
import { CreditCardBrandImage, RadioBoxes } from '..';
import { unmountPaymentElement } from '$lib/stores/stripe';

export let methods: Record<string, unknown>[];
export let group: string;
Expand Down Expand Up @@ -33,6 +34,7 @@

onDestroy(() => {
observer.disconnect();
unmountPaymentElement();
});

$: if (element) {
Expand Down
9 changes: 8 additions & 1 deletion src/lib/elements/forms/button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
let classes: string = undefined;
export { classes as class };
export let actions: MultiActionArray = [];
export let submissionLoader = false;

const isSubmitting = hasContext('form')
? getContext<FormContext>('form').isSubmitting
Expand Down Expand Up @@ -77,6 +78,12 @@
aria-label={ariaLabel}
type={submit ? 'submit' : 'button'}
use:multiAction={actions}>
<slot />
{#if $isSubmitting && submissionLoader}
<span
class="loader is-small"
style:--p-loader-base-full-color="transparent"
aria-hidden="true" />
{/if}
<slot isSubmitting={$isSubmitting} />
</button>
{/if}
1 change: 1 addition & 0 deletions src/lib/layout/wizard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
} else {
$wizard.step--;
}
wizard.setInterceptor(null);
trackEvent('wizard_back');
}

Expand Down
9 changes: 8 additions & 1 deletion src/lib/layout/wizardExitModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@

function handleSubmit() {
dispatch('exit');
show = false;
}
</script>

<Modal title="Exit Process" bind:show onSubmit={handleSubmit} icon="exclamation" state="warning">
<Modal
title="Exit Process"
bind:show
onSubmit={handleSubmit}
icon="exclamation"
state="warning"
headerDivider={false}>
<p>
Are you sure you want to exit from <slot />? All data will be deleted. This action is
irreversible.
Expand Down
21 changes: 2 additions & 19 deletions src/lib/stores/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { cachedStore } from '$lib/helpers/cache';
import { Query, type Models } from '@appwrite.io/console';
import { headerAlert } from './headerAlert';
import PaymentAuthRequired from '$lib/components/billing/alerts/paymentAuthRequired.svelte';
import { diffDays, toLocaleDate } from '$lib/helpers/date';
import { diffDays } from '$lib/helpers/date';
import { addNotification, notifications } from './notifications';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
Expand Down Expand Up @@ -166,24 +166,6 @@ export function calculateTrialDay(org: Organization) {
return days;
}

export function checkForTrialEnding(org: Organization) {
const days = calculateTrialDay(org);
if (localStorage.getItem('trialEndingNotification') === 'true' || !days) return;
else if (days <= 5) {
addNotification({
type: 'info',
isHtml: true,
message: `<b>We hope you've been enjoying the ${
tierToPlan(org.billingPlan).name
} plan.</b>
You will be billed on a recurring 30-day cycle after your trial period ends on <b>${toLocaleDate(
org.billingStartDate
)}</b>`
});
localStorage.setItem('trialEndingNotification', 'true');
}
}

export async function checkForUsageLimit(org: Organization) {
if (!org?.billingLimits) {
readOnly.set(false);
Expand Down Expand Up @@ -295,6 +277,7 @@ export async function checkForFreeOrgOverflow(orgs: Models.TeamList<Record<strin

export async function checkForPostReleaseProModal(orgs: Models.TeamList<Record<string, unknown>>) {
if (!orgs?.teams?.length) return;
if (orgs.total > orgs.teams.length) return; // if the total is greater that the free orgs it means that there are pro orgs
const modalTime = localStorage.getItem('postReleaseProModal');
const now = Date.now();
// show the modal if it was never shown
Expand Down
8 changes: 7 additions & 1 deletion src/lib/stores/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export async function initializeStripe() {
paymentElement.mount('#payment-element');
}

// TODO: fix redirect
export async function unmountPaymentElement() {
isStripeInitialized.set(false);
paymentElement?.unmount();
clientSecret = null;
paymentMethod = null;
elements = null;
}

export async function submitStripeCard(name: string, urlRoute?: string) {
try {
Expand Down
8 changes: 6 additions & 2 deletions src/lib/stores/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ function createWizardStore() {
return {
subscribe,
set,
start: (component: typeof SvelteComponent<unknown>, media: string = null) =>
start: (
component: typeof SvelteComponent<unknown>,
media: string = null,
step: number = 1
) =>
update((n) => {
n.show = true;
n.component = component;
n.interceptor = null;
n.interceptorNotificationEnabled = true;
n.media = media;
n.step = 1;
n.step = step;
n.cover = null;
n.nextDisabled = false;
n.finalAction = null;
Expand Down
2 changes: 0 additions & 2 deletions src/routes/console/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
checkForUsageLimit,
checkPaymentAuthorizationRequired,
calculateTrialDay,
checkForTrialEnding,
paymentExpired,
checkForFreeOrgOverflow,
checkForPostReleaseProModal,
Expand Down Expand Up @@ -282,7 +281,6 @@
if (!org) return;
if (isCloud) {
calculateTrialDay(org);
checkForTrialEnding(org);
await paymentExpired(org);
await checkForUsageLimit(org);
checkForMarkedForDeletion(org);
Expand Down
3 changes: 2 additions & 1 deletion src/routes/console/changeOrganizationTierCloud.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,5 @@
title="Change plan"
steps={$changeTierSteps}
finalAction={$changeOrganizationFinalAction}
on:exit={onFinish} />
on:exit={onFinish}
confirmExit />
28 changes: 21 additions & 7 deletions src/routes/console/createOrganizationCloud.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@

async function create() {
try {
// Create free organization if coming from onboarding
if ($page.url.pathname.includes('/console/onboarding')) {
await sdk.forConsole.billing.createOrganization(
ID.unique(),
'Personal Projects',
BillingPlan.STARTER,
null,
null
);
}

const org = await sdk.forConsole.billing.createOrganization(
$createOrganization.id ?? ID.unique(),
$createOrganization.name,
Expand Down Expand Up @@ -64,19 +75,21 @@
await sdk.forConsole.billing.updateTaxId(org.$id, $createOrganization.taxId);
}

trackEvent(Submit.OrganizationCreate, {
customId: !!$createOrganization.id,
plan: tierToPlan($createOrganization.billingPlan)?.name,
budget_cap_enabled: !!$createOrganization?.billingBudget,
members_invited: $createOrganization?.collaborators?.length
});

await invalidate(Dependencies.ACCOUNT);
await preloadData(`/console/organization-${org.$id}`);
await goto(`/console/organization-${org.$id}`);
addNotification({
type: 'success',
message: `${$createOrganization.name ?? 'Organization'} has been created`
});
trackEvent(Submit.OrganizationCreate, {
customId: !!$createOrganization.id,
plan: tierToPlan($createOrganization.billingPlan)?.name,
budget_cap_enabled: !!$createOrganization?.billingBudget,
members_invited: $createOrganization?.collaborators?.length
});

wizard.hide();
if (org.billingPlan === BillingPlan.PRO) {
wizard.showCover(HoodieCover);
Expand Down Expand Up @@ -129,4 +142,5 @@
title="Create organization"
steps={$createOrgSteps}
finalAction={$createOrganizationFinalAction}
on:exit={onFinish} />
on:exit={onFinish}
confirmExit />
Loading