diff --git a/src/components/auth/AccountSwitcher.tsx b/src/components/auth/AccountSwitcher.tsx index e098e70..c271538 100644 --- a/src/components/auth/AccountSwitcher.tsx +++ b/src/components/auth/AccountSwitcher.tsx @@ -1,5 +1,5 @@ -import React, { useState } from 'react'; -import { ChevronDown, LogOut, User, UserPlus } from 'lucide-react'; +import React from 'react'; +import { ChevronDown, LogOut, UserPlus } from 'lucide-react'; import { DropdownMenu, DropdownMenuContent, @@ -8,110 +8,65 @@ import { DropdownMenuTrigger, } from '@/components/ui/dropdown-menu.tsx'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar.tsx'; -import { Button } from '@/components/ui/button.tsx'; -import LoginDialog from './LoginDialog'; -import SignupDialog from './SignupDialog'; import { useLoggedInAccounts } from '@/hooks/useLoggedInAccounts'; -export function AccountSwitcher() { +interface AccountSwitcherProps { + onAddAccountClick: () => void; +} + +export function AccountSwitcher({ onAddAccountClick }: AccountSwitcherProps) { const { currentUser, otherUsers, setLogin, removeLogin } = useLoggedInAccounts(); - const [loginDialogOpen, setLoginDialogOpen] = useState(false); - const [signupDialogOpen, setSignupDialogOpen] = useState(false); - - const handleLogin = () => { - setLoginDialogOpen(false); - setSignupDialogOpen(false); - }; - - if (!currentUser) { - return ( - <> - - - setLoginDialogOpen(false)} - onLogin={handleLogin} - onSignup={() => setSignupDialogOpen(true)} - /> - - setSignupDialogOpen(false)} - /> - - ); - } + if (!currentUser) return null; return ( - <> - - - - - -
Switch Account
- {otherUsers.map((user) => ( - setLogin(user.id)} - className='flex items-center gap-2 cursor-pointer p-2 rounded-md' - > - - - {user.metadata.name?.charAt(0)} - -
-

{user.metadata.name}

-
- {user.id === currentUser.id &&
} -
- ))} - + + + + + +
Switch Account
+ {otherUsers.map((user) => ( setLoginDialogOpen(true)} + key={user.id} + onClick={() => setLogin(user.id)} className='flex items-center gap-2 cursor-pointer p-2 rounded-md' > - - Add another account + + + {user.metadata.name?.charAt(0)} + +
+

{user.metadata.name}

+
+ {user.id === currentUser.id &&
}
- removeLogin(currentUser.id)} - className='flex items-center gap-2 cursor-pointer p-2 rounded-md text-red-500' - > - - Log out - -
-
- - setLoginDialogOpen(false)} - onLogin={handleLogin} - onSignup={() => setSignupDialogOpen(true)} - /> - - setSignupDialogOpen(false)} - /> - + ))} + + + + Add another account + + removeLogin(currentUser.id)} + className='flex items-center gap-2 cursor-pointer p-2 rounded-md text-red-500' + > + + Log out + +
+
); } \ No newline at end of file diff --git a/src/components/auth/LoginArea.tsx b/src/components/auth/LoginArea.tsx new file mode 100644 index 0000000..6f1bfa8 --- /dev/null +++ b/src/components/auth/LoginArea.tsx @@ -0,0 +1,64 @@ +import React, { useState } from 'react'; +import { User } from 'lucide-react'; +import { Button } from '@/components/ui/button.tsx'; +import LoginDialog from './LoginDialog'; +import SignupDialog from './SignupDialog'; +import { useLoggedInAccounts } from '@/hooks/useLoggedInAccounts'; +import { AccountSwitcher } from './AccountSwitcher'; + +export function LoginArea() { + const { currentUser } = useLoggedInAccounts(); + const [loginDialogOpen, setLoginDialogOpen] = useState(false); + const [signupDialogOpen, setSignupDialogOpen] = useState(false); + + const handleLogin = () => { + setLoginDialogOpen(false); + setSignupDialogOpen(false); + }; + + if (!currentUser) { + return ( + <> + + + setLoginDialogOpen(false)} + onLogin={handleLogin} + onSignup={() => setSignupDialogOpen(true)} + /> + + setSignupDialogOpen(false)} + /> + + ); + } + + return ( + <> + setLoginDialogOpen(true)} + /> + + setLoginDialogOpen(false)} + onLogin={handleLogin} + onSignup={() => setSignupDialogOpen(true)} + /> + + setSignupDialogOpen(false)} + /> + + ); +} \ No newline at end of file