implement resubscribe modal

This commit is contained in:
tdgao
2026-03-26 19:14:40 -06:00
parent d2ec943e25
commit 557eed9759
4 changed files with 364 additions and 38 deletions
@@ -1,5 +1,9 @@
<template>
<ServersUpgradeModalWrapper ref="upgradeModal" />
<ResubscribeModal
ref="pyroResubscribeModal"
@resubscribe="handlePyroResubscribeConfirm"
/>
<section class="universal-card experimental-styles-within">
<h2>{{ formatMessage(messages.subscriptionTitle) }}</h2>
<p>{{ formatMessage(messages.subscriptionDescription) }}</p>
@@ -425,12 +429,7 @@
color="green"
>
<button
@click="
resubscribePyro(
subscription.id,
$dayjs(getPyroCharge(subscription).due).isBefore($dayjs()),
)
"
@click="openPyroResubscribeModal(subscription)"
>
Resubscribe <RightArrowIcon />
</button>
@@ -619,6 +618,7 @@ import {
OverflowMenu,
paymentMethodMessages,
PurchaseModal,
ResubscribeModal,
ServerListing,
useFormatDateTime,
useFormatPrice,
@@ -824,6 +824,7 @@ const pyroSubscriptions = computed(() => {
})
const midasPurchaseModal = ref()
const pyroResubscribeModal = ref()
const country = useUserCountry()
const price = computed(() =>
midasProduct.value?.prices?.find((x) => x.currency_code === getCurrency(country.value)),
@@ -1010,6 +1011,31 @@ const resubscribePyro = async (subscriptionId, wasSuspended) => {
}
}
function openPyroResubscribeModal(subscription) {
const charge = getPyroCharge(subscription)
const product = getPyroProduct(subscription)
const interval = charge?.subscription_interval || subscription?.interval
const productPrice = getProductPrice(product, interval)
pyroResubscribeModal.value?.show({
subscriptionId: subscription?.id ?? '',
wasSuspended: charge?.due ? new Date(charge.due).getTime() < Date.now() : false,
serverName: subscription?.serverInfo?.name ?? 'this server',
planName: `${getProductSize(product)} plan`,
ramGb: product?.metadata?.ram ? product.metadata.ram / 1024 : undefined,
storageGb: product?.metadata?.storage ? product.metadata.storage / 1024 : undefined,
sharedCpus: product?.metadata?.cpu ? product.metadata.cpu / 2 : undefined,
priceCents: charge?.amount ?? productPrice?.prices?.intervals?.[interval],
currencyCode: charge?.currency_code ?? productPrice?.currency_code,
interval,
nextChargeDate: charge?.due,
})
}
function handlePyroResubscribeConfirm({ subscriptionId, wasSuspended }) {
return resubscribePyro(subscriptionId, wasSuspended)
}
function getLatestBackupDownload(serverInfo) {
const serverFull = serverFullList.value?.find((s) => s.id === serverInfo.server_id)
if (!serverFull) return null