update subscription CANCELLED status
This commit is contained in:
parent
c8b67a291c
commit
7e7a15c52b
@ -7,7 +7,6 @@ import {
|
|||||||
useContext,
|
useContext,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
import { Button, Typography } from "@/components/ui";
|
import { Button, Typography } from "@/components/ui";
|
||||||
@ -16,7 +15,6 @@ import { performUserSubscriptionAction } from "@/entities/subscriptions/actions"
|
|||||||
import { UserSubscription } from "@/entities/subscriptions/types";
|
import { UserSubscription } from "@/entities/subscriptions/types";
|
||||||
import { useRetainingStore } from "@/providers/retaining-store-provider";
|
import { useRetainingStore } from "@/providers/retaining-store-provider";
|
||||||
import { useToast } from "@/providers/toast-provider";
|
import { useToast } from "@/providers/toast-provider";
|
||||||
import { ROUTES } from "@/shared/constants/client-routes";
|
|
||||||
|
|
||||||
import styles from "./CancelSubscriptionModalProvider.module.scss";
|
import styles from "./CancelSubscriptionModalProvider.module.scss";
|
||||||
|
|
||||||
@ -36,7 +34,6 @@ export default function CancelSubscriptionModalProvider({
|
|||||||
}: {
|
}: {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
|
||||||
const t = useTranslations("Subscriptions");
|
const t = useTranslations("Subscriptions");
|
||||||
const { addToast } = useToast();
|
const { addToast } = useToast();
|
||||||
|
|
||||||
@ -74,10 +71,8 @@ export default function CancelSubscriptionModalProvider({
|
|||||||
message: t("success_cancel_message"),
|
message: t("success_cancel_message"),
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
});
|
});
|
||||||
const timer = setTimeout(() => {
|
// Data will be automatically refreshed due to cache invalidation in the action
|
||||||
router.push(ROUTES.profile());
|
// No need to redirect, let the user see the updated subscription status
|
||||||
}, 3000);
|
|
||||||
return () => clearTimeout(timer);
|
|
||||||
}
|
}
|
||||||
setIsLoadingCancelButton(false);
|
setIsLoadingCancelButton(false);
|
||||||
|
|
||||||
@ -88,7 +83,6 @@ export default function CancelSubscriptionModalProvider({
|
|||||||
close,
|
close,
|
||||||
addToast,
|
addToast,
|
||||||
t,
|
t,
|
||||||
router,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const handleStay = useCallback(() => {
|
const handleStay = useCallback(() => {
|
||||||
|
|||||||
@ -30,12 +30,16 @@ export default function SubscriptionTable({ subscription }: ITableProps) {
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
t("table.subscription_status"),
|
t("table.subscription_status"),
|
||||||
t(
|
subscription.subscriptionStatus === "CANCELLED" && subscription.cancellationDate
|
||||||
`table.subscription_status_value.${subscription.subscriptionStatus}`,
|
? t(
|
||||||
{
|
`table.subscription_status_value.${subscription.subscriptionStatus}`,
|
||||||
date: formatDate(subscription.cancellationDate) || "",
|
{
|
||||||
}
|
date: formatDate(subscription.cancellationDate) as string,
|
||||||
),
|
}
|
||||||
|
)
|
||||||
|
: subscription.subscriptionStatus === "CANCELLED"
|
||||||
|
? "Cancelled"
|
||||||
|
: t(`table.subscription_status_value.${subscription.subscriptionStatus}`),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
t("table.billing_period"),
|
t("table.billing_period"),
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
|
import { revalidateTag } from "next/cache";
|
||||||
|
|
||||||
import { http } from "@/shared/api/httpClient";
|
import { http } from "@/shared/api/httpClient";
|
||||||
import { API_ROUTES } from "@/shared/constants/api-routes";
|
import { API_ROUTES } from "@/shared/constants/api-routes";
|
||||||
import { ActionResponse } from "@/types";
|
import { ActionResponse } from "@/types";
|
||||||
@ -23,6 +25,9 @@ export async function performUserSubscriptionAction(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Invalidate subscriptions cache to refresh the data
|
||||||
|
revalidateTag("subscriptions");
|
||||||
|
|
||||||
return { data: response, error: null };
|
return { data: response, error: null };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user