Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix/transfer-of-machi…
Browse files Browse the repository at this point in the history
…ne-ownership-seller-cant-be-buyer
  • Loading branch information
sigruntg committed Sep 24, 2024
2 parents cf14b55 + c5d69fd commit a8a5206
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
38 changes: 24 additions & 14 deletions libs/api/domains/work-machines/src/lib/workMachines.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TechInfoItemDto,
WorkMachinesClientService,
} from '@island.is/clients/work-machines'
import { isDefined } from '@island.is/shared/utils'
import { User } from '@island.is/auth-nest-tools'
import {
WorkMachine,
Expand All @@ -19,6 +20,8 @@ import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { MachineDto } from '@island.is/clients/work-machines'
import { GetMachineParentCategoryByTypeAndModelInput } from './dto/getMachineParentCategoryByTypeAndModel.input'
import isValid from 'date-fns/isValid'

@Injectable()
export class WorkMachinesService {
constructor(
Expand Down Expand Up @@ -75,17 +78,22 @@ export class WorkMachinesService {
)
}

const value = data.value?.map(
(v) =>
({
...v,
dateLastInspection: v.dateLastInspection
const workMachines: Array<WorkMachine> =
data.value
?.map((v) => {
const inspectionDate = v.dateLastInspection
? new Date(v.dateLastInspection)
: undefined,
ownerName: v.owner,
supervisorName: v.supervisor,
} as WorkMachine),
) as Array<WorkMachine>
: undefined
return {
...v,
dateLastInspection: isValid(inspectionDate)
? inspectionDate
: undefined,
ownerName: v.owner,
supervisorName: v.supervisor,
}
})
.filter(isDefined) ?? []

const links = data.links?.length
? data.links.map((l) => {
Expand All @@ -97,7 +105,7 @@ export class WorkMachinesService {
: null

return {
data: value,
data: workMachines,
links,
labels: data.labels,
totalCount: data.pagination?.totalCount ?? 0,
Expand Down Expand Up @@ -133,11 +141,13 @@ export class WorkMachinesService {
})
: null

const inspectionDate = data.dateLastInspection
? new Date(data.dateLastInspection)
: undefined

return {
...data,
dateLastInspection: data.dateLastInspection
? new Date(data.dateLastInspection)
: undefined,
dateLastInspection: isValid(inspectionDate) ? inspectionDate : undefined,
links,
}
}
Expand Down
4 changes: 4 additions & 0 deletions libs/service-portal/assets/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ export const messages = defineMessages({
id: 'sp.work-machines:search-placeholder',
defaultMessage: 'Leita',
},
noInspection: {
id: 'sp.work-machines:no-inspection',
defaultMessage: 'Óskoðuð',
},
})

export const vehicleMessage = defineMessages({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ const WorkMachinesDetail = () => {
/>
<InfoLine
label={labels.dateLastInspection ?? ''}
content={formatDate(workMachine?.dateLastInspection ?? '')}
content={
workMachine?.dateLastInspection
? formatDate(workMachine.dateLastInspection)
: formatMessage(messages.noInspection)
}
loading={loading}
/>
<InfoLine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,6 @@ const WorkMachinesOverview = () => {
},
})
}
const generateCardText = (wm: WorkMachine): string | undefined => {
let text = wm.registrationNumber ?? undefined
const inspectionText = wm.dateLastInspection
? `${formatMessage(vehicleMessage.lastInspection)}: ${formatDate(
wm.dateLastInspection,
)}`
: undefined

if (wm.dateLastInspection) {
text = wm.registrationNumber
? `${text}, ${inspectionText}`
: inspectionText
}

return text
}

return (
<Box marginBottom={[6, 6, 10]}>
Expand Down Expand Up @@ -273,7 +257,11 @@ const WorkMachinesOverview = () => {
return (
<Box marginBottom={3} key={index}>
<ActionCard
text={generateCardText(wm)}
text={`${formatMessage(vehicleMessage.lastInspection)}: ${
wm.dateLastInspection
? formatDate(wm.dateLastInspection)
: formatMessage(messages.noInspection)
}`}
heading={wm.type ?? ''}
cta={{
label: formatMessage(m.seeDetails),
Expand Down

0 comments on commit a8a5206

Please sign in to comment.