-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
288 additions
and
91 deletions.
There are no files selected for viewing
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,42 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
const createDummyUser = () => { | ||
return { | ||
id: 1, | ||
name: "dummy.cat", | ||
image: | ||
"https://user-images.githubusercontent.com/25859075/29918905-88dcc646-8e5c-11e7-81ec-242bc58dce1b.jpg", | ||
email: "[email protected]", | ||
emailVerified: false, | ||
phoneNumber: null, | ||
displayName: "dummy.cat", | ||
}; | ||
}; | ||
|
||
export const useDummyAuth = () => { | ||
const [user, setUser] = useState({}); | ||
|
||
useEffect(() => { | ||
const isStoredInSession = JSON.parse(sessionStorage.getItem("dummy_user")); | ||
if (isStoredInSession) { | ||
setUser(isStoredInSession); | ||
} | ||
}, []); | ||
|
||
const handleLogin = () => { | ||
const dummy_user = createDummyUser(); | ||
setUser(dummy_user); | ||
sessionStorage.setItem("dummy_user", JSON.stringify(dummy_user)); | ||
}; | ||
|
||
const handleLogout = () => { | ||
setUser({}); | ||
sessionStorage.removeItem("dummy_user"); | ||
}; | ||
|
||
return { | ||
user, | ||
handleLogin, | ||
handleLogout, | ||
}; | ||
}; |
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 @@ | ||
export { default as DummyLoginButton } from './ui/DummyLoginButton'; |
54 changes: 54 additions & 0 deletions
54
app/components/auth/dummy/styles/DummyLoginButton.module.css
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,54 @@ | ||
.authDialogWrapper { | ||
position: relative; | ||
} | ||
.authContainer { | ||
display: block; | ||
position: fixed; | ||
right: 50%; | ||
transform: translate(50%,0); | ||
top: 62px; | ||
width: 350px; | ||
max-height: -webkit-calc(100vh - 62px - 100px); | ||
max-height: calc(100vh - 62px - 100px); | ||
overflow-y: auto; | ||
overflow-x: hidden; | ||
border-radius: 8px; | ||
margin-left: 12px; | ||
z-index: 991; | ||
line-height: normal; | ||
background: #fff; | ||
border: 1px solid #ccc; | ||
border-color: rgba(0,0,0,.2); | ||
color: #000; | ||
-webkit-box-shadow: 0 2px 10px rgb(0 0 0 / 20%); | ||
box-shadow: 0 2px 10px rgb(0 0 0 / 20%); | ||
-webkit-user-select: text; | ||
user-select: text; | ||
} | ||
@media(min-width: 570px) { | ||
.authContainer { | ||
position: absolute; | ||
right: 8px; | ||
top: 62px; | ||
width: 354px; | ||
transform: translateX(0); | ||
} | ||
} | ||
.avatar { | ||
background: var(--bs-gray-300); | ||
border-radius: 50%; | ||
width: 42px; | ||
height: 42px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.avatarButton { | ||
background: none; | ||
border: none; | ||
} | ||
|
||
.avatarButton:focus { | ||
outline: none; | ||
} |
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,73 @@ | ||
import { useState } from "react"; | ||
import { NoUserAvatar } from "../../NoUserAvatar"; | ||
import { Button } from "react-bootstrap"; | ||
import styles from "../styles/DummyLoginButton.module.css"; | ||
import { useDummyAuth } from "../hooks/useDummyAuth"; | ||
|
||
export default function DummyLoginButton() { | ||
const [isLoginUiOpen, setIsLoginUiOpen] = useState(false); | ||
const { user, handleLogin, handleLogout } = useDummyAuth(); | ||
|
||
return ( | ||
<div className={styles.authDialogWrapper}> | ||
<div className={styles.avatar}> | ||
<button className={styles.avatarButton}> | ||
<span | ||
className="d-flex align-items-center" | ||
onClick={() => setIsLoginUiOpen((prev) => !prev)} | ||
> | ||
{user?.image ? ( | ||
<img | ||
src={user.image} | ||
alt={user.name} | ||
className="rounded-circle" | ||
height="42px" | ||
width="42px" | ||
/> | ||
) : ( | ||
<NoUserAvatar name={user?.name} size="42" /> | ||
)} | ||
</span> | ||
</button> | ||
</div> | ||
{isLoginUiOpen && ( | ||
<div className={styles.authContainer}> | ||
{user.id ? ( | ||
<> | ||
<div className="d-flex flex-column align-items-center mt-4 mb-3 ml-3 mr-3 border-bottom"> | ||
<div className="mb-1"> | ||
{user.image ? ( | ||
<img | ||
src={user.image} | ||
alt={user.name} | ||
style={{ | ||
borderRadius: "50%", | ||
}} | ||
height="64px" | ||
width="64px" | ||
/> | ||
) : ( | ||
<NoUserAvatar size="64" name={user.name} /> | ||
)} | ||
</div> | ||
<div className="font-weight-bold mb-1">{user.name}</div> | ||
<div className="mb-1" style={{ color: "var(--bs-gray-700)" }}> | ||
{user.email} | ||
</div> | ||
</div> | ||
<div className="d-flex justify-content-center mb-4 mt-3 ml-3 mr-3"> | ||
<Button variant="secondary" onClick={handleLogout}> | ||
Sign Out | ||
</Button> | ||
</div> | ||
</> | ||
) : ( | ||
<div className="d-flex flex-column align-items-center my-3"> | ||
<Button onClick={handleLogin}>Login</Button> | ||
</div> | ||
)} | ||
</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
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
Oops, something went wrong.