-
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.
feat: unify action form and review structures (#8253)
* feat: unify action form and review structures * fix: add missing license header * fix: use register routes in register preview * fix: typo in readme
- Loading branch information
1 parent
85887d6
commit e290682
Showing
15 changed files
with
362 additions
and
201 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 @@ | ||
| Entity | Description | | ||
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| Event | A life event (e.g., dog adoption). An entry in the database describing a past life event and all steps (actions) involved in the process. | | ||
| EventConfig | Description of event features defined by the country. Includes configuration for process steps (`Action`) and forms (`ActionConfig`) involved. | | ||
| EventInput | A subset of an event. Describes fields that can be sent to the system with the intention of either creating or mutating a an event | | ||
| EventIndex | A subset of an event. Describes how the event is stored in the search index. Contains static fields shared by all event types and custom fields defined by event configuration | | ||
| User | User in the system. Might be a practitioner or an admin or something else. | | ||
| Location | Describes a physical location. Can be a admin structure, an office or something else. Cannot be anyone's personal home address | | ||
| Action | Event contains one or more actions. Action is a system event which triggers a status change. See `ActionConfig` | | ||
| ActionConfig | Each action defines a form, which needs to be filled in order for the status to change. Configuration can have multiple forms, out of which **only one can be active**. | | ||
| FormConfig | Form config defines separate read (`review`) and write (`pages`) configurations for itself. | |
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
149 changes: 0 additions & 149 deletions
149
packages/client/src/v2-events/features/events/actions/declare/Declare.tsx
This file was deleted.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
packages/client/src/v2-events/features/events/actions/declare/Pages.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,86 @@ | ||
/* | ||
* 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, { useEffect } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
import { | ||
useTypedParams, | ||
useTypedSearchParams | ||
} from 'react-router-typesafe-routes/dom' | ||
import { ActionType } from '@opencrvs/commons/client' | ||
import { useEventConfiguration } from '@client/v2-events/features/events/useEventConfiguration' | ||
import { useEventFormNavigation } from '@client/v2-events/features/events/useEventFormNavigation' | ||
import { useEvents } from '@client/v2-events//features/events/useEvents/useEvents' | ||
import { ROUTES } from '@client/v2-events/routes' | ||
import { Pages as PagesComponent } from '@client/v2-events/features/events/components/Pages' | ||
|
||
export function Pages() { | ||
const { eventId, pageId } = useTypedParams(ROUTES.V2.EVENTS.DECLARE.PAGES) | ||
const [searchParams] = useTypedSearchParams(ROUTES.V2.EVENTS.DECLARE.PAGES) | ||
const navigate = useNavigate() | ||
const events = useEvents() | ||
const { modal } = useEventFormNavigation() | ||
|
||
const [event] = events.getEvent(eventId) | ||
|
||
const { eventConfiguration: configuration } = useEventConfiguration( | ||
event.type | ||
) | ||
const formPages = configuration?.actions | ||
.find((action) => action.type === ActionType.DECLARE) | ||
?.forms.find((form) => form.active)?.pages | ||
|
||
if (!formPages) { | ||
throw new Error('Form configuration not found for type: ' + event.type) | ||
} | ||
|
||
const currentPageId = | ||
formPages.find((p) => p.id === pageId)?.id || formPages[0]?.id | ||
|
||
if (!currentPageId) { | ||
throw new Error('Form does not have any pages') | ||
} | ||
|
||
useEffect(() => { | ||
if (pageId !== currentPageId) { | ||
navigate( | ||
ROUTES.V2.EVENTS.DECLARE.PAGES.buildPath({ | ||
eventId, | ||
pageId: currentPageId | ||
}), | ||
{ replace: true } | ||
) | ||
} | ||
}, [pageId, currentPageId, navigate, eventId]) | ||
|
||
return ( | ||
<> | ||
{modal} | ||
<PagesComponent | ||
eventId={eventId} | ||
formPages={formPages} | ||
pageId={currentPageId} | ||
showReviewButton={searchParams.from === 'review'} | ||
onFormPageChange={(nextPageId: string) => | ||
navigate( | ||
ROUTES.V2.EVENTS.DECLARE.PAGES.buildPath({ | ||
eventId, | ||
pageId: nextPageId | ||
}) | ||
) | ||
} | ||
onSubmit={() => | ||
navigate(ROUTES.V2.EVENTS.DECLARE.REVIEW.buildPath({ eventId })) | ||
} | ||
/> | ||
</> | ||
) | ||
} |
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
15 changes: 15 additions & 0 deletions
15
packages/client/src/v2-events/features/events/actions/declare/index.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,15 @@ | ||
/* | ||
* 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 { Pages } from './Pages' | ||
import { Review } from './Review' | ||
|
||
export { Pages, Review } |
Oops, something went wrong.