From eeb533fdd9ef21d4c8a129eac86ed2cc0fa3e3ba Mon Sep 17 00:00:00 2001 From: Aj Wazzan Date: Thu, 8 May 2025 19:41:36 -0700 Subject: [PATCH] refactor: clean up unused imports and comment out upgrade logic in multiple components --- apps/mail/components/connection/add.tsx | 22 ++++----- apps/mail/components/create/ai-chat.tsx | 32 ++++++------ apps/mail/components/ui/ai-sidebar.tsx | 52 ++++++++++--------- apps/mail/hooks/use-billing.ts | 63 +++++++++--------------- apps/mail/providers/server-providers.tsx | 8 ++- 5 files changed, 84 insertions(+), 93 deletions(-) diff --git a/apps/mail/components/connection/add.tsx b/apps/mail/components/connection/add.tsx index 6410f7f3b..8f58c6775 100644 --- a/apps/mail/components/connection/add.tsx +++ b/apps/mail/components/connection/add.tsx @@ -36,17 +36,17 @@ export const AddConnectionDialog = ({ }, [connections]); const handleUpgrade = async () => { - if (attach) { - return attach({ - productId: 'pro-example', - }) - .catch((error: Error) => { - console.error('Failed to upgrade:', error); - }) - .then(() => { - console.log('Upgraded successfully'); - }); - } + // if (attach) { + // return attach({ + // productId: 'pro-example', + // }) + // .catch((error: Error) => { + // console.error('Failed to upgrade:', error); + // }) + // .then(() => { + // console.log('Upgraded successfully'); + // }); + // } }; return ( diff --git a/apps/mail/components/create/ai-chat.tsx b/apps/mail/components/create/ai-chat.tsx index f75b2e15c..a7c120ae4 100644 --- a/apps/mail/components/create/ai-chat.tsx +++ b/apps/mail/components/create/ai-chat.tsx @@ -16,13 +16,13 @@ import { useStats } from '@/hooks/use-stats'; import { useParams } from 'next/navigation'; import { CheckCircle2 } from 'lucide-react'; import { useChat } from '@ai-sdk/react'; +import { Button } from '../ui/button'; import { format } from 'date-fns-tz'; import { useQueryState } from 'nuqs'; import { Input } from '../ui/input'; import { useState } from 'react'; import VoiceChat from './voice'; import Image from 'next/image'; -import { Button } from '../ui/button'; const renderThread = (thread: { id: string; title: string; snippet: string }) => { const [, setThreadId] = useQueryState('threadId'); @@ -177,17 +177,17 @@ export function AIChat() { }, [messages, scrollToBottom]); const handleUpgrade = async () => { - if (attach) { - return attach({ - productId: 'pro-example', - }) - .catch((error: Error) => { - console.error('Failed to upgrade:', error); - }) - .then(() => { - console.log('Upgraded successfully'); - }); - } + // if (attach) { + // return attach({ + // productId: 'pro-example', + // }) + // .catch((error: Error) => { + // console.error('Failed to upgrade:', error); + // }) + // .then(() => { + // console.log('Upgraded successfully'); + // }); + // } }; return ( @@ -196,8 +196,12 @@ export function AIChat() {
{chatMessages && !chatMessages.enabled ? (
- Upgrade to Zero Pro for unlimited AI chats - + + Upgrade to Zero Pro for unlimited AI chats + +
) : !messages.length ? (
diff --git a/apps/mail/components/ui/ai-sidebar.tsx b/apps/mail/components/ui/ai-sidebar.tsx index 5d28ccd35..8443d0e89 100644 --- a/apps/mail/components/ui/ai-sidebar.tsx +++ b/apps/mail/components/ui/ai-sidebar.tsx @@ -9,23 +9,23 @@ import { DialogTrigger, } from './dialog'; import { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from '@/components/ui/tooltip'; +import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@/components/ui/resizable'; import { useState, useEffect, useContext, createContext, useCallback } from 'react'; import { AI_SIDEBAR_COOKIE_NAME, SIDEBAR_COOKIE_MAX_AGE } from '@/lib/constants'; -import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@/components/ui/resizable'; import { StyledEmailAssistantSystemPrompt, AiChatPrompt } from '@/lib/prompts'; import { useEditor } from '@/components/providers/editor-provider'; import { AIChat } from '@/components/create/ai-chat'; import { X, Paper } from '@/components/icons/icons'; import { GitBranchPlus, Plus } from 'lucide-react'; +import { useBilling } from '@/hooks/use-billing'; import { Button } from '@/components/ui/button'; import { useHotkeys } from 'react-hotkeys-hook'; +import { Gauge } from '@/components/ui/gauge'; import { usePathname } from 'next/navigation'; import { getCookie } from '@/lib/utils'; import { Textarea } from './textarea'; import { cn } from '@/lib/utils'; import Link from 'next/link'; -import { useBilling } from '@/hooks/use-billing'; -import { Gauge } from '@/components/ui/gauge'; interface AISidebarProps { className?: string; @@ -80,17 +80,17 @@ export function AISidebar({ children, className }: AISidebarProps & { children: const { chatMessages, attach } = useBilling(); const handleUpgrade = async () => { - if (attach) { - return attach({ - productId: 'pro-example', - }) - .catch((error: Error) => { - console.error('Failed to upgrade:', error); - }) - .then(() => { - console.log('Upgraded successfully'); - }); - } + // if (attach) { + // return attach({ + // productId: 'pro-example', + // }) + // .catch((error: Error) => { + // console.error('Failed to upgrade:', error); + // }) + // .then(() => { + // console.log('Upgraded successfully'); + // }); + // } }; useHotkeys('Meta+0', () => { @@ -113,14 +113,12 @@ export function AISidebar({ children, className }: AISidebarProps & { children: return ( - - {children} - + {open && ( <> -
+
- +
- +
-

You've used {50 - chatMessages.remaining!} out of 50 chat messages.

-

Upgrade for unlimited messages!

- +

+ You've used {50 - chatMessages.remaining!} out of 50 chat messages. +

+

Upgrade for unlimited messages!

+
diff --git a/apps/mail/hooks/use-billing.ts b/apps/mail/hooks/use-billing.ts index 6720bc13a..988db280e 100644 --- a/apps/mail/hooks/use-billing.ts +++ b/apps/mail/hooks/use-billing.ts @@ -1,4 +1,3 @@ -import { useAutumn, useCustomer } from 'autumn-js/next'; import { useMemo } from 'react'; type Feature = { @@ -34,49 +33,33 @@ const FEATURE_IDS = { } as const; export const useBilling = () => { - const { customer, refetch } = useCustomer(); - const { attach, track } = useAutumn(); - const customerFeatures = useMemo(() => { - if (!customer) return DEFAULT_FEATURES; - - const features = customer.features.reduce( - (acc: Features, feature: Feature) => { - const id = feature.feature_id; - if (id === FEATURE_IDS.CHAT) { - acc.chatMessages = { - total: feature.included_usage || 0, - remaining: feature.balance || 0, - unlimited: feature.unlimited, - enabled: feature.unlimited || Number(feature.balance) > 0, - }; - } else if (id === FEATURE_IDS.CONNECTIONS) { - acc.connections = { - total: feature.included_usage || 0, - remaining: feature.balance || 0, - unlimited: feature.unlimited, - enabled: feature.unlimited || Number(feature.balance) > 0, - }; - } else if (id === FEATURE_IDS.BRAIN) { - acc.brainActivity = { - total: feature.included_usage || 0, - remaining: feature.balance || 0, - unlimited: feature.unlimited, - enabled: feature.unlimited || Number(feature.balance) > 0, - }; - } - return acc; + return { + chatMessages: { + total: 100, + remaining: 75, + unlimited: false, + enabled: true, }, - { ...DEFAULT_FEATURES }, - ); - - return features; - }, [customer]); + connections: { + total: 5, + remaining: 3, + unlimited: false, + enabled: true, + }, + brainActivity: { + total: 1000, + remaining: 850, + unlimited: false, + enabled: true, + }, + }; + }, []); return { - refetch, - attach, - track, + refetch: () => {}, + attach: () => {}, + track: () => {}, ...customerFeatures, }; }; diff --git a/apps/mail/providers/server-providers.tsx b/apps/mail/providers/server-providers.tsx index ee975d162..9f9257432 100644 --- a/apps/mail/providers/server-providers.tsx +++ b/apps/mail/providers/server-providers.tsx @@ -8,10 +8,8 @@ import { authProxy } from '@/lib/auth-proxy'; export async function ServerProviders({ children }: PropsWithChildren) { const messages = await getMessages(); return ( - - - {children} - - + + {children} + ); }