From 3017c63a4905aec6723bec2be040dc557ab6301c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Tue, 5 Nov 2024 10:42:13 +0000 Subject: [PATCH 01/14] fix: display latest reg --- .../VehicleBulkMileageRow.tsx | 50 +++++++++++++++---- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileageRow.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileageRow.tsx index 6536795c32aa..93a18bbae7c5 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileageRow.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileageRow.tsx @@ -8,7 +8,7 @@ import { useGetUsersMileageLazyQuery, } from './VehicleBulkMileage.generated' -import { useEffect, useState, useCallback } from 'react' +import { useEffect, useState, useCallback, useMemo } from 'react' import { ExpandRow, NestedFullTable, @@ -22,6 +22,7 @@ import { InputController } from '@island.is/shared/form-fields' import * as styles from './VehicleBulkMileage.css' import { displayWithUnit } from '../../utils/displayWithUnit' import { isReadDateToday } from '../../utils/readDate' +import { isDefined } from '@island.is/shared/utils' const ORIGIN_CODE = 'ISLAND.IS' @@ -210,6 +211,42 @@ export const VehicleBulkMileageRow = ({ vehicle }: Props) => { } }, [mileageData?.vehicleMileageDetails, vehicle.vehicleId]) + const nestedTable = useMemo(() => { + if (!data?.vehiclesMileageRegistrationHistory) { + return [[]] + } + const tableData: Array> = [[]] + if (data?.vehiclesMileageRegistrationHistory?.lastMileageRegistration) { + tableData.push([ + formatDate( + data.vehiclesMileageRegistrationHistory.lastMileageRegistration.date, + ), + data.vehiclesMileageRegistrationHistory.lastMileageRegistration + .originCode, + //'-', + displayWithUnit( + data.vehiclesMileageRegistrationHistory.lastMileageRegistration + .mileage, + 'km', + true, + ), + ]) + } + for (const mileageRegistration of data?.vehiclesMileageRegistrationHistory + ?.mileageRegistrationHistory ?? []) { + if (mileageRegistration) { + tableData.push([ + formatDate(mileageRegistration.date), + mileageRegistration.originCode, + //'-', + displayWithUnit(mileageRegistration.mileage, 'km', true), + ]) + } + } + + return tableData + }, [data?.vehiclesMileageRegistrationHistory]) + return ( { ]} loading={loading} emptyMessage={formatMessage(vehicleMessage.mileageHistoryNotFound)} - data={ - data?.vehiclesMileageRegistrationHistory?.mileageRegistrationHistory?.map( - (r) => [ - formatDate(r.date), - r.originCode, - //'-', - displayWithUnit(r.mileage, 'km', true), - ], - ) ?? [] - } + data={nestedTable} /> )} From f557a65574e3b98b7cf96113f9a000b74cdffb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Tue, 5 Nov 2024 11:00:32 +0000 Subject: [PATCH 02/14] feat: add error code map --- .../vehicles/src/lib/services/errorCodes.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 libs/api/domains/vehicles/src/lib/services/errorCodes.ts diff --git a/libs/api/domains/vehicles/src/lib/services/errorCodes.ts b/libs/api/domains/vehicles/src/lib/services/errorCodes.ts new file mode 100644 index 000000000000..7db45151d6de --- /dev/null +++ b/libs/api/domains/vehicles/src/lib/services/errorCodes.ts @@ -0,0 +1,21 @@ +export const errorCodeMessageMap: Record = { + 3: 'Fastanúmer vantar', + 4: 'Dagsetning álesturs vantar', + 5: 'Uppruna álesturs vantar', + 6: 'Álestur vantar', + 7: 'Km staða getur ekki verið minna en 0', + 8: 'Km staða álesturs getur ekki verið minni en síðasta gildi sem skráð hefur verið á ökutækið', + 9: 'Staðartegund í álestri finnst ekki', + 10: 'Ökutæki finnst ekki', + 11: 'Dagsetning færslu minni en nýjasta færsla á ökutæki', + 12: 'Ekki má breyta færslu sem er ekki innan dagsins í dag', + 13: 'Villa við skráningu, ekki má skrá innan 30 daga frá síðustu færslu', + 14: 'Ekki má breyta færslu sem er ekki nýjasta færsla ökutækis', + 15: 'Tilkynnandi eða innsendur tilkynnandi er hvorki umráðamaður né eigandi ökutækis', + 16: 'Tegund álesturs ekki til', + 17: 'Aðeins er leyfilegt að eyða nýjustu km skráningu', + 18: 'Færsla til að eyða finnst ekki', + 19: 'Ökutæki krefst ekki aflesturs', + 20: 'Km staða fer yfir hámark per dag', + 21: 'Km staða fer yfir hámark per dag', +} From 580deb47ce3f92d9b588884cfade2a750f66b808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Wed, 6 Nov 2024 14:01:57 +0000 Subject: [PATCH 03/14] feat: add errors --- libs/api/domains/vehicles/project.json | 6 ++ ...BulkVehicleMileageRequestOverview.input.ts | 4 + libs/api/domains/vehicles/src/lib/messages.ts | 79 +++++++++++++++++++ ...lkMileageRegistrationRequestError.model.ts | 8 +- .../src/lib/resolvers/bulkMileage.resolver.ts | 1 + .../src/lib/services/bulkMileage.service.ts | 13 ++- .../vehicles/src/lib/services/errorCodes.ts | 42 +++++----- .../src/lib/services/vehicles.service.ts | 14 ++-- .../vehicles/src/lib/vehicles.module.ts | 2 + .../vehicles-mileage/src/clientConfig.json | 20 +++-- .../VehicleBulkMileageJobDetail.graphql | 2 + .../VehicleBulkMileageJobDetail.tsx | 3 +- 12 files changed, 155 insertions(+), 39 deletions(-) create mode 100644 libs/api/domains/vehicles/src/lib/messages.ts diff --git a/libs/api/domains/vehicles/project.json b/libs/api/domains/vehicles/project.json index 12892a54a5b4..b08b0b11eb44 100644 --- a/libs/api/domains/vehicles/project.json +++ b/libs/api/domains/vehicles/project.json @@ -14,6 +14,12 @@ "options": { "jestConfig": "libs/api/domains/vehicles/jest.config.ts" } + }, + "extract-strings": { + "executor": "nx:run-commands", + "options": { + "command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/api/domains/vehicles/src/lib/messages.ts'" + } } } } diff --git a/libs/api/domains/vehicles/src/lib/dto/getBulkVehicleMileageRequestOverview.input.ts b/libs/api/domains/vehicles/src/lib/dto/getBulkVehicleMileageRequestOverview.input.ts index 65b238fb9150..3ad3e1bb1e97 100644 --- a/libs/api/domains/vehicles/src/lib/dto/getBulkVehicleMileageRequestOverview.input.ts +++ b/libs/api/domains/vehicles/src/lib/dto/getBulkVehicleMileageRequestOverview.input.ts @@ -1,7 +1,11 @@ import { Field, ID, InputType } from '@nestjs/graphql' +import type { Locale } from '@island.is/shared/types' @InputType() export class BulkVehicleMileageRequestOverviewInput { + @Field(() => String) + locale!: Locale + @Field(() => ID) guid!: string } diff --git a/libs/api/domains/vehicles/src/lib/messages.ts b/libs/api/domains/vehicles/src/lib/messages.ts new file mode 100644 index 000000000000..a89944230332 --- /dev/null +++ b/libs/api/domains/vehicles/src/lib/messages.ts @@ -0,0 +1,79 @@ +import { defineMessages } from 'react-intl' + +export const m = defineMessages({ + missingPermno: { + id: 'api.bulk-vehicle-mileage:missing-permno', + defaultMessage: 'Fastanúmer vantar', + }, + dateMissing: { + id: 'api.bulk-vehicle-mileage:date-missing', + defaultMessage: 'Dagsetning álesturs vantar', + }, + originMissing: { + id: 'api.bulk-vehicle-mileage:missing-origin', + defaultMessage: 'Uppruna álesturs vantar', + }, + mileageMissing: { + id: 'api.bulk-vehicle-mileage:missing-mileage', + defaultMessage: 'Álestur vantar', + }, + mileageTooLow: { + id: 'api.bulk-vehicle-mileage:mileage-too-low', + defaultMessage: 'Km staða getur ekki verið minna en 0', + }, + mileageLowerThanBefore: { + id: 'api.bulk-vehicle-mileage:mileage-lower-than-before', + defaultMessage: + 'Km staða álesturs getur ekki verið minni en síðasta gildi sem skráð hefur verið á ökutækið', + }, + originNotFound: { + id: 'api.bulk-vehicle-mileage:origin-not-found', + defaultMessage: 'Staðartegund í álestri finnst ekki', + }, + carNotFound: { + id: 'api.bulk-vehicle-mileage:car-not-found', + defaultMessage: 'Ökutæki finnst ekki', + }, + dateTooEarly: { + id: 'api.bulk-vehicle-mileage:date-too-early', + defaultMessage: 'Dagsetning færslu minni en nýjasta færsla á ökutæki', + }, + invalidUpdate: { + id: 'api.bulk-vehicle-mileage:invalid-update', + defaultMessage: 'Ekki má breyta færslu sem er ekki innan dagsins í dag', + }, + registerTooEarly: { + id: 'api.bulk-vehicle-mileage:register-too-early', + defaultMessage: + 'Villa við skráningu, ekki má skrá innan 30 daga frá síðustu færslu', + }, + forbiddenUpdate: { + id: 'api.bulk-vehicle-mileage:forbidden-update', + defaultMessage: 'Ekki má breyta færslu sem er ekki nýjasta færsla ökutækis', + }, + unauthorizedUpdater: { + id: 'api.bulk-vehicle-mileage:unauthorized-updater', + defaultMessage: + 'Tilkynnandi eða innsendur tilkynnandi er hvorki umráðamaður né eigandi ökutækis', + }, + invalidMileage: { + id: 'api.bulk-vehicle-mileage:invalid-mileage', + defaultMessage: 'Tegund álesturs ekki til', + }, + invalidDelete: { + id: 'api.bulk-vehicle-mileage:invalid-delete', + defaultMessage: 'Aðeins er leyfilegt að eyða nýjustu km skráningu', + }, + notFoundDelete: { + id: 'api.bulk-vehicle-mileage:not-found-delete', + defaultMessage: 'Færsla til að eyða finnst ekki', + }, + unnecessaryRegistration: { + id: 'api.bulk-vehicle-mileage:unnecessary-registration', + defaultMessage: 'Ökutæki krefst ekki aflesturs', + }, + tooHighMileage: { + id: 'api.bulk-vehicle-mileage:too-high-mileage', + defaultMessage: 'Km staða fer yfir hámark per dag', + }, +}) diff --git a/libs/api/domains/vehicles/src/lib/models/v3/bulkMileage/bulkMileageRegistrationRequestError.model.ts b/libs/api/domains/vehicles/src/lib/models/v3/bulkMileage/bulkMileageRegistrationRequestError.model.ts index a289df9b6cfa..f8f6bf80f1dc 100644 --- a/libs/api/domains/vehicles/src/lib/models/v3/bulkMileage/bulkMileageRegistrationRequestError.model.ts +++ b/libs/api/domains/vehicles/src/lib/models/v3/bulkMileage/bulkMileageRegistrationRequestError.model.ts @@ -1,4 +1,4 @@ -import { Field, ObjectType } from '@nestjs/graphql' +import { Field, Int, ObjectType } from '@nestjs/graphql' @ObjectType() export class VehiclesBulkMileageRegistrationRequestError { @@ -7,4 +7,10 @@ export class VehiclesBulkMileageRegistrationRequestError { @Field({ nullable: true }) message?: string + + @Field(() => Int, { nullable: true }) + warningSerialCode?: number + + @Field({ nullable: true }) + warningText?: string } diff --git a/libs/api/domains/vehicles/src/lib/resolvers/bulkMileage.resolver.ts b/libs/api/domains/vehicles/src/lib/resolvers/bulkMileage.resolver.ts index a551c3dc893a..f8c40cfdfa30 100644 --- a/libs/api/domains/vehicles/src/lib/resolvers/bulkMileage.resolver.ts +++ b/libs/api/domains/vehicles/src/lib/resolvers/bulkMileage.resolver.ts @@ -66,6 +66,7 @@ export class VehiclesBulkMileageResolver { ) { return this.bulkService.getBulkMileageRegistrationRequestOverview( user, + input.locale, input.guid, ) } diff --git a/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts b/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts index d5aec6f44140..82796263f9c0 100644 --- a/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts +++ b/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts @@ -7,6 +7,7 @@ import { AuthMiddleware } from '@island.is/auth-nest-tools' import type { Auth, User } from '@island.is/auth-nest-tools' import { PostVehicleBulkMileageInput } from '../dto/postBulkVehicleMileage.input' import { isDefined } from '@island.is/shared/utils' +import type { Locale } from '@island.is/shared/types' import { LOG_CATEGORY } from '../constants' import { LOGGER_PROVIDER, type Logger } from '@island.is/logging' import { VehiclesBulkMileageReadingResponse } from '../models/v3/bulkMileage/bulkMileageReadingResponse.model' @@ -14,11 +15,16 @@ import { VehiclesBulkMileageRegistrationJobHistory } from '../models/v3/bulkMile import { VehiclesBulkMileageRegistrationRequestStatus } from '../models/v3/bulkMileage/bulkMileageRegistrationRequestStatus.model' import { VehiclesBulkMileageRegistrationRequestOverview } from '../models/v3/bulkMileage/bulkMileageRegistrationRequestOverview.model' import { FetchError } from '@island.is/clients/middlewares' +import { IntlService } from '@island.is/cms-translations' +import { errorCodeMessageMap } from './errorCodes' + +const namespaces = ['api.bulk-vehicle-mileage'] @Injectable() export class BulkMileageService { constructor( private mileageReadingApi: MileageReadingApi, + private readonly intlService: IntlService, @Inject(LOGGER_PROVIDER) private readonly logger: Logger, ) {} @@ -59,7 +65,6 @@ export class BulkMileageService { return { requestId: res.guid, - errorMessage: res.errorMessage ?? undefined, } } catch (e) { const error: Error = e @@ -127,8 +132,10 @@ export class BulkMileageService { async getBulkMileageRegistrationRequestOverview( auth: User, + locale: Locale, input: GetbulkmileagereadingrequeststatusGuidGetRequest['guid'], ): Promise { + const { formatMessage } = await this.intlService.useIntl(namespaces, locale) const data = await this.getMileageWithAuth( auth, ).getbulkmileagereadingrequestdetailsGuidGet({ guid: input }) @@ -147,6 +154,10 @@ export class BulkMileageService { errors: d.errors?.map((e) => ({ code: e.errorCode ?? undefined, message: e.errorText ?? undefined, + warningSerialCode: e.warningSerial ?? 0, + warningText: e.warningSerial + ? formatMessage(errorCodeMessageMap[e.warningSerial ?? 0]) + : undefined, })), } }) diff --git a/libs/api/domains/vehicles/src/lib/services/errorCodes.ts b/libs/api/domains/vehicles/src/lib/services/errorCodes.ts index 7db45151d6de..3188e871aa8f 100644 --- a/libs/api/domains/vehicles/src/lib/services/errorCodes.ts +++ b/libs/api/domains/vehicles/src/lib/services/errorCodes.ts @@ -1,21 +1,23 @@ -export const errorCodeMessageMap: Record = { - 3: 'Fastanúmer vantar', - 4: 'Dagsetning álesturs vantar', - 5: 'Uppruna álesturs vantar', - 6: 'Álestur vantar', - 7: 'Km staða getur ekki verið minna en 0', - 8: 'Km staða álesturs getur ekki verið minni en síðasta gildi sem skráð hefur verið á ökutækið', - 9: 'Staðartegund í álestri finnst ekki', - 10: 'Ökutæki finnst ekki', - 11: 'Dagsetning færslu minni en nýjasta færsla á ökutæki', - 12: 'Ekki má breyta færslu sem er ekki innan dagsins í dag', - 13: 'Villa við skráningu, ekki má skrá innan 30 daga frá síðustu færslu', - 14: 'Ekki má breyta færslu sem er ekki nýjasta færsla ökutækis', - 15: 'Tilkynnandi eða innsendur tilkynnandi er hvorki umráðamaður né eigandi ökutækis', - 16: 'Tegund álesturs ekki til', - 17: 'Aðeins er leyfilegt að eyða nýjustu km skráningu', - 18: 'Færsla til að eyða finnst ekki', - 19: 'Ökutæki krefst ekki aflesturs', - 20: 'Km staða fer yfir hámark per dag', - 21: 'Km staða fer yfir hámark per dag', +import { MessageDescriptor } from 'react-intl' +import { m } from '../../lib/messages' + +export const errorCodeMessageMap: Record = { + 3: m.missingPermno, + 4: m.dateMissing, + 5: m.originMissing, + 6: m.mileageMissing, + 7: m.mileageTooLow, + 8: m.mileageLowerThanBefore, + 9: m.originNotFound, + 10: m.carNotFound, + 11: m.dateTooEarly, + 12: m.invalidUpdate, + 13: m.registerTooEarly, + 14: m.forbiddenUpdate, + 15: m.unauthorizedUpdater, + 16: m.invalidMileage, + 17: m.invalidDelete, + 18: m.notFoundDelete, + 19: m.unnecessaryRegistration, + 20: m.tooHighMileage, } diff --git a/libs/api/domains/vehicles/src/lib/services/vehicles.service.ts b/libs/api/domains/vehicles/src/lib/services/vehicles.service.ts index b573cdeec805..e5ada4713f53 100644 --- a/libs/api/domains/vehicles/src/lib/services/vehicles.service.ts +++ b/libs/api/domains/vehicles/src/lib/services/vehicles.service.ts @@ -11,7 +11,6 @@ import { VehicleDtoListPagedResponse, PersidnoLookupResultDto, CurrentVehiclesWithMilageAndNextInspDtoListPagedResponse, - ApiResponse, } from '@island.is/clients/vehicles' import { CanregistermileagePermnoGetRequest, @@ -19,7 +18,6 @@ import { MileageReadingApi, MileageReadingDto, PostMileageReadingModel, - PutMileageReadingModel, RequiresmileageregistrationPermnoGetRequest, RootPostRequest, RootPutRequest, @@ -35,10 +33,7 @@ import { GetVehiclesForUserInput, GetVehiclesListV2Input, } from '../dto/getVehiclesForUserInput' -import { - VehicleMileageDetail, - VehicleMileageOverview, -} from '../models/getVehicleMileage.model' +import { VehicleMileageOverview } from '../models/getVehicleMileage.model' import isSameDay from 'date-fns/isSameDay' import { mileageDetailConstructor } from '../utils/helpers' import { FetchError, handle404 } from '@island.is/clients/middlewares' @@ -470,9 +465,11 @@ export class VehiclesService { throw new ForbiddenException(UNAUTHORIZED_OWNERSHIP_LOG) } - return this.getMileageWithAuth(auth).rootPut({ + const dtos = await this.getMileageWithAuth(auth).rootPut({ putMileageReadingModel: input, }) + + return dtos[0] } async postMileageReadingV2( @@ -537,9 +534,10 @@ export class VehiclesService { } try { - return this.getMileageWithAuth(auth).rootPut({ + const dtos = await this.getMileageWithAuth(auth).rootPut({ putMileageReadingModel: input, }) + return dtos[0] } catch (e) { if (e instanceof FetchError && (e.status === 400 || e.status === 429)) { const errorBody = e.body as UpdateResponseError diff --git a/libs/api/domains/vehicles/src/lib/vehicles.module.ts b/libs/api/domains/vehicles/src/lib/vehicles.module.ts index 3fcb00edafd3..86dbbc62cce4 100644 --- a/libs/api/domains/vehicles/src/lib/vehicles.module.ts +++ b/libs/api/domains/vehicles/src/lib/vehicles.module.ts @@ -11,6 +11,7 @@ import { FeatureFlagModule } from '@island.is/nest/feature-flags' import { BulkMileageService } from './services/bulkMileage.service' import { VehiclesV3Resolver } from './resolvers/vehicleV3.resolver' import { VehiclesBulkMileageResolver } from './resolvers/bulkMileage.resolver' +import { CmsTranslationsModule } from '@island.is/cms-translations' @Module({ providers: [ @@ -26,6 +27,7 @@ import { VehiclesBulkMileageResolver } from './resolvers/bulkMileage.resolver' VehiclesClientModule, VehiclesMileageClientModule, AuthModule, + CmsTranslationsModule, FeatureFlagModule, ], exports: [VehiclesService], diff --git a/libs/clients/vehicles-mileage/src/clientConfig.json b/libs/clients/vehicles-mileage/src/clientConfig.json index b934c4f3088e..1af507c8b7a0 100644 --- a/libs/clients/vehicles-mileage/src/clientConfig.json +++ b/libs/clients/vehicles-mileage/src/clientConfig.json @@ -2,13 +2,14 @@ "openapi": "3.0.1", "info": { "title": "SGS Rest API", - "description": "Mileage reading API developed in .Net8.0 - Release-6 : 20231122.2", + "description": "Mileage reading API developed in .Net8.0 - Release-21 : 20241105.1", "contact": { "name": "Samgöngustofa", "email": "tolvuhjalp@samgongustofa.is" }, "version": "1.0" }, + "servers": [{ "url": "/vehicle/mileagereading" }], "paths": { "/authenticate": { "post": { @@ -243,11 +244,14 @@ } }, "responses": { - "201": { + "200": { "description": "OK", "content": { "application/json": { - "schema": { "$ref": "#/components/schemas/MileageReadingDto" } + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/MileageReadingDto" } + } } } }, @@ -788,6 +792,11 @@ "description": "Error code", "nullable": true }, + "warningSerial": { + "type": "integer", + "description": "Warning serial", + "format": "int32" + }, "errorText": { "type": "string", "description": "Error text", @@ -850,11 +859,6 @@ "type": "string", "description": "Guid to check for status and results", "nullable": true - }, - "errorMessage": { - "type": "string", - "description": "Error message if any", - "nullable": true } }, "additionalProperties": false, diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.graphql b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.graphql index 41047a57ba5c..d6c342f0a2b8 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.graphql +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.graphql @@ -18,6 +18,8 @@ query getJobRegistrations($input: BulkVehicleMileageRequestOverviewInput!) { errors { code message + warningSerialCode + warningText } } } diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx index 8b2bc2750962..52129d9fc04d 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx @@ -34,7 +34,7 @@ type UseParams = { const VehicleBulkMileageJobDetail = () => { useNamespaces('sp.vehicles') - const { formatMessage } = useLocale() + const { formatMessage, locale } = useLocale() const { id } = useParams() as UseParams const { data, loading, error, refetch, networkStatus } = @@ -57,6 +57,7 @@ const VehicleBulkMileageJobDetail = () => { notifyOnNetworkStatusChange: true, variables: { input: { + locale: locale, guid: id, }, }, From 0a12151f5b2bcb278ab7b1e6ff3a831270ccb57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Wed, 6 Nov 2024 15:55:19 +0000 Subject: [PATCH 04/14] fix: csv parse --- libs/service-portal/assets/src/lib/messages.ts | 4 ++++ .../VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx | 4 +++- .../service-portal/assets/src/utils/parseFileToMileage.ts | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/service-portal/assets/src/lib/messages.ts b/libs/service-portal/assets/src/lib/messages.ts index caef9991b01f..2c4f65976e3f 100644 --- a/libs/service-portal/assets/src/lib/messages.ts +++ b/libs/service-portal/assets/src/lib/messages.ts @@ -981,6 +981,10 @@ export const vehicleMessage = defineMessages({ id: 'sp.vehicles:upload-failed', defaultMessage: 'Upphleðsla mistókst', }, + noDataInUploadedFile: { + id: 'sp.vehicles:no-data-in-uploaded-file', + defaultMessage: 'Upphleðsla mistókst. Engin gögn í skjali', + }, wrongFileType: { id: 'sp.vehicles:wrong-file-type', defaultMessage: 'Vitlaus skráartýpa. Skrá verður að vera .csv eða .xslx', diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx index 54aa3ad49589..a2fedf450a18 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx @@ -57,7 +57,9 @@ const VehicleBulkMileageUpload = () => { try { const records = await parseFileToMileageRecord(file, type) if (!records.length) { - setUploadErrorMessage(formatMessage(vehicleMessage.uploadFailed)) + setUploadErrorMessage( + formatMessage(vehicleMessage.noDataInUploadedFile), + ) return } if (typeof records === 'string') { diff --git a/libs/service-portal/assets/src/utils/parseFileToMileage.ts b/libs/service-portal/assets/src/utils/parseFileToMileage.ts index 7382ab57e315..16ad19e73b4c 100644 --- a/libs/service-portal/assets/src/utils/parseFileToMileage.ts +++ b/libs/service-portal/assets/src/utils/parseFileToMileage.ts @@ -28,6 +28,7 @@ export const parseFileToMileageRecord = async ( const vehicleIndex = header.findIndex((l) => vehicleIndexTitle.includes(l.toLowerCase()), ) + if (vehicleIndex < 0) { throw new Error( `Invalid vehicle column header. Must be one of the following: ${vehicleIndexTitle.join( @@ -76,7 +77,6 @@ const parseCsv = async (file: File) => { accumulatedChunk += decoder.decode(res.value) } } - return parseCsvString(accumulatedChunk) } @@ -105,13 +105,13 @@ const parseCsvString = (chunk: string): Promise => { const records: string[][] = [] const parser = parse({ - cast: true, - skipEmptyLines: true, delimiter: [';', ','], + skipLinesWithEmptyValues: true, + trim: true, }) parser.on('readable', () => { - let record + let record: Array while ((record = parser.read()) !== null) { records.push(record) } From 903dab8ed8d27925efae79ef5d77041771b2e65b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Wed, 6 Nov 2024 16:14:43 +0000 Subject: [PATCH 05/14] fix: jobs sorting --- .../VehicleBulkMileageJobOverview.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobOverview/VehicleBulkMileageJobOverview.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobOverview/VehicleBulkMileageJobOverview.tsx index 648ef2116b7c..056e9f37eeb9 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobOverview/VehicleBulkMileageJobOverview.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobOverview/VehicleBulkMileageJobOverview.tsx @@ -63,8 +63,11 @@ const VehicleBulkMileageUploadJobOverview = () => { const jobs: Array = data?.vehicleBulkMileageRegistrationJobHistory?.history ?? [] - const sortedJobs = jobs.length > 1 ? [...jobs] : [] - sortedJobs.sort((a, b) => sortJobs(a, b)) + const sortedJobs = [...jobs] + if (sortedJobs.length > 1) { + sortedJobs.sort((a, b) => sortJobs(a, b)) + } + return ( Date: Wed, 6 Nov 2024 16:20:55 +0000 Subject: [PATCH 06/14] fix: remove strip --- libs/service-portal/assets/src/utils/parseFileToMileage.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/service-portal/assets/src/utils/parseFileToMileage.ts b/libs/service-portal/assets/src/utils/parseFileToMileage.ts index 16ad19e73b4c..97b22facd440 100644 --- a/libs/service-portal/assets/src/utils/parseFileToMileage.ts +++ b/libs/service-portal/assets/src/utils/parseFileToMileage.ts @@ -89,7 +89,6 @@ const parseXlsx = async (file: File) => { const jsonData = XLSX.utils.sheet_to_csv( parsedFile.Sheets[parsedFile.SheetNames[0]], { - strip: true, blankrows: false, }, ) From 9bb08fdb5bc5e53ebc5410456cd79c47616c1299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 8 Nov 2024 10:42:30 +0000 Subject: [PATCH 07/14] fix: translations --- libs/api/domains/vehicles/src/lib/messages.ts | 4 ++++ .../src/lib/services/bulkMileage.service.ts | 22 ++++++++++++------- .../vehicles/src/lib/services/errorCodes.ts | 1 + .../VehicleBulkMileageJobDetail.tsx | 6 +++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/libs/api/domains/vehicles/src/lib/messages.ts b/libs/api/domains/vehicles/src/lib/messages.ts index a89944230332..2d3b82517ee0 100644 --- a/libs/api/domains/vehicles/src/lib/messages.ts +++ b/libs/api/domains/vehicles/src/lib/messages.ts @@ -1,6 +1,10 @@ import { defineMessages } from 'react-intl' export const m = defineMessages({ + tooManyPermno: { + id: 'api.bulk-vehicle-mileage:too-many-permno', + defaultMessage: 'Sama fastanúmer birtist oft í skjali', + }, missingPermno: { id: 'api.bulk-vehicle-mileage:missing-permno', defaultMessage: 'Fastanúmer vantar', diff --git a/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts b/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts index 82796263f9c0..ded6e2188f97 100644 --- a/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts +++ b/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts @@ -146,19 +146,25 @@ export class BulkMileageService { if (!d.guid || !d.permno) { return null } + return { guid: d.guid, vehicleId: d.permno, mileage: d.mileage ?? undefined, returnCode: d.returnCode ?? undefined, - errors: d.errors?.map((e) => ({ - code: e.errorCode ?? undefined, - message: e.errorText ?? undefined, - warningSerialCode: e.warningSerial ?? 0, - warningText: e.warningSerial - ? formatMessage(errorCodeMessageMap[e.warningSerial ?? 0]) - : undefined, - })), + errors: d.errors?.map((e) => { + const warningSerial = + e.warningSerial === -1 ? 999 : e.warningSerial + + return { + code: e.errorCode ?? undefined, + message: e.errorText ?? undefined, + warningSerialCode: e.warningSerial ?? 0, + warningText: warningSerial + ? formatMessage(errorCodeMessageMap[warningSerial ?? 0]) + : undefined, + } + }), } }) .filter(isDefined), diff --git a/libs/api/domains/vehicles/src/lib/services/errorCodes.ts b/libs/api/domains/vehicles/src/lib/services/errorCodes.ts index 3188e871aa8f..ba2f1423f82f 100644 --- a/libs/api/domains/vehicles/src/lib/services/errorCodes.ts +++ b/libs/api/domains/vehicles/src/lib/services/errorCodes.ts @@ -2,6 +2,7 @@ import { MessageDescriptor } from 'react-intl' import { m } from '../../lib/messages' export const errorCodeMessageMap: Record = { + 999: m.tooManyPermno, //returned error code is -1, which cant be used to index. Transform to 999 3: m.missingPermno, 4: m.dateMissing, 5: m.originMissing, diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx index 52129d9fc04d..0f8112e7357f 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx @@ -90,7 +90,7 @@ const VehicleBulkMileageJobDetail = () => { } return [ erroredVehicle.vehicleId, - erroredVehicle.errors.map((j) => j.message).join(', '), + erroredVehicle.errors.map((j) => j.warningText).join(', '), ] }) .filter(isDefined) @@ -250,7 +250,9 @@ const VehicleBulkMileageJobDetail = () => { {displayWithUnit(j.mileage, 'km', true)} - {(j.errors ?? []).map((j) => j.message).join(', ')} + {(j.errors ?? []) + .map((j) => j.warningText) + .join(', ')} )) From 9f3ef8f521d519f7296c2be0477cdebaee3efce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 8 Nov 2024 11:15:09 +0000 Subject: [PATCH 08/14] fix: add sanitization on number --- libs/service-portal/assets/src/utils/parseFileToMileage.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/service-portal/assets/src/utils/parseFileToMileage.ts b/libs/service-portal/assets/src/utils/parseFileToMileage.ts index 97b22facd440..8c596e4f472d 100644 --- a/libs/service-portal/assets/src/utils/parseFileToMileage.ts +++ b/libs/service-portal/assets/src/utils/parseFileToMileage.ts @@ -50,7 +50,7 @@ export const parseFileToMileageRecord = async ( const uploadedOdometerStatuses: Array = values .map((row) => { - const mileage = Number(row[mileageIndex]) + const mileage = Number(sanitizeNumber(row[mileageIndex])) if (Number.isNaN(mileage)) { return undefined } @@ -128,3 +128,5 @@ const parseCsvString = (chunk: string): Promise => { parser.end() }) } + +const sanitizeNumber = (n: string) => n.replace(/[^\d]/g, '') From 72ac3c59737716158420d535ba77869c9abaa727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 8 Nov 2024 13:11:24 +0000 Subject: [PATCH 09/14] fix: sanitization --- libs/service-portal/assets/src/utils/parseFileToMileage.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/service-portal/assets/src/utils/parseFileToMileage.ts b/libs/service-portal/assets/src/utils/parseFileToMileage.ts index 8c596e4f472d..6b5cb5c41efa 100644 --- a/libs/service-portal/assets/src/utils/parseFileToMileage.ts +++ b/libs/service-portal/assets/src/utils/parseFileToMileage.ts @@ -51,6 +51,7 @@ export const parseFileToMileageRecord = async ( const uploadedOdometerStatuses: Array = values .map((row) => { const mileage = Number(sanitizeNumber(row[mileageIndex])) + console.log(mileage) if (Number.isNaN(mileage)) { return undefined } @@ -129,4 +130,4 @@ const parseCsvString = (chunk: string): Promise => { }) } -const sanitizeNumber = (n: string) => n.replace(/[^\d]/g, '') +const sanitizeNumber = (n: string) => n.replace('/,/\\./g', '') From 39ed79bdad300ff2dd887c7dad0b4987e448b6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 8 Nov 2024 13:15:52 +0000 Subject: [PATCH 10/14] fix: add secret from aws paramter store --- apps/application-system/api/infra/application-system-api.ts | 2 ++ charts/islandis/values.dev.yaml | 1 + charts/islandis/values.prod.yaml | 1 + charts/islandis/values.staging.yaml | 1 + 4 files changed, 5 insertions(+) diff --git a/apps/application-system/api/infra/application-system-api.ts b/apps/application-system/api/infra/application-system-api.ts index 41738c668a20..d7e2dec8ba98 100644 --- a/apps/application-system/api/infra/application-system-api.ts +++ b/apps/application-system/api/infra/application-system-api.ts @@ -339,6 +339,8 @@ export const serviceSetup = (services: { '/k8s/api/ALTHINGI_OMBUDSMAN_XROAD_USERNAME', ALTHINGI_OMBUDSMAN_XROAD_PASSWORD: '/k8s/api/ALTHINGI_OMBUDSMAN_XROAD_PASSWORD', + NATIONAL_REGISTRY_B2C_CLIENT_SECRET: + '/k8s/api/NATIONAL_REGISTRY_B2C_CLIENT_SECRET', }) .db() .migrations() diff --git a/charts/islandis/values.dev.yaml b/charts/islandis/values.dev.yaml index ca6d0b8694db..c623fa075f17 100644 --- a/charts/islandis/values.dev.yaml +++ b/charts/islandis/values.dev.yaml @@ -796,6 +796,7 @@ application-system-api: IDENTITY_SERVER_CLIENT_SECRET: '/k8s/application-system/api/IDENTITY_SERVER_CLIENT_SECRET' ISLYKILL_SERVICE_BASEPATH: '/k8s/api/ISLYKILL_SERVICE_BASEPATH' ISLYKILL_SERVICE_PASSPHRASE: '/k8s/api/ISLYKILL_SERVICE_PASSPHRASE' + NATIONAL_REGISTRY_B2C_CLIENT_SECRET: '/k8s/api/NATIONAL_REGISTRY_B2C_CLIENT_SECRET' NOVA_PASSWORD: '/k8s/application-system/api/NOVA_PASSWORD' NOVA_URL: '/k8s/application-system-api/NOVA_URL' SYSLUMENN_HOST: '/k8s/application-system-api/SYSLUMENN_HOST' diff --git a/charts/islandis/values.prod.yaml b/charts/islandis/values.prod.yaml index 0564cf2d03c7..475d6bf4064f 100644 --- a/charts/islandis/values.prod.yaml +++ b/charts/islandis/values.prod.yaml @@ -784,6 +784,7 @@ application-system-api: IDENTITY_SERVER_CLIENT_SECRET: '/k8s/application-system/api/IDENTITY_SERVER_CLIENT_SECRET' ISLYKILL_SERVICE_BASEPATH: '/k8s/api/ISLYKILL_SERVICE_BASEPATH' ISLYKILL_SERVICE_PASSPHRASE: '/k8s/api/ISLYKILL_SERVICE_PASSPHRASE' + NATIONAL_REGISTRY_B2C_CLIENT_SECRET: '/k8s/api/NATIONAL_REGISTRY_B2C_CLIENT_SECRET' NOVA_PASSWORD: '/k8s/application-system/api/NOVA_PASSWORD' NOVA_URL: '/k8s/application-system-api/NOVA_URL' SYSLUMENN_HOST: '/k8s/application-system-api/SYSLUMENN_HOST' diff --git a/charts/islandis/values.staging.yaml b/charts/islandis/values.staging.yaml index c7e4a2583b0d..402379a9766c 100644 --- a/charts/islandis/values.staging.yaml +++ b/charts/islandis/values.staging.yaml @@ -793,6 +793,7 @@ application-system-api: IDENTITY_SERVER_CLIENT_SECRET: '/k8s/application-system/api/IDENTITY_SERVER_CLIENT_SECRET' ISLYKILL_SERVICE_BASEPATH: '/k8s/api/ISLYKILL_SERVICE_BASEPATH' ISLYKILL_SERVICE_PASSPHRASE: '/k8s/api/ISLYKILL_SERVICE_PASSPHRASE' + NATIONAL_REGISTRY_B2C_CLIENT_SECRET: '/k8s/api/NATIONAL_REGISTRY_B2C_CLIENT_SECRET' NOVA_PASSWORD: '/k8s/application-system/api/NOVA_PASSWORD' NOVA_URL: '/k8s/application-system-api/NOVA_URL' SYSLUMENN_HOST: '/k8s/application-system-api/SYSLUMENN_HOST' From 97385d150f802eec4750f41c345c5c354feb81ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 8 Nov 2024 13:39:25 +0000 Subject: [PATCH 11/14] fix: sanitize bit less powerfully --- libs/service-portal/assets/src/utils/parseFileToMileage.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/service-portal/assets/src/utils/parseFileToMileage.ts b/libs/service-portal/assets/src/utils/parseFileToMileage.ts index 6b5cb5c41efa..4deb8497fe3c 100644 --- a/libs/service-portal/assets/src/utils/parseFileToMileage.ts +++ b/libs/service-portal/assets/src/utils/parseFileToMileage.ts @@ -50,6 +50,8 @@ export const parseFileToMileageRecord = async ( const uploadedOdometerStatuses: Array = values .map((row) => { + const l = sanitizeNumber(row[mileageIndex]) + console.log('sanitized ', l) const mileage = Number(sanitizeNumber(row[mileageIndex])) console.log(mileage) if (Number.isNaN(mileage)) { @@ -130,4 +132,4 @@ const parseCsvString = (chunk: string): Promise => { }) } -const sanitizeNumber = (n: string) => n.replace('/,/\\./g', '') +const sanitizeNumber = (n: string) => n.replace(new RegExp(/[.,]/g), '') From 88222ca5f9aae4f7632f1e6d8466227e744508bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 8 Nov 2024 16:10:27 +0000 Subject: [PATCH 12/14] fix: more handling --- .../service-portal/assets/src/lib/messages.ts | 15 +++ .../VehicleBulkMileage/VehicleBulkMileage.tsx | 78 +++++++-------- .../VehicleBulkMileageJobDetail.tsx | 32 +++--- .../VehicleBulkMileageJobOverview.tsx | 16 +-- .../VehicleBulkMileageUpload.tsx | 97 +++++++++++-------- .../assets/src/utils/parseFileToMileage.ts | 38 +++++--- 6 files changed, 157 insertions(+), 119 deletions(-) diff --git a/libs/service-portal/assets/src/lib/messages.ts b/libs/service-portal/assets/src/lib/messages.ts index 2c4f65976e3f..3e6a455f3bac 100644 --- a/libs/service-portal/assets/src/lib/messages.ts +++ b/libs/service-portal/assets/src/lib/messages.ts @@ -218,6 +218,11 @@ export const vehicleMessage = defineMessages({ id: 'sp.vehicles:not-found', defaultMessage: 'Ökutæki fannst ekki', }, + invalidFileType: { + id: 'sp.vehicles:invalid-file-type', + defaultMessage: + 'Ógild skráargerð. Einungis .xlsx og .csv skrár eru samþykktar', + }, infoNote: { id: 'sp.vehicles:detail-info-note', defaultMessage: @@ -993,6 +998,16 @@ export const vehicleMessage = defineMessages({ id: 'sp.vehicles:error-while-processing', defaultMessage: 'Villa við að meðhöndla skjal. Villur: ', }, + invalidPermNoColumn: { + id: 'sp.vehicles:invalid-perm-no-column', + defaultMessage: + 'Fastanúmersdálk vantar eða er skrifaður rangt. Dálkanafn þarf að vera eitt af eftirfarandi; "permno", "vehicleid", "bilnumer","okutaeki","fastanumer"', + }, + invalidMileageColumn: { + id: 'sp.vehicles:invalid-mileage-column', + defaultMessage: + 'Kílómetrastöðudálk vantar eða er skrifaður rangt. Dálkanafn þarf að vera eitt af eftirfarandi; "kilometrastada", "mileage", "odometer"', + }, downloadFailed: { id: 'sp.vehicles:download-failed', defaultMessage: 'Niðurhal mistókst', diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileage.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileage.tsx index 635218334b18..fbfc1fe7b642 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileage.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileage.tsx @@ -5,6 +5,7 @@ import { SAMGONGUSTOFA_SLUG, IntroHeader, LinkButton, + IntroWrapper, } from '@island.is/service-portal/core' import { vehicleMessage as messages, vehicleMessage } from '../../lib/messages' import * as styles from './VehicleBulkMileage.css' @@ -61,7 +62,7 @@ const VehicleBulkMileage = () => { return ( - @@ -83,44 +84,45 @@ const VehicleBulkMileage = () => { } serviceProviderSlug={SAMGONGUSTOFA_SLUG} serviceProviderTooltip={formatMessage(m.vehiclesTooltip)} - /> - - - - - - {error && !loading && } - {!error && ( - - )} + > + + + + + + {error && !loading && } + {!error && ( + + )} - {totalPages > 1 && ( - ( - - )} - /> - )} - + {totalPages > 1 && ( + ( + + )} + /> + )} + + ) diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx index 0f8112e7357f..a82691339e33 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobDetail/VehicleBulkMileageJobDetail.tsx @@ -8,12 +8,12 @@ import { } from '@island.is/island-ui/core' import { useLocale, useNamespaces } from '@island.is/localization' import { - IntroHeader, SAMGONGUSTOFA_SLUG, m, EmptyTable, TableGrid, downloadFile, + IntroWrapper, } from '@island.is/service-portal/core' import { Problem } from '@island.is/react-spa/shared' import { VehiclesBulkMileageRegistrationRequestStatus } from '@island.is/api/schema' @@ -104,19 +104,18 @@ const VehicleBulkMileageJobDetail = () => { !(registrationNetworkStatus === NetworkStatus.refetch) return ( - - - {formatMessage(vehicleMessage.dataAboutJob)} -
- {formatMessage(vehicleMessage.refreshDataAboutJob)} - - } - serviceProviderSlug={SAMGONGUSTOFA_SLUG} - serviceProviderTooltip={formatMessage(m.vehiclesTooltip)} - > + + {formatMessage(vehicleMessage.dataAboutJob)} +
+ {formatMessage(vehicleMessage.refreshDataAboutJob)} + + } + serviceProviderSlug={SAMGONGUSTOFA_SLUG} + serviceProviderTooltip={formatMessage(m.vehiclesTooltip)} + buttonGroup={ -
+ } + > {!error && !loading && !jobsStatus && ( {
)} -
+ ) } diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobOverview/VehicleBulkMileageJobOverview.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobOverview/VehicleBulkMileageJobOverview.tsx index 056e9f37eeb9..ae2b5f970c30 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageJobOverview/VehicleBulkMileageJobOverview.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageJobOverview/VehicleBulkMileageJobOverview.tsx @@ -7,6 +7,7 @@ import { LinkButton, EmptyTable, formatDateWithTime, + IntroWrapper, } from '@island.is/service-portal/core' import { Problem } from '@island.is/react-spa/shared' import { useGetRequestsStatusQuery } from './VehicleBulkMileageJobOverview.generated' @@ -69,13 +70,12 @@ const VehicleBulkMileageUploadJobOverview = () => { } return ( - - + {error && } {!error && ( @@ -144,7 +144,7 @@ const VehicleBulkMileageUploadJobOverview = () => { message={formatMessage(vehicleMessage.noJobsFound)} /> )} - + ) } diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx index a2fedf450a18..8d6441b45a45 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx @@ -10,18 +10,18 @@ import { fileExtensionWhitelist } from '@island.is/island-ui/core/types' import { useLocale, useNamespaces } from '@island.is/localization' import { useEffect, useState } from 'react' import { FileRejection } from 'react-dropzone' +import { AssetsPaths } from '../../lib/paths' +import { useVehicleBulkMileagePostMutation } from './VehicleBulkMileageUpload.generated' +import { vehicleMessage } from '../../lib/messages' +import { parseFileToMileageRecord } from '../../utils/parseFileToMileage' import { - IntroHeader, + IntroWrapper, LinkButton, SAMGONGUSTOFA_SLUG, m, } from '@island.is/service-portal/core' -import { Problem } from '@island.is/react-spa/shared' -import { AssetsPaths } from '../../lib/paths' -import { useVehicleBulkMileagePostMutation } from './VehicleBulkMileageUpload.generated' import VehicleBulkMileageFileDownloader from '../VehicleBulkMileage/VehicleBulkMileageFileDownloader' -import { vehicleMessage } from '../../lib/messages' -import { parseFileToMileageRecord } from '../../utils/parseFileToMileage' +import { Problem } from '@island.is/react-spa/shared' const extensionToType = { [fileExtensionWhitelist['.csv']]: 'csv', @@ -54,39 +54,51 @@ const VehicleBulkMileageUpload = () => { }, [data?.vehicleBulkMileagePost?.requestId]) const postMileage = async (file: File, type: 'xlsx' | 'csv') => { - try { - const records = await parseFileToMileageRecord(file, type) - if (!records.length) { + const records = await parseFileToMileageRecord(file, type) + + if (!Array.isArray(records)) { + if (records.code === 1) { + setUploadErrorMessage(formatMessage(vehicleMessage.invalidPermNoColumn)) + } else if (records.code === 2) { setUploadErrorMessage( - formatMessage(vehicleMessage.noDataInUploadedFile), + formatMessage(vehicleMessage.invalidMileageColumn), ) - return + } else { + setUploadErrorMessage(formatMessage(vehicleMessage.uploadFailed)) } - if (typeof records === 'string') { - setUploadErrorMessage(records) - return - } - vehicleBulkMileagePostMutation({ - variables: { - input: { - mileageData: records.map((r) => ({ - mileageNumber: r.mileage, - vehicleId: r.vehicleId, - })), - originCode: 'ISLAND.IS', - }, - }, - }) - } catch (error) { - setUploadErrorMessage( - `${formatMessage(vehicleMessage.errorWhileProcessing) + error.message} - `, - ) + return + } + + if (!records.length) { + setUploadErrorMessage(formatMessage(vehicleMessage.noDataInUploadedFile)) + return + } + if (typeof records === 'string') { + setUploadErrorMessage(records) + return } + vehicleBulkMileagePostMutation({ + variables: { + input: { + mileageData: records.map((r) => ({ + mileageNumber: r.mileage, + vehicleId: r.vehicleId, + })), + originCode: 'ISLAND.IS', + }, + }, + }) } - const handleOnInputFileUploadError = (files: FileRejection[]) => - setUploadErrorMessage(files[0].errors[0].message) + const handleOnInputFileUploadError = (files: FileRejection[]) => { + console.log(files[0].errors[0].code) + console.log(files[0].errors[0].code === 'file-invalid-type') + if (files[0].errors[0].code === 'file-invalid-type') { + setUploadErrorMessage(formatMessage(vehicleMessage.invalidFileType)) + } else { + setUploadErrorMessage(files[0].errors[0].message) + } + } const handleOnInputFileUploadRemove = () => setUploadedFile(null) @@ -115,18 +127,17 @@ const VehicleBulkMileageUpload = () => { } return ( - - + - - + } + > {error && } {data?.vehicleBulkMileagePost?.errorMessage && !loading && !error && ( @@ -189,7 +200,7 @@ const VehicleBulkMileageUpload = () => { errorMessage={uploadErrorMessage ?? undefined} /> - + ) } diff --git a/libs/service-portal/assets/src/utils/parseFileToMileage.ts b/libs/service-portal/assets/src/utils/parseFileToMileage.ts index 4deb8497fe3c..1c76e4f19a1b 100644 --- a/libs/service-portal/assets/src/utils/parseFileToMileage.ts +++ b/libs/service-portal/assets/src/utils/parseFileToMileage.ts @@ -7,6 +7,11 @@ export interface MileageRecord { mileage: number } +export interface MileageError { + code: 1 | 2 + message: string +} + const vehicleIndexTitle = [ 'permno', 'vehicleid', @@ -16,10 +21,19 @@ const vehicleIndexTitle = [ ] const mileageIndexTitle = ['kilometrastada', 'mileage', 'odometer'] +export const errorMap: Record = { + 1: `Invalid vehicle column header. Must be one of the following: ${vehicleIndexTitle.join( + ', ', + )}`, + 2: `Invalid mileage column header. Must be one of the following: ${mileageIndexTitle.join( + ', ', + )}`, +} + export const parseFileToMileageRecord = async ( file: File, type: 'csv' | 'xlsx', -): Promise> => { +): Promise | MileageError> => { const parsedLines: Array> = await (type === 'csv' ? parseCsv(file) : parseXlsx(file)) @@ -30,30 +44,26 @@ export const parseFileToMileageRecord = async ( ) if (vehicleIndex < 0) { - throw new Error( - `Invalid vehicle column header. Must be one of the following: ${vehicleIndexTitle.join( - ', ', - )}`, - ) + return { + code: 1, + message: errorMap[1], + } } + const mileageIndex = header.findIndex((l) => mileageIndexTitle.includes(l.toLowerCase()), ) if (mileageIndex < 0) { - throw new Error( - `Invalid mileage column header. Must be one of the following: ${mileageIndexTitle.join( - ', ', - )}`, - ) + return { + code: 2, + message: errorMap[2], + } } const uploadedOdometerStatuses: Array = values .map((row) => { - const l = sanitizeNumber(row[mileageIndex]) - console.log('sanitized ', l) const mileage = Number(sanitizeNumber(row[mileageIndex])) - console.log(mileage) if (Number.isNaN(mileage)) { return undefined } From 91267ab50b08a4b28edb459654cdb8a49c3f5c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81sd=C3=ADs=20Erna=20Gu=C3=B0mundsd=C3=B3ttir?= Date: Mon, 11 Nov 2024 15:53:54 +0000 Subject: [PATCH 13/14] Update libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx index 8d6441b45a45..b06d783cfba2 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx @@ -91,8 +91,6 @@ const VehicleBulkMileageUpload = () => { } const handleOnInputFileUploadError = (files: FileRejection[]) => { - console.log(files[0].errors[0].code) - console.log(files[0].errors[0].code === 'file-invalid-type') if (files[0].errors[0].code === 'file-invalid-type') { setUploadErrorMessage(formatMessage(vehicleMessage.invalidFileType)) } else { From 1c0d8af25dc2975a47e1dee31cc0fece01f8f1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Tue, 12 Nov 2024 08:51:23 +0000 Subject: [PATCH 14/14] fix: coderabbit suggestions --- .../domains/vehicles/src/lib/services/bulkMileage.service.ts | 4 ++-- .../api/domains/vehicles/src/lib/services/vehicles.service.ts | 4 ++-- .../src/screens/VehicleBulkMileage/VehicleBulkMileage.tsx | 1 - .../VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx | 4 ---- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts b/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts index ded6e2188f97..f34392b199aa 100644 --- a/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts +++ b/libs/api/domains/vehicles/src/lib/services/bulkMileage.service.ts @@ -159,9 +159,9 @@ export class BulkMileageService { return { code: e.errorCode ?? undefined, message: e.errorText ?? undefined, - warningSerialCode: e.warningSerial ?? 0, + warningSerialCode: e.warningSerial, warningText: warningSerial - ? formatMessage(errorCodeMessageMap[warningSerial ?? 0]) + ? formatMessage(errorCodeMessageMap[warningSerial]) : undefined, } }), diff --git a/libs/api/domains/vehicles/src/lib/services/vehicles.service.ts b/libs/api/domains/vehicles/src/lib/services/vehicles.service.ts index e5ada4713f53..018749f96b3c 100644 --- a/libs/api/domains/vehicles/src/lib/services/vehicles.service.ts +++ b/libs/api/domains/vehicles/src/lib/services/vehicles.service.ts @@ -469,7 +469,7 @@ export class VehiclesService { putMileageReadingModel: input, }) - return dtos[0] + return dtos.length > 0 ? dtos[0] : null } async postMileageReadingV2( @@ -537,7 +537,7 @@ export class VehiclesService { const dtos = await this.getMileageWithAuth(auth).rootPut({ putMileageReadingModel: input, }) - return dtos[0] + return dtos.length > 0 ? dtos[0] : null } catch (e) { if (e instanceof FetchError && (e.status === 400 || e.status === 429)) { const errorBody = e.body as UpdateResponseError diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileage.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileage.tsx index fbfc1fe7b642..787ab421d3a7 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileage.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileage/VehicleBulkMileage.tsx @@ -3,7 +3,6 @@ import { useLocale, useNamespaces } from '@island.is/localization' import { m, SAMGONGUSTOFA_SLUG, - IntroHeader, LinkButton, IntroWrapper, } from '@island.is/service-portal/core' diff --git a/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx b/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx index b06d783cfba2..a822c80f359b 100644 --- a/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx +++ b/libs/service-portal/assets/src/screens/VehicleBulkMileageUpload/VehicleBulkMileageUpload.tsx @@ -73,10 +73,6 @@ const VehicleBulkMileageUpload = () => { setUploadErrorMessage(formatMessage(vehicleMessage.noDataInUploadedFile)) return } - if (typeof records === 'string') { - setUploadErrorMessage(records) - return - } vehicleBulkMileagePostMutation({ variables: { input: {