Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update authentication links and clean up routes. #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/elements/AppRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ContactPage from 'components/pages/ContactPage';
import PrivacyPage from 'components/pages/PrivacyPolicyPage';
import ContactSuccessPage from 'components/pages/ContactSuccessPage';
import TermsPage from 'components/pages/TermsPage';
import AccountSettingsPage from 'components/pages/AccountSettingsPage';

// Elements
import RequireAuth from 'components/elements/RequireAuth';
Expand Down Expand Up @@ -94,6 +95,7 @@ function AppRoutes() {
element={<VerifyMagicLinkPage />}
/>
<Route path="/contact-success" element={<ContactSuccessPage />} />
<Route path="/account-settings" element={<AccountSettings />} />
</Routes>
);
}
Expand Down
31 changes: 24 additions & 7 deletions src/components/elements/DropdownMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ import { Link } from 'react-router-dom';
import { navStyleClasses } from 'styles/navbar';
import DownArrowIcon from 'components/elements/DownArrowIcon';

function DropDownAction({ value, label, route, action }) {
if (action) {
return (
<a href="#" onClick={action} className={navStyleClasses.navDropdownItem}>{label}</a>
)
} else {
return (
<Link
to={route}
value={value}
className={navStyleClasses.navDropdownItem}
>
{label}
</Link>
)
}
}

function DropdownMenu({ label, options }) {
return (
<div className="flex justify-center mt-4 mr-10">
Expand All @@ -22,16 +40,15 @@ function DropdownMenu({ label, options }) {
className={navStyleClasses.navSelectMenu}
aria-labelledby="dropdownMenuButton2"
>
{options.map(({ value, label, route }) => {
{options.map(({ value, label, route, action }) => {
return (
<li key={value}>
<Link
to={route}
<DropDownAction
value={value}
className={navStyleClasses.navDropdownItem}
>
{label}
</Link>
label={label}
route={route}
action={action}
/>
</li>
)
})}
Expand Down
20 changes: 14 additions & 6 deletions src/components/elements/NavigationBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { NAVBAR_EVENT_OPTIONS } from 'constants/navbar';
function NavigationBar() {
const auth = useAuth();
const [colorTheme, setTheme] = useDarkMode();
const signOut = () => auth.signOutCurrentUser();
const authLinks = [
{ label: 'Settings', value: 'settings', route: '/account-settings' },
{ label: 'Sign Out', value: 'sign-out', action: () => auth.signOutCurrentUser() },
]

return (
<>
Expand Down Expand Up @@ -44,12 +47,14 @@ function NavigationBar() {
alt="logo"
/>
</div>
<div className={navStyleClasses.navLink}>
{auth.currentUser.isAuthenticated
? <button onClick={signOut}>Sign Out</button>
: <Link to="/sign-in">Sign In</Link>

<div>
{ auth.currentUser.isAuthenticated
? <DropdownMenu label="Account" options={authLinks} />
: <div className={navStyleClasses.navLink}><Link to="/sign-in">Sign In</Link></div>
}
</div>

<div className={navStyleClasses.navLink}>
<a
href="https://www.dataumbrella.org"
Expand All @@ -64,7 +69,10 @@ function NavigationBar() {
Sponsors
</a>
</div>
<DropdownMenu label="Events" options={NAVBAR_EVENT_OPTIONS} />

<div>
<DropdownMenu label="Events" options={NAVBAR_EVENT_OPTIONS} />
</div>
</div>
</div>
</div>
Expand Down
15 changes: 15 additions & 0 deletions src/components/pages/AccountSettingsPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { useAuth } from 'hooks/authentication';

function AccountSettingsPage() {
const auth = useAuth();

return (
<div className="w-3/4 container mx-auto p-20">
<h1 className="text-2xl font-bold">Email</h1>
<p>{auth.currentUser.email}</p>
</div>
);
}

export default AccountSettingsPage;