Skip to content

Commit

Permalink
refactor(new products): added multiple subscription cards in payment …
Browse files Browse the repository at this point in the history
…page
  • Loading branch information
joeldsouzax committed Oct 5, 2023
1 parent ea4082c commit ddea36c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
25 changes: 23 additions & 2 deletions apps/research/src/components/settings/payments/Payments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Image from 'next/image';
import { getUserInformation } from 'core';
import { SignUpCall } from '@/components';
import { appStructure } from '@/config';
import { ProductPlans } from '@/types';

const { Text, Link } = Typography;
const { Ribbon } = Badge;
Expand Down Expand Up @@ -66,7 +67,25 @@ const Payments: React.FC = () => {
});
}, []);

const getPaymentCard = (status: typeof productStatus.state) => {
const getPaymentCard = (plan: ProductPlans) => {
let status: string | null = 'loading';

if (plan === 'aoc') {
status = aocProductStatus.state;
}

if (plan === 'nn') {
status = nnProductStatus.state;
}

if (plan === 'twic') {
status = twicProductStatus.state;
}

if (plan === 'pro') {
status = productStatus.state;
}

switch (status) {
case 'blocked':
return (
Expand Down Expand Up @@ -282,7 +301,9 @@ const Payments: React.FC = () => {
showIcon
/>
)}
{getPaymentCard(productStatus.state)}
{Object.keys(appStructure.payments).map((plan) =>
getPaymentCard(plan as ProductPlans)
)}
</>
);
};
Expand Down
10 changes: 5 additions & 5 deletions apps/research/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export const appStructure: AppStructure = {
},
],
payments: {
default: {
productId: process.env.NEXT_PUBLIC_STRIPE_PRODUCT_ID! as string,
annualPriceId: process.env.NEXT_PUBLIC_STRIPE_YEARLY_PRICE_ID!,
monthlyPriceId: process.env.NEXT_PUBLIC_STRIPE_MONTHLY_PRICE_ID!,
},
// default: {
// productId: process.env.NEXT_PUBLIC_STRIPE_PRODUCT_ID! as string,
// annualPriceId: process.env.NEXT_PUBLIC_STRIPE_YEARLY_PRICE_ID!,
// monthlyPriceId: process.env.NEXT_PUBLIC_STRIPE_MONTHLY_PRICE_ID!,
// },
pro: {
productId: process.env.NEXT_PUBLIC_STRIPE_PRODUCT_ID_PRO! as string,
annualPriceId: process.env.NEXT_PUBLIC_STRIPE_YEARLY_PRICE_ID_PRO!,
Expand Down
3 changes: 2 additions & 1 deletion apps/research/src/types/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export interface Payments {
monthlyPriceId: string;
}

export type ProductPlans = 'aoc' | 'nn' | 'twic' | 'pro';
export interface AppStructure {
navigation: Array<Navigation>;
payments: Record<'default' | 'aoc' | 'nn' | 'twic' | 'pro', Payments>;
payments: Record<'aoc' | 'nn' | 'twic' | 'pro', Payments>;
notifications: Record<number, { description: string; isPro: boolean }>;
}

Expand Down

0 comments on commit ddea36c

Please sign in to comment.