-
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.
Merge pull request #5 from khanghy2130/add-displayname-to-side-panel
Saving user name & improved auth handling
- Loading branch information
Showing
8 changed files
with
1,634 additions
and
1,740 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 |
---|---|---|
@@ -1,45 +1,59 @@ | ||
import { Link } from '@remix-run/react'; | ||
import { Link } from "@remix-run/react"; | ||
|
||
import { useTheme } from '~/utils/Navbar/ThemeProvider'; | ||
|
||
import type { ContextProps } from '../utils/types/ContextProps.type'; | ||
import { useTheme } from "~/utils/Navbar/ThemeProvider"; | ||
|
||
import type { ContextProps } from "../utils/types/ContextProps.type"; | ||
|
||
type Props = { | ||
sidePanelIsShown: boolean; | ||
setSidePanelIsShown: React.Dispatch<React.SetStateAction<boolean>>; | ||
user: ContextProps["user"]; | ||
supabase: ContextProps["supabase"] | ||
supabase: ContextProps["supabase"]; | ||
}; | ||
|
||
export default function SidePanel( | ||
{sidePanelIsShown, setSidePanelIsShown, user, supabase} | ||
: Props){ | ||
export default function SidePanel({ | ||
sidePanelIsShown, | ||
setSidePanelIsShown, | ||
user, | ||
supabase, | ||
}: Props) { | ||
const [theme, setTheme] = useTheme(); | ||
const toggleTheme = () => { | ||
setTheme((prevTheme) => (prevTheme === "light" ? "dark" : "light")); | ||
}; | ||
|
||
const logout = async () => { | ||
const {error} = await supabase.auth.signOut(); | ||
const { error } = await supabase.auth.signOut(); | ||
if (error) alert("Error while logging out."); | ||
} | ||
|
||
return <div | ||
className={(sidePanelIsShown ? "right-0" : "-right-96") + | ||
` fixed h-screen transition-[right] ease-in-out duration-500 | ||
w-96 max-w-full bg-gray-800 flex flex-col items-center` | ||
}> | ||
<button className='btn' | ||
onClick={()=>setSidePanelIsShown(false)}>CLOSE</button> | ||
<button className='btn' onClick={toggleTheme}>Theme: {theme}</button> | ||
|
||
{user? <div className='flex flex-col mt-12'> | ||
<p>Logged in as {user.email}</p> | ||
<button className='btn' onClick={logout}>Log out</button> | ||
</div> : <Link to="/login"> | ||
<button className='btn'>Login</button> | ||
</Link>} | ||
}; | ||
|
||
</div> | ||
} | ||
return ( | ||
<div | ||
className={ | ||
(sidePanelIsShown ? "right-0" : "-right-96") + | ||
` fixed flex h-screen w-96 max-w-full | ||
flex-col items-center bg-gray-800 transition-[right] duration-500 ease-in-out` | ||
} | ||
> | ||
<button className="btn" onClick={() => setSidePanelIsShown(false)}> | ||
CLOSE | ||
</button> | ||
<button className="btn" onClick={toggleTheme}> | ||
Theme: {theme} | ||
</button> | ||
|
||
{user ? ( | ||
<div className="mt-12 flex flex-col"> | ||
<p>Logged in as {user.user_metadata.full_name}!</p> | ||
<button className="btn" onClick={logout}> | ||
Log out | ||
</button> | ||
</div> | ||
) : ( | ||
<Link to="/login"> | ||
<button className="btn">Login</button> | ||
</Link> | ||
)} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ export default function LoginForm({ | |
}) { | ||
const fillDemoAcc = () => { | ||
setEmail("[email protected]"); | ||
setPassword("123+Ab"); | ||
setPassword("Test!123"); | ||
}; | ||
|
||
return ( | ||
|
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 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,23 +1,20 @@ | ||
import {describe, it, expect} from "vitest" | ||
import {render, screen} from '@testing-library/react' | ||
import {userEvent} from "@testing-library/user-event" | ||
import "@testing-library/jest-dom" | ||
import { describe, it, expect } from "vitest"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { userEvent } from "@testing-library/user-event"; | ||
import "@testing-library/jest-dom"; | ||
|
||
import Index from '../routes/_index'; | ||
import Index from "../routes/_index"; | ||
|
||
|
||
describe('App', () => { | ||
|
||
it('clicks to change text', async () => { | ||
describe("App", () => { | ||
it("clicks to change text", async () => { | ||
// ARRANGE | ||
render(<Index/>) | ||
render(<Index />); | ||
|
||
// ACT | ||
await userEvent.click(screen.getByText('click here')) | ||
await screen.findByRole('heading') | ||
|
||
// ASSERT | ||
expect(screen.getByRole('heading')).toHaveTextContent("done") | ||
}) | ||
await userEvent.click(screen.getByText("click here")); | ||
await screen.findByRole("heading"); | ||
|
||
}) | ||
// ASSERT | ||
expect(screen.getByRole("heading")).toHaveTextContent("done"); | ||
}); | ||
}); |
Oops, something went wrong.