From 1b903caa1928ebebdb887a803d70b3b53955abcd Mon Sep 17 00:00:00 2001 From: Eric Bower Date: Fri, 1 Nov 2024 11:22:25 -0400 Subject: [PATCH] fix(cc): preserve previous organization details json in billing detail --- src/billing/index.ts | 5 +++++ src/schema/factory.ts | 1 + src/types/state.ts | 1 + src/ui/pages/billing-method.tsx | 8 +++++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/billing/index.ts b/src/billing/index.ts index 1002b6f0b..7336360d2 100644 --- a/src/billing/index.ts +++ b/src/billing/index.ts @@ -27,6 +27,7 @@ export const defaultBillingDetailResponse = ( ): BillingDetailResponse => { return { id: "", + organization_details_json: {}, _links: { payment_method: defaultHalHref() }, ...bt, }; @@ -34,6 +35,7 @@ export const defaultBillingDetailResponse = ( interface BillingDetailResponse { id: string; + organization_details_json: { [key: string]: any } | null; _links: { payment_method: LinkResponse; }; @@ -42,6 +44,7 @@ interface BillingDetailResponse { const deserializeBillingDetail = (bt: BillingDetailResponse): BillingDetail => { return { id: bt.id, + organizationDetailsJson: bt.organization_details_json || {}, paymentMethodUrl: bt._links.payment_method ? bt._links.payment_method.href : "", @@ -176,10 +179,12 @@ interface UpdateBillingDetailProps { export const updateBillingDetail = billingApi.patch( "/billing_details/:id", function* (ctx, next) { + const bd = yield* select(selectBillingDetail); ctx.request = ctx.req({ body: JSON.stringify({ payment_method: ctx.payload.paymentMethodUrl, organization_details_json: { + ...bd.organizationDetailsJson, billing_address: { street_one: ctx.payload.address1, street_two: ctx.payload.address2, diff --git a/src/schema/factory.ts b/src/schema/factory.ts index c0f8b7ee2..dc1a48779 100644 --- a/src/schema/factory.ts +++ b/src/schema/factory.ts @@ -789,6 +789,7 @@ export const defaultBillingDetail = ( return { id: "", paymentMethodUrl: "", + organizationDetailsJson: {}, ...bt, }; }; diff --git a/src/types/state.ts b/src/types/state.ts index 4d17bc8d2..6e14a5562 100644 --- a/src/types/state.ts +++ b/src/types/state.ts @@ -53,6 +53,7 @@ export interface ContainerMetrics { export interface BillingDetail { id: string; paymentMethodUrl: string; + organizationDetailsJson: { [key: string]: any }; } export interface DeployActivityRow extends DeployOperation { diff --git a/src/ui/pages/billing-method.tsx b/src/ui/pages/billing-method.tsx index 7409ef31a..cc60966f2 100644 --- a/src/ui/pages/billing-method.tsx +++ b/src/ui/pages/billing-method.tsx @@ -1,4 +1,9 @@ -import { addCreditCard, getStripe, selectBillingDetail } from "@app/billing"; +import { + addCreditCard, + fetchBillingDetail, + getStripe, + selectBillingDetail, +} from "@app/billing"; import { selectEnv } from "@app/config"; import { fetchActivePlans, @@ -334,6 +339,7 @@ const CreditCardForm = () => { export const BillingMethodPage = () => { const org = useSelector(selectOrganizationSelected); + useQuery(fetchBillingDetail({ id: org.id })); useQuery(fetchActivePlans({ orgId: org.id })); useQuery(fetchPlans()); const activePlan = useSelector(selectFirstActivePlan);