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

Refactor/improvements #6

Open
wants to merge 3 commits 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
33 changes: 31 additions & 2 deletions packages/web/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,42 @@
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": ["react", "react-hooks", "@typescript-eslint"],
"plugins": ["react", "react-hooks", "import", "@typescript-eslint"],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-namespace": "off"
"@typescript-eslint/no-namespace": "off",
"import/order": [
"error",
{
"newlines-between": "always",
"groups": [
"external",
"index",
"sibling",
"parent",
"internal",
"builtin",
"object",
"type"
],
"pathGroups": [
{
"pattern": "react",
"group": "external",
"position": "before"
},
{
"pattern": "{next,next/**}",
"group": "external",
"position": "before"
}
],
"pathGroupsExcludedImportTypes": []
}
]
}
}
2 changes: 1 addition & 1 deletion packages/web/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import GlobalStyles from '../src/styles/global'
import { GlobalStyles } from '../src/styles/global'

export const decorators = [
(Story) => (
Expand Down
1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"babel-loader": "^8.2.3",
"eslint": "7.21.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-prettier": "3.3.1",
"eslint-plugin-react": "7.22.0",
"eslint-plugin-react-hooks": "4.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type AutoCompleteProps = {
onBlur?: () => void
}

const AutoComplete: React.FC<AutoCompleteProps> = ({
export const AutoComplete: React.FC<AutoCompleteProps> = ({
id,
defaultValue = '',
onChange = () => '',
Expand Down Expand Up @@ -48,5 +48,3 @@ const AutoComplete: React.FC<AutoCompleteProps> = ({
</S.Wrapper>
)
}

export default AutoComplete
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Story, Meta } from '@storybook/react/types-6-0'

import AutoCompĺete from '.'
import { AutoComplete } from '.'

export default {
title: 'AutoCompĺete',
component: AutoCompĺete,
title: 'AutoComplete',
component: AutoComplete,
args: {}
} as Meta

export const Default: Story = () => (
<AutoCompĺete
<AutoComplete
id="AutoCompleteId"
label="AutoCompleteLabel"
placeholder="AutoCompletePlaceholder"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled, { css, FlattenSimpleInterpolation } from 'styled-components'

import { AutoCompleteVariants } from '.'

type VariantsDecorators = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fireEvent, render, screen } from '@testing-library/react'

import AutoComplete, { AutoCompleteProps } from '.'
import { AutoComplete, AutoCompleteProps } from '.'

const BaseComponent = (props: Partial<AutoCompleteProps>) => (
<AutoComplete
Expand Down
9 changes: 5 additions & 4 deletions packages/web/src/components/BusSchedule/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BusTime } from 'models'
import { BusScheduleViewModel, ScheduleMapNonNull } from 'view-model'
import { modifiersMap } from 'components/ModifiersTooltip'
import { modifiersMap } from 'components'

import * as S from './styles'

Expand All @@ -9,7 +9,10 @@ export type BusScheduleProps = {
schedule: BusTime[]
}

const BusSchedule: React.FC<BusScheduleProps> = ({ title, schedule }) => {
export const BusSchedule: React.FC<BusScheduleProps> = ({
title,
schedule
}) => {
const scheduleMap = BusScheduleViewModel.parse(schedule) as ScheduleMapNonNull

return (
Expand Down Expand Up @@ -40,5 +43,3 @@ const BusSchedule: React.FC<BusScheduleProps> = ({ title, schedule }) => {
</S.Wrapper>
)
}

export default BusSchedule
2 changes: 1 addition & 1 deletion packages/web/src/components/BusSchedule/stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Story, Meta } from '@storybook/react/types-6-0'
import { BusTime, Time } from 'models'

import BusSchedule from '.'
import { BusSchedule } from '.'

export default {
title: 'BusSchedule',
Expand Down
8 changes: 2 additions & 6 deletions packages/web/src/components/Dialog/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ContextOutsideProviderError } from 'errors'
import React, { useState, createContext, useContext } from 'react'

import { ContextOutsideProviderError } from 'errors'

import { Dialog } from '.'

type openDialogParam = React.FC<{ close: () => void }>
Expand Down Expand Up @@ -51,8 +52,3 @@ export const useDialog = () => {

return context
}

export default {
DialogProvider,
useDialog
}
4 changes: 3 additions & 1 deletion packages/web/src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Text } from 'components/Text'
import React from 'react'

import { Text } from 'components'

import * as S from './styles'

export const Footer: React.FC = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/components/Footer/styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextStyles } from 'components/Text'
import * as TextStyles from 'components/Text/styles'
import styled from 'styled-components'

export const Content = styled.div`
Expand Down
6 changes: 2 additions & 4 deletions packages/web/src/components/LabelsLegend/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BusModifiers } from 'models'
import { modifiersMap } from 'components/ModifiersTooltip'
import { modifiersMap } from 'components'

import * as S from './styles'

export type LabelsLegendProps = {
labels: { [key in BusModifiers]?: string }
}

const LabelsLegend: React.FC<LabelsLegendProps> = ({ labels }) => {
export const LabelsLegend: React.FC<LabelsLegendProps> = ({ labels }) => {
const labelsEntries = Object.entries(labels)

if (labelsEntries.length === 0) return <></>
Expand All @@ -23,5 +23,3 @@ const LabelsLegend: React.FC<LabelsLegendProps> = ({ labels }) => {
</S.Wrapper>
)
}

export default LabelsLegend
4 changes: 1 addition & 3 deletions packages/web/src/components/Loader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as S from './styles'

const Loader: React.FC = () => {
export const Loader: React.FC = () => {
return (
<S.Wrapper>
<div></div>
Expand All @@ -9,5 +9,3 @@ const Loader: React.FC = () => {
</S.Wrapper>
)
}

export default Loader
2 changes: 1 addition & 1 deletion packages/web/src/components/ModifiersTooltip/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components'
import Tooltip from 'components/Tooltip'
import { Tooltip } from 'components/Tooltip'

type WidgetProps = {
color?: string
Expand Down
3 changes: 1 addition & 2 deletions packages/web/src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react'

import * as S from './styles'
import { ValidHtmlTextTags } from './types'

export * as TextStyles from './styles'

export type TextVariants =
| 'default'
| 'title'
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/components/Text/stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'

import { ComponentStory, ComponentMeta } from '@storybook/react'

import { Text } from '.'
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/components/Text/styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled, { css, FlattenSimpleInterpolation } from 'styled-components'

import { TextVariants } from '.'

type VariantsDecorators = { [key in TextVariants]: FlattenSimpleInterpolation }
Expand Down
5 changes: 4 additions & 1 deletion packages/web/src/components/Toolbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useRouter } from 'next/router'
import React from 'react'

import { useRouter } from 'next/router'

import { IoMdArrowBack } from 'react-icons/io'

import * as S from './styles'

export interface ToolbarProps {
Expand Down
5 changes: 2 additions & 3 deletions packages/web/src/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'

import * as S from './styles'

export interface TooltipProps {
Expand All @@ -8,7 +9,7 @@ export interface TooltipProps {
position?: 'top' | 'bottom'
}

const Tooltip = ({
export const Tooltip = ({
className,
children,
text,
Expand All @@ -22,5 +23,3 @@ const Tooltip = ({
</S.Wrapper>
)
}

export default Tooltip
3 changes: 2 additions & 1 deletion packages/web/src/components/Tooltip/stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Story, Meta } from '@storybook/react/types-6-0'
import Tooltip, { TooltipProps } from '.'

import { Tooltip, TooltipProps } from '.'

export default {
title: 'Tooltip',
Expand Down
11 changes: 11 additions & 0 deletions packages/web/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export * from './AlertBanner'
export * from './AutoComplete'
export * from './BusSchedule'
export * from './Dialog'
export * from './Footer'
export * from './LabelsLegend'
export * from './Loader'
export * from './ModifiersTooltip'
export * from './Text'
export * from './Toolbar'
export * from './Tooltip'
11 changes: 11 additions & 0 deletions packages/web/src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const configs = {
busValues: {
external_bus_value: 'R$ 7,65',

internal_bus_value: 'R$ 5,30',
internal_integration_value: 'R$ 2,35',

municipal_bus_value: 'R$ 4,25',
municipal_integration_value: 'R$ 3,40'
}
}
6 changes: 4 additions & 2 deletions packages/web/src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Loader from 'components/Loader'
import { useRouter } from 'next/router'
import { useEffect } from 'react'

import { useRouter } from 'next/router'

import { Loader } from 'components'

export default function Page404() {
const router = useRouter()

Expand Down
6 changes: 4 additions & 2 deletions packages/web/src/pages/500.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Loader from 'components/Loader'
import { useRouter } from 'next/router'
import { useEffect } from 'react'

import { useRouter } from 'next/router'

import { Loader } from 'components'

export default function Page500() {
const router = useRouter()

Expand Down
6 changes: 2 additions & 4 deletions packages/web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AppProps } from 'next/app'
import Head from 'next/head'

import GlobalStyles from 'styles/global'
import { GlobalStyles } from 'styles/global'

function App({ Component, pageProps }: AppProps) {
export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Head>
Expand All @@ -22,5 +22,3 @@ function App({ Component, pageProps }: AppProps) {
</>
)
}

export default App
1 change: 1 addition & 0 deletions packages/web/src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Document, {
NextScript,
DocumentContext
} from 'next/document'

import { ServerStyleSheet } from 'styled-components'

export default class MyDocument extends Document {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import HomePage from 'screens/home'
import { HomePage } from 'screens'

export default HomePage
5 changes: 1 addition & 4 deletions packages/web/src/pages/linhas/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
BusScheduleDetailsPage,
getServerSideProps
} from 'screens/bus-schedule-details'
import { BusScheduleDetailsPage, getServerSideProps } from 'screens'

export { getServerSideProps }

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/politicas-de-privacidade/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import PrivacyPoliciesPage from 'screens/privacy-policies'
import { PrivacyPoliciesPage } from 'screens'

export default PrivacyPoliciesPage
Loading