-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Amsterdam/feature/122885-zaakhistorie-com…
…ponent 122885 Added case events history
- Loading branch information
Showing
13 changed files
with
163 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type EventType = "CASE" | "GENERIC_TASK" | ||
|
||
type CaseEvent = { | ||
id: number | ||
event_values: Record<string, string> | ||
event_variables: Record<string, string> | ||
date_created: string // date-time | ||
type: EventType | ||
emitter_id: number | ||
case: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from "react" | ||
import { DescriptionList } from "@amsterdam/design-system-react" | ||
import { getEventValueName } from "./dictionaries" | ||
import { isValidDate, formatDate } from "app/utils/dates" | ||
import { styled } from "styled-components" | ||
|
||
|
||
type Props = { | ||
event: CaseEvent | ||
} | ||
|
||
const Wrapper = styled.div` | ||
padding: 25px; | ||
background-color: #E6E6E6; | ||
border: 0.5px solid #d4d2d2; | ||
border-radius: 4px; | ||
box-shadow: | ||
0px 6px 16px -8px rgba(0, 0, 0, 0.08), | ||
0px 9px 28px 0px rgba(0, 0, 0, 0.05), | ||
0px 12px 48px 16px rgba(0, 0, 0, 0.03); | ||
` | ||
|
||
export const TimelineEvent: React.FC<Props> = ({ event }) => { | ||
const { event_values } = event | ||
return ( | ||
<Wrapper> | ||
<DescriptionList> | ||
{ Object.entries(event_values).map(([key, value], index) => ( | ||
<React.Fragment key={ `event_values-${ index }` }> | ||
<DescriptionList.Term> | ||
{ getEventValueName(key) } | ||
</DescriptionList.Term><DescriptionList.Details> | ||
{ isValidDate(value) ? formatDate(value, true) : value } | ||
</DescriptionList.Details> | ||
</React.Fragment> | ||
))} | ||
</DescriptionList> | ||
</Wrapper> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Accordion } from "@amsterdam/design-system-react" | ||
import { getEventTitle } from "./dictionaries" | ||
import { TimelineEvent } from "./TimelineEvent" | ||
|
||
|
||
export const TimelineEvents: React.FC<{ events: CaseEvent[] }> = ({ events }) => ( | ||
<> | ||
<Accordion | ||
headingLevel={1} | ||
sectionAs="div" | ||
> | ||
{ events.map((event, index) => ( | ||
<Accordion.Section | ||
key={ event.id } | ||
label={ getEventTitle(event) } | ||
expanded={ index === 0 } | ||
> | ||
<TimelineEvent event={ event }/> | ||
</Accordion.Section> | ||
))} | ||
</Accordion> | ||
</> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Event types | ||
export const EVENT_TYPES: Record<CaseEvent["type"], string> = { | ||
"CASE": "Aanleiding", | ||
"GENERIC_TASK": "GENERIC_TASK" | ||
} | ||
|
||
|
||
export const getEventTitle = (event: CaseEvent): string => { | ||
const { type, event_values } = event | ||
if (type === EVENT_TYPES.GENERIC_TASK) { | ||
return event_values.description | ||
} | ||
if (EVENT_TYPES[type]) { | ||
return EVENT_TYPES[type] | ||
} | ||
return type | ||
} | ||
|
||
export const EVENT_VALUES: Record<string, string> = { | ||
"date_added": "Datum", | ||
"author": "Medewerker", | ||
"description": "Toelichting" | ||
} | ||
|
||
export const getEventValueName = (value: string): string => ( | ||
EVENT_VALUES[value] ?? value | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useCaseEvents } from "app/state/rest" | ||
import { SmallSkeleton, PageHeading, TimelineEvents } from "app/components" | ||
|
||
|
||
type Props = { | ||
caseId: Components.Schemas.Case["id"] | ||
} | ||
|
||
export const CaseHistory: React.FC<Props> = ({ caseId }) => { | ||
const [data, { isBusy }] = useCaseEvents(caseId) | ||
const events = data ? [...data]?.reverse() : [] | ||
|
||
if (isBusy) { | ||
return <SmallSkeleton height={ 4 } /> | ||
} | ||
return ( | ||
<> | ||
<PageHeading label="Zaakhistorie" level={ 4 } border/> | ||
<TimelineEvents events={ events }/> | ||
</> | ||
) | ||
} | ||
|
||
export default CaseHistory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import dayjs from "dayjs" | ||
|
||
export const isValidDate = (dateString: string): boolean => { | ||
// Parse the date string with dayjs | ||
const date = dayjs(dateString) | ||
// Check if the parsed date is valid | ||
return date.isValid() | ||
} | ||
|
||
const DEFAULT_DATE_FORMAT = "DD-MM-YYYY" | ||
const DEFAULT_DATE_FORMAT_TIME = "DD-MM-YYYY HH:mm" | ||
|
||
export const formatDate = (dateString: string, includeTime: boolean = false): string => ( | ||
dayjs(dateString).format(includeTime ? DEFAULT_DATE_FORMAT_TIME : DEFAULT_DATE_FORMAT) | ||
) |