price cards
This commit is contained in:
1 parent
07efd08837
commit
53355cad04
7 files changed
+155
-33
No files matched your search
@@ -4,10 +4,13 @@ import Box from "@mui/material/Box";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { Button } from "@/components/inputs";
|
||||
|
||||
import { useAppSelector } from "@/hooks/AppHooks";
|
||||
import { useAppDispatch, useAppSelector } from "@/hooks/AppHooks";
|
||||
import { useGet, usePost } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import type { Entitlements, PlanKey } from "@/types/entitlements";
|
||||
import { useEffect } from "react";
|
||||
import type { IUser } from "@/types/user";
|
||||
import { setSelectedTeamId, setUser } from "@/features/authSlice";
|
||||
|
||||
const BillingPage = () => {
|
||||
const { user } = useAppSelector((state) => state.auth);
|
||||
@@ -16,10 +19,31 @@ const BillingPage = () => {
|
||||
{},
|
||||
{}
|
||||
);
|
||||
const { response: meResponse } = useGet<ApiResponse<IUser>>(
|
||||
"/auth/me",
|
||||
{},
|
||||
{ refreshInterval: 10000 }
|
||||
);
|
||||
const { post, loading: isPosting } = usePost();
|
||||
const plans = response?.data ?? [];
|
||||
|
||||
const theme = useTheme();
|
||||
const selectedPlan = user?.entitlements?.plan || null;
|
||||
const dispatch = useAppDispatch();
|
||||
const selectedTeamId = useAppSelector((s) => s.auth.selectedTeamId);
|
||||
|
||||
useEffect(() => {
|
||||
const freshUser = meResponse?.data;
|
||||
if (!freshUser) return;
|
||||
dispatch(setUser(freshUser));
|
||||
|
||||
if (
|
||||
!selectedTeamId ||
|
||||
!freshUser.teams.find((t) => t.id === selectedTeamId)
|
||||
) {
|
||||
dispatch(setSelectedTeamId(freshUser.teams[0].id));
|
||||
}
|
||||
}, [meResponse, dispatch, selectedTeamId]);
|
||||
|
||||
const handlePlanClick = async (planKey: PlanKey) => {
|
||||
const result = await post("/billing/subscribe", { planKey });
|
||||
|
||||
Reference in new issue
Block a user