Skip to content

Commit

Permalink
fix(bulk-vehicle-mileage): Fixes (#16210)
Browse files Browse the repository at this point in the history
* fix. init

* chore: add loading

* fix: intro

* chore: console

* chore: import

* fix: error state

* fix: single vehicle mileage input

* chore: leftoevers

* chore: coderabbit suggestions

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thorkellmani and kodiakhq[bot] authored Oct 1, 2024
1 parent ff7d751 commit 9ef986b
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { MileageRegistrationHistory } from './mileageRegistrationHistory.model'

@ObjectType('VehiclesMileageDetails')
export class MileageDetails {
@Field()
canRegisterMileage!: boolean
@Field({ nullable: true })
canRegisterMileage?: boolean

@Field()
requiresMileageRegistration!: boolean
@Field({ nullable: true })
requiresMileageRegistration?: boolean

@Field(() => MileageRegistrationHistory, { nullable: true })
mileageRegistrations?: MileageRegistrationHistory
Expand Down
12 changes: 4 additions & 8 deletions libs/api/domains/vehicles/src/lib/services/vehicles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@ export class VehiclesService {
data:
res.data
?.map((d) => {
if (
!d.permno ||
!d.regno ||
!d.canRegisterMilage ||
!d.requiresMileageRegistration
) {
if (!d.permno || !d.regno) {
return null
}
return {
Expand All @@ -145,8 +140,9 @@ export class VehiclesService {
type: d.make ?? undefined,
color: d.colorName ?? undefined,
mileageDetails: {
canRegisterMileage: d.canRegisterMilage,
requiresMileageRegistration: d.requiresMileageRegistration,
canRegisterMileage: d.canRegisterMilage ?? undefined,
requiresMileageRegistration:
d.requiresMileageRegistration ?? undefined,
},
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@ query vehiclesList($input: VehiclesListInputV3!) {
}
}

mutation postSingleVehicleMileage($input: PostVehicleMileageInput!) {
vehicleMileagePost(input: $input) {
permno
readDate
originCode
mileageNumber
internalId
}
}

mutation putSingleVehicleMileage($input: PutVehicleMileageInput!) {
vehicleMileagePut(input: $input) {
permno
internalId
mileageNumber
}
}

query GetUsersMileage($input: GetVehicleMileageInput!) {
vehicleMileageDetails(input: $input) {
data {
permno
readDate
originCode
mileageNumber
internalId
}
editing
canRegisterMileage
requiresMileageRegistration
canUserRegisterVehicleMileage
}
}

fragment mileageRegistration on VehiclesMileageRegistration {
originCode
mileage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { vehicleMessage as messages, vehicleMessage } from '../../lib/messages'
import * as styles from './VehicleBulkMileage.css'
import { useEffect, useState } from 'react'
import VehicleBulkMileageTable from './VehicleBulkMileageTable'
import { SubmissionState, VehicleType } from './types'
import { VehicleType } from './types'
import { FormProvider, useForm } from 'react-hook-form'
import { useVehiclesListQuery } from './VehicleBulkMileage.generated'
import { isDefined } from '@island.is/shared/utils'
Expand Down Expand Up @@ -50,7 +50,6 @@ const VehicleBulkMileage = () => {
return {
vehicleId: v.vehicleId,
vehicleType: v.type,
submissionStatus: 'idle' as const,
lastMileageRegistration: undefined,
}
})
Expand All @@ -60,18 +59,6 @@ const VehicleBulkMileage = () => {
}
}, [data?.vehiclesListV3])

const updateVehicleStatus = (status: SubmissionState, vehicleId: string) => {
const newVehicles = vehicles.map((v) => {
if (v.vehicleId === vehicleId) {
return {
...v,
submissionStatus: status,
}
} else return v
})
setVehicles(newVehicles)
}

return (
<Stack space={2}>
<FormProvider {...methods}>
Expand Down Expand Up @@ -115,11 +102,7 @@ const VehicleBulkMileage = () => {
</Inline>
{error && !loading && <Problem error={error} noBorder={false} />}
{!error && (
<VehicleBulkMileageTable
updateVehicleStatus={updateVehicleStatus}
loading={loading}
vehicles={vehicles}
/>
<VehicleBulkMileageTable loading={loading} vehicles={vehicles} />
)}

{totalPages > 1 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ const VehicleBulkMileageFileDownloader = ({ onError }: Props) => {
try {
downloadFile(
`magnskraning_kilometrastodu_example`,
['Ökutæki', 'Kílómetrastaða'],
[['ABC001', 10000]],
['permno', 'mileage'],
[
['ABC001', 10000],
['DEF002', 99999],
],
'csv',
)
} catch (error) {
Expand Down
Loading

0 comments on commit 9ef986b

Please sign in to comment.