Skip to content

Commit

Permalink
fix(cc): preserve previous organization details json in billing detail
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Nov 1, 2024
1 parent dd266b7 commit 1b903ca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/billing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export const defaultBillingDetailResponse = (
): BillingDetailResponse => {
return {
id: "",
organization_details_json: {},
_links: { payment_method: defaultHalHref() },
...bt,
};
};

interface BillingDetailResponse {
id: string;
organization_details_json: { [key: string]: any } | null;
_links: {
payment_method: LinkResponse;
};
Expand All @@ -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
: "",
Expand Down Expand Up @@ -176,10 +179,12 @@ interface UpdateBillingDetailProps {
export const updateBillingDetail = billingApi.patch<UpdateBillingDetailProps>(
"/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,
Expand Down
1 change: 1 addition & 0 deletions src/schema/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ export const defaultBillingDetail = (
return {
id: "",
paymentMethodUrl: "",
organizationDetailsJson: {},
...bt,
};
};
Expand Down
1 change: 1 addition & 0 deletions src/types/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface ContainerMetrics {
export interface BillingDetail {
id: string;
paymentMethodUrl: string;
organizationDetailsJson: { [key: string]: any };
}

export interface DeployActivityRow extends DeployOperation {
Expand Down
8 changes: 7 additions & 1 deletion src/ui/pages/billing-method.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1b903ca

Please sign in to comment.