wip: zen
This commit is contained in:
parent
aae387f7dc
commit
1d58b55482
3 changed files with 19 additions and 25 deletions
|
|
@ -2,17 +2,7 @@ import "./workspace.css"
|
||||||
import { useAuthSession } from "~/context/auth.session"
|
import { useAuthSession } from "~/context/auth.session"
|
||||||
import { IconLogo } from "../component/icon"
|
import { IconLogo } from "../component/icon"
|
||||||
import { withActor } from "~/context/auth.withActor"
|
import { withActor } from "~/context/auth.withActor"
|
||||||
import {
|
import { query, action, redirect, createAsync, RouteSectionProps, useParams, A } from "@solidjs/router"
|
||||||
query,
|
|
||||||
action,
|
|
||||||
redirect,
|
|
||||||
createAsync,
|
|
||||||
RouteSectionProps,
|
|
||||||
Navigate,
|
|
||||||
useNavigate,
|
|
||||||
useParams,
|
|
||||||
A,
|
|
||||||
} from "@solidjs/router"
|
|
||||||
import { User } from "@opencode/console-core/user.js"
|
import { User } from "@opencode/console-core/user.js"
|
||||||
import { Actor } from "@opencode/console-core/actor.js"
|
import { Actor } from "@opencode/console-core/actor.js"
|
||||||
import { getRequestEvent } from "solid-js/web"
|
import { getRequestEvent } from "solid-js/web"
|
||||||
|
|
@ -21,7 +11,8 @@ const getUserInfo = query(async (workspaceID: string) => {
|
||||||
"use server"
|
"use server"
|
||||||
return withActor(async () => {
|
return withActor(async () => {
|
||||||
const actor = Actor.assert("user")
|
const actor = Actor.assert("user")
|
||||||
return await User.fromID(actor.properties.userID)
|
const email = await User.getAccountEmail(actor.properties.userID)
|
||||||
|
return { email }
|
||||||
}, workspaceID)
|
}, workspaceID)
|
||||||
}, "userInfo")
|
}, "userInfo")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@ import { z } from "zod"
|
||||||
import { Resource } from "@opencode/console-resource"
|
import { Resource } from "@opencode/console-resource"
|
||||||
import { Identifier } from "./identifier"
|
import { Identifier } from "./identifier"
|
||||||
import { centsToMicroCents } from "./util/price"
|
import { centsToMicroCents } from "./util/price"
|
||||||
import { UserTable } from "./schema/user.sql"
|
import { User } from "./user"
|
||||||
import { AccountTable } from "./schema/account.sql"
|
|
||||||
|
|
||||||
export namespace Billing {
|
export namespace Billing {
|
||||||
export const CHARGE_NAME = "opencode credits"
|
export const CHARGE_NAME = "opencode credits"
|
||||||
|
|
@ -172,16 +171,7 @@ export namespace Billing {
|
||||||
const user = Actor.assert("user")
|
const user = Actor.assert("user")
|
||||||
const { successUrl, cancelUrl } = input
|
const { successUrl, cancelUrl } = input
|
||||||
|
|
||||||
const email = await Database.use((tx) =>
|
const email = await User.getAccountEmail(user.properties.userID)
|
||||||
tx
|
|
||||||
.select({
|
|
||||||
email: AccountTable.email,
|
|
||||||
})
|
|
||||||
.from(UserTable)
|
|
||||||
.innerJoin(AccountTable, eq(UserTable.accountID, AccountTable.id))
|
|
||||||
.where(and(eq(UserTable.id, user.properties.userID), eq(UserTable.workspaceID, Actor.workspace())))
|
|
||||||
.then((rows) => rows[0]?.email),
|
|
||||||
)
|
|
||||||
const customer = await Billing.get()
|
const customer = await Billing.get()
|
||||||
const session = await Billing.stripe().checkout.sessions.create({
|
const session = await Billing.stripe().checkout.sessions.create({
|
||||||
mode: "payment",
|
mode: "payment",
|
||||||
|
|
@ -216,7 +206,7 @@ export namespace Billing {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
customer_email: email,
|
customer_email: email!,
|
||||||
customer_creation: "always",
|
customer_creation: "always",
|
||||||
}),
|
}),
|
||||||
currency: "usd",
|
currency: "usd",
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,19 @@ export namespace User {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const getAccountEmail = fn(z.string(), (id) =>
|
||||||
|
Database.use((tx) =>
|
||||||
|
tx
|
||||||
|
.select({
|
||||||
|
email: AccountTable.email,
|
||||||
|
})
|
||||||
|
.from(UserTable)
|
||||||
|
.leftJoin(AccountTable, eq(UserTable.accountID, AccountTable.id))
|
||||||
|
.where(and(eq(UserTable.workspaceID, Actor.workspace()), eq(UserTable.id, id)))
|
||||||
|
.then((rows) => rows[0]?.email),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
export const invite = fn(
|
export const invite = fn(
|
||||||
z.object({
|
z.object({
|
||||||
email: z.string(),
|
email: z.string(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue