-
Notifications
You must be signed in to change notification settings - Fork 5
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
188 additions
and
194 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"use client"; | ||
import { AnimatePresence } from "framer-motion"; | ||
import { useSession } from "next-auth/react"; | ||
|
||
import { LoadingScreen } from "@/components/elements/loading-screen"; | ||
import { Modal } from "@/components/elements/modal"; | ||
|
||
import { useAuthFlow } from "../hooks/use-auth-flow"; | ||
|
||
import { SignInModal } from "./sign-in-modal"; | ||
import { SignOutModal } from "./signout-modal"; | ||
import styles from "./styles/auth-modal-trigger.module.scss"; | ||
|
||
export const AuthFlow = () => { | ||
const { data: session, status } = useSession(); | ||
|
||
const { | ||
isLogInModalOpen, | ||
isLogOutModalOpen, | ||
openLogInModal, | ||
closeLogInModal, | ||
closeLogOutModal, | ||
} = useAuthFlow(); | ||
|
||
if (status === "loading") return <LoadingScreen />; | ||
|
||
return ( | ||
<> | ||
<AnimatePresence> | ||
{isLogInModalOpen && ( | ||
<Modal onClose={closeLogInModal}> | ||
<SignInModal onClose={closeLogInModal} /> | ||
</Modal> | ||
)} | ||
|
||
{isLogOutModalOpen && ( | ||
<Modal onClose={closeLogOutModal}> | ||
<SignOutModal onClose={closeLogOutModal} /> | ||
</Modal> | ||
)} | ||
</AnimatePresence> | ||
|
||
{!session && ( | ||
<div className={styles.container}> | ||
<div className={styles.content}> | ||
<div className={styles.text}> | ||
<h1>Don’t miss what’s happening</h1> | ||
<p>People on Twitter are the first to know.</p> | ||
</div> | ||
<div className={styles.buttons}> | ||
<button onClick={openLogInModal} className={styles.signIn}> | ||
Log in | ||
</button> | ||
<button onClick={openLogInModal} className={styles.signUp}> | ||
Sign up | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
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,58 +1,74 @@ | ||
"use client"; | ||
import { motion } from "framer-motion"; | ||
import Link from "next/link"; | ||
import { useSession } from "next-auth/react"; | ||
import { forwardRef } from "react"; | ||
|
||
import { Button } from "@/components/elements/button"; | ||
import { useTrackPosition } from "@/components/elements/modal"; | ||
|
||
import { useAuthFlow } from "../hooks/use-auth-flow"; | ||
|
||
import styles from "./styles/session-owner-modal.module.scss"; | ||
|
||
export const SessionOwnerModal = forwardRef< | ||
HTMLButtonElement, | ||
{ onClose: () => void } | ||
>(({ onClose }, ref) => { | ||
const { data: session } = useSession(); | ||
|
||
const buttonBoundaries = useTrackPosition({ | ||
buttonRef: ref as React.RefObject<HTMLButtonElement>, | ||
trackScroll: false, | ||
}); | ||
|
||
const style: React.CSSProperties = { | ||
position: "fixed", | ||
top: buttonBoundaries?.top | ||
? buttonBoundaries?.top - buttonBoundaries?.height - 50 | ||
: "50%", | ||
left: buttonBoundaries?.left ? buttonBoundaries?.left : "50%", | ||
transform: buttonBoundaries?.top | ||
? "translate(0, 0)" | ||
: "translate(-50%, -50%)", | ||
}; | ||
|
||
if (!session) return null; | ||
|
||
return ( | ||
<motion.div | ||
initial={{ opacity: 0, y: "100%" }} | ||
animate={{ opacity: 1, y: 0 }} | ||
exit={{ opacity: 0, y: "100%" }} | ||
transition={{ | ||
ease: "easeInOut", | ||
duration: 0.2, | ||
}} | ||
className={styles.container} | ||
style={style} | ||
role="group" | ||
> | ||
<Link href={`/auth/signin`} role="menuitem" onClick={onClose}> | ||
Add an existing account | ||
</Link> | ||
<Link href={`/auth/signout`} role="menuitem" onClick={onClose}> | ||
Log out @{session?.user?.email.split("@")[0]} | ||
</Link> | ||
</motion.div> | ||
); | ||
}); | ||
export const SessionOwnerModal = forwardRef<HTMLButtonElement>( | ||
(_props, ref) => { | ||
const { data: session } = useSession(); | ||
|
||
const { openLogInModal, openLogOutModal } = useAuthFlow(); | ||
|
||
const buttonBoundaries = useTrackPosition({ | ||
buttonRef: ref as React.RefObject<HTMLButtonElement>, | ||
trackScroll: false, | ||
}); | ||
|
||
const style: React.CSSProperties = { | ||
position: "fixed", | ||
top: buttonBoundaries?.top | ||
? buttonBoundaries?.top - buttonBoundaries?.height - 50 | ||
: "50%", | ||
left: buttonBoundaries?.left ? buttonBoundaries?.left : "50%", | ||
transform: buttonBoundaries?.top | ||
? "translate(0, 0)" | ||
: "translate(-50%, -50%)", | ||
}; | ||
|
||
if (!session) return null; | ||
|
||
return ( | ||
<motion.div | ||
initial={{ opacity: 0, y: "100%" }} | ||
animate={{ opacity: 1, y: 0 }} | ||
exit={{ opacity: 0, y: "100%" }} | ||
transition={{ | ||
ease: "easeInOut", | ||
duration: 0.2, | ||
}} | ||
className={styles.container} | ||
style={style} | ||
role="group" | ||
> | ||
<Button | ||
className="w-full justify-start rounded-none py-[0.8em] -outline-offset-2 hover:bg-neutral-400 focus-visible:bg-neutral-400 active:bg-neutral-500" | ||
onClick={() => { | ||
openLogInModal(); | ||
}} | ||
role="menuitem" | ||
> | ||
Add an existing account | ||
</Button> | ||
|
||
<Button | ||
className="w-full justify-start rounded-none py-[0.8em] -outline-offset-2 hover:bg-neutral-400 focus-visible:bg-neutral-400 active:bg-neutral-500" | ||
onClick={() => { | ||
openLogOutModal(); | ||
}} | ||
role="menuitem" | ||
> | ||
Log out @{session?.user?.email.split("@")[0]} | ||
</Button> | ||
</motion.div> | ||
); | ||
}, | ||
); | ||
|
||
SessionOwnerModal.displayName = "SessionOwnerModal"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.