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 Vehicle types #32

Merged
merged 1 commit into from
Jun 28, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed
- upgrade to MSW 2.x
- refactor MSW server handlers
- refactor Vehicle types


## [v0.7.2 - 2024-06-06](https://github.com/GemeenteUtrecht/bereikbaarheid-frontend/compare/v0.7.1...v0.7.2)
Expand Down
2 changes: 1 addition & 1 deletion src/api/nationaalwegenbestand/rvv/locatie/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import { Point } from 'geojson'

import { Address } from '../../../../types/address'
import { Vehicle } from '../../../../pages/ProhibitorySigns/types/vehicle'
import { Vehicle } from '../../../../types/vehicle'

import { API_ROOT } from '../../index'

Expand Down
2 changes: 1 addition & 1 deletion src/api/nationaalwegenbestand/rvv/verkeersborden/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import { Feature, FeatureCollection, Point } from 'geojson'

import { Vehicle } from '../../../../pages/ProhibitorySigns/types/vehicle'
import { Vehicle } from '../../../../types/vehicle'

import { API_ROOT } from '../../index'

Expand Down
2 changes: 1 addition & 1 deletion src/api/nationaalwegenbestand/rvv/wegvakken/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
MultiLineString,
} from 'geojson'

import { Vehicle } from '../../../../pages/ProhibitorySigns/types/vehicle'
import { Vehicle } from '../../../../types/vehicle'

import { API_ROOT } from '../../index'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ProhibitorySignsFormScenarioRdwInfo,
ProhibitorySignsFormScenarioRdwInfoProps,
} from './Form'
import { Vehicle } from '../../../types/vehicle'
import { ProhibitorySignsVehicle } from '../../../types/vehicle'

describe('ProhibitorySignsFormScenarioRdwInfo', () => {
const props: ProhibitorySignsFormScenarioRdwInfoProps = {
Expand All @@ -29,7 +29,7 @@ describe('ProhibitorySignsFormScenarioRdwInfo', () => {
vehicle: {
height: 2.34,
licensePlate: licensePlate,
} as Vehicle,
} as ProhibitorySignsVehicle,
}),
),
}
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('ProhibitorySignsFormScenarioRdwInfo', () => {
vehicle: {
height: 3.25,
licensePlate: '85BPF2',
} as Vehicle,
} as ProhibitorySignsVehicle,
},
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { FormLabel } from '../../../../../shared/components/FormLabel'
import InputWithSuffix from '../../../../../shared/components/InputWithSuffix'
import { useProhibitorySignsPageContext } from '../../../contexts/PageContext'

