Skip to content

Commit f19742a

Browse files
feat: Removed PlansModal and consolidated logic into PlanPricingTable
1 parent 8928b62 commit f19742a

File tree

5 files changed

+26
-65
lines changed

5 files changed

+26
-65
lines changed

apps/web/components/UpgradePlan/Plans/PlanCard.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import { useSubOSIntegration } from '@hooks/useSubOSIntegration';
1010
interface PlanCardProps {
1111
plan: Plan;
1212
isYearly: boolean;
13-
activePlanCode: string;
14-
email: string;
15-
projectId?: string;
1613
}
1714

1815
type BillingCycle = 'monthly' | 'yearly';
@@ -40,9 +37,10 @@ const mapToSubOSPlan = (plan: Plan, cycle: BillingCycle): any => {
4037
};
4138
};
4239

43-
export function PlanCard({ plan, isYearly, activePlanCode }: PlanCardProps) {
40+
export function PlanCard({ plan, isYearly }: PlanCardProps) {
4441
const { classes } = useStyles();
45-
const { selectPlan } = useSubOSIntegration();
42+
const { selectPlan, subscription } = useSubOSIntegration();
43+
console.log(subscription);
4644

4745
return (
4846
<Card
@@ -67,9 +65,9 @@ export function PlanCard({ plan, isYearly, activePlanCode }: PlanCardProps) {
6765
className={classes.button}
6866
fullWidth
6967
onClick={() => selectPlan(mapToSubOSPlan(plan, planBillingCycle))}
70-
disabled={plan.code === PLANCODEENUM.STARTER || activePlanCode === plan.code}
68+
disabled={plan.code === PLANCODEENUM.STARTER || subscription?.plan.code === plan.code}
7169
>
72-
{activePlanCode === plan.code ? 'Active Plan' : 'Choose Plan'}
70+
{subscription?.plan.code === plan.code ? 'Active Plan' : 'Choose Plan'}
7371
</Button>
7472
<Divider />
7573
</Stack>

apps/web/components/UpgradePlan/Plans/Plans.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@ export interface Plan {
2828
content: PlanContent;
2929
}
3030

31-
interface PlansProps {
32-
activePlanCode: string;
33-
email: string;
34-
projectId?: string;
35-
canceledOn?: string;
36-
expiryDate?: string;
37-
}
38-
39-
export function Plans({ activePlanCode, email, projectId }: PlansProps) {
31+
export function Plans() {
4032
const [showYearly, setShowYearly] = useState(true);
4133

4234
return (
@@ -61,14 +53,7 @@ export function Plans({ activePlanCode, email, projectId }: PlansProps) {
6153
<Divider />
6254
<Group grow align="flex-start">
6355
{plans[showYearly ? 'yearly' : 'monthly'].map((plan) => (
64-
<PlanCard
65-
key={plan.code}
66-
plan={plan}
67-
isYearly={showYearly}
68-
activePlanCode={activePlanCode}
69-
email={email}
70-
projectId={projectId}
71-
/>
56+
<PlanCard key={plan.code} plan={plan} isYearly={showYearly} />
7257
))}
7358
</Group>
7459
</Stack>

apps/web/components/UpgradePlan/Plans/PlansModal.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
import { Flex } from '@mantine/core';
2-
import { PlansModal } from './PlansModal';
1+
import { Flex, Title, Text } from '@mantine/core';
2+
import { Plans } from './Plans';
33

44
interface PlanPricingTableProps {
55
userProfile: IProfileData;
6-
activePlanCode: string;
76
}
87

9-
export function PlanPricingTable({ userProfile, activePlanCode }: PlanPricingTableProps) {
8+
export function PlanPricingTable({ userProfile }: PlanPricingTableProps) {
9+
if (!userProfile) {
10+
return (
11+
<Flex direction="column" align="center" justify="center" style={{ flexGrow: 1 }}>
12+
<Text>Loading profile information...</Text>
13+
</Flex>
14+
);
15+
}
16+
1017
return (
11-
<Flex key={userProfile?.email}>
12-
<PlansModal userProfile={userProfile} activePlanCode={activePlanCode} />
18+
<Flex direction="column" align="center" justify="flex-start">
19+
<Title order={2} align="center" mb="md">
20+
Choose the plan that works best for you
21+
</Title>
22+
<Flex direction="column" align="center" justify="center" style={{ flexGrow: 1 }}>
23+
<Plans />
24+
</Flex>
1325
</Flex>
1426
);
1527
}

apps/web/pages/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ import { AppLayout } from '@layouts/AppLayout';
77
import { PlanDetails } from '@components/home/PlanDetails';
88
import { PlanPricingTable } from '@components/UpgradePlan/Plans/PlansPricingTable';
99
import { useAppState } from 'store/app.context';
10-
import { useSubOSIntegration } from '@hooks/useSubOSIntegration';
1110
const { publicRuntimeConfig } = getConfig();
1211

1312
export default function Home() {
1413
const { profileInfo } = useAppState();
15-
const { subscription } = useSubOSIntegration();
1614

1715
return (
1816
<>
@@ -28,7 +26,7 @@ export default function Home() {
2826
<Stack>
2927
<Title order={2}>Home</Title>
3028
{publicRuntimeConfig.NEXT_PUBLIC_PAYMENT_GATEWAY_URL && <PlanDetails />}
31-
<PlanPricingTable userProfile={profileInfo!} activePlanCode={subscription?.plan.code} />
29+
<PlanPricingTable userProfile={profileInfo!} />
3230
</Stack>
3331
</>
3432
);

0 commit comments

Comments
 (0)