chore: use new method to fetch address

This commit is contained in:
Arman
2024-03-21 14:11:51 +01:00
parent 15835af4f7
commit 9cd02d9dd3
4 changed files with 20 additions and 7 deletions
+1 -1
View File
@@ -766,7 +766,7 @@ export class Billing {
async getOrganizationBillingAddress(
organizationId: string,
billingAddressId: string
): Promise<PaymentMethodData> {
): Promise<Address> {
const path = `/organizations/${organizationId}/billing-addresses/${billingAddressId}`;
const params = {
organizationId,
@@ -23,6 +23,8 @@
import RetryPaymentModal from './retryPaymentModal.svelte';
import { selectedInvoice, showRetryModal } from './store';
export let data;
$: defaultPaymentMethod = $paymentMethods?.paymentMethods?.find(
(method: PaymentMethodData) => method.$id === $organization?.paymentMethodId
);
@@ -106,7 +108,7 @@
<PlanSummary />
<PaymentHistory />
<PaymentMethods />
<BillingAddress />
<BillingAddress billingAddress={data.billingAddress} />
<TaxId />
<BudgetCap />
{#if $organization?.billingPlan !== BillingPlan.STARTER && !!$organization?.billingBudget}
@@ -1,4 +1,6 @@
import { Dependencies } from '$lib/constants';
import type { Address } from '$lib/sdk/billing';
import type { Organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import type { PageLoad } from './$types';
@@ -10,9 +12,19 @@ export const load: PageLoad = async ({ parent, depends }) => {
depends(Dependencies.INVOICES);
depends(Dependencies.ADDRESS);
let billingAddress: Address = null;
const billingAddressId = (organization as Organization)?.billingAddressId;
if (billingAddressId) {
billingAddress = await sdk.forConsole.billing.getOrganizationBillingAddress(
organization.$id,
billingAddressId
);
}
return {
paymentMethods: await sdk.forConsole.billing.listPaymentMethods(),
addressList: await sdk.forConsole.billing.listAddresses(),
aggregationList: await sdk.forConsole.billing.listAggregation(organization.$id)
aggregationList: await sdk.forConsole.billing.listAggregation(organization.$id),
billingAddress
};
};
@@ -5,6 +5,7 @@
import DropListItem from '$lib/components/dropListItem.svelte';
import { Dependencies } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import type { Address } from '$lib/sdk/billing';
import { addressList } from '$lib/stores/billing';
import { addNotification } from '$lib/stores/notifications';
import { organization } from '$lib/stores/organization';
@@ -13,6 +14,8 @@
import EditAddressModal from '$routes/console/account/payments/editAddressModal.svelte';
import ReplaceAddress from './replaceAddress.svelte';
export let billingAddress: Address = null;
let showDropdown = false;
let showBillingAddressDropdown = false;
let showCreate = false;
@@ -40,10 +43,6 @@
trackError(error, Submit.OrganizationBillingAddressUpdate);
}
}
$: billingAddress = $addressList?.billingAddresses?.find(
(address) => address.$id === $organization?.billingAddressId
);
</script>
<CardGrid>