-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathbillingAddress.svelte
More file actions
147 lines (139 loc) · 6.61 KB
/
Copy pathbillingAddress.svelte
File metadata and controls
147 lines (139 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<script lang="ts">
import { CardGrid, Empty } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { addressList } from '$lib/stores/billing';
import AddressModal from './addressModal.svelte';
import type { Models } from '@appwrite.io/console';
import DeleteAddress from './deleteAddressModal.svelte';
import EditAddressModal from './editAddressModal.svelte';
import { organizationList } from '$lib/stores/organization';
import { base } from '$app/paths';
import {
IconDotsHorizontal,
IconInfo,
IconPencil,
IconPlus,
IconTrash
} from '@appwrite.io/pink-icons-svelte';
import {
ActionMenu,
Icon,
Layout,
Link,
Popover,
Table,
Tag,
Typography
} from '@appwrite.io/pink-svelte';
import type { PageData } from './$types';
export let data: PageData;
const locale: Models.CloudLocale = data.locale;
const countryList: Models.CountryList = data.countryList;
let show = false;
let showEdit = false;
let selectedAddress: Models.BillingAddress;
let selectedLinkedOrgs: Array<Models.Organization> = [];
let showDelete = false;
$: orgList = $organizationList.teams as unknown as Array<Models.Organization>;
</script>
<CardGrid>
<svelte:fragment slot="title">Billing address</svelte:fragment>
View or update your billing address. This address will be included in your invoices from Appwrite.
<svelte:fragment slot="aside">
{#if $addressList.total && countryList?.total}
<Table.Root
let:root
columns={[{ id: 'address' }, { id: 'links' }, { id: 'actions', width: 40 }]}>
{#each $addressList.billingAddresses as address}
{@const country = countryList?.countries?.find(
(c) => c.code === address.country
)}
{@const linkedOrgs = orgList?.filter(
(org) => address.$id === org.billingAddressId
)}
<Table.Row.Base {root}>
<Table.Cell column="address" {root}>
{address.streetAddress},
{#if address?.addressLine2}
{address.addressLine2},
{/if}
{address.city},
{#if address?.state}
{address.state},
{/if}
{#if address?.postalCode}
{address.postalCode},
{/if}
{country ? country.name : address.country}
</Table.Cell>
<Table.Cell column="links" {root}>
{#if linkedOrgs?.length > 0}
<Popover let:toggle>
<Tag on:click={toggle} size="s">
<Icon icon={IconInfo} slot="start" />
linked to organization
</Tag>
<svelte:fragment slot="tooltip">
<Layout.Stack>
<Typography.Text>
This billing address is linked to the following
organizations:
</Typography.Text>
<Layout.Stack gap="xxs">
{#each linkedOrgs as org}
<Link.Anchor
href={`${base}/organization-${org.$id}/billing`}>
{org.name}
</Link.Anchor>
{/each}
</Layout.Stack>
</Layout.Stack>
</svelte:fragment>
</Popover>
{/if}
</Table.Cell>
<Table.Cell column="actions" {root}>
<Popover let:toggle placement="bottom-end" padding="none">
<Button icon text ariaLabel="More options" on:click={toggle}>
<Icon icon={IconDotsHorizontal} size="s" />
</Button>
<ActionMenu.Root slot="tooltip">
<ActionMenu.Item.Button
leadingIcon={IconPencil}
on:click={() => {
showEdit = true;
selectedAddress = address;
}}>
Edit
</ActionMenu.Item.Button>
<ActionMenu.Item.Button
leadingIcon={IconTrash}
on:click={() => {
showDelete = true;
selectedAddress = address;
selectedLinkedOrgs = linkedOrgs;
}}>
Delete
</ActionMenu.Item.Button>
</ActionMenu.Root>
</Popover>
</Table.Cell>
</Table.Row.Base>
{/each}
</Table.Root>
<div>
<Button secondary on:click={() => (show = true)}>
<Icon icon={IconPlus} slot="start" size="s" />
Add a billing address
</Button>
</div>
{:else}
<Empty on:click={() => (show = true)}>
<p class="text">Add a billing address</p>
</Empty>
{/if}
</svelte:fragment>
</CardGrid>
<AddressModal {locale} {countryList} bind:show />
<EditAddressModal bind:show={showEdit} {selectedAddress} {locale} {countryList} />
<DeleteAddress bind:showDelete {selectedAddress} linkedOrgs={selectedLinkedOrgs} />