mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2025-08-28 13:39:23 +00:00
Refactor AccountSwitcher / LoginArea
This commit is contained in:
parent
d88285480c
commit
dec966b693
@ -1,5 +1,5 @@
|
|||||||
import React, { useState } from 'react';
|
import React from 'react';
|
||||||
import { ChevronDown, LogOut, User, UserPlus } from 'lucide-react';
|
import { ChevronDown, LogOut, UserPlus } from 'lucide-react';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
@ -8,50 +8,18 @@ import {
|
|||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from '@/components/ui/dropdown-menu.tsx';
|
} from '@/components/ui/dropdown-menu.tsx';
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar.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';
|
import { useLoggedInAccounts } from '@/hooks/useLoggedInAccounts';
|
||||||
|
|
||||||
export function AccountSwitcher() {
|
interface AccountSwitcherProps {
|
||||||
|
onAddAccountClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AccountSwitcher({ onAddAccountClick }: AccountSwitcherProps) {
|
||||||
const { currentUser, otherUsers, setLogin, removeLogin } = useLoggedInAccounts();
|
const { currentUser, otherUsers, setLogin, removeLogin } = useLoggedInAccounts();
|
||||||
|
|
||||||
const [loginDialogOpen, setLoginDialogOpen] = useState(false);
|
if (!currentUser) return null;
|
||||||
const [signupDialogOpen, setSignupDialogOpen] = useState(false);
|
|
||||||
|
|
||||||
const handleLogin = () => {
|
|
||||||
setLoginDialogOpen(false);
|
|
||||||
setSignupDialogOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!currentUser) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
onClick={() => setLoginDialogOpen(true)}
|
|
||||||
className='flex items-center gap-2 px-4 py-2 rounded-full bg-primary text-primary-foreground w-full font-medium transition-all hover:bg-primary/90 animate-scale-in'
|
|
||||||
>
|
|
||||||
<User className='w-4 h-4' />
|
|
||||||
<span>Log in</span>
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<LoginDialog
|
|
||||||
isOpen={loginDialogOpen}
|
|
||||||
onClose={() => setLoginDialogOpen(false)}
|
|
||||||
onLogin={handleLogin}
|
|
||||||
onSignup={() => setSignupDialogOpen(true)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<SignupDialog
|
|
||||||
isOpen={signupDialogOpen}
|
|
||||||
onClose={() => setSignupDialogOpen(false)}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<button className='flex items-center gap-3 p-3 rounded-full hover:bg-accent transition-all w-full text-foreground'>
|
<button className='flex items-center gap-3 p-3 rounded-full hover:bg-accent transition-all w-full text-foreground'>
|
||||||
@ -85,7 +53,7 @@ export function AccountSwitcher() {
|
|||||||
))}
|
))}
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => setLoginDialogOpen(true)}
|
onClick={onAddAccountClick}
|
||||||
className='flex items-center gap-2 cursor-pointer p-2 rounded-md'
|
className='flex items-center gap-2 cursor-pointer p-2 rounded-md'
|
||||||
>
|
>
|
||||||
<UserPlus className='w-4 h-4' />
|
<UserPlus className='w-4 h-4' />
|
||||||
@ -100,18 +68,5 @@ export function AccountSwitcher() {
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
|
|
||||||
<LoginDialog
|
|
||||||
isOpen={loginDialogOpen}
|
|
||||||
onClose={() => setLoginDialogOpen(false)}
|
|
||||||
onLogin={handleLogin}
|
|
||||||
onSignup={() => setSignupDialogOpen(true)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<SignupDialog
|
|
||||||
isOpen={signupDialogOpen}
|
|
||||||
onClose={() => setSignupDialogOpen(false)}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
64
src/components/auth/LoginArea.tsx
Normal file
64
src/components/auth/LoginArea.tsx
Normal file
@ -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 (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
onClick={() => setLoginDialogOpen(true)}
|
||||||
|
className='flex items-center gap-2 px-4 py-2 rounded-full bg-primary text-primary-foreground w-full font-medium transition-all hover:bg-primary/90 animate-scale-in'
|
||||||
|
>
|
||||||
|
<User className='w-4 h-4' />
|
||||||
|
<span>Log in</span>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<LoginDialog
|
||||||
|
isOpen={loginDialogOpen}
|
||||||
|
onClose={() => setLoginDialogOpen(false)}
|
||||||
|
onLogin={handleLogin}
|
||||||
|
onSignup={() => setSignupDialogOpen(true)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SignupDialog
|
||||||
|
isOpen={signupDialogOpen}
|
||||||
|
onClose={() => setSignupDialogOpen(false)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<AccountSwitcher
|
||||||
|
onAddAccountClick={() => setLoginDialogOpen(true)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<LoginDialog
|
||||||
|
isOpen={loginDialogOpen}
|
||||||
|
onClose={() => setLoginDialogOpen(false)}
|
||||||
|
onLogin={handleLogin}
|
||||||
|
onSignup={() => setSignupDialogOpen(true)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SignupDialog
|
||||||
|
isOpen={signupDialogOpen}
|
||||||
|
onClose={() => setSignupDialogOpen(false)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user