Skip to content

Commit c59da55

Browse files
drew-harrisskeptrunedev
authored andcommitted
feat: billing pages
1 parent b21a69f commit c59da55

File tree

6 files changed

+265
-217
lines changed

6 files changed

+265
-217
lines changed

frontends/dashboard/src/components/EditUserModal.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { Show, createEffect, createMemo, useContext } from "solid-js";
22
import { createSignal } from "solid-js";
33
import { Dialog, DialogOverlay, DialogPanel, DialogTitle } from "terracotta";
44
import { UserContext } from "../contexts/UserContext";
5-
import { DefaultError, SlimUser, fromI32ToUserRole } from "shared/types";
5+
import { DefaultError, fromI32ToUserRole } from "shared/types";
66
import { UserRole, fromUserRoleToI32, stringToUserRole } from "shared/types";
77
import { createToast } from "./ShowToasts";
8+
import { SlimUser } from "trieve-ts-sdk";
89

910
export interface InviteUserModalProps {
1011
editingUser: SlimUser | null;
@@ -23,13 +24,13 @@ export const EditUserModal = (props: InviteUserModalProps) => {
2324

2425
const currentUserRole = createMemo(() => {
2526
return userContext.user?.()?.user_orgs.find((val) => {
26-
return val.organization_id === userContext.selectedOrganizationId?.();
27+
return val.organization_id === userContext.selectedOrg().id;
2728
})?.role;
2829
});
2930

3031
const editingUserRole = createMemo(() => {
3132
return props.editingUser?.user_orgs.find((val) => {
32-
return val.organization_id === userContext.selectedOrganizationId?.();
33+
return val.organization_id === userContext.selectedOrg().id;
3334
})?.role;
3435
});
3536

@@ -41,7 +42,7 @@ export const EditUserModal = (props: InviteUserModalProps) => {
4142
"Content-Type": "application/json",
4243
},
4344
body: JSON.stringify({
44-
organization_id: userContext.selectedOrganizationId?.(),
45+
organization_id: userContext.selectedOrg().id,
4546
user_id: props.editingUser?.id,
4647
role: fromUserRoleToI32(role()),
4748
}),

frontends/dashboard/src/components/InviteUserModal.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const InviteUserModal = (props: InviteUserModalProps) => {
2121
const userContext = useContext(UserContext);
2222

2323
const currentUserRole = createMemo(() => {
24-
const selectedOrgId = userContext.selectedOrganizationId?.();
24+
const selectedOrgId = userContext.selectedOrg().id;
2525
if (!selectedOrgId) return 0;
2626
return (
2727
userContext
@@ -49,16 +49,16 @@ export const InviteUserModal = (props: InviteUserModalProps) => {
4949
credentials: "include",
5050
headers: {
5151
"Content-Type": "application/json",
52-
"TR-Organization": userContext.selectedOrganizationId?.() ?? "",
52+
"TR-Organization": userContext.selectedOrg().id ?? "",
5353
},
5454
body: JSON.stringify({
55-
organization_id: userContext.selectedOrganizationId?.(),
55+
organization_id: userContext.selectedOrg().id,
5656
email: email(),
5757
user_role: fromUserRoleToI32(role()),
5858
app_url: apiHost,
59-
redirect_uri: `${
60-
window.location.origin
61-
}/dashboard/${userContext.selectedOrganizationId?.()}`,
59+
redirect_uri: `${window.location.origin}/?org=${
60+
userContext.selectedOrg().id
61+
}`,
6262
}),
6363
}).then((res) => {
6464
setSendingEmail(false);

frontends/dashboard/src/components/InvoicesTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
} from "solid-js";
1111
import { UserContext } from "../contexts/UserContext";
1212
import { createToast } from "./ShowToasts";
13-
import { StripeInvoice } from "../types/apiTypes";
1413
import { TbFileInvoice } from "solid-icons/tb";
15-
import { formatDate, usdFormatter } from "../formatters";
14+
import { formatDate } from "../utils/formatters";
15+
import { StripeInvoice } from "trieve-ts-sdk";
1616

1717
export const InvoicesTable = () => {
1818
const api_host = import.meta.env.VITE_API_HOST as unknown as string;

frontends/dashboard/src/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ApiKeys } from "./pages/dataset/ApiKeys.tsx";
1717
import { OrganizationLayout } from "./layouts/OrganizationLayout.tsx";
1818
import { OrganizationHomepage } from "./pages/orgs/OrganizationHomepage.tsx";
1919
import { OrgUserPage } from "./pages/orgs/OrgUserPage.tsx";
20+
import { OrgBillingPage } from "./pages/orgs/OrgBillingPage.tsx";
2021

2122
if (!DEV) {
2223
Sentry.init({
@@ -64,6 +65,10 @@ const routes: RouteDefinition[] = [
6465
path: "/users",
6566
component: OrgUserPage,
6667
},
68+
{
69+
path: "/billing",
70+
component: OrgBillingPage,
71+
},
6772
{
6873
path: "*404",
6974
component: () => <div>404</div>,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { createEffect, createSignal, onCleanup, useContext } from "solid-js";
2+
import { UserContext } from "../../contexts/UserContext";
3+
import { OrganizationAndSubAndPlan } from "shared/types";
4+
import { PlansTable } from "../../components/PlansTable";
5+
import { createToast } from "../../components/ShowToasts";
6+
import { InvoicesTable } from "../../components/InvoicesTable";
7+
8+
export const OrgBillingPage = () => {
9+
const api_host = import.meta.env.VITE_API_HOST as unknown as string;
10+
11+
const userContext = useContext(UserContext);
12+
const [orgSubPlan, setOrgSubPlan] =
13+
createSignal<OrganizationAndSubAndPlan | null>(null);
14+
15+
createEffect(() => {
16+
const orgSubPlanAbortController = new AbortController();
17+
void fetch(`${api_host}/organization/${userContext.selectedOrg().id}`, {
18+
credentials: "include",
19+
headers: {
20+
"TR-Organization": userContext.selectedOrg().id,
21+
},
22+
signal: orgSubPlanAbortController.signal,
23+
})
24+
.then((res) => {
25+
if (res.status === 403) {
26+
createToast({
27+
title: "Error",
28+
type: "error",
29+
message:
30+
"It is likely that an admin or owner recently increased your role to admin or owner. Please sign out and sign back in to see the changes.",
31+
timeout: 10000,
32+
});
33+
return null;
34+
}
35+
36+
return res.json();
37+
})
38+
.then((data) => {
39+
setOrgSubPlan(data);
40+
});
41+
42+
onCleanup(() => {
43+
orgSubPlanAbortController.abort();
44+
});
45+
});
46+
47+
return (
48+
<div class="flex w-full flex-col gap-y-12">
49+
<PlansTable currentOrgSubPlan={orgSubPlan()} />
50+
<InvoicesTable />
51+
</div>
52+
);
53+
};

0 commit comments

Comments
 (0)