Skip to content

Commit c6c2b54

Browse files
committed
rework user dropdown for logout button and fix tests
1 parent a39aae2 commit c6c2b54

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

app/components/user-dropdown.tsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useRef } from 'react'
2-
import { useSubmit, Link, Form } from 'react-router'
2+
import { Link, Form } from 'react-router'
33
import { getUserImgSrc } from '#app/utils/misc.tsx'
44
import { useUser } from '#app/utils/user.ts'
55
import { Button } from './ui/button'
@@ -14,10 +14,9 @@ import { Icon } from './ui/icon'
1414

1515
export function UserDropdown() {
1616
const user = useUser()
17-
const submit = useSubmit()
1817
const formRef = useRef<HTMLFormElement>(null)
1918
return (
20-
<DropdownMenu modal={false}>
19+
<DropdownMenu>
2120
<DropdownMenuTrigger asChild>
2221
<Button asChild variant="secondary">
2322
<Link
@@ -53,20 +52,15 @@ export function UserDropdown() {
5352
</Icon>
5453
</Link>
5554
</DropdownMenuItem>
56-
<DropdownMenuItem
57-
asChild
58-
// this prevents the menu from closing before the form submission is completed
59-
onSelect={async (event) => {
60-
event.preventDefault()
61-
await submit(formRef.current)
62-
}}
63-
>
64-
<Form action="/logout" method="POST" ref={formRef}>
65-
<Icon className="text-body-md" name="exit">
66-
<button type="submit">Logout</button>
67-
</Icon>
68-
</Form>
69-
</DropdownMenuItem>
55+
<Form action="/logout" method="POST" ref={formRef}>
56+
<DropdownMenuItem asChild>
57+
<button type="submit" className="w-full">
58+
<Icon className="text-body-md" name="exit">
59+
Logout
60+
</Icon>
61+
</button>
62+
</DropdownMenuItem>
63+
</Form>
7064
</DropdownMenuContent>
7165
</DropdownMenuPortal>
7266
</DropdownMenu>

tests/e2e/2fa.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test('Users can add 2FA to their account and use it when logging in', async ({
3737
await expect(main.getByRole('link', { name: /disable 2fa/i })).toBeVisible()
3838

3939
await page.getByRole('link', { name: user.name ?? user.username }).click()
40-
await page.getByRole('button', { name: /logout/i }).click()
40+
await page.getByRole('menuitem', { name: /logout/i }).click()
4141
await expect(page).toHaveURL(`/`)
4242

4343
await page.goto('/login')

0 commit comments

Comments
 (0)