-
Notifications
You must be signed in to change notification settings - Fork 73
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 #8313 from opencrvs/feat/events-resolve-ids
Feat/events resolve ids
- Loading branch information
Showing
63 changed files
with
1,458 additions
and
471 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
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,29 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* OpenCRVS is also distributed under the terms of the Civil Registration | ||
* & Healthcare Disclaimer located at http://opencrvs.org/license. | ||
* | ||
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | ||
*/ | ||
|
||
import React from 'react' | ||
import { Spinner } from '@opencrvs/components' | ||
|
||
/** | ||
* HOC to wrap a component in a suspense boundary with a spinner fallback. | ||
*/ | ||
export function withSuspense< | ||
ComponentProps extends React.JSX.IntrinsicAttributes | ||
>(Component: React.ComponentType<ComponentProps>) { | ||
// eslint-disable-next-line react/display-name | ||
return (props: ComponentProps) => ( | ||
<React.Suspense | ||
fallback={<Spinner id={`page-spinner-${new Date().getTime()}`} />} | ||
> | ||
<Component {...props} /> | ||
</React.Suspense> | ||
) | ||
} |
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
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
80 changes: 80 additions & 0 deletions
80
packages/client/src/v2-events/features/workqueues/EventOverview/EventOverviewContext.tsx
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,80 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* OpenCRVS is also distributed under the terms of the Civil Registration | ||
* & Healthcare Disclaimer located at http://opencrvs.org/license. | ||
* | ||
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | ||
*/ | ||
|
||
import React, { createContext, useContext } from 'react' | ||
import { ResolvedUser } from '@opencrvs/commons/client' | ||
// eslint-disable-next-line no-restricted-imports | ||
import { ILocation } from '@client/offline/reducer' | ||
|
||
const EventOverviewContext = createContext<{ | ||
getUser: (id: string) => ResolvedUser | ||
getLocation: (id: string) => ILocation | ||
} | null>(null) | ||
|
||
const MISSING_USER = { | ||
id: 'ID_MISSING', | ||
name: [ | ||
{ | ||
use: 'en', | ||
given: ['Missing'], | ||
family: 'user' | ||
} | ||
], | ||
systemRole: '-' | ||
} | ||
|
||
/** | ||
* Provides methods for resolving users and locations within the event. | ||
*/ | ||
export const EventOverviewProvider = ({ | ||
children, | ||
locations, | ||
users | ||
}: { | ||
children: React.ReactNode | ||
users: ResolvedUser[] | ||
locations: Record<string, ILocation> | ||
}) => { | ||
const getUser = (id: string) => { | ||
const user = users.find((u) => u.id === id) | ||
|
||
if (!user) { | ||
// eslint-disable-next-line no-console | ||
console.error(`User with id ${id} not found.`) | ||
|
||
return MISSING_USER | ||
} | ||
|
||
return user | ||
} | ||
|
||
const getLocation = (id: string) => { | ||
// @TODO: Remove this fallback once developers have had time to update their data. | ||
// eslint-disable-next-line | ||
return locations[id] ?? { id, name: 'Unknown location' } | ||
} | ||
|
||
return ( | ||
<EventOverviewContext.Provider value={{ getUser, getLocation }}> | ||
{children} | ||
</EventOverviewContext.Provider> | ||
) | ||
} | ||
|
||
export const useEventOverviewContext = () => { | ||
const context = useContext(EventOverviewContext) | ||
|
||
if (!context) { | ||
throw new Error('EventOverviewContext not found') | ||
} | ||
|
||
return context | ||
} |
Oops, something went wrong.