32 | )}
33 | >
34 | );
35 | };
36 |
37 | const renderField = (props) => {
38 | const {
39 | input,
40 | label,
41 | name,
42 | type,
43 | placeholder,
44 | disabled,
45 | validationError,
46 | meta: { touched, error, warning },
47 | } = props;
48 |
49 | return (
50 |
51 |
54 |
63 |
71 |
72 | );
73 | };
74 |
75 | const renderDatePicker = (props) => {
76 | const {
77 | input: { onChange, value },
78 | label,
79 | disabled,
80 | formatType,
81 | timeFormating,
82 | name,
83 | step,
84 | time,
85 | date,
86 | placeholder,
87 | validationError,
88 | meta: { touched, error, warning },
89 | } = props;
90 |
91 | return (
92 |
93 |
96 |
112 |
120 |
121 | );
122 | };
123 |
124 | const renderCheckbox = (props) => {
125 | const {
126 | input,
127 | placeholder,
128 | validationError,
129 | checked,
130 | meta: { touched, error, warning },
131 | } = props;
132 |
133 | return (
134 |
135 |
138 |
146 |
147 | );
148 | };
149 |
150 | const renderSelectField = (props) => {
151 | const {
152 | input,
153 | label,
154 | validationError,
155 | name,
156 | options,
157 | disabled,
158 | defaultSelected,
159 | placeholder,
160 | meta: { touched, error, warning },
161 | } = props;
162 |
163 | return (
164 |
165 |
168 |
179 |
187 |
188 | );
189 | };
190 |
191 | export { renderField, renderSelectField, renderCheckbox, renderDatePicker };
192 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.1/8 is considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then((registration) => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch((error) => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl)
104 | .then((response) => {
105 | // Ensure service worker exists, and that we really are getting a JS file.
106 | const contentType = response.headers.get('content-type');
107 | if (
108 | response.status === 404 ||
109 | (contentType != null && contentType.indexOf('javascript') === -1)
110 | ) {
111 | // No service worker found. Probably a different app. Reload the page.
112 | navigator.serviceWorker.ready.then((registration) => {
113 | registration.unregister().then(() => {
114 | window.location.reload();
115 | });
116 | });
117 | } else {
118 | // Service worker found. Proceed as normal.
119 | registerValidSW(swUrl, config);
120 | }
121 | })
122 | .catch(() => {
123 | console.log(
124 | 'No internet connection found. App is running in offline mode.'
125 | );
126 | });
127 | }
128 |
129 | export function unregister() {
130 | if ('serviceWorker' in navigator) {
131 | navigator.serviceWorker.ready.then((registration) => {
132 | registration.unregister();
133 | });
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 | Redux Sagas config setup is on `master` branch
3 | Redux Thunk config setup is on `redux-thunk` branch
4 | Feel free to use whichever you like depending upon the project's requirement.
5 |
6 | ## Note: To access redux-thunk code, checkout to branch `redux-thunk`
7 |
8 | ## Available Scripts
9 |
10 | In the project directory, you can run:
11 |
12 | ### `npm start`
13 |
14 | Runs the app in the development mode.
15 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
16 |
17 | The page will reload if you make edits.
18 | You will also see any lint errors in the console.
19 |
20 | ### `npm test`
21 |
22 | Launches the test runner in the interactive watch mode.
23 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
24 |
25 | ### `npm run build`
26 |
27 | Builds the app for production to the `build` folder.
28 | It correctly bundles React in production mode and optimizes the build for the best performance.
29 |
30 | The build is minified and the filenames include the hashes.
31 | Your app is ready to be deployed!
32 |
33 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
34 |
35 | ### `npm run eject`
36 |
37 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
38 |
39 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
40 |
41 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
42 |
43 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
44 |
45 | ## Learn More
46 |
47 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
48 |
49 | To learn React, check out the [React documentation](https://reactjs.org/).
50 |
51 | ### Code Splitting
52 |
53 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
54 |
55 | ### Analyzing the Bundle Size
56 |
57 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
58 |
59 | ### Making a Progressive Web App
60 |
61 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
62 |
63 | ### Advanced Configuration
64 |
65 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
66 |
67 | ### Deployment
68 |
69 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
70 |
71 | ### `npm run build` fails to minify
72 |
73 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
74 |
75 | ### Folder structure writeup
76 | ### Public -
77 | This folder contains all the static assets including index.html, images & css that will be injected into the build folder created from the command npm run build.Here we also have manifest. json , where we specify basic metadata about extensions such as the name and version, and can also specify aspects of your extension's functionality, one can configure to make an app PWA. Along with that it also has a favicon & images folder that has common image assets in it.
78 |
79 | ### src -
80 | Under src folder we have various sub folders that are important in maintaining the good understandable code structure:
81 | ## actions -
82 | The actions folder consist of an actionType and index file the actionType has const to identify actions uniquely and the index files has actions definitions that needs to be dispatched
83 | ## assets -
84 | assets folder further consist of images folder that is required to put images and other assets to be accessed within src
85 | ## common -
86 | the common folder consist of the components that common for all other components and are frequently used, like header, footer and a common layout
87 | ## components -
88 | components folder consist of various components that are used in different parts of the app and are part of component attributes in route definition. It is structured in a manner that has a component named folder that further consist of index file and a styling scss file for that component.
89 | ## constants -
90 | as the name suggests the constant folders has the file that consist logically grouped constants like static text and urls used in the app.
91 | ## container -
92 | the container consists of files that imports a stateless component and wraps it with actions and state to be able to access store and dispatch necessary actions.
93 | ## reducer -
94 | this folder consists of different reducers based on the types of actions and these reducer functions are finally responsible for managing the data store, we have a root reducer where we combine all the reducers that are logically segregated and export them as one combine reducer.
95 | ## saga -
96 | Redux-saga is a redux middleware library that makes handling side effects in redux app nice and simple. In this folder we have a different saga file corresponding to each action and request js that has different functions defined that are a part of axios instance with different configs. Also it consists of a rootsaga.js file that combines all different component specific sagas into one rootsaga.
97 | ## service -
98 | the service folder consists of api js file that has the instance of axios defined with all the required configs to make a rest call.
99 | ## utils -
100 | The utils folder consist of all the utility part of app that we would need frequently in different parts of app like
101 | a) the formUtils has different form components along with validator,
102 | b) also it has history js utils that we might need to route logically between views,
103 | c) interceptor js that is used to intercept the request like adding tokens,
104 | d) notification js build to display various alert notifications on the top either corners in case of success, alert, info or warnings to be shown to user
105 | e) private routes js this is a logical route component to stop user from accessing the unauthorized routes.
106 | ## index css -
107 | this is the common css file where we can add the common styling that applies to all parts of the app.
108 | ## index js -
109 | This is the most important file where we mount our app onto a root element
110 | ## push-notifications js -
111 | this is useful in implementing the push notification from firebase, basically needed for PWA.
112 | ## serviceWorkers js -
113 | the serviceworker file is again important in terms of PWA it helps enable you to run JavaScript before a page even exists, makes your site faster, and allows you to display content even if there is no internet connection.
114 | ## store js -
115 | this file is important in terms of implementing redux in our app the store is created here using the middleware
116 |
117 | ### babelrc js -
118 | would be useful if you want to run certain transformations / plugins on a subset of files /directories.
119 | ### .env -
120 | This is the file where we write all our environment variables like the api base url and other keys.
121 | ### .gitignore -
122 | This is the file where we mention the files and folder to be ignored by our versioning tool like git
123 | ### babel.config js -
124 | This establishes Babel's core concept of the base directory of your repository. You can place all of your repo configuration in the root babel.config
125 | ### jest-setup js -
126 | this is the file where we declare out adapter that are useful in terms of unit testing code
127 | ### jsconfig js -
128 | the js config js consist of declaration for absolute routing, the paths here must be predefined
129 | ### package json -
130 | this is the heart of a react app that has all information about the package dependency, dev dependency and app info
131 | ### test-env js -
132 | this is the file configuration for the env file.
133 |
--------------------------------------------------------------------------------