suna/frontend/src/app/dashboard/(teamAccount)/[accountSlug]/settings/billing/page.tsx

76 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-04-18 06:49:07 +08:00
'use client';
import React from 'react';
2025-04-12 02:57:17 +08:00
import {createClient} from "@/lib/supabase/server";
import AccountBillingStatus from "@/components/basejump/account-billing-status";
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";
const returnUrl = process.env.NEXT_PUBLIC_URL as string;
2025-04-18 06:49:07 +08:00
type AccountParams = {
accountSlug: string;
};
export default function TeamBillingPage({ params }: { params: Promise<AccountParams> }) {
const unwrappedParams = React.use(params);
const { accountSlug } = unwrappedParams;
// Use an effect to load team account data
const [teamAccount, setTeamAccount] = React.useState<any>(null);
const [error, setError] = React.useState<string | null>(null);
React.useEffect(() => {
async function loadData() {
try {
const supabaseClient = await createClient();
const {data} = await supabaseClient.rpc('get_account_by_slug', {
slug: accountSlug
});
setTeamAccount(data);
} catch (err) {
setError("Failed to load account data");
console.error(err);
}
}
loadData();
}, [accountSlug]);
if (error) {
return (
<Alert variant="destructive" className="border-red-300 dark:border-red-800 rounded-xl">
<AlertTitle>Error</AlertTitle>
<AlertDescription>{error}</AlertDescription>
</Alert>
);
}
if (!teamAccount) {
return <div>Loading...</div>;
}
2025-04-12 02:57:17 +08:00
if (teamAccount.account_role !== 'owner') {
return (
<Alert variant="destructive" className="border-red-300 dark:border-red-800 rounded-xl">
<AlertTitle>Access Denied</AlertTitle>
<AlertDescription>You do not have permission to access this page.</AlertDescription>
</Alert>
)
}
return (
<div className="space-y-6">
<div>
<h3 className="text-lg font-medium text-card-title">Team Billing</h3>
<p className="text-sm text-foreground/70">
Manage your team's subscription and billing details.
</p>
</div>
<AccountBillingStatus
accountId={teamAccount.account_id}
returnUrl={`${returnUrl}/dashboard/${accountSlug}/settings/billing`}
/>
</div>
)
}