Skip to content

Commit 458d903

Browse files
MytsVmaany
authored andcommitted
Implement log out of all accounts functionality
1 parent 0b917a7 commit 458d903

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/component-library/Pages/Layout/AccountDropdown.tsx

+21-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {twMerge} from "tailwind-merge"
22
import {ForwardedRef, forwardRef, useState} from "react"
33
import {HiSwitchHorizontal, HiLogout, HiUserAdd} from "react-icons/hi"
44
import Link from "next/link"
5+
import {useRouter} from "next/navigation";
56

67
const AccountList = (props: { accountList: string[] }) => {
78
return <div className="flex flex-col">
@@ -31,26 +32,36 @@ const AccountList = (props: { accountList: string[] }) => {
3132
};
3233

3334
const SignOutOfAllButton = () => {
34-
return <Link
35+
const router = useRouter();
36+
37+
const signOut = async () => {
38+
const request = new Request('/api/auth/logout', {
39+
method: 'POST'
40+
})
41+
//TODO: handle errors
42+
await fetch(request)
43+
router.push('/auth/login')
44+
};
45+
46+
return <div
3547
className={twMerge(
3648
"text-text-800 hover:bg-base-warning-200 hover:cursor-pointer",
3749
"dark:text-text-100 dark:hover:bg-base-warning-600",
3850
"flex items-center justify-between py-2 px-1 space-x-4",
3951
"text-right",
4052
)}
41-
href="/api/auth/logout"
42-
prefetch={false}
53+
onClick={() => signOut()}
4354
>
44-
<span><b>Sign out</b> of all accounts</span>
55+
<span>Sign <b>out</b> of all accounts</span>
4556
<HiLogout className="dark:text-text-100 text-2xl text-text-900 shrink-0"/>
46-
</Link>
57+
</div>
4758
}
4859

4960
const SignIntoButton = () => {
5061
return <Link
5162
className={twMerge(
52-
"text-text-800 hover:bg-base-warning-200 hover:cursor-pointer",
53-
"dark:text-text-100 dark:hover:bg-base-warning-600",
63+
"text-text-800 hover:bg-base-success-200 hover:cursor-pointer",
64+
"dark:text-text-100 dark:hover:bg-base-success-600",
5465
"flex items-center justify-between py-2 px-1 space-x-4",
5566
"text-right",
5667
)}
@@ -71,6 +82,7 @@ export const AccountDropdown = forwardRef(function AccountDropdown
7182
},
7283
ref: ForwardedRef<HTMLDivElement>
7384
) {
85+
const hasAccountChoice = props.accountsPossible.length !== 1;
7486
return (
7587

7688
<div
@@ -112,10 +124,11 @@ export const AccountDropdown = forwardRef(function AccountDropdown
112124
</a>
113125
</div>
114126
</div>
115-
{props.accountsPossible.length !== 1 &&
127+
{hasAccountChoice &&
116128
<AccountList accountList={props.accountsPossible.filter(account => account !== props.accountActive)}/>
117129
}
118130
<SignIntoButton/>
131+
{hasAccountChoice && <SignOutOfAllButton/>}
119132
</div>
120133
)
121134
}

src/component-library/outputtailwind.css

+10
Original file line numberDiff line numberDiff line change
@@ -2214,6 +2214,11 @@ html {
22142214
background-color: rgb(56 189 248 / var(--tw-bg-opacity));
22152215
}
22162216

2217+
.hover\:bg-base-success-200:hover {
2218+
--tw-bg-opacity: 1;
2219+
background-color: rgb(187 247 208 / var(--tw-bg-opacity));
2220+
}
2221+
22172222
.hover\:bg-base-success-600:hover {
22182223
--tw-bg-opacity: 1;
22192224
background-color: rgb(22 163 74 / var(--tw-bg-opacity));
@@ -2802,6 +2807,11 @@ html {
28022807
background-color: rgb(30 41 59 / var(--tw-bg-opacity));
28032808
}
28042809

2810+
.dark\:hover\:bg-base-success-600:hover {
2811+
--tw-bg-opacity: 1;
2812+
background-color: rgb(22 163 74 / var(--tw-bg-opacity));
2813+
}
2814+
28052815
.dark\:hover\:bg-base-warning-600:hover {
28062816
--tw-bg-opacity: 1;
28072817
background-color: rgb(217 119 6 / var(--tw-bg-opacity));

0 commit comments

Comments
 (0)