Skip to content

Commit 00877b8

Browse files
committed
feat: custom plans
1 parent 1b6f7ca commit 00877b8

File tree

2 files changed

+176
-38
lines changed

2 files changed

+176
-38
lines changed

apps/frontend/src/pages/servers/index.vue

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
ref="purchaseModal"
1111
:product="selectedProduct"
1212
:country="country"
13+
:custom-server="customServer"
1314
:publishable-key="config.public.stripePublishableKey"
1415
:send-billing-request="
1516
async (body) =>
@@ -456,7 +457,7 @@
456457
<button
457458
v-if="!isSmallAtCapacity"
458459
class="!bg-highlight-blue !font-medium !text-blue"
459-
@click="selectProduct(pyroProducts[0])"
460+
@click="selectProduct(pyroPlanProducts[0])"
460461
>
461462
Get Started
462463
<RightArrowIcon class="!min-h-4 !min-w-4 !text-blue" />
@@ -514,7 +515,7 @@
514515
<button
515516
v-if="!isMediumAtCapacity"
516517
class="shadow-xl"
517-
@click="selectProduct(pyroProducts[1])"
518+
@click="selectProduct(pyroPlanProducts[1])"
518519
>
519520
Get Started
520521
<RightArrowIcon class="!min-h-4 !min-w-4" />
@@ -561,7 +562,7 @@
561562
<button
562563
v-if="!isLargeAtCapacity"
563564
class="!bg-highlight-purple !font-medium !text-purple"
564-
@click="selectProduct(pyroProducts[2])"
565+
@click="selectProduct(pyroPlanProducts[2])"
565566
>
566567
Get Started
567568
<RightArrowIcon class="!min-h-4 !min-w-4 !text-purple" />
@@ -598,14 +599,27 @@
598599

599600
<div class="flex w-full flex-col-reverse gap-2 md:w-auto md:flex-col md:items-center">
600601
<ButtonStyled color="standard" size="large">
601-
<NuxtLink :to="loggedOut ? redirectUrl : '/servers/custom'" class="w-full md:w-fit">
602+
<button
603+
v-if="!isLargeAtCapacity"
604+
class="w-full md:w-fit"
605+
@click="selectProduct(pyroProducts, true)"
606+
>
607+
Build your own
608+
<RightArrowIcon class="!min-h-4 !min-w-4" />
609+
</button>
610+
<NuxtLink
611+
v-else
612+
:to="loggedOut ? redirectUrl : 'https://support.modrinth.com'"
613+
:target="loggedOut ? '_self' : '_blank'"
614+
class="w-full md:w-fit"
615+
>
602616
<template v-if="loggedOut">
603617
Login
604618
<UserIcon class="!min-h-4 !min-w-4" />
605619
</template>
606620
<template v-else>
607-
Build your own
608-
<RightArrowIcon class="!min-h-4 !min-w-4" />
621+
Out of Stock
622+
<ExternalIcon class="!min-h-4 !min-w-4" />
609623
</template>
610624
</NuxtLink>
611625
</ButtonStyled>
@@ -633,7 +647,15 @@ import { products } from "~/generated/state.json";
633647
import LoaderIcon from "~/components/ui/servers/icons/LoaderIcon.vue";
634648
635649
const pyroProducts = products.filter((p) => p.metadata.type === "pyro");
636-
pyroProducts.sort((a, b) => a.metadata.ram - b.metadata.ram);
650+
const pyroPlanProducts = pyroProducts.filter(
651+
(p) => p.metadata.ram === 4096 || p.metadata.ram === 6144 || p.metadata.ram === 8192,
652+
);
653+
pyroPlanProducts.sort((a, b) => a.metadata.ram - b.metadata.ram);
654+
// yep. this is a thing.
655+
if (!pyroProducts.metadata) {
656+
pyroProducts.metadata = {};
657+
}
658+
pyroProducts.metadata.type = "pyro";
637659
638660
const title = "Modrinth Servers";
639661
const description =
@@ -664,6 +686,7 @@ const country = useUserCountry();
664686
const customer = ref(null);
665687
const paymentMethods = ref([]);
666688
const selectedProduct = ref(null);
689+
const customServer = ref(false);
667690
const showModal = ref(false);
668691
const modalKey = ref(0);
669692
@@ -692,7 +715,7 @@ const { data: capacityStatuses, refresh: refreshCapacity } = await useAsyncData(
692715
"ServerCapacityAll",
693716
async () => {
694717
try {
695-
const capacityChecks = pyroProducts.map((product) =>
718+
const capacityChecks = pyroPlanProducts.map((product) =>
696719
usePyroFetch("capacity", {
697720
method: "POST",
698721
body: {
@@ -796,7 +819,7 @@ const isAtCapacity = computed(
796819
() => isSmallAtCapacity.value && isMediumAtCapacity.value && isLargeAtCapacity.value,
797820
);
798821
799-
const selectProduct = async (product) => {
822+
const selectProduct = async (product, custom) => {
800823
if (isAtCapacity.value) {
801824
addNotification({
802825
group: "main",
@@ -824,6 +847,7 @@ const selectProduct = async (product) => {
824847
return;
825848
}
826849
850+
customServer.value = !!custom;
827851
selectedProduct.value = product;
828852
showModal.value = true;
829853
modalKey.value++;
@@ -856,7 +880,8 @@ const openPurchaseModal = () => {
856880
return;
857881
}
858882
859-
selectedProduct.value = pyroProducts[0];
883+
customServer.value = false;
884+
selectedProduct.value = pyroPlanProducts[0];
860885
showModal.value = true;
861886
modalKey.value++;
862887
nextTick(() => {

0 commit comments

Comments
 (0)