-
Notifications
You must be signed in to change notification settings - Fork 75
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 #8252 from opencrvs/chore/update-events-structure
Chore/update events structure
- Loading branch information
Showing
13 changed files
with
259 additions
and
136 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,29 @@ | ||
# V2 Events | ||
|
||
Client for managing custom events. | ||
|
||
## Directory structure | ||
|
||
``` | ||
# Reusable components used by features. | ||
/components | ||
# Features used by routes | ||
/features | ||
# Reusable layouts used between features | ||
/layouts | ||
# Route definitions and application structure | ||
/routes | ||
# Route definitions | ||
routes.ts | ||
# Structured route configuration | ||
config.tsx | ||
``` | ||
|
||
We will be iterating over the structure during the project. Treat it as a starting point. Many times the important thing is to have any structure. | ||
|
||
## Development practices | ||
|
||
- Do not import components outside v2-events. If you need a component, copy it in and refactor it. | ||
- When building new features, aim to have a separate component that handles interaction with router and data fetching when it makes sense. Features should be route independent, and necessary information (ids and such) should be passed in as props or similar. See (`features/events/actions/register/Register.tsx`) | ||
- Use constants through object pattern. e.g.`ActionType.CREATE` over `'CREATE'`. In most situations, it does not matter. However, changing the names will get much easier. | ||
- When building new features, prefer to import them through `index.ts`. Managing imports will be cleaner and easier that way. See (`/layouts`) |
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
File renamed without changes.
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,59 @@ | ||
/* | ||
* 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 { useTypedParams } from 'react-router-typesafe-routes/dom' | ||
|
||
import { Frame, Spinner } from '@opencrvs/components' | ||
import { useEventConfiguration } from '@client/v2-events/features/events/useEventConfiguration' | ||
import { useEvents } from '@client/v2-events/features/events/useEvents/useEvents' | ||
import { ROUTES } from '@client/v2-events/routes' | ||
import { FormHeader } from './FormHeader' | ||
|
||
type AllowedRoute = | ||
| typeof ROUTES.V2.EVENTS.REGISTER | ||
| typeof ROUTES.V2.EVENTS.DECLARE | ||
|
||
/** | ||
* Layout for form and review pages. | ||
* | ||
*/ | ||
export function FormLayout({ | ||
route, | ||
children | ||
}: { | ||
route: AllowedRoute | ||
children: React.ReactNode | ||
}) { | ||
const { eventId } = useTypedParams(route) | ||
const events = useEvents() | ||
|
||
const [event] = events.getEvent(eventId) | ||
|
||
const { eventConfiguration: configuration } = useEventConfiguration( | ||
event.type | ||
) | ||
|
||
if (!configuration) { | ||
throw new Error('Event configuration not found') | ||
} | ||
|
||
return ( | ||
<Frame | ||
header={<FormHeader label={configuration.label} />} | ||
skipToContentText="Skip to form" | ||
> | ||
<React.Suspense fallback={<Spinner id="event-form-spinner" />}> | ||
{children} | ||
</React.Suspense> | ||
</Frame> | ||
) | ||
} |
Oops, something went wrong.