summaryrefslogtreecommitdiffhomepage
path: root/packages/console/app/src/routes/workspace
diff options
context:
space:
mode:
Diffstat (limited to 'packages/console/app/src/routes/workspace')
-rw-r--r--packages/console/app/src/routes/workspace/[id]/billing/black-section.module.css6
-rw-r--r--packages/console/app/src/routes/workspace/[id]/billing/black-section.tsx50
2 files changed, 54 insertions, 2 deletions
diff --git a/packages/console/app/src/routes/workspace/[id]/billing/black-section.module.css b/packages/console/app/src/routes/workspace/[id]/billing/black-section.module.css
index c3a2af639..c189f0d64 100644
--- a/packages/console/app/src/routes/workspace/[id]/billing/black-section.module.css
+++ b/packages/console/app/src/routes/workspace/[id]/billing/black-section.module.css
@@ -1,2 +1,8 @@
.root {
+ [data-slot="title-row"] {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ gap: var(--space-4);
+ }
}
diff --git a/packages/console/app/src/routes/workspace/[id]/billing/black-section.tsx b/packages/console/app/src/routes/workspace/[id]/billing/black-section.tsx
index d4876b242..2eece1b62 100644
--- a/packages/console/app/src/routes/workspace/[id]/billing/black-section.tsx
+++ b/packages/console/app/src/routes/workspace/[id]/billing/black-section.tsx
@@ -1,11 +1,57 @@
+import { action, useParams, useAction, useSubmission, json } from "@solidjs/router"
+import { createStore } from "solid-js/store"
+import { Billing } from "@opencode-ai/console-core/billing.js"
+import { withActor } from "~/context/auth.withActor"
+import { queryBillingInfo } from "../../common"
import styles from "./black-section.module.css"
+const createSessionUrl = action(async (workspaceID: string, returnUrl: string) => {
+ "use server"
+ return json(
+ await withActor(
+ () =>
+ Billing.generateSessionUrl({ returnUrl })
+ .then((data) => ({ error: undefined, data }))
+ .catch((e) => ({
+ error: e.message as string,
+ data: undefined,
+ })),
+ workspaceID,
+ ),
+ { revalidate: queryBillingInfo.key },
+ )
+}, "sessionUrl")
+
export function BlackSection() {
+ const params = useParams()
+ const sessionAction = useAction(createSessionUrl)
+ const sessionSubmission = useSubmission(createSessionUrl)
+ const [store, setStore] = createStore({
+ sessionRedirecting: false,
+ })
+
+ async function onClickSession() {
+ const result = await sessionAction(params.id!, window.location.href)
+ if (result.data) {
+ setStore("sessionRedirecting", true)
+ window.location.href = result.data
+ }
+ }
+
return (
<section class={styles.root}>
<div data-slot="section-title">
- <h2>Black</h2>
- <p>You are subscribed to Black.</p>
+ <h2>Subscription</h2>
+ <div data-slot="title-row">
+ <p>You are subscribed to OpenCode Black for $200 per month.</p>
+ <button
+ data-color="primary"
+ disabled={sessionSubmission.pending || store.sessionRedirecting}
+ onClick={onClickSession}
+ >
+ {sessionSubmission.pending || store.sessionRedirecting ? "Loading..." : "Manage Subscription"}
+ </button>
+ </div>
</div>
</section>
)