fix: patching issue where orgs could be submitted twice

This commit is contained in:
Arman committed 2023-12-08 16:12:24 +01:00
1 parent f21757cef9
commit 05b417a9d5
4 files changed
+54 -45

No files matched your search

+3 -5
View File
@@ -62,6 +62,7 @@
async function submit() {
if ($wizard.interceptor) {
$wizard.nextDisabled = true;
try {
await $wizard.interceptor();
} catch (error) {
@@ -71,18 +72,15 @@
type: 'error'
});
return;
} finally {
$wizard.nextDisabled = false;
}
}
wizard.setInterceptor(null);
if (isLastStep) {
$wizard.nextDisabled = true;
trackEvent('wizard_finish');
dispatch('finish');
//Reactivate button in case there are errors
setTimeout(() => {
$wizard.nextDisabled = false;
}, 2000);
} else {
if (steps.get($wizard.step + 1)?.disabled) {
$wizard.step++;
@@ -33,6 +33,8 @@
}
async function changeTier() {
$wizard.nextDisabled = true;
//Downgrade
if ($changeOrganizationTier.billingPlan === 'tier-0') {
try {
await sdk.forConsole.billing.updatePlan(
@@ -70,6 +72,8 @@
e,
$isUpgrade ? Submit.OrganizationUpgrade : Submit.OrganizationDowngrade
);
} finally {
$wizard.nextDisabled = false;
}
} else {
try {
@@ -174,6 +178,8 @@
e,
$isUpgrade ? Submit.OrganizationUpgrade : Submit.OrganizationDowngrade
);
} finally {
$wizard.nextDisabled = false;
}
}
}
@@ -1,7 +1,7 @@
<script lang="ts">
import { Wizard } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { createEventDispatcher, onDestroy } from 'svelte';
import { onDestroy } from 'svelte';
import { addNotification } from '$lib/stores/notifications';
import OrganizationDetails from './wizard/cloudOrganization/organizationDetails.svelte';
import PaymentDetails from './wizard/cloudOrganization/paymentDetails.svelte';
@@ -12,7 +12,7 @@
createOrganizationFinalAction,
createOrgSteps
} from './wizard/cloudOrganization/store';
import { goto, invalidate } from '$app/navigation';
import { goto, invalidate, preloadData } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { ID } from '@appwrite.io/console';
@@ -21,13 +21,12 @@
import { tierToPlan } from '$lib/stores/billing';
import AddressDetails from './wizard/cloudOrganization/addressDetails.svelte';
const dispatch = createEventDispatcher();
async function onFinish() {
await invalidate(Dependencies.ORGANIZATION);
}
async function create() {
$wizard.nextDisabled = true;
try {
const org = await sdk.forConsole.billing.createOrganization(
$createOrganization.id ?? ID.unique(),
@@ -86,7 +85,7 @@
}
await invalidate(Dependencies.ACCOUNT);
dispatch('created');
await preloadData(`/console/organization-${org.$id}`);
await goto(`/console/organization-${org.$id}`);
addNotification({
type: 'success',
@@ -98,6 +97,7 @@
budget_cap_enabled: !!$createOrganization?.billingBudget,
members_invited: $createOrganization?.collaborators?.length
});
console.log('TEST');
wizard.hide();
} catch (e) {
addNotification({
@@ -105,6 +105,8 @@
message: e.mesage
});
trackError(e, Submit.OrganizationCreate);
} finally {
$wizard.nextDisabled = false;
}
}
onDestroy(() => {
@@ -12,7 +12,7 @@
export let data;
$: files = normalizeFileSize(data.filesTotal);
$: files = data.filesTotal ? normalizeFileSize(data.filesTotal) : null;
$: requests = data.requestsTotal;
$: executions = data.executionsTotal;
$: users = data.usersTotal;
@@ -24,11 +24,12 @@
value: number;
}[]
) {
const sizes = files.map((e) => e.value);
console.log(data.filesTotal);
const sizes = files?.map((e) => e.value);
const biggestSize = Math.max(...sizes);
const unit = humanFileSize(biggestSize).unit;
return {
data: files.map((e) => ({
data: files?.map((e) => ({
date: new Date(e.date).toLocaleDateString(),
value: toDecimals(bytesToSize(e.value, unit), 2)
})),
@@ -74,16 +75,16 @@
<Heading tag="h4" size="7">Bandwidth</Heading>
<p class="text">Calculated for all bandwidth used across your project.</p>
<svelte:fragment slot="aside">
{#if total(requests)}
{#if data?.requestsTotal && total(data.requestsTotal)}
<div class="u-flex u-gap-8 u-cross-baseline">
<Heading tag="h5" size="4">{total(requests)}</Heading>
<Heading tag="h5" size="4">{total(data.requestsTotal)}</Heading>
<Heading tag="h6" size="6">GB</Heading>
</div>
<BarChart
series={[
{
name: 'Bandwidth over time',
data: [...requests.map((e) => [e.date, e.value])]
data: [...data.requestsTotal.map((e) => [e.date, e.value])]
}
]} />
{:else}
@@ -157,36 +158,38 @@
{/if}
</svelte:fragment>
</CardGrid>
<CardGrid>
<Heading tag="h4" size="7">Storage</Heading>
<p class="text">Calculated for all storage operations in your project.</p>
<svelte:fragment slot="aside">
{@const size = humanFileSize(total(data.filesTotal))}
{#if size}
<div class="u-flex u-gap-8 u-cross-baseline">
<Heading tag="h5" size="4">{size.value}</Heading>
<Heading tag="h6" size="6">{size.unit}</Heading>
</div>
<BarChart
series={[
{
name: `Storage over time in ${files.unit}`,
data: [...files.data]
}
]} />
{:else}
<Card isDashed>
<div class="u-flex u-cross-center u-flex-vertical u-main-center u-flex">
<span
class="icon-chart-square-bar text-large"
aria-hidden="true"
style="font-size: 32px;" />
<p class="u-bold">No data to show</p>
{#if data.filesTotal}
<CardGrid>
<Heading tag="h4" size="7">Storage</Heading>
<p class="text">Calculated for all storage operations in your project.</p>
<svelte:fragment slot="aside">
{@const size = humanFileSize(total(data.filesTotal))}
{#if size}
<div class="u-flex u-gap-8 u-cross-baseline">
<Heading tag="h5" size="4">{size.value}</Heading>
<Heading tag="h6" size="6">{size.unit}</Heading>
</div>
</Card>
{/if}
</svelte:fragment>
</CardGrid>
<BarChart
series={[
{
name: `Storage over time in ${files.unit}`,
data: [...files.data]
}
]} />
{:else}
<Card isDashed>
<div class="u-flex u-cross-center u-flex-vertical u-main-center u-flex">
<span
class="icon-chart-square-bar text-large"
aria-hidden="true"
style="font-size: 32px;" />
<p class="u-bold">No data to show</p>
</div>
</Card>
{/if}
</svelte:fragment>
</CardGrid>
{/if}
<p class="text u-text-color-gray u-margin-block-start-16">
Metrics are estimates updated every 24 hours and may not accurately reflect your invoice.
</p>