import { Vehicle } from '../../../types/vehicle'
import { ProhibitorySignsVehicle } from '../../../types/vehicle'
import {
FormInputLicensePlate,
FormInputLicensePlateWidth,
Expand Down Expand Up @@ -58,9 +58,9 @@ export interface ProhibitorySignsFormScenarioStartProps {

export type FormScenarioStartInputs = {
addressInputEnabled: ProhibitorySignsFormScenarioStartProps['addressInputEnabled']
licensePlate: Vehicle['licensePlate']
vehicleHasTrailer: Vehicle['hasTrailer']
vehicleHeight: Vehicle['height']
licensePlate: ProhibitorySignsVehicle['licensePlate']
vehicleHasTrailer: ProhibitorySignsVehicle['hasTrailer']
vehicleHeight: ProhibitorySignsVehicle['height']
}

export const ProhibitorySignsFormScenarioStart = ({
Expand Down Expand Up @@ -95,7 +95,7 @@ export const ProhibitorySignsFormScenarioStart = ({
licensePlate: data.licensePlate,
hasTrailer: data.vehicleHasTrailer ?? false,
height: data.vehicleHeight,
} as Vehicle)
} as ProhibitorySignsVehicle)

setActiveStepWizard(nextFormStep)
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ProhibitorySigns/contexts/PageContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, Dispatch, SetStateAction, useContext } from 'react'

import { Address } from '../../../types/address'
import { Vehicle } from '../types/vehicle'
import { ProhibitorySignsVehicle } from '../types/vehicle'

export type ProhibitorySignsPageContextProps = {
activeStepWizard: number
Expand All @@ -11,15 +11,15 @@
expertMode: boolean
showScenarioWizard: boolean
setShowScenarioWizard: Dispatch<SetStateAction<boolean>>
vehicle: Vehicle
setVehicle: Dispatch<SetStateAction<Vehicle>>
vehicle: ProhibitorySignsVehicle
setVehicle: Dispatch<SetStateAction<ProhibitorySignsVehicle>>
}

export const ProhibitorySignsPageContext = createContext<
ProhibitorySignsPageContextProps | undefined
>(undefined)

export function useProhibitorySignsPageContext() {

Check warning on line 22 in src/pages/ProhibitorySigns/contexts/PageContext.tsx

View workflow job for this annotation

GitHub Actions / run (lint)

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
const context = useContext(ProhibitorySignsPageContext)
if (context === undefined) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ProhibitorySigns/contexts/PageProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode, useState } from 'react'
import { useSearchParams } from 'react-router-dom'

import { Address } from '../../../types/address'
import { Vehicle } from '../types/vehicle'
import { ProhibitorySignsVehicle } from '../types/vehicle'

import { ProhibitorySignsPageContext } from './PageContext'

Expand All @@ -16,7 +16,7 @@ const ProhibitorySignsPageProvider = ({ children }: Props) => {
const [queryParams] = useSearchParams()
const expertMode = queryParams.get('expertMode') ? true : false
const [showScenarioWizard, setShowScenarioWizard] = useState(true)
const [vehicle, setVehicle] = useState({} as Vehicle)
const [vehicle, setVehicle] = useState({} as ProhibitorySignsVehicle)

return (
<ProhibitorySignsPageContext.Provider
Expand Down
10 changes: 3 additions & 7 deletions src/pages/ProhibitorySigns/types/vehicle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export interface Vehicle {
axleWeight: number
hasTrailer: boolean
height: number
length: number
import { Vehicle } from '../../../types/vehicle'

export interface ProhibitorySignsVehicle extends Vehicle {
licensePlate: string
payload: number
weight: number
width: number
}
2 changes: 0 additions & 2 deletions src/pages/Restrictions/defaultVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ export const defaultVehicle: RestrictionsVehicle = {
hasTrailer: false,
height: 1,
length: 0,
licensePlate: '',
maxAllowedWeight: 0,
payload: 0,
type: 'Bedrijfsauto',
weight: 0,
width: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Restrictions/types/vehicle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Vehicle } from '../../ProhibitorySigns/types/vehicle'
import { Vehicle } from '../../../types/vehicle'

export interface RestrictionsVehicle extends Vehicle {
maxAllowedWeight: number
Expand Down
8 changes: 8 additions & 0 deletions src/types/vehicle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Vehicle {
axleWeight: number
hasTrailer: false
height: number
length: number
weight: number
width: number
}
4 changes: 2 additions & 2 deletions test/utils/prohibitorySigns/withPageContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ProhibitorySignsPageContextProps,
} from '../../../src/pages/ProhibitorySigns/contexts/PageContext'
import { Address } from '../../../src/types/address'
import { Vehicle } from '../../../src/pages/ProhibitorySigns/types/vehicle'
import { ProhibitorySignsVehicle } from '../../../src/pages/ProhibitorySigns/types/vehicle'

export const initialState: ProhibitorySignsPageContextProps = {
activeStepWizard: 0,
Expand All @@ -15,7 +15,7 @@ export const initialState: ProhibitorySignsPageContextProps = {
expertMode: false,
showScenarioWizard: false,
setShowScenarioWizard: () => {},
vehicle: {} as Vehicle,
vehicle: {} as ProhibitorySignsVehicle,
setVehicle: () => {},
}

Expand Down
Loading