-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavbar.tsx
60 lines (55 loc) · 1.85 KB
/
Navbar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"use client";
import { loginAction, signoutAction } from "@/actions/users";
import { Provider } from "@supabase/supabase-js";
import { useRouter } from "next/navigation";
import { useTransition } from "react";
import { MdOutlineLogin, MdOutlineLogout } from "react-icons/md";
import CustomButton from "./CustomButton";
import NavLogo from "@/assets/icon.png";
import Image from "next/image";
import Link from "next/link";
const Navbar = ({auth} : {auth:any}) => {
const [isPending, startTransistion] = useTransition();
const router = useRouter();
const handleSignIn = (provider: Provider) => {
startTransistion(async () => {
const {error, url} = await loginAction(provider);
if (!error && url) router.push(url);
else console.log("not loggedin")
})
}
const handleSignOut = () => {
startTransistion(async () => {
const {error} = await signoutAction();
if (error) console.log(error)
else router.push('/');
})
}
return (
<nav className="absolute top-0 py-2 px-4 rounded-xl w-full flex items-center justify-between bg-zinc-950 h-[60px] text-white">
<Link href="/">
<Image src={NavLogo} alt="logo" className="max-h-10 max-w-10"/>
</Link>
<div className="flex gap-2 items-center justify-center">
{auth ?
<CustomButton
text="Sign Out"
handleClick={() => handleSignOut()}
varient="navbar"
isPending={isPending}
isPendingText="Signing Out..."
RightIcon={<MdOutlineLogout/>}
/>
: <CustomButton
text="Sign In"
handleClick={() => handleSignIn('google')}
varient="navbar"
isPending={isPending}
isPendingText="Signing In..."
RightIcon={<MdOutlineLogin/>}
/>}
</div>
</nav>
)
}
export default Navbar;