Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions frontend/src/components/AccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,29 @@ function ConfirmDeleteDialog() {
export function AccountMenu() {
const os = useOpenSecret();
const router = useRouter();
const { billingStatus } = useLocalState();
const [isPortalLoading, setIsPortalLoading] = useState(false);
const [isTeamDialogOpen, setIsTeamDialogOpen] = useState(false);

// Fetch billing status directly instead of relying on local state
const { data: billingStatus } = useQuery({
queryKey: ["billingStatus"],
queryFn: async () => {
const billingService = getBillingService();
return await billingService.getBillingStatus();
},
enabled: !!os.auth.user
});

const hasStripeAccount = billingStatus?.stripe_customer_id !== null;
const productName = billingStatus?.product_name || "";
const isPro = productName.toLowerCase().includes("pro");
const isMax = productName.toLowerCase().includes("max");
const isStarter = productName.toLowerCase().includes("starter");
const isTeamPlan = productName.toLowerCase().includes("team");
const isTeamPlan = productName.toLowerCase().includes("team") ?? false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The ?? false is unnecessary here since includes() already returns a boolean and productName is guaranteed to be a string (empty string fallback on line 96)

Suggested change
const isTeamPlan = productName.toLowerCase().includes("team") ?? false;
const isTeamPlan = productName.toLowerCase().includes("team");

const showUpgrade = !isMax && !isTeamPlan;
const showManage = (isPro || isMax || isStarter || isTeamPlan) && hasStripeAccount;

// Fetch team status if user has team plan
// Fetch team status only if user has team plan
const { data: teamStatus } = useQuery<TeamStatus>({
queryKey: ["teamStatus"],
queryFn: async () => {
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/BillingStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ export function BillingStatus() {
const status = await billingService.getBillingStatus();
setBillingStatus(status);
return status;
}
},
enabled: !!os.auth.user
});

// Check if user has team plan
const isTeamPlan = billingStatus?.product_name?.toLowerCase().includes("team");
const isTeamPlan = billingStatus?.product_name?.toLowerCase().includes("team") ?? false;

// Fetch team status if user has team plan
// Fetch team status only if user has team plan
const { data: teamStatus } = useQuery<TeamStatus>({
queryKey: ["teamStatus"],
queryFn: async () => {
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/routes/_auth.chat.$chatId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,18 @@ function ChatComponent() {
setUserImages([]);

// Send message with system prompt as separate parameter
appendUserMessage(prompt, images, undefined, undefined, sysPrompt || undefined).catch((error) => {
// Only reset if it wasn't an abort
if (!(error instanceof Error) || error.message !== "Stream aborted") {
console.error("[ChatComponent] Failed to append message:", error);
setUserPrompt(prompt);
setSystemPrompt(sysPrompt);
setUserImages(images);
initialPromptProcessedRef.current = false;
appendUserMessage(prompt, images, undefined, undefined, sysPrompt || undefined).catch(
(error) => {
// Only reset if it wasn't an abort
if (!(error instanceof Error) || error.message !== "Stream aborted") {
console.error("[ChatComponent] Failed to append message:", error);
setUserPrompt(prompt);
setSystemPrompt(sysPrompt);
setUserImages(images);
initialPromptProcessedRef.current = false;
}
}
});
);
}
}, [
userPrompt,
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TeamManagementDialog } from "@/components/team/TeamManagementDialog";
import { useQuery } from "@tanstack/react-query";
import { getBillingService } from "@/billing/billingService";
import type { TeamStatus } from "@/types/team";
import type { BillingStatus as BillingStatusType } from "@/billing/billingApi";

const homeVariants = cva("grid h-full w-full overflow-hidden", {
variants: {
Expand Down Expand Up @@ -69,14 +70,27 @@ function Index() {
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
const [teamDialogOpen, setTeamDialogOpen] = useState(false);

// Fetch team status for the dialog
// Fetch billing status first to check if user has team plan
const { data: billingStatus } = useQuery<BillingStatusType>({
queryKey: ["billingStatus"],
queryFn: async () => {
const billingService = getBillingService();
return await billingService.getBillingStatus();
},
enabled: !!os.auth.user
});

// Check if user has team plan
const isTeamPlan = billingStatus?.product_name?.toLowerCase().includes("team") ?? false;

// Fetch team status only if user has team plan
const { data: teamStatus } = useQuery<TeamStatus>({
queryKey: ["teamStatus"],
queryFn: async () => {
const billingService = getBillingService();
return await billingService.getTeamStatus();
},
enabled: !!os.auth.user
enabled: isTeamPlan && !!os.auth.user && !!billingStatus
});

// Auto-open team dialog if team_setup is true
Expand Down
Loading