@pplancq/react-template 2.8.17 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/_README.md +57 -52
  3. package/mise.toml +2 -2
  4. package/mocks/browser.ts +1 -1
  5. package/mocks/fixtures/user.ts +14 -14
  6. package/mocks/handlers/userHandlers.ts +3 -3
  7. package/mocks/server.ts +1 -1
  8. package/package.json +30 -30
  9. package/playwright-report/html/index.html +90 -0
  10. package/playwright-report/sonar-results.xml +20 -0
  11. package/playwright.config.ts +3 -3
  12. package/scripts/removeDemo.cjs +105 -66
  13. package/src/README.md +81 -0
  14. package/src/app/App.tsx +18 -0
  15. package/src/{bootstrap.tsx → app/AppHTMLElement.tsx} +5 -5
  16. package/src/app/README.md +69 -0
  17. package/src/app/assets/css/index.ts +2 -0
  18. package/src/{assets → app/assets}/css/reset.css +3 -3
  19. package/src/app/config/queryClientConfig.ts +3 -0
  20. package/src/app/config/serviceContainer.ts +6 -0
  21. package/src/app/providers/Providers/Providers.tsx +18 -0
  22. package/src/app/providers/QueryClientProvider/QueryClientProvider.tsx +16 -0
  23. package/src/app/providers/ServiceProvider/ServiceContext.ts +8 -0
  24. package/src/app/providers/ServiceProvider/ServiceProvider.tsx +14 -0
  25. package/src/app/routing/Router.tsx +14 -0
  26. package/src/app/routing/appRoutes.ts +3 -0
  27. package/src/app/routing/routes.tsx +9 -0
  28. package/src/demo/README.md +149 -0
  29. package/src/demo/application/dtos/ArchitecturePrinciple.ts +5 -0
  30. package/src/{types/profileTypes.ts → demo/application/dtos/ProfileFormValues.ts} +1 -1
  31. package/src/demo/application/use-cases/GetArchitecturePrinciplesUseCase.ts +11 -0
  32. package/src/demo/application/use-cases/GetArchitecturePrinciplesUseCaseInterface.ts +5 -0
  33. package/src/demo/application/use-cases/GetDemoUsersUseCase.ts +11 -0
  34. package/src/demo/application/use-cases/GetDemoUsersUseCaseInterface.ts +5 -0
  35. package/src/demo/domain/entities/DemoUser.ts +7 -0
  36. package/src/demo/domain/repositories/ArchitecturePrincipleRepositoryInterface.d.ts +5 -0
  37. package/src/demo/domain/repositories/DemoUserRepositoryInterface.d.ts +5 -0
  38. package/src/demo/infrastructure/repositories/HttpDemoUserRepository.ts +29 -0
  39. package/src/demo/infrastructure/repositories/StaticArchitecturePrincipleRepository.ts +33 -0
  40. package/src/demo/serviceDemo.ts +40 -0
  41. package/src/demo/serviceIdentifiers.ts +6 -0
  42. package/src/demo/ui/components/DemoFooter/DemoFooter.tsx +17 -0
  43. package/src/demo/ui/components/DemoFooter/index.ts +1 -0
  44. package/src/demo/ui/components/DemoHeader/DemoHeader.tsx +25 -0
  45. package/src/demo/ui/components/DemoHeader/index.ts +1 -0
  46. package/src/{ui/molecules/Navigation/Navigation.tsx → demo/ui/components/DemoNavigation/DemoNavigation.tsx} +6 -6
  47. package/src/demo/ui/components/DemoNavigation/index.ts +1 -0
  48. package/src/{ui/atoms → demo/ui/components}/Input/Input.tsx +3 -3
  49. package/src/demo/ui/components/Input/index.ts +1 -0
  50. package/src/{ui/atoms → demo/ui/components}/Logo/Logo.tsx +2 -2
  51. package/src/demo/ui/components/Logo/index.ts +1 -0
  52. package/src/{ui/atoms → demo/ui/components}/NavLink/NavLink.tsx +3 -3
  53. package/src/demo/ui/components/NavLink/index.ts +1 -0
  54. package/src/{components → demo/ui/components}/TextInput/TextInput.tsx +3 -3
  55. package/src/demo/ui/components/TextInput/index.ts +1 -0
  56. package/src/{forms → demo/ui/forms}/ProfileForm/ProfileForm.tsx +13 -13
  57. package/src/demo/ui/forms/ProfileForm/index.ts +1 -0
  58. package/src/demo/ui/hooks/useDemoUsersQuery/useDemoUsersQuery.ts +13 -0
  59. package/src/demo/ui/layouts/DemoLayout/DemoLayout.tsx +12 -0
  60. package/src/demo/ui/layouts/MainTemplate/MainTemplate.module.css +21 -0
  61. package/src/demo/ui/layouts/MainTemplate/MainTemplate.tsx +26 -0
  62. package/src/demo/ui/layouts/MainTemplate/index.ts +1 -0
  63. package/src/{pages/Demo/Demo.module.scss → demo/ui/pages/DemoHome/DemoHome.module.scss} +5 -5
  64. package/src/demo/ui/pages/DemoHome/DemoHome.tsx +117 -0
  65. package/src/demo/ui/pages/DependencyInjectionDemo/DependencyInjectionDemo.tsx +47 -0
  66. package/src/{pages/Demo → demo/ui/pages}/ReactHookFormDemo/ReactHookFormDemo.tsx +8 -8
  67. package/src/demo/ui/pages/ReactQueryDemo/ReactQueryDemo.module.scss +38 -0
  68. package/src/{pages/Demo → demo/ui/pages}/ReactQueryDemo/ReactQueryDemo.tsx +6 -5
  69. package/src/demo/ui/routing/demoAppRoutes.ts +6 -0
  70. package/src/demo/ui/routing/demoRoutes.tsx +31 -0
  71. package/src/main.ts +5 -5
  72. package/src/react-app-env.d.ts +1 -1
  73. package/src/shared/README.md +53 -0
  74. package/src/shared/application/README.md +49 -0
  75. package/src/shared/domain/README.md +52 -0
  76. package/src/shared/infrastructure/README.md +51 -0
  77. package/src/shared/infrastructure/http/constant.ts +16 -0
  78. package/src/{api → shared/infrastructure/http}/fetchApi.ts +3 -3
  79. package/src/shared/ui/README.md +50 -0
  80. package/src/shared/ui/hooks/useService/useService.ts +13 -0
  81. package/test-results/.last-run.json +4 -0
  82. package/tests/e2e/demo.test.ts +17 -0
  83. package/tests/e2e/fixture/playwright.fixture.ts +15 -0
  84. package/tests/{utils → e2e/utils}/createNetworkFixture.ts +2 -2
  85. package/tests/{utils → e2e/utils}/createTestWithCoverageFixture.ts +8 -8
  86. package/tests/{utils → e2e/utils}/playwright.globalSetup.ts +4 -4
  87. package/tests/{utils → e2e/utils}/playwright.globalTeardown.ts +3 -3
  88. package/{src/__tests__/bootstraps.test.tsx → tests/unit/app/AppHTMLElement.test.tsx} +14 -14
  89. package/tests/unit/demo/ui/components/DemoFooter/Footer.test.tsx +15 -0
  90. package/{src/components/Footer/__tests__ → tests/unit/demo/ui/components/DemoFooter}/__snapshots__/Footer.test.tsx.snap +3 -3
  91. package/tests/unit/demo/ui/components/DemoHeader/Header.test.tsx +15 -0
  92. package/tests/unit/demo/ui/components/DemoHeader/__snapshots__/Header.test.tsx.snap +64 -0
  93. package/tests/unit/demo/ui/components/Logo/Logo.test.tsx +12 -0
  94. package/tsconfig.json +4 -2
  95. package/vitest.config.mts +6 -2
  96. package/postcss.config.mjs +0 -5
  97. package/src/api/README.md +0 -65
  98. package/src/api/constant.ts +0 -16
  99. package/src/api/demoApi.ts +0 -10
  100. package/src/assets/README.md +0 -54
  101. package/src/assets/css/index.ts +0 -2
  102. package/src/components/App/App.tsx +0 -18
  103. package/src/components/App/index.ts +0 -1
  104. package/src/components/Footer/Footer.tsx +0 -16
  105. package/src/components/Footer/__tests__/Footer.test.tsx +0 -15
  106. package/src/components/Footer/index.ts +0 -1
  107. package/src/components/Header/Header.tsx +0 -17
  108. package/src/components/Header/__tests__/Header.test.tsx +0 -15
  109. package/src/components/Header/__tests__/__snapshots__/Header.test.tsx.snap +0 -37
  110. package/src/components/Header/index.ts +0 -1
  111. package/src/components/README.md +0 -33
  112. package/src/components/TextInput/index.ts +0 -1
  113. package/src/config/README.md +0 -63
  114. package/src/config/index.ts +0 -1
  115. package/src/config/queryClientConfig.ts +0 -3
  116. package/src/forms/ProfileForm/index.ts +0 -1
  117. package/src/forms/README.md +0 -142
  118. package/src/hooks/README.md +0 -83
  119. package/src/hooks/api/queryKey.ts +0 -1
  120. package/src/hooks/api/useDemoApi.ts +0 -16
  121. package/src/pages/Demo/Demo.tsx +0 -236
  122. package/src/pages/Demo/ReactHookFormDemo/index.ts +0 -1
  123. package/src/pages/Demo/ReactHookFormDemo/routes.tsx +0 -7
  124. package/src/pages/Demo/ReactQueryDemo/index.ts +0 -1
  125. package/src/pages/Demo/ReactQueryDemo/routes.tsx +0 -7
  126. package/src/pages/Demo/__tests__/Demo.test.tsx +0 -15
  127. package/src/pages/Demo/__tests__/__snapshots__/Demo.test.tsx.snap +0 -557
  128. package/src/pages/Demo/index.ts +0 -1
  129. package/src/pages/Demo/routes.tsx +0 -8
  130. package/src/pages/Layout/Layout.tsx +0 -12
  131. package/src/pages/Layout/index.ts +0 -1
  132. package/src/pages/README.md +0 -91
  133. package/src/pages/UnexpectedError/UnexpectedError.module.css +0 -8
  134. package/src/pages/UnexpectedError/UnexpectedError.tsx +0 -22
  135. package/src/pages/UnexpectedError/index.ts +0 -1
  136. package/src/providers/QueryClientProvider/QueryClientProvider.tsx +0 -16
  137. package/src/providers/QueryClientProvider/index.ts +0 -1
  138. package/src/providers/README.md +0 -112
  139. package/src/providers/index.ts +0 -1
  140. package/src/providers/withProviders/index.ts +0 -1
  141. package/src/providers/withProviders/withProviders.tsx +0 -18
  142. package/src/routing/README.md +0 -76
  143. package/src/routing/appRoutes.ts +0 -5
  144. package/src/routing/routerFactory.ts +0 -12
  145. package/src/routing/routes.tsx +0 -13
  146. package/src/types/README.md +0 -62
  147. package/src/types/demoApi.ts +0 -25
  148. package/src/ui/README.md +0 -144
  149. package/src/ui/atoms/Input/index.ts +0 -1
  150. package/src/ui/atoms/Logo/__tests__/Logo.test.tsx +0 -12
  151. package/src/ui/atoms/Logo/index.ts +0 -1
  152. package/src/ui/atoms/NavLink/index.ts +0 -1
  153. package/src/ui/molecules/Navigation/index.ts +0 -1
  154. package/src/ui/organisms/Footer/Footer.module.css +0 -10
  155. package/src/ui/organisms/Footer/Footer.tsx +0 -10
  156. package/src/ui/organisms/Footer/index.ts +0 -1
  157. package/src/ui/organisms/Header/Header.module.css +0 -17
  158. package/src/ui/organisms/Header/Header.tsx +0 -16
  159. package/src/ui/organisms/Header/index.ts +0 -1
  160. package/src/ui/organisms/MainContent/MainContent.module.css +0 -3
  161. package/src/ui/organisms/MainContent/MainContent.tsx +0 -6
  162. package/src/ui/organisms/MainContent/index.ts +0 -1
  163. package/src/ui/templates/MainTemplate/MainTemplate.module.css +0 -5
  164. package/src/ui/templates/MainTemplate/MainTemplate.tsx +0 -26
  165. package/src/ui/templates/MainTemplate/index.ts +0 -1
  166. package/src/utils/README.md +0 -70
  167. package/tests/demo.test.ts +0 -17
  168. package/tests/fixture/playwright.fixture.ts +0 -15
  169. /package/src/{assets → app/assets}/css/mainBody.css +0 -0
  170. /package/src/{assets → demo/ui/assets}/images/logo.png +0 -0
  171. /package/src/{assets → demo/ui/assets}/images/templatePlugins.png +0 -0
  172. /package/src/{components/Footer/Footer.module.css → demo/ui/components/DemoFooter/DemoFooter.module.css} +0 -0
  173. /package/src/{components/Header/Header.module.css → demo/ui/components/DemoHeader/DemoHeader.module.css} +0 -0
  174. /package/src/{ui/molecules/Navigation/Navigation.module.css → demo/ui/components/DemoNavigation/DemoNavigation.module.css} +0 -0
  175. /package/src/{ui/atoms → demo/ui/components}/Input/Input.module.scss +0 -0
  176. /package/src/{ui/atoms → demo/ui/components}/Logo/Logo.module.css +0 -0
  177. /package/src/{forms → demo/ui/forms}/ProfileForm/ProfileForm.module.scss +0 -0
  178. /package/src/{pages/Demo/ReactQueryDemo/ReactQueryDemo.module.scss → demo/ui/pages/DependencyInjectionDemo/DependencyInjectionDemo.module.scss} +0 -0
  179. /package/src/{pages/Demo/ReactHookFormDemo/ReactHookFormDemo.module.css → demo/ui/pages/ReactHookFormDemo/ReactHookFormDemo.module.scss} +0 -0
  180. /package/src/{types/api.ts → shared/infrastructure/http/fetchApi.type.d.ts} +0 -0
