opencrvs / opencrvs-core

A global solution to civil registration
https://www.opencrvs.org
Other
90 stars 73 forks source link

React stack modernization #3978

Open jpye-finch opened 2 years ago

jpye-finch commented 2 years ago

Our frontend is getting fairly complicated - and some parts outdated - given it's written with modern technologies. Some patterns are getting old and are not being learned by new developers. We need to actively continue refactoring the frontend to keep it modern and exciting for developers to use.

Status: 🟢 ongoing work by the core team and @Eezi ❤️

Status: 🟠 Let's begin using. https://redux-toolkit.js.org/introduction/why-rtk-is-redux-today

Let's start using redux-toolkit and utilizing Apollo and its cache more. Let's get into a mindset to avoid state management. Often what first feels like a new global state is needed, is achieved via the Apollo's data fetching tools or URL parameters. If a use case cannot be solved with those, let's use redux-toolkit.

Status: 🟢 https://github.com/opencrvs/opencrvs-core/issues/7073 picked for 1.7

https://github.com/opencrvs/opencrvs-core/blob/develop/packages/client/src/views/OfficeHome/inProgress/InProgress.tsx

Problems:

Status: 🟡 could be simplified within the workqueue rework. There are bits in the submission middleware that update the workqueues

https://github.com/opencrvs/opencrvs-core/blob/develop/packages/client/src/declarations/submissionMiddleware.ts

Submission middleware is a centralized place for submitting different events and actions. It can grow to be a difficult to read function figureOutWhatsHappening(declaration) => Promise<APIResponse> utility that grows and grows. We want to cut the paths early and create more specific handlers for event right after the submit action is done by the users. Middlewares in general can be a bit hidden compared to declarative functions.

Lets investigate how we could simplify it and move parts closer to the actual birth, death, marriage, etc. events and the actual form.

Status: 🟢 In backlog: https://github.com/opencrvs/opencrvs-core/issues/7682

Status: 🔴 in beta, not worth considering in 2024

tareq89 commented 5 months ago

For central state management library, can Zustand be a candidate? It is catching up very fast and have hooks like familiar interface.

https://npm-compare.com/@reduxjs/toolkit,zustand,jotai,recoil,valtio/#timeRange=ALL

Zangetsu101 commented 5 months ago

React Router v6

The other thing about search/route params is that we should consider using some runtime validations(e.g. zod) and proper error handling for incorrect values

Zangetsu101 commented 5 months ago

Another thing to consider is how we want to handle the offline data which is crucial for us. Is using a library sufficient for us? Are there any use cases that require a more custom solution perhaps?

naftis commented 5 months ago

For central state management library, can Zustand be a candidate? It is catching up very fast and have hooks like familiar interface.

npm-compare.com/@reduxjs/toolkit,zustand,jotai,recoil,valtio/#timeRange=ALL

Yep it's a good option if we need to build/refactor our centralized state management. Here is a interesting comparison about the differences in the state management tools from Jotai's website: https://jotai.org/docs/basics/comparison

Out of them all I think Recoil is something we should skip as it seems stale compared to zustand/jotai.

naftis commented 5 months ago

Another thing to consider is how we want to handle the offline data which is crucial for us. Is using a library sufficient for us? Are there any use cases that require a more custom solution perhaps?

Definitely..

Could we suffice with Apollo doing most of offline caching? If there's something special (like PIN) we need to add to localStorage we could listen to the changes using Jotai https://jotai.org/docs/utilities/storage or Zustand https://docs.pmnd.rs/zustand/integrations/persisting-store-data

This would require refactors like location tree being fetched from gateway