Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Change billing urls
Jakub Novakfa9093b63cc9
diff --git a/apps/web/src/app/(dashboard)/dashboard/page.tsx b/apps/web/src/app/(dashboard)/dashboard/page.tsxindex 80db92f24..0c3ea82f2 100644--- a/apps/web/src/app/(dashboard)/dashboard/page.tsx+++ b/apps/web/src/app/(dashboard)/dashboard/page.tsx@@ -198,7 +198,7 @@ function MainContent({ selectedItem, user, team, accessToken, currentApiKey, teacase 'keys':return <KeysContent currentTeam={team} />case 'usage':- return <UsageContent currentApiKey={currentApiKey} />+ return <UsageContent currentApiKey={currentApiKey} team={team} />case 'billing':return <BillingContent currentApiKey={currentApiKey} team={team} />case 'team':diff --git a/apps/web/src/app/(docs)/docs/pricing/Promo.tsx b/apps/web/src/app/(docs)/docs/pricing/Promo.tsxdeleted file mode 100644index 5344a39c7..000000000--- a/apps/web/src/app/(docs)/docs/pricing/Promo.tsx+++ /dev/null@@ -1,72 +0,0 @@-'use client'--import { useState } from 'react'-import { Button } from '@/components/Button'-import { useUser } from '@/utils/useUser'--function sendPromoCode(promoCode: string, teamID: string) {- return fetch('/docs/pricing/promo', {- method: 'POST',- body: JSON.stringify({- teamID,- promoCode,- }),- })-}--function Promo() {- const [code, setCode] = useState('')- const [error, setError] = useState('')- const { user } = useUser()-- async function applyPromoCode() {- if (!code) return- if (!user) {- setError('You must be signed in to apply a promo code')- }- setError('')-- if (!user || user?.teams.length === 0) {- setError('You must be a member of a team to apply a promo code')- return- }-- // TODO: Actually apply the promo code- const response = await sendPromoCode(code, user.teams[0].id)- const responseData = await response.json()-- console.log('repsonseData', responseData)- if (responseData.error) {- console.error('Error applying promo code:', responseData.error)- setError(responseData.error)- } else {- console.log('Promo code applied successfully')- location.reload()- }- }-- return (- <div className="flex flex-col items-start justify-start gap-1">- <div className="flex items-center justify-start gap-2">- <div className="flex flex-col items-start justify-start">- <input- className="p-2 min-w-[300px] bg-transparent text-zinc-900 outline-none placeholder:text-zinc-500 dark:text-white sm:text-sm border border-gray-800 rounded-lg"- placeholder="Enter promo code to unlock Pro tier"- value={code}- onChange={e => setCode(e.target.value)}- />- </div>- <Button- onClick={applyPromoCode}- >- Apply- </Button>- </div>- {error && (- <span className="text-red-500 font-medium">{error}</span>- )}- </div>- )-}--export default Promodiff --git a/apps/web/src/app/(docs)/docs/pricing/promo/route.ts b/apps/web/src/app/(docs)/docs/pricing/promo/route.tsdeleted file mode 100644index e0b7af912..000000000--- a/apps/web/src/app/(docs)/docs/pricing/promo/route.ts+++ /dev/null@@ -1,123 +0,0 @@-import { NextResponse as Response } from 'next/server'-import { createClient } from '@supabase/supabase-js'--const supabase = createClient(- process.env.NEXT_PUBLIC_SUPABASE_URL!,- process.env.SUPABASE_SERVICE_ROLE_KEY!,-)--export const dynamic = 'force-dynamic' // defaults to force-static-export async function POST(request: Request) {- // Read json data from request- const { promoCode, teamID } = await request.json()-- if (!promoCode) {- return new Response('Missing promo code', { status: 400 })- }-- if (!teamID) {- return new Response('Missing team ID', { status: 400 })- }-- // Check if there's associated tier with promo code- const { data: tiersData, error: tiersError } = await supabase- .from('tiers')- .select('id, promo_code, promo_starts_at, promo_ends_at')- .eq('promo_code', promoCode)-- if (tiersError) {- return new Response(tiersError.message, { status: 500 })- }-- if (tiersData.length === 0) {- return Response.json({- error: `Invalid promo code '${promoCode}'`,- })- }--- const { data: teamData, error: teamError } = await supabase- .from('teams')- .select('tier')- .eq('id', teamID)--- if (teamError) {- return new Response(teamError.message, { status: 500 })- }-- if (teamData.length === 0) {- return Response.json({- error: `Invalid team ID '${teamID}' - team not found`,- })- }-- const teamTier: string = teamData[0].tier-- // If team tier isn't a pro tier already, apply the promo tier- if (teamTier.startsWith('free_')) {- const now = new Date()-- const validFrom = new Date(tiersData[0].promo_starts_at)- if (now < validFrom) {- return Response.json({- error: `Promo code '${promoCode}' is not valid yet`,- })- }-- const validTo = new Date(tiersData[0].promo_ends_at)- if (now > validTo) {- return Response.json({- error: `Promo code '${promoCode}' has expired`,- })- }-- await supabase- .from('teams')- .update({ tier: tiersData[0].id })- .eq('id', teamID)-- } else if (teamTier.startsWith('promo_')) {- return Response.json({- error: 'Team already has promo active',- })- } else if (teamTier.startsWith('pro_')) {- return Response.json({- error: 'Team already has a pro tier',- })- }-- return Response.json({- message: `Applied promo code '${promoCode}' to team '${teamID}'`,- })-}--// Get the info about promo-export async function GET(request: Request) {- // Check if there's associated tier with promo code- const { searchParams } = new URL(request.url)- const id = searchParams.get('id')-- const { data: tiersData, error: tiersError } = await supabase- .from('tiers')- .select('id, promo_starts_at, promo_ends_at')- .eq('id', id)-- if (tiersError) {- return new Response(tiersError.message, { status: 500 })- }-- if (tiersData.length === 0) {- return Response.json({- error: `Invalid tier ID '${id}'`,- })- }-- const promo = tiersData[0]-- return Response.json({- name: promo.id,- validFrom: promo.promo_starts_at,- validTo: promo.promo_ends_at,- })-}\ No newline at end of filediff --git a/apps/web/src/components/Dashboard/Billing.tsx b/apps/web/src/components/Dashboard/Billing.tsxindex 4456c5286..550277039 100644--- a/apps/web/src/components/Dashboard/Billing.tsx+++ b/apps/web/src/components/Dashboard/Billing.tsx@@ -10,8 +10,6 @@ function formatCurrency(value: number) {return value.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}-const invoiceUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/invoices`-const creditsUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/usage`interface Invoice {cost: number@@ -27,7 +25,8 @@ export const BillingContent = ({ currentApiKey, team }: { currentApiKey: stringuseEffect(() => {const getInvoices = async function getInvoices() {setInvoices([])- const res = await fetch(invoiceUrl, {+ const res = await fetch(`${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/${team.id}/invoices`+, {headers: {'X-Team-API-Key': currentApiKey!,},@@ -42,7 +41,7 @@ export const BillingContent = ({ currentApiKey, team }: { currentApiKey: stringsetInvoices(invoices)setCredits(null)- const creditsRes = await fetch(creditsUrl, {+ const creditsRes = await fetch( `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/${team.id}/usage`, {headers: {'X-Team-API-Key': currentApiKey!,},diff --git a/apps/web/src/components/Dashboard/Keys.tsx b/apps/web/src/components/Dashboard/Keys.tsxindex d0fbb30be..de8ed38c8 100644--- a/apps/web/src/components/Dashboard/Keys.tsx+++ b/apps/web/src/components/Dashboard/Keys.tsx@@ -17,8 +17,6 @@ import { useToast } from '../ui/use-toast'import { createPagesBrowserClient } from '@supabase/auth-helpers-nextjs'import { Team } from '@/utils/useUser'-const createApiKeyUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/api-keys`-export const KeysContent = ({ currentTeam }: { currentTeam: Team }) => {const supabase = createPagesBrowserClient()@@ -77,7 +75,7 @@ export const KeysContent = ({ currentTeam }: { currentTeam: Team }) => {})}- const res = await fetch(createApiKeyUrl, {+ const res = await fetch(`${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/${currentTeam.id}/api-keys`, {method: 'POST',headers: {'X-Team-API-Key': currentTeam.apiKeys[0],diff --git a/apps/web/src/components/Dashboard/Team.tsx b/apps/web/src/components/Dashboard/Team.tsxindex 022634513..c60e6688c 100644--- a/apps/web/src/components/Dashboard/Team.tsx+++ b/apps/web/src/components/Dashboard/Team.tsx@@ -15,8 +15,6 @@ interface TeamMember {email: string}-const teamUsersUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/users`-const teamUpdateNameUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams`export const TeamContent = ({ team, user, teams, currentApiKey, setTeams, setCurrentTeam }: { team: Team, user: User, teams: Team[], currentApiKey: string | null, setTeams: (teams: Team[]) => void, setCurrentTeam: (team: Team) => void }) => {const supabase = createPagesBrowserClient()@@ -31,7 +29,7 @@ export const TeamContent = ({ team, user, teams, currentApiKey, setTeams, setCuruseEffect(() => {const getTeamMembers = async () => {- const res = await fetch(teamUsersUrl, {+ const res = await fetch(`${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/${team.id}/users`, {headers: {'X-Team-API-Key': currentApiKey!,},@@ -88,7 +86,7 @@ export const TeamContent = ({ team, user, teams, currentApiKey, setTeams, setCur}const changeTeamName = async () => {- const res = await fetch(teamUpdateNameUrl, {+ const res = await fetch(`${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/${team.id}`, {headers: {'X-Team-API-Key': currentApiKey!,'Content-Type': 'application/json',diff --git a/apps/web/src/components/Dashboard/Usage.tsx b/apps/web/src/components/Dashboard/Usage.tsxindex 4bf7fb53a..06e64f401 100644--- a/apps/web/src/components/Dashboard/Usage.tsx+++ b/apps/web/src/components/Dashboard/Usage.tsx@@ -3,8 +3,7 @@ import { Card, CardContent } from '@/components/ui/card'import LineChart from '@/components/Dashboard/Chart'import Spinner from '@/components/Spinner'import { toast } from '@/components/ui/use-toast'--const usageUrl = `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/usage`+import { Team } from '@/utils/useUser'type Usage = {@@ -23,7 +22,7 @@ type Series = {data: PlotData[]}-export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null }) => {+export const UsageContent = ({ currentApiKey, team }: { currentApiKey: string | null, team: Team }) => {const [vcpuData, setVcpuData] = useState<Series[]>([])const [vcpuHoursThisMonth, setVcpuHoursThisMonth] = useState<number | undefined>()const [ramData, setRamData] = useState<Series[]>([])@@ -37,7 +36,7 @@ export const UsageContent = ({ currentApiKey }: { currentApiKey: string | null }setRamData([])setCostUsage([])- const response = await fetch(usageUrl, {+ const response = await fetch( `${process.env.NEXT_PUBLIC_BILLING_API_URL}/teams/${team.id}/usage`, {headers: {'X-Team-API-Key': apiKey}