Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions apps/web/components/UpgradePlan/Plans/PlanCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import { plansApi, useSubscription } from 'subos-frontend';
import { Card, Text, Badge, Stack, Divider, LoadingOverlay } from '@mantine/core';
import { Button } from '@ui/button';
import { colors, PLANCODEENUM, ROUTES } from '@config';
import { colors, NOTIFICATION_KEYS, PLANCODEENUM, ROUTES } from '@config';
import { Plan } from './Plans';
import { PlanFeature } from './PlanFeature';
import useStyles from './Plans.styles';
Expand All @@ -28,8 +28,11 @@ export function PlanCard({ plan, isYearly }: PlanCardProps) {
try {
setIsLoading(true);
await fetchSubscription(profileInfo.email);
} catch (err) {
notify('Failed to fetch subscription');
} catch (err: any) {
notify(NOTIFICATION_KEYS.ERROR_FETCHING_SUBSCRIPTION_DETAILS, {
title: 'Failed to fetch subscription',
message: err?.message,
});
} finally {
setIsLoading(false);
}
Expand All @@ -42,9 +45,9 @@ export function PlanCard({ plan, isYearly }: PlanCardProps) {
setIsLoading(true);
try {
const response = await createPaymentSession(plan.code, {
returnUrl: `${window.location.origin}/${ROUTES.SUBSCRIPTION_STATUS}`,
returnUrl: `${window.location.origin}${ROUTES.SUBSCRIPTION_STATUS}`,
externalId: profileInfo?.email,
cancelUrl: `${window.location.origin}/${ROUTES.PAYMENT_CANCEL}`,
cancelUrl: `${window.location.origin}${ROUTES.PAYMENT_CANCEL}`,
});
if (response?.success && response?.data?.checkoutUrl) {
window.location.href = response?.data?.checkoutUrl;
Expand All @@ -54,7 +57,10 @@ export function PlanCard({ plan, isYearly }: PlanCardProps) {

return null;
} catch (err: any) {
notify('Failed to create payment session');
notify(NOTIFICATION_KEYS.ERROR_CREATE_CHECKOUT_SESSION, {
title: 'Failed to create the checkout session',
message: err?.message,
});
} finally {
setIsLoading(false);
}
Expand Down
1 change: 1 addition & 0 deletions apps/web/config/constants.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export const NOTIFICATION_KEYS = {

MEMBERSHIP_CANCELLED: 'MEMBERSHIP_CANCELLED',
MEMBERSHIP_PURCHASED: 'MEMBERSHIP_PURCHASED',
ERROR_CREATE_CHECKOUT_SESSION: 'ERROR_CREATE_PAYMENT_SESSION',
ERROR_FETCHING_SUBSCRIPTION_DETAILS: 'ERROR_FETCHING_SUBSCRIPTION_DETAILS',

IMPORT_DUPLICATED: 'IMPORT_DUPLICATED',
Expand Down
Loading