feat: move invoices into billing tab

This commit is contained in:
Arman committed 2023-07-19 12:13:42 +02:00
1 parent 835eed727e
commit 134b153c86
11 files changed
+144 -137

No files matched your search

+1
View File
@@ -4,6 +4,7 @@ export const INTERVAL = 5 * 60000; // default interval to check for feedback
export enum Dependencies {
CREDIT = 'dependency:credit',
INVOICES = 'dependency:invoices',
PAYMENT_METHODS = 'dependency:paymentMethods',
ORGANIZATION = 'dependency:organization',
PROJECT = 'dependency:project',
+6 -1
View File
@@ -19,11 +19,16 @@ export type PaymentList = {
export type Invoice = {
$id: string;
$createdAt: Date;
$updatedAt: Date;
teamId: string;
aggregationId: string;
amount: number;
currency: string;
date: number;
from: string;
to: string;
status: string;
paymentMethod: PaymentMethodData;
};
export type InvoiceList = {
-1
View File
@@ -9,7 +9,6 @@ export const VARS = {
| string
| undefined,
CONSOLE_MODE: import.meta.env?.VITE_CONSOLE_MODE?.toString() as string | undefined,
CONSOLE_TIER: import.meta.env?.VITE_CONSOLE_TIER?.toString() as string | undefined,
VERCEL_ENV: import.meta.env?.VITE_VERCEL_ENV?.toString() as string | undefined,
GOOGLE_ANALYTICS: import.meta.env?.VITE_GA_PROJECT?.toString() as string | undefined,
STRIPE_PUBLIC_KEY: import.meta.env?.VITE_STRIPE_PUBLIC_KEY?.toString() as string | undefined
@@ -7,10 +7,12 @@
import BillingAddress from './billingAddress.svelte';
import PaymentMethods from './paymentMethods.svelte';
import AvailableCredit from './availableCredit.svelte';
import PaymentHistory from './paymentHistory.svelte';
</script>
<Container>
<PlanSummary />
<PaymentHistory />
<PaymentMethods />
<BillingAddress />
<BudgetCap />
@@ -1,14 +1,20 @@
import { Dependencies } from '$lib/constants';
import { sdk } from '$lib/stores/sdk';
import { Query } from '@appwrite.io/console';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params, parent, depends }) => {
await parent();
depends(Dependencies.PAYMENT_METHODS);
depends(Dependencies.ORGANIZATION);
depends(Dependencies.CREDIT);
depends(Dependencies.INVOICES);
return {
paymentMethods: await sdk.forConsole.billing.listPaymentMethods(),
creditList: await sdk.forConsole.billing.listCredits(params.organization)
creditList: await sdk.forConsole.billing.listCredits(params.organization),
invoiceList: await sdk.forConsole.billing.listInvoices(params.organization, [
Query.limit(5)
])
};
};
@@ -0,0 +1,122 @@
<script lang="ts">
import { page } from '$app/stores';
import { CardGrid, DropList, EmptySearch, Heading, PaginationInline } from '$lib/components';
import DropListItem from '$lib/components/dropListItem.svelte';
import { Pill } from '$lib/elements';
import { Button } from '$lib/elements/forms';
import {
Table,
TableBody,
TableCell,
TableCellHead,
TableCellText,
TableHeader,
TableRow
} from '$lib/elements/table';
import { toLocaleDate } from '$lib/helpers/date';
import { sdk } from '$lib/stores/sdk';
import { Query } from '@appwrite.io/console';
import { invoiceList } from './store';
let showDropdown = [];
let selectedInvoice: string;
let offset = 0;
async function download() {
sdk.forConsole.billing.downloadInvoice($page.params.organization, selectedInvoice);
}
async function view() {
sdk.forConsole.billing.getInvoiceView($page.params.organization, selectedInvoice);
}
async function request() {
$invoiceList = await sdk.forConsole.billing.listInvoices($page.params.organization, [
Query.limit(5),
Query.offset(offset)
]);
}
$: if (offset !== null) {
request();
}
</script>
<CardGrid>
<Heading tag="h2" size="6">Payment history</Heading>
<p class="text">
Transaction history for this Organization. Download invoices for more details about your
payments.
</p>
<svelte:fragment slot="aside">
{#if $invoiceList.total}
<Table noMargin noStyles>
<TableHeader>
<TableCellHead>Date</TableCellHead>
<TableCellHead>Status</TableCellHead>
<TableCellHead>Amount Due</TableCellHead>
<TableCellHead>Invoce #</TableCellHead>
<TableCellHead width={20} />
</TableHeader>
<TableBody>
{#each $invoiceList?.invoices as invoice, i}
<TableRow>
<TableCellText title="date">{toLocaleDate(invoice.from)}</TableCellText>
<TableCell title="status">
<Pill>test</Pill>
</TableCell>
<TableCellText title="due">{invoice.amount}</TableCellText>
<TableCellText title="invoice number"
>{invoice.aggregationId}
</TableCellText>
<TableCell showOverflow>
<DropList
bind:show={showDropdown[i]}
placement="bottom-start"
noArrow>
<Button
round
text
ariaLabel="More options"
on:click={() => {
showDropdown[i] = !showDropdown[i];
}}>
<span class="icon-dots-horizontal" aria-hidden="true" />
</Button>
<svelte:fragment slot="list">
<DropListItem
icon="external-link"
on:click={() => {
selectedInvoice = invoice.$id;
view();
}}>
View invoice
</DropListItem>
<DropListItem
icon="download"
on:click={() => {
selectedInvoice = invoice.$id;
download();
}}>Download PDF</DropListItem>
</svelte:fragment>
</DropList>
</TableCell>
</TableRow>
{/each}
</TableBody>
</Table>
<div class="u-flex u-margin-block-start-32 u-main-space-between">
<p class="text">Total results: {$invoiceList?.total}</p>
<PaginationInline limit={5} bind:offset sum={$invoiceList?.total} hidePages />
</div>
{:else}
<EmptySearch cardOnly>
<p class="text u-text-center">
You have no payment history. After you receive your first invoice, you'll see it
here.
</p>
</EmptySearch>
{/if}
</svelte:fragment>
</CardGrid>
@@ -1,4 +1,7 @@
import { page } from '$app/stores';
import { derived } from 'svelte/store';
import type { CreditList, InvoiceList } from '$lib/sdk/billing';
import { derived, type Readable } from 'svelte/store';
export const creditList = derived(page, ($page) => $page.data.creditList);
export const creditList: Readable<CreditList> = derived(page, ($page) => $page.data.creditList);
export const invoiceList: Readable<InvoiceList> = derived(page, ($page) => $page.data.invoiceList);
@@ -61,11 +61,6 @@
href: `${path}/billing`,
event: 'billing',
title: 'Billing'
},
{
href: `${path}/invoices`,
event: 'invoices',
title: 'Invoices'
}
]
: permanentTabs;
@@ -1,103 +0,0 @@
<script lang="ts">
import { page } from '$app/stores';
import {
DropList,
DropListItem,
EmptySearch,
Heading,
PaginationInline
} from '$lib/components';
import { Pill } from '$lib/elements';
import { Button } from '$lib/elements/forms/index.js';
import {
TableBody,
TableCell,
TableCellHead,
TableCellText,
TableHeader,
TableRow,
TableScroll
} from '$lib/elements/table';
import { Container } from '$lib/layout';
import { sdk } from '$lib/stores/sdk.js';
export let data;
export let offset = 0;
let showDropdown = [];
let selectedInvoice: string;
async function download() {
sdk.forConsole.billing.downloadInvoice($page.params.organization, selectedInvoice);
}
async function view() {
sdk.forConsole.billing.getInvoiceView($page.params.organization, selectedInvoice);
}
</script>
<Container>
<div class="common-section">
<Heading tag="h2" size="5">Invoices</Heading>
</div>
{#if data?.invoices?.total}
<TableScroll>
<TableHeader>
<TableCellHead width={100}>Date</TableCellHead>
<TableCellHead width={100}>Status</TableCellHead>
<TableCellHead width={80}>Amount Due</TableCellHead>
<TableCellHead width={90}>Invoce #</TableCellHead>
<TableCellHead width={40} />
</TableHeader>
<TableBody>
{#each data.invoices?.invoices as invoice, i}
<TableRow>
<TableCellText title="date">test</TableCellText>
<TableCell title="status">
<Pill>test</Pill>
</TableCell>
<TableCellText title="due">{invoice}</TableCellText>
<TableCellText title="invoice number">test</TableCellText>
<TableCell showOverflow>
<DropList bind:show={showDropdown[i]} placement="bottom-start" noArrow>
<Button
round
text
ariaLabel="More options"
on:click={() => {
showDropdown[i] = !showDropdown[i];
}}>
<span class="icon-dots-horizontal" aria-hidden="true" />
</Button>
<svelte:fragment slot="list">
<DropListItem
icon="external-link"
on:click={() => {
selectedInvoice = invoice.$id;
view();
}}>
View invoice
</DropListItem>
<DropListItem
icon="download"
on:click={() => {
selectedInvoice = invoice.$id;
download();
}}>Download PDF</DropListItem>
</svelte:fragment>
</DropList>
</TableCell>
</TableRow>
{/each}
</TableBody>
</TableScroll>
<div class="u-flex u-margin-block-start-32 u-main-space-between">
<p class="text">Total results: {data.invoices?.total}</p>
<PaginationInline limit={5} bind:offset sum={data.invoices?.total} />
</div>
{:else}
<EmptySearch>
You have no payment history. After you receive your first invoice, you'll see it here.
</EmptySearch>
{/if}
</Container>
@@ -1,23 +0,0 @@
import { Query } from '@appwrite.io/console';
import { sdk } from '$lib/stores/sdk';
import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
import { PAGE_LIMIT } from '$lib/constants';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params, url, route }) => {
const page = getPage(url);
const limit = getLimit(url, route, PAGE_LIMIT);
const offset = pageToOffset(page, PAGE_LIMIT);
const invoices = await sdk.forConsole.billing.listInvoices(params.organization, [
Query.offset(offset),
Query.limit(limit),
Query.orderDesc('$createdAt')
]);
console.log(invoices);
return {
offset,
invoices
};
};
@@ -2,7 +2,7 @@
import { Container } from '$lib/layout';
import { CardGrid, Heading, ProgressBarBig, ProjectUsage } from '$lib/components';
export let data;
// export let data;
</script>
<Container>