You've already forked AstralRinth
forked from didirus/AstralRinth
Initial servers upgrades frontend (#3219)
* Initial servers upgrades frontend * Fix error when purchasing non-custom servers * fix backend * Fix comment --------- Signed-off-by: Jai Agrawal <18202329+Geometrically@users.noreply.github.com> Co-authored-by: Jai A <jaiagr+gpg@pm.me> Co-authored-by: Jai Agrawal <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<section class="universal-card">
|
||||
<section class="universal-card experimental-styles-within">
|
||||
<h2>{{ formatMessage(messages.subscriptionTitle) }}</h2>
|
||||
<p>{{ formatMessage(messages.subscriptionDescription) }}</p>
|
||||
<div class="universal-card recessed">
|
||||
@@ -88,67 +88,69 @@
|
||||
v-if="midasCharge && midasCharge.status === 'failed'"
|
||||
class="ml-auto flex flex-row-reverse items-center gap-2"
|
||||
>
|
||||
<ButtonStyled v-if="midasCharge && midasCharge.status === 'failed'">
|
||||
<button
|
||||
@click="
|
||||
() => {
|
||||
$refs.midasPurchaseModal.show();
|
||||
}
|
||||
"
|
||||
>
|
||||
<UpdatedIcon />
|
||||
Update method
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
<ButtonStyled type="transparent" circular>
|
||||
<OverflowMenu
|
||||
:dropdown-id="`${baseId}-cancel-midas`"
|
||||
:options="[
|
||||
{
|
||||
id: 'cancel',
|
||||
action: () => {
|
||||
cancelSubscriptionId = midasSubscription.id;
|
||||
$refs.modalCancel.show();
|
||||
},
|
||||
},
|
||||
]"
|
||||
>
|
||||
<MoreVerticalIcon />
|
||||
<template #cancel><XIcon /> Cancel</template>
|
||||
</OverflowMenu>
|
||||
</ButtonStyled>
|
||||
</div>
|
||||
<ButtonStyled v-else-if="midasCharge && midasCharge.status !== 'cancelled'">
|
||||
<button
|
||||
v-if="midasCharge && midasCharge.status === 'failed'"
|
||||
class="iconified-button raised-button"
|
||||
class="ml-auto"
|
||||
@click="
|
||||
() => {
|
||||
purchaseModalStep = 0;
|
||||
$refs.purchaseModal.show();
|
||||
cancelSubscriptionId = midasSubscription.id;
|
||||
$refs.modalCancel.show();
|
||||
}
|
||||
"
|
||||
>
|
||||
<UpdatedIcon />
|
||||
Update method
|
||||
<XIcon /> Cancel
|
||||
</button>
|
||||
<OverflowMenu
|
||||
class="btn icon-only transparent"
|
||||
:options="[
|
||||
{
|
||||
id: 'cancel',
|
||||
action: () => {
|
||||
cancelSubscriptionId = midasSubscription.id;
|
||||
$refs.modalCancel.show();
|
||||
},
|
||||
},
|
||||
]"
|
||||
>
|
||||
<MoreVerticalIcon />
|
||||
<template #cancel><XIcon /> Cancel</template>
|
||||
</OverflowMenu>
|
||||
</div>
|
||||
<button
|
||||
v-else-if="midasCharge && midasCharge.status !== 'cancelled'"
|
||||
class="iconified-button raised-button !ml-auto"
|
||||
@click="
|
||||
() => {
|
||||
cancelSubscriptionId = midasSubscription.id;
|
||||
$refs.modalCancel.show();
|
||||
}
|
||||
"
|
||||
>
|
||||
<XIcon /> Cancel
|
||||
</button>
|
||||
<button
|
||||
</ButtonStyled>
|
||||
<ButtonStyled
|
||||
v-else-if="midasCharge && midasCharge.status === 'cancelled'"
|
||||
class="btn btn-purple btn-large ml-auto"
|
||||
@click="cancelSubscription(midasSubscription.id, false)"
|
||||
color="purple"
|
||||
>
|
||||
<RightArrowIcon /> Resubscribe
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
class="btn btn-purple btn-large ml-auto"
|
||||
@click="
|
||||
() => {
|
||||
purchaseModalStep = 0;
|
||||
$refs.purchaseModal.show();
|
||||
}
|
||||
"
|
||||
>
|
||||
<RightArrowIcon />
|
||||
Subscribe
|
||||
</button>
|
||||
<button class="ml-auto" @click="cancelSubscription(midasSubscription.id, false)">
|
||||
Resubscribe <RightArrowIcon />
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
<ButtonStyled v-else color="purple" size="large">
|
||||
<button
|
||||
class="ml-auto"
|
||||
@click="
|
||||
() => {
|
||||
$refs.midasPurchaseModal.show();
|
||||
}
|
||||
"
|
||||
>
|
||||
Subscribe <RightArrowIcon />
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -282,25 +284,37 @@
|
||||
getPyroCharge(subscription).status !== 'cancelled' &&
|
||||
getPyroCharge(subscription).status !== 'failed'
|
||||
"
|
||||
type="standard"
|
||||
@click="showPyroCancelModal(subscription.id)"
|
||||
>
|
||||
<button class="text-contrast">
|
||||
<button @click="showPyroCancelModal(subscription.id)">
|
||||
<XIcon />
|
||||
Cancel
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
<ButtonStyled
|
||||
v-if="
|
||||
getPyroCharge(subscription) &&
|
||||
getPyroCharge(subscription).status !== 'cancelled' &&
|
||||
getPyroCharge(subscription).status !== 'failed'
|
||||
"
|
||||
color="green"
|
||||
color-fill="text"
|
||||
>
|
||||
<button @click="showPyroUpgradeModal(subscription)">
|
||||
<ArrowBigUpDashIcon />
|
||||
Upgrade
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
<ButtonStyled
|
||||
v-else-if="
|
||||
getPyroCharge(subscription) &&
|
||||
(getPyroCharge(subscription).status === 'cancelled' ||
|
||||
getPyroCharge(subscription).status === 'failed')
|
||||
"
|
||||
type="standard"
|
||||
color="green"
|
||||
@click="resubscribePyro(subscription.id)"
|
||||
>
|
||||
<button class="text-contrast">Resubscribe</button>
|
||||
<button @click="resubscribePyro(subscription.id)">
|
||||
Resubscribe <RightArrowIcon />
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
</div>
|
||||
</div>
|
||||
@@ -312,7 +326,7 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="universal-card">
|
||||
<section class="universal-card experimental-styles-within">
|
||||
<ConfirmModal
|
||||
ref="modal_confirm"
|
||||
:title="formatMessage(deleteModalMessages.title)"
|
||||
@@ -321,7 +335,7 @@
|
||||
@proceed="removePaymentMethod(removePaymentMethodIndex)"
|
||||
/>
|
||||
<PurchaseModal
|
||||
ref="purchaseModal"
|
||||
ref="midasPurchaseModal"
|
||||
:product="midasProduct"
|
||||
:country="country"
|
||||
:publishable-key="config.public.stripePublishableKey"
|
||||
@@ -342,6 +356,37 @@
|
||||
:payment-methods="paymentMethods"
|
||||
:return-url="`${config.public.siteUrl}/settings/billing`"
|
||||
/>
|
||||
<PurchaseModal
|
||||
ref="pyroPurchaseModal"
|
||||
:product="upgradeProducts"
|
||||
:country="country"
|
||||
custom-server
|
||||
:existing-subscription="currentSubscription"
|
||||
:existing-plan="currentProduct"
|
||||
:publishable-key="config.public.stripePublishableKey"
|
||||
:send-billing-request="
|
||||
async (body) =>
|
||||
await useBaseFetch(`billing/subscription/${currentSubscription.id}`, {
|
||||
internal: true,
|
||||
method: `PATCH`,
|
||||
body: body,
|
||||
})
|
||||
"
|
||||
:renewal-date="currentSubRenewalDate"
|
||||
:on-error="
|
||||
(err) =>
|
||||
data.$notify({
|
||||
group: 'main',
|
||||
title: 'An error occurred',
|
||||
type: 'error',
|
||||
text: err.message ?? (err.data ? err.data.description : err),
|
||||
})
|
||||
"
|
||||
:customer="customer"
|
||||
:payment-methods="paymentMethods"
|
||||
:return-url="`${config.public.siteUrl}/servers/manage`"
|
||||
:server-name="`${auth?.user?.username}'s server`"
|
||||
/>
|
||||
<NewModal ref="addPaymentMethodModal">
|
||||
<template #title>
|
||||
<span class="text-lg font-extrabold text-contrast">
|
||||
@@ -359,15 +404,19 @@
|
||||
<div id="address-element"></div>
|
||||
<div id="payment-element" class="mt-4"></div>
|
||||
</div>
|
||||
<div v-show="loadingPaymentMethodModal === 2" class="input-group push-right mt-auto pt-4">
|
||||
<button class="btn" @click="$refs.addPaymentMethodModal.hide()">
|
||||
<XIcon />
|
||||
{{ formatMessage(commonMessages.cancelButton) }}
|
||||
</button>
|
||||
<button class="btn btn-primary" :disabled="loadingAddMethod" @click="submit">
|
||||
<PlusIcon />
|
||||
{{ formatMessage(messages.paymentMethodAdd) }}
|
||||
</button>
|
||||
<div v-show="loadingPaymentMethodModal === 2" class="input-group mt-auto pt-4">
|
||||
<ButtonStyled color="brand">
|
||||
<button :disabled="loadingAddMethod" @click="submit">
|
||||
<PlusIcon />
|
||||
{{ formatMessage(messages.paymentMethodAdd) }}
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
<ButtonStyled>
|
||||
<button @click="$refs.addPaymentMethodModal.hide()">
|
||||
<XIcon />
|
||||
{{ formatMessage(commonMessages.cancelButton) }}
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
</div>
|
||||
</div>
|
||||
</NewModal>
|
||||
@@ -442,6 +491,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<OverflowMenu
|
||||
:dropdown-id="`${baseId}-payment-method-overflow-${index}`"
|
||||
class="btn icon-only transparent"
|
||||
:options="
|
||||
[
|
||||
@@ -493,6 +543,7 @@ import {
|
||||
} from "@modrinth/ui";
|
||||
import {
|
||||
PlusIcon,
|
||||
ArrowBigUpDashIcon,
|
||||
XIcon,
|
||||
CardIcon,
|
||||
MoreVerticalIcon,
|
||||
@@ -515,6 +566,9 @@ definePageMeta({
|
||||
middleware: "auth",
|
||||
});
|
||||
|
||||
const auth = await useAuth();
|
||||
const baseId = useId();
|
||||
|
||||
useHead({
|
||||
script: [
|
||||
{
|
||||
@@ -704,7 +758,7 @@ const pyroSubscriptions = computed(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const purchaseModal = ref();
|
||||
const midasPurchaseModal = ref();
|
||||
const country = useUserCountry();
|
||||
const price = computed(() =>
|
||||
midasProduct.value?.prices?.find((x) => x.currency_code === getCurrency(country.value)),
|
||||
@@ -896,6 +950,46 @@ const showPyroCancelModal = (subscriptionId) => {
|
||||
}
|
||||
};
|
||||
|
||||
const pyroPurchaseModal = ref();
|
||||
const currentSubscription = ref(null);
|
||||
const currentProduct = ref(null);
|
||||
const upgradeProducts = ref([]);
|
||||
upgradeProducts.value.metadata = { type: "pyro" };
|
||||
|
||||
const currentSubRenewalDate = ref();
|
||||
|
||||
const showPyroUpgradeModal = async (subscription) => {
|
||||
currentSubscription.value = subscription;
|
||||
currentSubRenewalDate.value = getPyroCharge(subscription).due;
|
||||
currentProduct.value = getPyroProduct(subscription);
|
||||
upgradeProducts.value = products.filter(
|
||||
(p) =>
|
||||
p.metadata.type === "pyro" &&
|
||||
(!currentProduct.value || p.metadata.ram > currentProduct.value.metadata.ram),
|
||||
);
|
||||
upgradeProducts.value.metadata = { type: "pyro" };
|
||||
|
||||
await nextTick();
|
||||
|
||||
if (!currentProduct.value) {
|
||||
console.error("Could not find product for current subscription");
|
||||
data.$notify({
|
||||
group: "main",
|
||||
title: "An error occurred",
|
||||
text: "Could not find product for current subscription",
|
||||
type: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pyroPurchaseModal.value) {
|
||||
console.error("pyroPurchaseModal ref is undefined");
|
||||
return;
|
||||
}
|
||||
|
||||
pyroPurchaseModal.value.show();
|
||||
};
|
||||
|
||||
const resubscribePyro = async (subscriptionId) => {
|
||||
try {
|
||||
await useBaseFetch(`billing/subscription/${subscriptionId}`, {
|
||||
|
||||
Reference in New Issue
Block a user