Skip to content

Commit

Permalink
move routes to folder
Browse files Browse the repository at this point in the history
Co-authored-by: Sayuck <[email protected]>
Co-authored-by: EduardoPicolo <[email protected]>
  • Loading branch information
3 people committed Aug 10, 2022
1 parent aa8521b commit 5fcdf7e
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 52 deletions.
13 changes: 3 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@
}
],
// "eslint-comments/no-use": ["warn", { "allow": [] }],
"eslint-comments/require-description": [
"error",
{ "ignore": [] }
]
"eslint-comments/require-description": ["error", { "ignore": [] }]
},
"ignorePatterns": ["**/*.json", "**/*.js"],
"overrides": [
Expand All @@ -143,18 +140,14 @@
["^react$", "^next", "^react", "^@?\\w"],
// Internal packages.
[
"^(@components|@pages|@hooks|@contexts|@templates|@layouts|@public|@constants|@utils|@controllers|@models|@services|@company|@ui|@UI|@stripe|@database|@aws|@lib|components|utils|config|vendored-lib|@prismadb)(/.*|$|..)"
"^(@components|@routes|@pages|@hooks|@contexts|@templates|@layouts|@public|@constants|@utils|@controllers|@models|@services|@company|@ui|@UI|@stripe|@database|@aws|@lib|components|utils|config|vendored-lib|@prismadb)(/.*|$|..)"
],
// Side effect imports.
["^\\u0000"],
// Parent imports. Put `..` last.
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
// Other relative imports. Put same-folder imports and `.` last.
[
"^\\./(?=.*/)(?!/?$)",
"^\\.(?!/?$)",
"^\\./?$"
],
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
// Style imports.
["@styles", "^.+\\.s?css$"]
]
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const customJestConfig = {
'^@utils': '<rootDir>/src/utils',
'^@utils/(.*)$': '<rootDir>/src/utils/$1',
'^@public/(.*)$': '<rootDir>/src/../public/$1',
'^@routes': '<rootDir>/src/routes',
},
};

Expand Down
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import '@testing-library/jest-dom/extend-expect';
import '@testing-library/jest-dom';
67 changes: 67 additions & 0 deletions src/components/SideBar/SidebarItem/SideBarItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Url } from 'url';

import React, { ReactElement, useMemo } from 'react';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { Flex } from '@chakra-ui/react';
import { IRoute } from 'routes';

export interface SideBarItemAttributes extends IRoute {
query?: { [key: string]: string };
as?: string;
isActive?: boolean;
}

export interface SideBarItemProps extends Partial<SideBarItemAttributes> {
children?: ReactElement<{ isActive: boolean }>;
}

export const SideBarItem = ({
pathname,
query,
as,
label,
icon,
}: SideBarItemProps) => {
const router = useRouter();

const href: Partial<Url> = useMemo(
() => ({
pathname,
query,
}),
[pathname, query]
);

// replace the pathname slug '/path/[slug]' with the actual slug
const path = query
? pathname?.replace(`[${Object.keys(query)[0]}]`, Object.values(query)[0])
: pathname;
const isActive = router?.asPath === path;

return (
<Link href={href} as={as} shallow={!pathname}>
<Flex
alignItems={'center'}
gap={2}
fontSize={18}
fontWeight={'medium'}
cursor='pointer'
px={2}
py={2.5}
borderRadius={'base'}
bg={isActive ? 'primary' : 'inherit'}
color={isActive ? 'white' : 'inherit'}
boxShadow={isActive ? 'soft' : 'none'}
// eslint-disable-next-line react-perf/jsx-no-new-object-as-prop -- não irei implementar uma classe que aplica hover
_hover={{
bg: 'primary',
color: 'white',
boxShadow: 'soft',
}}
>
{icon} {label}
</Flex>
</Link>
);
};
43 changes: 2 additions & 41 deletions src/components/SideBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
import { FaRegUser } from 'react-icons/fa';
import { FiLayout } from 'react-icons/fi';
import {
MdOutlineCallToAction,
MdOutlineDashboard,
MdOutlineLocationCity,
MdOutlineViewAgenda,
} from 'react-icons/md';
import { RiLogoutCircleFill } from 'react-icons/ri';
import { TbTestPipe } from 'react-icons/tb';
import { Box, Divider, Flex, Heading, Text } from '@chakra-ui/react';

import { SideBarItem, SideBarItemAttributes } from './SideBarItem';
import { routes } from '@routes';

const routes: SideBarItemAttributes[] = [
{
label: 'Dashboard',
pathname: '/dashboard',
icon: <MdOutlineDashboard size={28} />,
},
{
label: 'Chamados',
pathname: '/chamados',
icon: <MdOutlineViewAgenda size={28} />,
},
{
label: 'Registrar Chamado',
pathname: '/registrachamado',
icon: <MdOutlineCallToAction size={28} />,
},
{
label: 'Tipos De Problemas',
pathname: '/listaCategoria',
icon: <FiLayout size={28} />,
},
{
label: 'Cidades [admin]',
pathname: '/listaCidades',
icon: <MdOutlineLocationCity size={28} />,
},
{
label: 'Teste',
pathname: '/teste',
icon: <TbTestPipe size={28} />,
},
];
import { SideBarItem } from './SidebarItem/SideBarItem';

export const SideBar = () => {
return (
Expand Down
47 changes: 47 additions & 0 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { FiLayout } from 'react-icons/fi';
import {
MdOutlineCallToAction,
MdOutlineDashboard,
MdOutlineLocationCity,
MdOutlineViewAgenda,
} from 'react-icons/md';
import { TbTestPipe } from 'react-icons/tb';

export interface IRoute {
label: string;
pathname: string;
icon?: JSX.Element;
}

export const routes: IRoute[] = [
{
label: 'Dashboard',
pathname: '/dashboard',
icon: <MdOutlineDashboard size={28} />,
},
{
label: 'Chamados',
pathname: '/chamados',
icon: <MdOutlineViewAgenda size={28} />,
},
{
label: 'Registrar Chamado',
pathname: '/registrachamado',
icon: <MdOutlineCallToAction size={28} />,
},
{
label: 'Tipos De Problemas',
pathname: '/listaCategoria',
icon: <FiLayout size={28} />,
},
{
label: 'Cidades [admin]',
pathname: '/listaCidades',
icon: <MdOutlineLocationCity size={28} />,
},
{
label: 'Teste',
pathname: '/teste',
icon: <TbTestPipe size={28} />,
},
];
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"@UI/*": ["UI/*"],
"@utils": ["utils"],
"@utils/*": ["utils/*"],
"@public/*": ["../public/*"]
"@public/*": ["../public/*"],
"@routes": ["routes"]
},
"incremental": true
},
Expand Down

0 comments on commit 5fcdf7e

Please sign in to comment.