w-aura/src/routerComponents/Palmistry/v1/CheckSubscriptionOutlet/index.tsx
Daniil Chemerkin c4759f35a5 Develop
2024-09-26 14:24:20 +00:00

29 lines
821 B
TypeScript

import { useAuth } from "@/auth";
import routes from "@/routes";
import { selectors } from "@/store";
import { useSelector } from "react-redux";
import { Navigate, Outlet } from "react-router-dom";
interface ICheckSubscriptionOutletProps {
subscribedReturnUrl?: string;
unsubscribedReturnUrl?: string;
}
function CheckSubscriptionOutlet({
subscribedReturnUrl = routes.client.home(),
unsubscribedReturnUrl,
}: ICheckSubscriptionOutletProps) {
const status = useSelector(selectors.selectStatus);
const { user } = useAuth();
if (user && status === "subscribed") {
return <Navigate to={subscribedReturnUrl} replace={true} />;
}
if (unsubscribedReturnUrl?.length) {
return <Navigate to={unsubscribedReturnUrl} replace={true} />;
}
return <Outlet />;
}
export default CheckSubscriptionOutlet;