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
10 changes: 9 additions & 1 deletion apps/mail/actions/brain.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
'use server';
import { getActiveConnection } from './utils';
import axios from 'axios';

export const EnableBrain = async ({
connection,
}: {
connection: { id: string; providerId: string };
connection?: { id: string; providerId: string } | null;
}) => {
if (!process.env.BRAIN_URL) {
return false;
}
if (!connection) {
connection = await getActiveConnection();
}

if (!connection?.id) {
return false;
}

return await axios
.put(process.env.BRAIN_URL + `/subscribe/${connection.providerId}`, {
Expand Down
9 changes: 7 additions & 2 deletions apps/mail/app/api/driver/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,16 @@ export const driver = async (config: IConfig): Promise<MailManager> => {
getUserInfo: (tokens: IConfig['auth']) => {
return withErrorHandler(
'getUserInfo',
() => {
async () => {
auth.setCredentials({ ...tokens, scope: getScope() });
return google
const res = await google
.people({ version: 'v1', auth })
.people.get({ resourceName: 'people/me', personFields: 'names,photos,emailAddresses' });
return {
address: res.data.emailAddresses?.[0]?.value ?? '',
name: res.data.names?.[0]?.displayName ?? '',
photo: res.data.photos?.[0]?.url ?? '',
};
},
{ tokens },
);
Expand Down
40 changes: 27 additions & 13 deletions apps/mail/components/ui/nav-user.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import {
BrainCircuitIcon,
ChevronDown,
HelpCircle,
LogIn,
Expand All @@ -18,19 +19,20 @@ import {
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { SidebarMenu, SidebarMenuItem, SidebarMenuButton } from '@/components/ui/sidebar';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { usePathname, useSearchParams } from 'next/navigation';
import { useConnections } from '@/hooks/use-connections';
import { useRouter } from 'next/navigation';
import { signOut, useSession } from '@/lib/auth-client';
import { AddConnectionDialog } from '../connection/add';
import { putConnection } from '@/actions/connections';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { dexieStorageProvider } from '@/lib/idb';
import { SunIcon } from '../icons/animated/sun';
import { EnableBrain } from '@/actions/brain';
import { useRouter } from 'next/navigation';
import { useTranslations } from 'next-intl';
import { type IConnection } from '@/types';
import { useTheme } from 'next-themes';
import { toast } from 'sonner';
import { dexieStorageProvider } from '@/lib/idb';
import { usePathname, useSearchParams } from 'next/navigation';
import Link from 'next/link';

export function NavUser() {
Expand Down Expand Up @@ -62,6 +64,12 @@ export function NavUser() {
toast.success('Cache cleared successfully');
}, []);

const handleEnableBrain = useCallback(async () => {
// This takes too long, not waiting
const enabled = await EnableBrain({});
if (enabled) toast.success('Brain enabled successfully');
}, []);

const activeAccount = useMemo(() => {
if (!session) return null;
return connections?.find((connection) => connection.id === session?.connectionId);
Expand Down Expand Up @@ -95,11 +103,14 @@ export function NavUser() {
};

const handleLogout = async () => {
toast.promise(signOut().then(() => router.push('/login')), {
loading: 'Signing out...',
success: () => 'Signed out successfully!',
error: 'Error signing out',
});
toast.promise(
signOut().then(() => router.push('/login')),
{
loading: 'Signing out...',
success: () => 'Signed out successfully!',
error: 'Error signing out',
},
);
};

return (
Expand Down Expand Up @@ -266,7 +277,6 @@ export function NavUser() {
<p className="text-[13px] opacity-60">{t('common.actions.logout')}</p>
</div>
</DropdownMenuItem>

</>
) : (
<>
Expand All @@ -291,15 +301,19 @@ export function NavUser() {
</a>
</div>
<DropdownMenuSeparator className="mt-1" />
<p className="text-muted-foreground px-2 py-1 text-[11px] font-medium">
Debug
</p>
<p className="text-muted-foreground px-2 py-1 text-[11px] font-medium">Debug</p>
<DropdownMenuItem onClick={handleClearCache}>
<div className="flex items-center gap-2">
<HelpCircle size={16} className="opacity-60" />
<p className="text-[13px] opacity-60">Clear Local Cache</p>
</div>
</DropdownMenuItem>
<DropdownMenuItem onClick={handleEnableBrain}>
<div className="flex items-center gap-2">
<BrainCircuitIcon size={16} className="opacity-60" />
<p className="text-[13px] opacity-60">Enable Brain</p>
</div>
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
Expand Down