Skip to content

Commit

Permalink
use 'role' field in event history instead of system role, add formatt…
Browse files Browse the repository at this point in the history
…ing for history column values
  • Loading branch information
rikukissa committed Jan 28, 2025
1 parent 1658a6f commit 0221e9b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
3 changes: 2 additions & 1 deletion packages/client/src/v2-events/components/forms/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
validate,
DateFieldValue,
TextFieldValue,
RadioGroupFieldValue
RadioGroupFieldValue,
FileFieldValue
} from '@opencrvs/commons/client'
import {
CheckboxFieldValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const MISSING_USER = {
family: 'user'
}
],
systemRole: '-'
role: '-'
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import React from 'react'
import { format } from 'date-fns'
import styled from 'styled-components'
import { useIntl } from 'react-intl'
import { defineMessages, useIntl } from 'react-intl'
import { useNavigate } from 'react-router-dom'
import { stringify } from 'query-string'
import { Link } from '@opencrvs/components'
Expand All @@ -28,7 +28,6 @@ import { formatUrl } from '@client/navigation'
import { useEventOverviewContext } from '@client/v2-events/features/workqueues/EventOverview/EventOverviewContext'
import { EventHistoryModal } from './EventHistoryModal'
import { UserAvatar } from './UserAvatar'
import { messages } from './messages'

/**
* Based on packages/client/src/views/RecordAudit/History.tsx
Expand All @@ -40,6 +39,25 @@ const TableDiv = styled.div`

const DEFAULT_HISTORY_RECORD_PAGE_SIZE = 10

const messages = defineMessages({
'event.history.timeFormat': {
defaultMessage: 'MMMM dd, yyyy · hh.mm a',
id: 'event.history.timeFormat',
description: 'Time format for timestamps in event history'
},
'events.history.status': {
id: `events.history.status`,
defaultMessage:
'{status, select, CREATE {Draft} VALIDATE {Validated} DRAFT {Draft} DECLARE {Declared} REGISTER {Registered} other {Unknown}}'
},
'event.history.role': {
id: 'event.history.role',
defaultMessage:
'{role, select, LOCAL_REGISTRAR{Local Registrar} other{Unknown}}',
description: 'Role of the user in the event history'
}
})

/**
* Renders the event history table. Used for audit trail.
*/
Expand Down Expand Up @@ -72,7 +90,9 @@ export function EventHistory({ history }: { history: ActionDocument[] }) {
onHistoryRowClick(item, user)
}}
>
{item.type}
{intl.formatMessage(messages['events.history.status'], {
status: item.type
})}
</Link>
),
user: (
Expand All @@ -95,7 +115,9 @@ export function EventHistory({ history }: { history: ActionDocument[] }) {
/>
</Link>
),
role: user.systemRole,
role: intl.formatMessage(messages['event.history.role'], {
role: user.role
}),
location: (
<Link
font="bold14"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import React from 'react'
import { useIntl } from 'react-intl'
import { defineMessages, useIntl } from 'react-intl'
import format from 'date-fns/format'
import { ResponsiveModal, Stack } from '@opencrvs/components'
import { Text } from '@opencrvs/components/lib/Text'
import { ActionDocument } from '@opencrvs/commons/client'
import { ResolvedUser } from '@opencrvs/commons'
import { getUsersFullName, joinValues } from '@client/v2-events/utils'
import { messages } from './messages'

const messages = defineMessages({
'event.history.modal.timeFormat': {
defaultMessage: 'MMMM dd, yyyy · hh.mm a',
id: 'event.history.timeFormat',
description: 'Time format for timestamps in event history'
}
})

/**
* Detailed view of single Action, showing the history of the event.
Expand Down Expand Up @@ -52,7 +59,7 @@ export function EventHistoryModal({
name,
format(
new Date(history.createdAt),
intl.formatMessage(messages['event.history.timeFormat'])
intl.formatMessage(messages['event.history.modal.timeFormat'])
)
],
' — '
Expand Down

This file was deleted.

10 changes: 9 additions & 1 deletion packages/client/src/v2-events/hooks/useTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

import { useIntl } from 'react-intl'
import { useSelector } from 'react-redux'
import { ActionFormData, findPageFields } from '@opencrvs/commons/client'
import {
ActionFormData,
findPageFields,
FieldType
} from '@opencrvs/commons/client'
import { fieldValueToString } from '@client/v2-events/components/forms/utils'
import { useEventConfiguration } from '@client/v2-events/features/events/useEventConfiguration'
// eslint-disable-next-line no-restricted-imports
Expand All @@ -36,6 +40,10 @@ export const useTransformer = (eventType: string) => {
throw new Error(`Field not found for ${key}`)
}

if (fieldConfig.type === FieldType.FILE) {
continue
}

stringifiedValues[key] = fieldValueToString({
fieldConfig,
value,
Expand Down
2 changes: 1 addition & 1 deletion packages/commons/src/events/ActionDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export type ActionDocument = z.infer<typeof ActionDocument>

export const ResolvedUser = z.object({
id: z.string(),
systemRole: z.string(),
role: z.string(),
name: z.array(
z.object({
use: z.string(),
Expand Down
4 changes: 2 additions & 2 deletions packages/events/src/service/users/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getUsersById = async (ids: string[]) => {
.collection<{
_id: ObjectId
name: ResolvedUser['name']
systemRole: string
role: string
}>('users')
.find({
_id: {
Expand All @@ -38,6 +38,6 @@ export const getUsersById = async (ids: string[]) => {
return results.map((user) => ({
id: user._id.toString(),
name: user.name,
systemRole: user.systemRole
role: user.role
}))
}

0 comments on commit 0221e9b

Please sign in to comment.