forked from umami-software/umami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
268 additions
and
83 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import Page from './Page'; | ||
import styles from './Account.module.css'; | ||
|
||
export default function Account() { | ||
const user = useSelector(state => state.user); | ||
return ( | ||
<Page> | ||
<h2>Account</h2> | ||
<div className={styles.label}>username</div> | ||
<div>{user.username}</div> | ||
</Page> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.label { | ||
font-size: var(--font-size-normal); | ||
font-weight: 600; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.form { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
transform: translateX(-50%); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import styles from './Menu.module.css'; | ||
|
||
export default function Menu({ options = [], className, align = 'left', onSelect = () => {} }) { | ||
return ( | ||
<div | ||
className={classNames(styles.menu, className, { | ||
[styles.left]: align === 'left', | ||
[styles.right]: align === 'right', | ||
})} | ||
> | ||
{options.map(({ label, value, className: optionClassName }) => ( | ||
<div | ||
key={value} | ||
className={classNames(styles.option, optionClassName)} | ||
onClick={e => onSelect(value, e)} | ||
> | ||
{label} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.menu { | ||
position: absolute; | ||
min-width: 100px; | ||
top: 100%; | ||
margin-top: 4px; | ||
border: 1px solid var(--gray500); | ||
border-radius: 4px; | ||
overflow: hidden; | ||
z-index: 2; | ||
} | ||
|
||
.option { | ||
font-size: var(--font-size-small); | ||
font-weight: normal; | ||
background: #fff; | ||
padding: 4px 16px; | ||
cursor: pointer; | ||
white-space: nowrap; | ||
} | ||
|
||
.option:hover { | ||
background: #f5f5f5; | ||
} | ||
|
||
.left { | ||
left: 0; | ||
} | ||
|
||
.right { | ||
right: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useState, useRef } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useRouter } from 'next/router'; | ||
import Menu from './Menu'; | ||
import Icon from './Icon'; | ||
import useDocumentClick from 'hooks/useDocumentClick'; | ||
import User from 'assets/user.svg'; | ||
import Chevron from 'assets/chevron-down.svg'; | ||
import styles from './UserButton.module.css'; | ||
|
||
export default function UserButton() { | ||
const [showMenu, setShowMenu] = useState(false); | ||
const user = useSelector(state => state.user); | ||
const ref = useRef(); | ||
const router = useRouter(); | ||
|
||
const menuOptions = [ | ||
{ | ||
label: ( | ||
<> | ||
Logged in as <b>{user.username}</b> | ||
</> | ||
), | ||
value: 'username', | ||
className: styles.username, | ||
}, | ||
{ label: 'Account', value: 'account' }, | ||
{ label: 'Logout', value: 'logout' }, | ||
]; | ||
|
||
function handleSelect(value) { | ||
setShowMenu(false); | ||
|
||
if (value === 'account') { | ||
router.push('/account'); | ||
} else if (value === 'logout') { | ||
router.push('/logout'); | ||
} | ||
} | ||
|
||
useDocumentClick(e => { | ||
if (!ref.current.contains(e.target)) { | ||
setShowMenu(false); | ||
} | ||
}); | ||
|
||
return ( | ||
<div ref={ref} className={styles.container}> | ||
<div onClick={() => setShowMenu(state => !state)}> | ||
<Icon icon={<User />} size="L" className={styles.icon} /> | ||
<Icon icon={<Chevron />} size="S" /> | ||
</div> | ||
{showMenu && <Menu options={menuOptions} onSelect={handleSelect} align="right" />} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.container { | ||
display: flex; | ||
position: relative; | ||
cursor: pointer; | ||
} | ||
|
||
.icon { | ||
margin-right: 8px; | ||
} | ||
|
||
.username { | ||
border-bottom: 1px solid var(--gray500); | ||
} | ||
|
||
.username:hover { | ||
background: var(--gray50); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useEffect } from 'react'; | ||
|
||
export default function useDocumentClick(handler) { | ||
useEffect(() => { | ||
document.addEventListener('click', handler); | ||
|
||
return () => { | ||
document.removeEventListener('click', handler); | ||
}; | ||
}, [handler]); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import Layout from 'components/Layout'; | ||
import Account from 'components/Account'; | ||
import useRequireLogin from 'hooks/useRequireLogin'; | ||
|
||
export default function AccountPage() { | ||
const { loading } = useRequireLogin(); | ||
|
||
if (loading) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Layout> | ||
<Account /> | ||
</Layout> | ||
); | ||
} |
Oops, something went wrong.