Skip to content

Commit

Permalink
Change dashboard to use new DashboardPlacementRequest type.
Browse files Browse the repository at this point in the history
  • Loading branch information
danhumphreys-moj committed Jan 17, 2025
1 parent d8d5e92 commit df3b418
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
5 changes: 3 additions & 2 deletions server/data/placementRequestClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BookingNotMade,
Cas1CruManagementArea,
DashboardPlacementRequest,
NewBookingNotMade,
NewPlacementRequestBooking,
NewPlacementRequestBookingConfirmation,
Expand Down Expand Up @@ -48,7 +49,7 @@ export default class PlacementRequestClient {
page = 1,
sortBy: PlacementRequestSortField = 'created_at',
sortDirection: SortDirection = 'asc',
): Promise<PaginatedResponse<PlacementRequest>> {
): Promise<PaginatedResponse<DashboardPlacementRequest>> {
const params: DashboardQueryParams = {}

Object.keys(allParams).forEach(key => {
Expand All @@ -61,7 +62,7 @@ export default class PlacementRequestClient {
params.crnOrName = normaliseCrn(allParams.crnOrName)
}

return this.restClient.getPaginatedResponse<PlacementRequest>({
return this.restClient.getPaginatedResponse<DashboardPlacementRequest>({
path: paths.placementRequests.dashboard.pattern,
page: page.toString(),
query: { ...params, sortBy, sortDirection },
Expand Down
6 changes: 3 additions & 3 deletions server/services/placementRequestService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PaginatedResponse, PlacementRequestDashboardSearchOptions } from '@approved-premises/ui'
import {
DashboardPlacementRequest,
NewBookingNotMade,
NewPlacementRequestBooking,
NewPlacementRequestBookingConfirmation,
PlacementRequest,
PlacementRequestDetail,
PlacementRequestSortField,
SortDirection,
Expand All @@ -21,7 +21,7 @@ export default class PlacementRequestService {
page: number = 1,
sortBy: PlacementRequestSortField = 'created_at',
sortDirection: SortDirection = 'asc',
): Promise<PaginatedResponse<PlacementRequest>> {
): Promise<PaginatedResponse<DashboardPlacementRequest>> {
const placementRequestClient = this.placementRequestClientFactory(token)

return placementRequestClient.dashboard(filters, page, sortBy, sortDirection)
Expand All @@ -33,7 +33,7 @@ export default class PlacementRequestService {
page: number = 1,
sortBy: PlacementRequestSortField = 'created_at',
sortDirection: SortDirection = 'asc',
): Promise<PaginatedResponse<PlacementRequest>> {
): Promise<PaginatedResponse<DashboardPlacementRequest>> {
const placementRequestClient = this.placementRequestClientFactory(token)

return placementRequestClient.dashboard(searchParams, page, sortBy, sortDirection)
Expand Down
24 changes: 12 additions & 12 deletions server/utils/placementRequests/table.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addDays } from 'date-fns'
import {
PlacementRequest,
DashboardPlacementRequest,
PlacementRequestSortField,
PlacementRequestStatus,
PlacementRequestTask,
Expand Down Expand Up @@ -33,10 +33,10 @@ export const tableRows = (tasks: Array<PlacementRequestTask>): Array<TableRow> =
}

export const dashboardTableRows = (
placementRequests: Array<PlacementRequest>,
placementRequests: Array<DashboardPlacementRequest>,
status: PlacementRequestStatus | undefined,
): Array<TableRow> => {
return placementRequests.map((placementRequest: PlacementRequest) => {
return placementRequests.map((placementRequest: DashboardPlacementRequest) => {
return [
nameCell(placementRequest),
tierCell(placementRequest.risks),
Expand All @@ -50,25 +50,25 @@ export const dashboardTableRows = (
})
}

export const statusCell = (placementRequest: PlacementRequest): TableCell => {
export const statusCell = (placementRequest: DashboardPlacementRequest): TableCell => {
return {
text: placementRequestStatus[placementRequest.status],
text: `${placementRequestStatus[placementRequest.status]}dan`,
}
}

export const requestTypeCell = (placementRequest: PlacementRequest): TableCell => {
export const requestTypeCell = (placementRequest: DashboardPlacementRequest): TableCell => {
return {
text: placementRequest.isParole ? 'Parole' : 'Standard release',
}
}

export const premisesNameCell = (placementRequest: PlacementRequest): TableCell => {
export const premisesNameCell = (placementRequest: DashboardPlacementRequest): TableCell => {
return {
text: placementRequest.booking?.premisesName,
}
}

export const durationCell = (placementRequest: PlacementRequest): TableCell => {
export const durationCell = (placementRequest: DashboardPlacementRequest): TableCell => {
return { text: DateFormats.formatDuration(daysToWeeksAndDays(placementRequest.duration), ['weeks', 'days']) }
}

Expand All @@ -84,21 +84,21 @@ export const dueDateCell = (task: PlacementRequestTask, differenceBetweenDueDate
}

export const expectedArrivalDateCell = (
item: PlacementRequestTask | PlacementRequest,
item: PlacementRequestTask | DashboardPlacementRequest,
format: 'short' | 'long' = 'long',
): TableCell => ({
text: DateFormats.isoDateToUIDate(item.expectedArrival, { format }),
})

export const actualArrivalDateCell = (item: PlacementRequest): TableCell => ({
export const actualArrivalDateCell = (item: DashboardPlacementRequest): TableCell => ({
text: item.booking?.arrivalDate ? DateFormats.isoDateToUIDate(item.booking?.arrivalDate, { format: 'short' }) : 'N/A',
})

export const applicationDateCell = (item: PlacementRequest): TableCell => ({
export const applicationDateCell = (item: DashboardPlacementRequest): TableCell => ({
text: DateFormats.isoDateToUIDate(item.applicationDate, { format: 'short' }),
})

export const nameCell = (item: PlacementRequestTask | PlacementRequest): TableCell => {
export const nameCell = (item: PlacementRequestTask | DashboardPlacementRequest): TableCell => {
if ('personName' in item && item.personName) {
return {
html: linkTo(matchPaths.placementRequests.show({ id: item.id }), {
Expand Down

0 comments on commit df3b418

Please sign in to comment.