Skip to content

Commit

Permalink
feat(sidebar): updates sidebar to use material ui
Browse files Browse the repository at this point in the history
Updates the sidebar to use Material UI for its components

re #143
  • Loading branch information
anguspiv committed Mar 19, 2023
1 parent 7a002df commit f6dc60e
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/components/layout/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useDisclosure, useMediaQuery, Grid, GridItem, Box } from '@chakra-ui/re
import AppDrawer from '@components/navigation/AppDrawer';
import { useEffect } from 'react';
import AppHeader from '@components/organisms/AppHeader';
import SideBar from '@components/layout/SideBar';
import SideBar from '@components/organisms/SideBar';

interface PageLayoutProps {
children: React.ReactNode;
Expand Down Expand Up @@ -31,7 +31,7 @@ function PageLayout({ children }: PageLayoutProps) {
<GridItem gridArea="header">
{!isDesktop && (
<>
<AppHeader onMenuToggle={onToggle} isMenuOpen={isOpen && !isDesktop} />
<AppHeader onMenuToggle={onToggle} open={isOpen && !isDesktop} />
<AppDrawer isOpen={isOpen} onClose={onClose} />
</>
)}
Expand Down
15 changes: 0 additions & 15 deletions src/components/layout/SideBar/SideBar.stories.tsx

This file was deleted.

37 changes: 0 additions & 37 deletions src/components/layout/SideBar/SideBar.tsx

This file was deleted.

44 changes: 44 additions & 0 deletions src/components/organisms/SideBar/SideBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Story } from '@storybook/react';
import { SessionProvider } from 'next-auth/react';
import { profileQuery } from '@components/molecules/AccountLink';
import SideBar from './SideBar';

export default {
title: 'Oraganisms/SideBar',
component: SideBar,
};

const Template: Story = (args) => (
<SessionProvider session={{ expires: '' }}>
<SideBar {...args} />
</SessionProvider>
);

export const Default = Template.bind({});

Default.args = {
open: true,
};

Default.parameters = {
apolloClient: {
mocks: [
{
request: {
query: profileQuery,
},
result: {
data: {
profile: {
firstName: 'John',
lastName: 'Doe',
avatar: {
filepath: 'https://i.pravatar.cc/300',
},
},
},
},
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@ import { render } from '@testing-library/react';
import { useSession as useSessionOrig } from 'next-auth/react';
import SideBar from './SideBar';

jest.mock<typeof import('next/router')>('next/router', () => ({
...jest.requireActual<typeof import('next/router')>('next/router'),
useRouter: () =>
({
asPath: '/',
} as NextRouter),
}));

jest.mock<typeof import('next-auth/react')>('next-auth/react', () => ({
useSession: jest.fn(),
}));

jest.mock<typeof import('@apollo/client')>('@apollo/client', () => ({
useQuery: jest.fn().mockReturnValue({ data: { profile: { firstName: 'John' } } }),
useQuery: jest.fn().mockReturnValue({
data: { profile: { firstName: 'John', lastName: 'Doe', avatar: { filepath: 'test.jpg' } } },
}),
gql: jest.fn(),
}));

jest.mock<typeof import('next/router')>('next/router', () => ({
useRouter() {
return {
route: '/test',
pathname: '',
query: '',
asPath: '/test',
push: jest.fn(),
events: {
on: jest.fn(),
off: jest.fn(),
},
beforePopState: jest.fn(() => null),
prefetch: jest.fn(() => null),
};
},
}));

const useSession = useSessionOrig as jest.MockedFunction<typeof useSessionOrig>;

describe('<SideBar />', () => {
Expand Down
35 changes: 35 additions & 0 deletions src/components/organisms/SideBar/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Toolbar, Divider, Drawer } from '@mui/material';
import { AppMenu } from '@components/molecules/AppMenu';

interface SideBarProps {
open?: boolean;
onClose?: () => void;
}

function SideBar({ open = false, onClose = () => {} }: SideBarProps) {
return (
<Drawer
data-testid="app-sidebar"
variant="persistent"
anchor="left"
open={open}
sx={{
width: 240,
flexShrink: 0,
'& .MuiDrawer-paper': {
width: 240,
boxSizing: 'border-box',
backgroundColor: (theme) => theme.palette.primary.main,
color: (theme) => theme.palette.primary.contrastText,
},
}}
onClose={onClose}
>
<Toolbar />
<Divider />
<AppMenu />
</Drawer>
);
}

export default SideBar;
File renamed without changes.

0 comments on commit f6dc60e

Please sign in to comment.