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

Componentize Sidenav #1632

Merged
merged 2 commits into from
Aug 26, 2023
Merged
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
34 changes: 18 additions & 16 deletions app/javascript/components/common/SideNav/AdminMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
} from '../../../routes';

import Nonprofit from '../../../legacy/app_data/Nonprofit';
import Section from './Section';
import Link from './Link';


export interface AdminMenuProps {
Expand All @@ -21,43 +23,43 @@ export interface AdminMenuProps {

export default function AdminMenu(props: AdminMenuProps): JSX.Element {
return (
<section className='sideNav-section'>
<a className='sideNav-link' href={nonprofitPath(props.administeredNonprofit)}>
<Section>
<Link href={nonprofitPath(props.administeredNonprofit)}>
<img src={props.administeredNonprofit.logo.small} className={"sideNav-profile"} alt={props.administeredNonprofit.name} />

<span className='sideNav-text'>{props.administeredNonprofit.name}</span>
</a>
</Link>

<a className='sideNav-link' href={dashboardNonprofitPath(props.administeredNonprofit)}>
<Link href={dashboardNonprofitPath(props.administeredNonprofit)}>
<i className='sideNav-icon icon-camera-graph-2'></i>
<span className='sideNav-text'>Dashboard</span>
</a>
</Link>


<a className='sideNav-link' href={nonprofitsSupportersPath(props.administeredNonprofit)}>
<Link href={nonprofitsSupportersPath(props.administeredNonprofit)}>
<i className='sideNav-icon icon-contacts-3'></i>
<span className='sideNav-text'>Supporters</span>
</a>
</Link>

<a className='sideNav-link' href={nonprofitsPaymentsPath(props.administeredNonprofit)}>
<Link href={nonprofitsPaymentsPath(props.administeredNonprofit)}>
<i className='sideNav-icon icon-piggy-bank'></i>
<span className='sideNav-text'>Payments</span>
</a>
</Link>

<a className='sideNav-link' href={nonprofitEventsPath(props.administeredNonprofit)}>
<Link href={nonprofitEventsPath(props.administeredNonprofit)}>
<i className='sideNav-icon icon-ticket-2'></i>
<span className='sideNav-text'>Events</span>
</a>
</Link>

<a className='sideNav-link' href={nonprofitCampaignsPath(props.administeredNonprofit)}>
<Link href={nonprofitCampaignsPath(props.administeredNonprofit)}>
<i className='sideNav-icon icon-thermometer-medium'></i>
<span className='sideNav-text'>Campaigns</span>
</a>
</Link>

<a className='sideNav-link' href={nonprofitsButtonBasicPath(props.administeredNonprofit)}>
<Link href={nonprofitsButtonBasicPath(props.administeredNonprofit)}>
<i className='sideNav-icon icon-credit-card'></i>
<span className='sideNav-text'>Donate Button</span>
</a>
</Link>

</section>);
</Section>);
}
10 changes: 10 additions & 0 deletions app/javascript/components/common/SideNav/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// License: LGPL-3.0-or-later
// from app/views/layouts/_user_menu.html.erb

import classNames from 'classnames';
import React from 'react';


export default function Link({ className = '', ...props}: React.ComponentPropsWithoutRef<"a">): JSX.Element {
return (<a {...props} className={classNames(...className, 'sideNav-link')}/>);
}
11 changes: 11 additions & 0 deletions app/javascript/components/common/SideNav/Section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// License: LGPL-3.0-or-later
import React from 'react';

export default function Section(props: React.PropsWithChildren<unknown>): JSX.Element {
return (
<section className='sideNav-section'>
{props.children}
</section>
);
}

23 changes: 12 additions & 11 deletions app/javascript/components/common/SideNav/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import {
} from '../../../routes';

import UserWithProfileAsChild from '../../../legacy/app_data/UserWithProfileAsChild';

import Section from './Section';
import Link from './Link';
export interface UserMenuProps {
currentUser: UserWithProfileAsChild;
}

export default function UserMenu(props: UserMenuProps): JSX.Element {
return (<>

<section className='sideNav-section'>
<a className='sideNav-link' href={(props.currentUser.profile && profilePath(props.currentUser.profile)) || "#"}>
<Section>
<Link href={(props.currentUser.profile && profilePath(props.currentUser.profile)) || "#"}>
{
props.currentUser.profile?.pic_tiny ?
<img
Expand All @@ -27,20 +28,20 @@ export default function UserMenu(props: UserMenuProps): JSX.Element {
}
<span className='sideNav-text'>{(props.currentUser?.profile?.name || '').length > 0 ? props.currentUser?.profile?.name : "Your Profile"}
</span>
</a>
</section>
</Link>
</Section>

<section className='sideNav-section'>
<a className='sideNav-link' href={settingsPath()}>
<Section>
<Link href={settingsPath()}>
<i className='sideNav-icon icon-setting-gear'></i>
<span className='sideNav-text'>Settings</span>
</a>
</Link>

<a className='sideNav-link' href={destroyUserSessionPath()}>
<Link href={destroyUserSessionPath()}>
<i className='sideNav-icon icon-log-out-1'></i>
<span className='sideNav-text'>Logout</span>
</a>
</section>
</Link>
</Section>



Expand Down
5 changes: 3 additions & 2 deletions app/javascript/components/common/SideNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import UserMenu from './UserMenu';
import Nonprofit from '../../../legacy/app_data/Nonprofit';
import UserWithProfileAsChild from '../../../legacy/app_data/UserWithProfileAsChild';
import classnames from 'classnames';
import Section from './Section';


export interface SideNavInput {
Expand Down Expand Up @@ -61,11 +62,11 @@ export default function SideNav(props: SideNavInput): JSX.Element {
<nav className={sideNavClasses} >
{
!userisNonprofitUser(props.currentUser, props.administeredNonprofit) ? (
<section className='sideNav-section'>
<Section>
<a className='sideNav-commitchangeLogo' href='<%= root_path %>' title='Go To Home Page'>
<Logo {...props.logo} />
</a>
</section>) : ''
</Section>) : ''
}


Expand Down