Skip to content

Commit 5d9f1fc

Browse files
committed
refactor: extract downgrade feedback logic into a separate function
1 parent 9ac21e9 commit 5d9f1fc

File tree

1 file changed

+28
-24
lines changed
  • src/routes/(console)/organization-[organization]/change-plan

1 file changed

+28
-24
lines changed

src/routes/(console)/organization-[organization]/change-plan/+page.svelte

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,33 @@
106106
}
107107
}
108108
109+
async function trackDowngradeFeedback() {
110+
const paidInvoices = await sdk.forConsole.billing.listInvoices(data.organization.$id, [
111+
Query.equal('status', 'succeeded')
112+
]);
113+
114+
await fetch(`${VARS.GROWTH_ENDPOINT}/feedback/billing`, {
115+
method: 'POST',
116+
headers: {
117+
'Content-Type': 'application/json'
118+
},
119+
body: JSON.stringify({
120+
from: tierToPlan(data.organization.billingPlan).name,
121+
to: tierToPlan(selectedPlan).name,
122+
email: data.account.email,
123+
reason: feedbackDowngradeOptions.find(
124+
(option) => option.value === feedbackDowngradeReason
125+
)?.label,
126+
orgId: data.organization.$id,
127+
userId: data.account.$id,
128+
orgAge: data.organization.$createdAt,
129+
userAge: data.account.$createdAt,
130+
paidInvoices: paidInvoices.total,
131+
message: feedbackMessage ?? ''
132+
})
133+
});
134+
}
135+
109136
async function downgrade() {
110137
try {
111138
await sdk.forConsole.billing.updatePlan(
@@ -115,30 +142,7 @@
115142
null
116143
);
117144
118-
const paidInvoices = await sdk.forConsole.billing.listInvoices(data.organization.$id, [
119-
Query.equal('status', 'succeeded')
120-
]);
121-
122-
await fetch(`${VARS.GROWTH_ENDPOINT}/feedback/billing`, {
123-
method: 'POST',
124-
headers: {
125-
'Content-Type': 'application/json'
126-
},
127-
body: JSON.stringify({
128-
from: tierToPlan(data.organization.billingPlan).name,
129-
to: tierToPlan(selectedPlan).name,
130-
email: data.account.email,
131-
reason: feedbackDowngradeOptions.find(
132-
(option) => option.value === feedbackDowngradeReason
133-
)?.label,
134-
orgId: data.organization.$id,
135-
userId: data.account.$id,
136-
orgAge: data.organization.$createdAt,
137-
userAge: data.account.$createdAt,
138-
paidInvoices: paidInvoices.total,
139-
message: feedbackMessage ?? ''
140-
})
141-
});
145+
trackDowngradeFeedback();
142146
143147
await invalidate(Dependencies.ORGANIZATION);
144148

0 commit comments

Comments
 (0)