Skip to content

Commit 1c8bfa9

Browse files
committed
refactor: components
1 parent 400b3e4 commit 1c8bfa9

File tree

6 files changed

+40
-26
lines changed

6 files changed

+40
-26
lines changed

src/app/(authenticated)/(dashboard)/[publicId]/settings/billing/page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { PlanDetails } from "@/components/billing/plan-details";
2-
import { Pricing } from "@/components/billing/pricing";
32
import { PageLayout } from "@/components/dashboard/page-layout";
43
import { api } from "@/trpc/server";
54
import type { Metadata } from "next";
@@ -15,8 +14,7 @@ const BillingPage = async () => {
1514

1615
return (
1716
<PageLayout title="Billing" description="manage your billing">
18-
<PlanDetails subscription={subscription} />
19-
<Pricing products={products} subscription={subscription} />
17+
<PlanDetails products={products} subscription={subscription} />
2018
</PageLayout>
2119
);
2220
};

src/components/billing/plan-details/index.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import { dayjsExt } from "@/common/dayjs";
22
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
33
import { badgeVariants } from "@/components/ui/badge";
4+
import { PricingModal, type PricingModalProps } from "../pricing-modal";
45

5-
import type { RouterOutputs } from "@/trpc/shared";
6+
interface PlanDetailsProps extends PricingModalProps {}
67

7-
type TSubscription =
8-
RouterOutputs["billing"]["getSubscription"]["subscription"];
9-
10-
interface PlanDetailsProps {
11-
subscription: TSubscription;
12-
}
13-
14-
export function PlanDetails({ subscription }: PlanDetailsProps) {
8+
export function PlanDetails({ subscription, products }: PlanDetailsProps) {
159
return (
1610
<div>
1711
<Alert>
1812
<AlertTitle>Plan Details</AlertTitle>
1913
<AlertDescription>
20-
<p>
21-
You are currently on the{" "}
22-
<span className={badgeVariants()}>
23-
{subscription ? subscription.price.product.name : "Free"}
24-
</span>{" "}
25-
plan.{" "}
26-
{subscription ? (
27-
<>
28-
Current billing cycle:{" "}
29-
{dayjsExt(subscription?.currentPeriodStart).format("ll")} -{" "}
30-
{dayjsExt(subscription?.currentPeriodEnd).format("ll")}
31-
</>
32-
) : null}
33-
</p>
14+
<div className="flex flex-col gap-y-3">
15+
<p>
16+
You are currently on the{" "}
17+
<span className={badgeVariants()}>
18+
{subscription ? subscription.price.product.name : "Free"}
19+
</span>{" "}
20+
plan.{" "}
21+
{subscription ? (
22+
<>
23+
Current billing cycle:{" "}
24+
{dayjsExt(subscription?.currentPeriodStart).format("ll")} -{" "}
25+
{dayjsExt(subscription?.currentPeriodEnd).format("ll")}
26+
</>
27+
) : null}
28+
</p>
29+
30+
<div className="flex items-center justify-center">
31+
<PricingModal subscription={subscription} products={products} />
32+
</div>
33+
</div>
3434
</AlertDescription>
3535
</Alert>
3636
</div>

src/components/billing/pricing/index.tsx renamed to src/components/billing/pricing-modal/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"use client";
22

33
import { getStripeClient } from "@/client-only/stripe";
4+
import Modal, { type ModalProps } from "@/components/common/modal";
5+
import { Button } from "@/components/ui/button";
46
import type { PricingPlanInterval, PricingType } from "@/prisma/enums";
57
import { api } from "@/trpc/react";
68
import type { RouterOutputs } from "@/trpc/shared";
@@ -136,3 +138,17 @@ export function Pricing({ products, subscription }: PricingProps) {
136138
<EmptyPlans />
137139
);
138140
}
141+
142+
export type PricingModalProps = PricingProps;
143+
144+
export function PricingModal({ products, subscription }: PricingModalProps) {
145+
return (
146+
<Modal
147+
title="Upgrade or manage plans"
148+
trigger={<Button variant="secondary">Upgrade or Manage plan</Button>}
149+
size="screen"
150+
>
151+
<Pricing products={products} subscription={subscription} />
152+
</Modal>
153+
);
154+
}

0 commit comments

Comments
 (0)