@@ -1,15 +0,0 @@
1
- import { render } from '@testing-library/react';
2
- import { BrowserRouter as Router } from 'react-router';
3
- import { Header } from '../Header';
4
-
5
- describe('Header Component', () => {
6
- it('should render the Header component correctly', () => {
7
- const { container } = render(
8
- <Router>
9
- <Header />
10
- </Router>,
11
- );
12
-
13
- expect(container).toMatchSnapshot();
14
- });
15
- });
@@ -1,37 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`Header Component > should render the Header component correctly 1`] = `
4
- <div>
5
- <div
6
- class="_container_a5b977"
7
- >
8
- <a
9
- data-discover="true"
10
- href="/"
11
- >
12
- <img
13
- alt="logo"
14
- class="_logoStyle_9e86a7"
15
- src="/src/assets/images/logo.png"
16
- style="width: 50px;"
17
- />
18
- </a>
19
- <nav>
20
- <ul
21
- class="_navList_eee024"
22
- >
23
- <li>
24
- <a
25
- aria-current="page"
26
- class="_a_eee024 active"
27
- data-discover="true"
28
- href="/"
29
- >
30
- Demo
31
- </a>
32
- </li>
33
- </ul>
34
- </nav>
35
- </div>
36
- </div>
37
- `;
@@ -1 +0,0 @@
1
- export { Header } from './Header';
@@ -1,33 +0,0 @@
1
- # 📁 components
2
-
3
- The "components" folder is a crucial element of any React application. It is used to organize and store reusable components that make up the user interface of your application. React components are self-contained pieces of the user interface, each having its own logic and rendering.
4
-
5
- ## 📑 Table of Contents
6
-
7
- - [Why Use a "components" Folder](#folder-organization)
8
- - [Usage](#usage)
9
-
10
- ## <span id="folder-organization">Why Use a "components" Folder?</span>
11
-
12
- 1. **Modularity** : Components can be reused across different parts of your application. This promotes code modularity and allows you to maintain your application more efficiently.
13
-
14
- 2. **Clarity** : By grouping all your components in a "components" folder, it is easier to understand the structure of your application. It also facilitates the search and management of components.
15
-
16
- 3. **Better Organization** : Organizing components in a dedicated folder helps clearly distinguish components from other elements of the application, such as styles, images, or configuration files.
17
-
18
- ## <span id="usage">🧑🏻‍💻 Usage Example </span>
19
-
20
- Suppose you have a "Header.js" component in the "components" folder. You can import and use it in other parts of your application like this:
21
-
22
- ```javascript
23
- import Header from '@Front/components/Header';
24
-
25
- export const App = () => {
26
- return (
27
- <div>
28
- <Header />
29
- {/* ... other elements of the application */}
30
- </div>
31
- );
32
- };
33
- ```
@@ -1 +0,0 @@
1
- export { TextInput } from './TextInput';
@@ -1,63 +0,0 @@
1
- # 📁 config
2
-
3
- The "config" folder is intended to store all important configurations and utilities needed for our React project. Bringing together this information in one place makes managing configuration settings easier and ensures better code organization.
4
-
5
- ## 📑 Table of Contents
6
-
7
- - [Folder Organization](#folder-organization)
8
- - [Content Example](#content-example)
9
- - [Usage](#usage)
10
- - [Best Practice](#best-practice)
11
-
12
- ## <span id="folder-organization">Folder Organization</span>
13
-
14
- Within the "config" folder, you can find the following elements:
15
-
16
- 1. **Configuration Files** : Files containing variables and configuration parameters, such as `apiConfig.ts` for configurations related to API calls, `appConfig.ts` for general application settings, `queryClientConfig.ts` for react-query-related configuration, etc.
17
-
18
- 2. **Configuration Scripts** : Scripts or utilities that facilitate dynamic configuration of the application, such as theme configuration, language management, etc.
19
-
20
- ## <span id="content-example">Content Example</span>
21
-
22
- Here is an example folder structure for "config":
23
-
24
- ```
25
- 📁config/
26
- ├── 📄 apiConfig.ts
27
- ├── 📄 appConfig.ts
28
- ├── 📄 queryClientConfig.ts
29
- ├── 📄 translationConfig.ts
30
- ```
31
-
32
- ## <span id="usage">🧑🏻‍💻Usage in the Project</span>
33
-
34
- When you need to access a specific configuration in your code, import the appropriate file from the "config" folder. For example:
35
-
36
- ```javascript
37
- // Example of using an API configuration
38
- import { apiEndpoint } from '@Front/config/apiConfig';
39
-
40
- // Example of using a react-query configuration
41
- import { queryClient } from '@Front/config/queryConfig';
42
-
43
- // Example of using a general application configuration
44
- import { appName } from '@Front/config/appConfig';
45
- ```
46
-
47
- ## <span id="best-practice">🎖️ Best Practice</span>
48
-
49
- Efficient configuration management is crucial for maintaining a clear and organized codebase. Follow these best practices for managing configuration files:
50
-
51
- #### - Context-Specific Configuration
52
-
53
- Separate configuration files based on different contexts, such as API configurations, QueryClient configurations, translations, etc.
54
-
55
- This helps in better organization and ease of maintenance.
56
-
57
- #### - File Naming Convention
58
-
59
- Suffix configuration files with `Config` to enhance visibility and make it easier to identify configuration files at a glance.
60
-
61
- ---
62
-
63
- **_By adopting these practices, you create a modular and organized approach to configuration management, making it simpler to locate and manage context-specific settings._**
@@ -1 +0,0 @@
1
- export { queryClient } from './queryClientConfig';
@@ -1,3 +0,0 @@
1
- import { QueryClient } from '@tanstack/react-query';
2
-
3
- export const queryClient = new QueryClient();
@@ -1 +0,0 @@
1
- export { ProfileForm } from './ProfileForm';
@@ -1,142 +0,0 @@
1
- # 📁 forms
2
-
3
- The "forms" folder is designed to organize and manage all the necessary forms in our application. Whether it's for managing vehicle-related risks, contact forms, or any other type of form, this folder is intended to centralize the logic and presentation of forms.
4
-
5
- ## 📑 Table of Contents
6
-
7
- - [Why Use a "forms" Folder](#folder-organization)
8
- - [Typical Structure of a "forms" Folder](#structure)
9
- - [Usage](#usage)
10
- - [Using React Hook Form](#react-hook-form)
11
- - [Best Practice](#best-practice)
12
-
13
- ## <span id="folder-organization">Why Use a "forms" Folder?</span>
14
-
15
- 1. **Organization** : By grouping all form components in a dedicated folder, we maintain a clean and clear project structure. This facilitates the search and management of forms.
16
-
17
- 2. **Reusability** : The form components we develop in this folder can be reused across different parts of the application, promoting code modularity.
18
-
19
- 3. **Code Clarity** : By separating form components from the application logic, we make our code more readable and easier to maintain.
20
-
21
- ## <span id="structure">Typical Structure of a "forms" Folder</span>
22
-
23
- The structure of a "forms" folder can vary based on our project's needs, but here is a typical structure we might adopt:
24
-
25
- ```
26
- 📁 forms
27
- ├── 📁VehicleRiskForm
28
- │ ├── 📄 index.ts
29
- │ ├── 📄 VehicleRiskForm.tsx
30
- │ ├── 📄 VehicleRiskForm.module.css
31
- ├── 📁ContactForm
32
- │ ├── 📄 index.ts
33
- │ ├── 📄 ContactForm.tsx
34
- │ ├── 📄 ContactForm.module.css
35
- ```
36
-
37
- In this structure, each form, such as "VehicleRiskForm" or "ContactForm," has its own sub-folder containing associated TypeScript and CSS files. This helps maintain a clear organization of our code.
38
-
39
- ## <span id="usage">🧑🏻‍💻Usage Example</span>
40
-
41
- Suppose we have a "VehicleRiskForm" form component in the "forms/VehicleRiskForm" folder. We can import and use it in our React components like this:
42
-
43
- ```javascript
44
- import { VehicleRiskForm } from '@Front/forms/VehicleRiskForm';
45
-
46
- export const App = () => {
47
- return (
48
- <div>
49
- <VehicleRiskForm />
50
- {/* ... other elements of the application */}
51
- </div>
52
- );
53
- };
54
- ```
55
-
56
- ## <span id="react-hook-form">💡 Using React Hook Form</span>
57
-
58
- This project utilizes [React Hook Form](https://react-hook-form.com/) for handling forms. React Hook Form is a powerful library for managing forms in React applications with a simple and intuitive API.
59
-
60
- ### React Hook Form Overview
61
-
62
- [React Hook Form](https://react-hook-form.com/) is a library for managing forms in React applications. It offers a declarative approach to handling form state and validation, making it easy to create complex forms with minimal boilerplate.
63
-
64
- #### Features:
65
-
66
- - **Declarative Approach:** Define your forms with a declarative syntax, making it easy to understand and maintain.
67
-
68
- - **Minimal Re-renders:** React Hook Form is designed to minimize re-renders for optimal performance.
69
-
70
- - **Form Validation:** Easily implement form validation with built-in validation rules or custom validation functions.
71
-
72
- - **Context API Integration:** Leverage React Hook Form's context API for managing form state across components.
73
-
74
- ### Implementation using React Hook Form Context
75
-
76
- In this project, we've taken advantage of React Hook Form's context API to manage the state of our forms across different components. This allows us to access and update form data without prop drilling, making the codebase cleaner and more maintainable.
77
-
78
- #### Example:
79
-
80
- ```jsx
81
- import React from 'react';
82
- import { useForm } from 'react-hook-form';
83
-
84
- // Form component using React Hook Form
85
- const MyForm = () => {
86
- const { register, handleSubmit, formState } = useForm();
87
-
88
- const onSubmit = data => {
89
- // Handle form submission
90
- console.log(data);
91
- };
92
-
93
- return (
94
- <form onSubmit={handleSubmit(onSubmit)}>
95
- <label>
96
- Name:
97
- <input {...register('name', { required: true })} />
98
- </label>
99
-
100
- {/* Add more form fields as needed */}
101
-
102
- <button type="submit" disabled={formState.isSubmitting}>
103
- Submit
104
- </button>
105
- </form>
106
- );
107
- };
108
- ```
109
-
110
- In the above example, we use the useForm hook to initialize the form and get the necessary methods (register, handleSubmit, and formState). The onSubmit function is called when the form is submitted, and you can access the form data from the data parameter.
111
-
112
- **_By using React Hook Form in this way, we've streamlined the form management process and created a more maintainable and efficient solution for handling forms in our project._**
113
-
114
- ## <span id="best-practice">🎖️ Best Practice</span>
115
-
116
- When working with `React-hook-form`, consider the following best practices to enhance maintainability and organization:
117
-
118
- #### - Use FormProvider
119
-
120
- Always use the `FormProvider` provided by `react-hook-form` to manage the form state.
121
-
122
- This ensures a centralized state management approach and simplifies form-related operations.
123
-
124
- #### - Separate Yup Validation Rules
125
-
126
- If validation rules become extensive, consider separating them into a dedicated file for better organization. This enhances readability and simplifies updates to validation logic.
127
-
128
- #### - Separate useForm Logic
129
-
130
- Separate the logic related to `useForm` into a custom hook file, especially if the form logic is complex or if it is shared across multiple components.
131
-
132
- #### - Separate onSubmit Function
133
-
134
- If the `onSubmit` function logic is substantial, consider separating it into a dedicated file. This promotes a clean separation of concerns and makes the codebase more modular.
135
-
136
- #### - Separate Submit Button
137
-
138
- If needed, separate the submit button into its own file to facilitate easy customization or relocation from the main form component.
139
-
140
- ---
141
-
142
- **_By adhering to these best practices, you create a structured and modular approach to form management, ensuring clarity and maintainability in your codebase._**
@@ -1,83 +0,0 @@
1
- # 📁 hooks
2
-
3
- The "hooks" folder is a directory you can create in your React project to group custom hooks you develop. Hooks are special functions introduced in React 16.8, allowing the management of state and lifecycle in functional components.
4
-
5
- ## 📑 Table of Contents
6
-
7
- - [Why Use a "hooks" Folder](#folder-organization)
8
- - [Usage Example](#usage)
9
- - [React-Query-Folder](#folder-react-query)
10
-
11
- ## <span id="folder-organization">Why Use a "hooks" Folder?</span>
12
-
13
- 1. **Code Reusability** : Custom hooks enable reusing state and lifecycle logic across multiple functional components, promoting code reuse and adhering to the DRY (Don't Repeat Yourself) principle.
14
-
15
- 2. **Separation of Concerns** : By grouping your custom hooks in a distinct folder, you maintain a clear separation between the business logic of your application and the React components themselves.
16
-
17
- 3. **Code Clarity** : Grouping custom hooks in a "hooks" folder simplifies code maintenance and readability, making it easier to locate and understand specific logic.
18
-
19
- ## <span id="usage">🧑🏻‍💻 Usage Example</span>
20
-
21
- Suppose you have a custom hook "useCustomHook1.js" in the "hooks" folder. You can import it and use it in a functional component like this :
22
-
23
- ```javascript
24
- import { useCustomHook1 } from './hooks/useCustomHook1';
25
-
26
- export const MyComponent = () => {
27
- const customData = useCustomHook1();
28
-
29
- return <div>{/* Use customData in your component */}</div>;
30
- };
31
- ```
32
-
33
- ## <span id="folder-react-query">"api" Folder for React Query Requests</span>
34
-
35
- Under the "hooks" folder, we have included a sub-folder "api" specifically designed to handle requests using React Query. This allows for more efficient organization of API requests, isolating them from component logic and leveraging the power of React Query for state and data caching.
36
-
37
- The typical structure of this "api" folder might look like this:
38
-
39
- ```
40
- 📁 hooks
41
- ├── 📁 api
42
- │ ├── 📄 useUsers.ts
43
- │ ├── 📄 usePosts.ts
44
- ```
45
-
46
- Each file, such as "useUsers.ts" or "usePosts.ts," contains logic to perform requests specific to a given resource. You can then use these queries in your components by importing them appropriately.
47
-
48
- Using React Query for API request management makes data retrieval, caching, and updating easier while reducing code complexity.
49
-
50
- ### What is React Query?
51
-
52
- React Query is an open-source JavaScript library that simplifies data management in a React application. It provides a simple and powerful way to handle network requests, data caching, error handling, and more. With React Query, you can significantly improve the development experience of your React applications by managing data efficiently.
53
-
54
- ### Key Features
55
-
56
- #### 1. Query Management
57
-
58
- - React Query simplifies making API requests by providing hooks for GET, POST, PUT, DELETE, etc.
59
- - You can easily specify query options such as parameters, headers, and more.
60
-
61
- #### 2. Data Caching
62
-
63
- - Retrieved data is automatically cached, avoiding unnecessary API calls.
64
- - Custom caching rules can be defined for each query.
65
-
66
- #### 3. State Management
67
-
68
- - React Query automatically manages data state, providing loading, success, and error states for each query.
69
- - You can easily access query states in your components.
70
-
71
- #### 4. Automatic Refetching
72
-
73
- - React Query offers automatic data refetching, ensuring data is automatically refreshed at regular intervals, improving data freshness.
74
-
75
- #### 5. Mutation Management
76
-
77
- - The library also facilitates mutation management, such as creating, updating, and deleting data.
78
- - Mutations are easy to define and manage.
79
-
80
- ---
81
-
82
- **_For more information and details, refer to the
83
- [official React Query documentation.](https://tanstack.com/query/v3/)_**
@@ -1 +0,0 @@
1
- export const demoQuery = () => ['dataWithDelay'];
@@ -1,16 +0,0 @@
1
- import { fetchDemoApi } from '@Front/api/demoApi';
2
- import type { Users } from '@Front/types/demoApi';
3
- import { useQuery } from '@tanstack/react-query';
4
- import { demoQuery } from './queryKey';
5
-
6
- type UseDemoApiReturn = {
7
- result: Users;
8
- isLoading: boolean;
9
- isError: boolean;
10
- };
11
-
12
- export const useDemoApi = (): UseDemoApiReturn => {
13
- const { data = [], isLoading, isError } = useQuery<Users>({ queryKey: demoQuery(), queryFn: fetchDemoApi });
14
-
15
- return { result: data, isLoading, isError };
16
- };
@@ -1,236 +0,0 @@
1
- import image from '@Front/assets/images/templatePlugins.png';
2
- import { approutes } from '@Front/routing/appRoutes';
3
- import { NavLink } from '@Front/ui/atoms/NavLink';
4
- import classes from './Demo.module.scss';
5
-
6
- export const Demo = () => {
7
- return (
8
- <div className={classes.container}>
9
- <div className={classes.bigTitleStyle}>
10
- Welcome to Your React Starter Kit <span>Welcome</span>
11
- </div>
12
-
13
- <div className={classes.foo}>FlexBlug</div>
14
-
15
- <div className={classes.paragraphContainer}>
16
- <h1 className={classes.titleStyle}>Overview</h1>
17
- <div className={classes.infoSection}>
18
- <span className={classes.centredText}>
19
- <p className={classes.paragraphStyle}>
20
- <span className={classes.highlight}>Congratulations</span> on starting your project with our{' '}
21
- <span className={classes.highlight}>React Starter Kit!</span> This kit is designed to jumpstart your
22
- development with a well-organized project structure and pre-configured tools.
23
- </p>
24
- <p className={classes.paragraphStyle}>
25
- Below, you'll find an overview of the key features, tools, and architecture used in this starter kit.
26
- </p>
27
- </span>
28
- </div>
29
- </div>
30
- <img src={image} alt="template" className={classes.imagePlace} />
31
-
32
- <div className={classes.paragraphContainer}>
33
- <h1 className={classes.titleStyle}>Objective</h1>
34
- <div className={classes.infoSection}>
35
- <p className={classes.paragraphStyle}>
36
- The goal of this <span className={classes.boldText}>starter kit</span> is to enable you to quickly start a
37
- new project with all the necessary tools.
38
- </p>
39
- <p className={classes.paragraphStyle}>
40
- Additionally, this <span className={classes.boldText}>starter kit</span> offers a robust set of options for
41
- structuring your <span className={classes.boldText}>React application</span>, providing flexibility to adapt
42
- to various project architectures.
43
- </p>
44
- <p className={classes.paragraphStyle}>
45
- It has been thoughtfully designed not only to expedite the initial setup but also to streamline the
46
- implementation of <span className={classes.highlight}>Micro-Frontends</span>, making it a versatile solution
47
- for projects of different scales. (for more details check the{' '}
48
- <span className={classes.highlight}>README.md</span> file)
49
- </p>
50
- </div>
51
- </div>
52
-
53
- <div className={classes.paragraphContainer}>
54
- <h1 className={classes.titleStyle}>Features</h1>
55
- <div className={classes.infoSection}>
56
- <p className={classes.paragraphStyle}>
57
- <span className={classes.boldText}>React: </span>A JavaScript library for building user interfaces.
58
- </p>
59
- </div>
60
- <div className={classes.infoSection}>
61
- <p className={classes.paragraphStyle}>
62
- <span className={classes.boldText}>TypeScript: </span>A superset of JavaScript that adds static typing.
63
- </p>
64
- </div>
65
- <div className={classes.infoSection}>
66
- <p className={classes.paragraphStyle}>
67
- <span className={classes.boldText}>React Query: </span>A library for managing, caching, and updating server
68
- state in React applications. (for more details check the{' '}
69
- <span className={classes.highlight}>README.md</span> file under the{' '}
70
- <span className={classes.boldText}>hooks</span> folder)
71
- </p>
72
- <div className={classes.demoStyle}>
73
- <NavLink to={approutes.reactQueryDemo} className={classes.a}>
74
- Run Demo
75
- </NavLink>
76
- </div>
77
- </div>
78
- <div className={classes.infoSection}>
79
- <p className={classes.paragraphStyle}>
80
- <span className={classes.boldText}>React Hook Form: </span>A library for managing forms with React hooks.
81
- (for more details check the <span className={classes.highlight}>README.md</span> file under the{' '}
82
- <span className={classes.boldText}>forms</span> folder)
83
- </p>
84
- <div className={classes.demoStyle}>
85
- <NavLink to={approutes.reactHookFormDemo} className={classes.a}>
86
- Run Demo
87
- </NavLink>
88
- </div>
89
- </div>
90
-
91
- <div className={classes.infoSection}>
92
- <p className={classes.paragraphStyle}>
93
- <span className={classes.boldText}>React Router: </span>A declarative routing solution for React. (for more
94
- details check the <span className={classes.highlight}>README.md</span> file under the{' '}
95
- <span className={classes.boldText}>routing</span> folder)
96
- </p>
97
- </div>
98
- <div className={classes.infoSection}>
99
- <p className={classes.paragraphStyle}>
100
- <span className={classes.boldText}>...and more: </span>Explore the{' '}
101
- <span className={classes.highlight}>Package.json</span> file to see additional dependencies.
102
- </p>
103
- </div>
104
- </div>
105
-
106
- <div className={classes.paragraphContainer}>
107
- <h1 className={classes.titleStyle}>Project Structure</h1>
108
-
109
- <div className={classes.infoSection}>
110
- <div className={classes.tableWrapper}>
111
- <table>
112
- <thead>
113
- <tr>
114
- <th>Folder</th>
115
- <th>Description</th>
116
- </tr>
117
- </thead>
118
- <tbody>
119
- <tr>
120
- <td>
121
- <span className={classes.boldText}>api</span>
122
- </td>
123
- <td>Place your API-related code here.</td>
124
- </tr>
125
- <tr>
126
- <td>
127
- <span className={classes.boldText}>assets</span>
128
- </td>
129
- <td>Store your static assets (images, fonts, etc.) in this directory.</td>
130
- </tr>
131
- <tr>
132
- <td>
133
- <span className={classes.boldText}>components</span>
134
- </td>
135
- <td>Reusable React components go here.</td>
136
- </tr>
137
- <tr>
138
- <td>
139
- <span className={classes.boldText}>config</span>
140
- </td>
141
- <td>Configuration files and environment variables are managed here.</td>
142
- </tr>
143
- <tr>
144
- <td>
145
- <span className={classes.boldText}>forms</span>
146
- </td>
147
- <td>Define your forms using React Hook Form.</td>
148
- </tr>
149
- <tr>
150
- <td>
151
- <span className={classes.boldText}>hooks</span>
152
- </td>
153
- <td>Custom React hooks to share logic across components.</td>
154
- </tr>
155
- <tr>
156
- <td>
157
- <span className={classes.boldText}>pages</span>
158
- </td>
159
- <td>React components that represent individual pages or views.</td>
160
- </tr>
161
- <tr>
162
- <td>
163
- <span className={classes.boldText}>providers</span>
164
- </td>
165
- <td>React context providers for state management.</td>
166
- </tr>
167
- <tr>
168
- <td>
169
- <span className={classes.boldText}>routing</span>
170
- </td>
171
- <td>Configure your application routes here.</td>
172
- </tr>
173
- <tr>
174
- <td>
175
- <span className={classes.boldText}>types</span>
176
- </td>
177
- <td>TypeScript type definitions.</td>
178
- </tr>
179
- <tr>
180
- <td>
181
- <span className={classes.boldText}>ui</span>
182
- </td>
183
- <td>Presentational components and styles.</td>
184
- </tr>
185
- <tr>
186
- <td>
187
- <span className={classes.boldText}>utils</span>
188
- </td>
189
- <td>General utility functions.</td>
190
- </tr>
191
- </tbody>
192
- </table>
193
- </div>
194
- </div>
195
- </div>
196
- <div className={classes.paragraphContainer}>
197
- <h1 className={classes.titleStyle}>Additional Information</h1>
198
- <div className={classes.infoSection}>
199
- <ul>
200
- <li>
201
- - Customize the project configuration in the <code>config</code> directory.
202
- </li>
203
- <li>
204
- - Explore the <code>utils</code> directory for utility functions.
205
- </li>
206
- <li>- Leverage React Query for efficient data fetching.</li>
207
- <li>- Take advantage of React Hook Form for managing forms seamlessly.</li>
208
- <li>
209
- - Refer to the <code>types</code> directory for TypeScript type definitions.
210
- </li>
211
- </ul>
212
- </div>
213
- <div className={classes.infoSection}>
214
- <span className={classes.centredText}>
215
- <p className={classes.paragraphStyle}>
216
- Our project is organized into various folders, each containing its own{' '}
217
- <span className={classes.highlight}>README.md</span> file with specific details, instructions, and
218
- additional information. This documentation will guide you through setting up the environment,
219
- understanding the project structure, and using the available components and features. For more details,
220
- check the <span className={classes.highlight}>README.md</span> file in{' '}
221
- <span className={classes.boldText}>each folder of the project</span>.
222
- </p>
223
- </span>
224
- </div>
225
- <div className={classes.infoSection}>
226
- <span className={classes.centredText}>
227
- <p className={classes.paragraphStyle}>
228
- Feel free to explore and modify the structure to suit your project's needs.{' '}
229
- <span className={classes.boldText}>Happy coding!</span>
230
- </p>
231
- </span>
232
- </div>
233
- </div>
234
- </div>
235
- );
236
- };
@@ -1 +0,0 @@
1
- export { reactHookFormDemoRoutes } from './routes';
@@ -1,7 +0,0 @@
1
- import { RouteObject } from 'react-router';
2
- import { ReactHookFormDemo } from './ReactHookFormDemo';
3
-
4
- export const reactHookFormDemoRoutes: RouteObject = {
5
- path: 'ReactHookFormDemo',
6
- element: <ReactHookFormDemo />,
7
- };
@@ -1 +0,0 @@
1
- export { reactQueryDemoRoutes } from './routes';