Skip to content

Commit aab4dbf

Browse files
committed
stripe working
1 parent e988202 commit aab4dbf

File tree

5 files changed

+86
-24
lines changed

5 files changed

+86
-24
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
{
44
"mode": "auto"
55
}
6-
]
6+
],
7+
"files.watcherExclude": {
8+
"**/target": true
9+
}
710
}

apps/dashboard/src/api/endpoints/teams/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ export async function postCreateCheckoutSession(
166166
}
167167
}
168168

169+
export interface IPostCustomerPortalResponse {
170+
url: string;
171+
}
172+
173+
export async function postCustomerPortal(
174+
teamId: string | number,
175+
): Promise<IPostCustomerPortalResponse> {
176+
const response = await client.post<IPostCustomerPortalResponse>(`/v1/teams/${teamId}/customer-portal`);
177+
178+
return response.data;
179+
}
180+
169181
export interface IGetCustomerSessionResponse {
170182
sessionId: string;
171183
}

apps/dashboard/src/hooks/team.query.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,23 @@ export const usePostCreateCheckoutSession = (
109109
);
110110
};
111111

112+
export const usePostCustomerPortal = (
113+
) => {
114+
const currentTeamId = useAuthenticationStore((state) => state.currentTeamId);
115+
return useQuery([], () => {
116+
if (!currentTeamId) {
117+
return Promise.resolve(null);
118+
}
119+
return TeamsAPI.postCustomerPortal(currentTeamId);
120+
});
121+
};
122+
123+
112124

113125
export const useGetCustomerSession = (
114126
) => {
115127
const currentTeamId = useAuthenticationStore((state) => state.currentTeamId);
116-
return useMutation(
117-
() => {
128+
return useQuery([], () => {
118129
if (!currentTeamId) {
119130
return Promise.resolve(null);
120131
}
Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
import { FunctionComponent, useState } from "react";
22
import Placeholder from "../../../../components/Placeholder";
33
import {
4+
Box,
5+
Button,
46
Card,
57
CardContent,
8+
CardHeader,
9+
Divider,
10+
Grid,
11+
List,
12+
ListItem,
13+
ListItemIcon,
14+
ListItemText,
15+
Typography,
16+
useTheme,
17+
Dialog,
18+
DialogActions,
19+
DialogContent,
20+
DialogContentText,
621
} from "@mui/material";
7-
import { useCurrentTeam, useGetCustomerSession } from "../../../../hooks/team.query";
22+
import { BsCheckLg } from "react-icons/bs";
23+
import {
24+
useCurrentTeam,
25+
usePostCustomerPortal,
26+
useGetCustomerSession,
27+
} from "../../../../hooks/team.query";
828
import * as TeamsAPI from "../../../../api/endpoints/teams";
929

1030
declare global {
@@ -20,30 +40,46 @@ declare global {
2040

2141
const TeamPlanTabView: FunctionComponent = () => {
2242
const { data: team, isLoading: isLoadingTeam } = useCurrentTeam();
23-
const { data: teamSubscription, isLoading: isLoadingSubscription } = useGetCustomerSession();
24-
25-
console.log(teamSubscription?.sessionId)
26-
43+
const { data: customerPortal, isLoading: isLoadingPortal } =
44+
usePostCustomerPortal();
45+
// const { data: teamSubscription, isLoading: isLoadingSubscription } =
46+
// useGetCustomerSession();
2747

2848
return (
2949
<>
30-
<Card>
31-
<CardContent>
32-
{(isLoadingTeam || isLoadingSubscription) ? (
33-
<Placeholder />
34-
) : (
50+
{isLoadingTeam ? (
51+
<Placeholder />
52+
) : (
53+
<>
54+
{team?.paymentPlan ? (
55+
<Card>
56+
<CardHeader title="Current Subscription" />
57+
<CardContent>
58+
<Typography variant="h6">{team?.paymentPlan}</Typography>
59+
<div>
60+
<a href={customerPortal?.url}>
61+
<button>Manage Subscriptions here </button>
62+
</a>
63+
</div>
64+
</CardContent>
65+
</Card>
66+
) : (
67+
<Card>
68+
<CardHeader title="Choose a Subscription"/>
69+
<CardContent>
3570
<stripe-pricing-table
36-
pricing-table-id="prctbl_1PzENqAAd26uMXu2gnpkNNGV"
37-
publishable-key="pk_test_51NjhPuAAd26uMXu2mDsC5CrJzCokmFCMDEiyZFGanTQAy2exlztxyuLDpg2TXC26LK8j9wqnACLAAwEyWS0AJ4r500U1rDn672"
38-
client-reference-id={team?.id}
39-
customer-session-client-secret={teamSubscription?.sessionId}
40-
41-
></stripe-pricing-table>
42-
)}
43-
</CardContent>
44-
</Card>
71+
pricing-table-id="prctbl_1PzENqAAd26uMXu2gnpkNNGV"
72+
publishable-key="pk_test_51NjhPuAAd26uMXu2mDsC5CrJzCokmFCMDEiyZFGanTQAy2exlztxyuLDpg2TXC26LK8j9wqnACLAAwEyWS0AJ4r500U1rDn672"
73+
client-reference-id={team?.id}
74+
// customer-session-client-secret={teamSubscription?.sessionId}
75+
></stripe-pricing-table>
76+
</CardContent>
77+
</Card>
78+
)}
79+
</>
80+
)}
4581
</>
4682
);
4783
};
4884

49-
export default TeamPlanTabView;
85+
export default TeamPlanTabView;

apps/dashboard/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineConfig({
1010
server: {
1111
proxy: {
1212
"/v1": {
13-
target: "http://localhost:8005",
13+
target: "http://localhost:8001",
1414
// target: "https://api.opsway.io",
1515
changeOrigin: true,
1616
},

0 commit comments

Comments
 (0)