Skip to content

Commit 790e8a0

Browse files
committed
Initial Commit with Listing and Add form
0 parents  commit 790e8a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+15643
-0
lines changed

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
/.storybook
8+
/storybook-static
9+
10+
11+
12+
# testing
13+
/coverage
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
.env.local
21+
.env.development.local
22+
.env.test.local
23+
.env.production.local
24+
25+
npm-debug.log*
26+
yarn-debug.log*
27+
yarn-error.log*

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app), using the [Redux](https://redux.js.org/) and [Redux Toolkit](https://redux-toolkit.js.org/) template.
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `yarn start`
8+
9+
Runs the app in the development mode.<br />
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br />
13+
You will also see any lint errors in the console.
14+
15+
### `yarn test`
16+
17+
Launches the test runner in the interactive watch mode.<br />
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `yarn build`
21+
22+
Builds the app for production to the `build` folder.<br />
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br />
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `yarn eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
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.
35+
36+
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.
37+
38+
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.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).

package.json

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "webapp",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@material-ui/core": "^4.10.1",
7+
"@material-ui/icons": "^4.9.1",
8+
"@testing-library/jest-dom": "^4.2.4",
9+
"@testing-library/react": "^9.3.2",
10+
"@testing-library/user-event": "^7.1.2",
11+
"@types/jest": "^24.0.0",
12+
"@types/node": "^12.0.0",
13+
"@types/react": "^16.9.0",
14+
"@types/react-dom": "^16.9.0",
15+
"@types/react-redux": "^7.1.7",
16+
"@types/react-router-dom": "5.1.5",
17+
"react": "^16.13.1",
18+
"react-dom": "^16.13.1",
19+
"react-hook-form": "^5.7.2",
20+
"react-hook-form-input": "^1.1.10",
21+
"react-redux": "^7.2.0",
22+
"react-router-dom": "^5.2.0",
23+
"react-scripts": "3.4.1",
24+
"redux-thunk": "^2.3.0",
25+
"typescript": "3.8.2"
26+
},
27+
"scripts": {
28+
"start": "react-scripts start",
29+
"watch": "cra-build-watch",
30+
"build": "react-scripts build",
31+
"test": "react-scripts test",
32+
"eject": "react-scripts eject",
33+
"storybook": "start-storybook -p 9009 -s public",
34+
"build-storybook": "build-storybook -s public"
35+
},
36+
"eslintConfig": {
37+
"extends": "react-app"
38+
},
39+
"browserslist": {
40+
"production": [
41+
">0.2%",
42+
"not dead",
43+
"not op_mini all"
44+
],
45+
"development": [
46+
"last 1 chrome version",
47+
"last 1 firefox version",
48+
"last 1 safari version"
49+
]
50+
},
51+
"devDependencies": {
52+
"@storybook/addon-actions": "^5.3.19",
53+
"@storybook/addon-links": "^5.3.19",
54+
"@storybook/addons": "^5.3.19",
55+
"@storybook/preset-create-react-app": "^3.0.0",
56+
"@storybook/react": "^5.3.19",
57+
"cra-build-watch": "^3.2.0"
58+
}
59+
}

public/index.html

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta name="description" content="Composite Products App" />
9+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
10+
<!--
11+
manifest.json provides metadata used when your web app is installed on a
12+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
13+
-->
14+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
15+
<!--
16+
Notice the use of %PUBLIC_URL% in the tags above.
17+
It will be replaced with the URL of the `public` folder during the build.
18+
Only files inside the `public` folder can be referenced from the HTML.
19+
20+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
21+
work correctly both with client-side routing and a non-root public URL.
22+
Learn how to configure a non-root public URL by running `npm run build`.
23+
-->
24+
<title>Composite Products App</title>
25+
</head>
26+
<body>
27+
<noscript>You need to enable JavaScript to run this app.</noscript>
28+
<div id="root"></div>
29+
<!--
30+
This HTML file is a template.
31+
If you open it directly in the browser, you will see an empty page.
32+
33+
You can add webfonts, meta tags, or analytics to this file.
34+
The build step will place the bundled scripts into the <body> tag.
35+
36+
To begin the development, run `npm start` or `yarn start`.
37+
To create a production bundle, use `npm run build` or `yarn build`.
38+
-->
39+
</body>
40+
</html>

public/manifest.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Composite Products App",
4+
"start_url": ".",
5+
"display": "standalone",
6+
"theme_color": "#000000",
7+
"background_color": "#ffffff"
8+
}

public/robots.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

src/App.css

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
font-family: -apple-system,
5+
BlinkMacSystemFont,
6+
"Segoe UI",
7+
Helvetica,
8+
Arial,
9+
sans-serif,
10+
"Apple Color Emoji",
11+
"Segoe UI Emoji",
12+
"Segoe UI Symbol";
13+
}

src/App.test.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import { Provider } from 'react-redux';
4+
import { store } from './app/store';
5+
import App from './App';
6+
7+
test('renders learn react link', () => {
8+
const { getByText } = render(
9+
<Provider store={store}>
10+
<App />
11+
</Provider>
12+
);
13+
14+
expect(getByText(/learn/i)).toBeInTheDocument();
15+
});

src/App.tsx

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
3+
import { Route, Switch, Link, useParams } from "react-router-dom";
4+
5+
import CompositeProductList from './containers/composite-product-list-container';
6+
import AddEditCompositeProductForm from './containers/add-edit-composite-product-form-container';
7+
import { List, ListItem, Grid } from '@material-ui/core';
8+
9+
10+
export default function App() {
11+
const OpenForm = () => {
12+
const { id } = useParams();
13+
console.log(id);
14+
return <AddEditCompositeProductForm id={id} />
15+
}
16+
return (
17+
<Grid>
18+
<List>
19+
<ListItem>
20+
<Link to="/">Home</Link>
21+
</ListItem>
22+
<ListItem>
23+
<Link to="/composite-products">Composite Product List</Link>
24+
</ListItem>
25+
<ListItem>
26+
<Link to="/composite-products/add">Add</Link>
27+
</ListItem>
28+
</List>
29+
<Switch>
30+
<Route path="/composite-products" exact component={CompositeProductList} />
31+
<Route path="/composite-products/add" component={OpenForm} />
32+
<Route path="/composite-products/:id" component={OpenForm} />
33+
</Switch>
34+
</Grid>
35+
);
36+
}
37+
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ActionCreator, Dispatch } from "redux";
2+
import { ThunkAction } from "redux-thunk";
3+
import config from "../config.json";
4+
5+
import { IComponentProductState } from "../reducers/component-product-reducer";
6+
import { Product } from "../types/types";
7+
8+
export enum ComponentProductActionTypes {
9+
LISTPRODUCTS = "LISTPRODUCTS",
10+
}
11+
12+
export interface IComponentProductGetAction {
13+
type: ComponentProductActionTypes.LISTPRODUCTS;
14+
list: Product[];
15+
}
16+
17+
export type ComponentProductActions = IComponentProductGetAction;
18+
19+
/*<Promise<Return Type>, State Interface, Type of Param, Type of Action> */
20+
export const getComponentProduct: ActionCreator<ThunkAction<
21+
Promise<any>,
22+
IComponentProductState,
23+
null,
24+
IComponentProductGetAction
25+
>> = () => {
26+
return async (dispatch: Dispatch) => {
27+
try {
28+
const response = await fetch(config.api_server_domain + "/products");
29+
let result = await response.json();
30+
31+
dispatch({
32+
list: result,
33+
type: ComponentProductActionTypes.LISTPRODUCTS,
34+
});
35+
} catch (err) {
36+
console.error(err);
37+
}
38+
};
39+
};
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { ActionCreator, Dispatch } from "redux";
2+
import { ThunkAction } from "redux-thunk";
3+
import config from "../config.json";
4+
5+
import { ICompositeProductState } from "../reducers/composite-product-reducer";
6+
import { CompositeProduct } from "../types/types";
7+
8+
export enum CompositeProductActionTypes {
9+
FETCH_COMPOSITE = "FETCH_COMPOSITE",
10+
SAVE_COMPOSITE = "SAVE_COMPOSITE",
11+
}
12+
13+
export interface ICompositeProductGetAction {
14+
type: CompositeProductActionTypes.FETCH_COMPOSITE;
15+
list: CompositeProduct[];
16+
}
17+
export interface ICompositeProductSaveAction {
18+
type: CompositeProductActionTypes.SAVE_COMPOSITE;
19+
status: any;
20+
}
21+
22+
export type CompositeProductActions =
23+
| ICompositeProductGetAction
24+
| ICompositeProductSaveAction;
25+
26+
/*<Promise<Return Type>, State Interface, Type of Param, Type of Action> */
27+
export const getCompositeProduct: ActionCreator<ThunkAction<
28+
Promise<any>,
29+
ICompositeProductState,
30+
null,
31+
ICompositeProductGetAction
32+
>> = () => {
33+
return async (dispatch: Dispatch) => {
34+
try {
35+
const response = await fetch(
36+
config.api_server_domain + "/composite-products"
37+
);
38+
let result = await response.json();
39+
40+
dispatch({
41+
list: result,
42+
type: CompositeProductActionTypes.FETCH_COMPOSITE,
43+
});
44+
} catch (err) {
45+
console.error(err);
46+
}
47+
};
48+
};
49+
50+
export const saveCompositeProduct: ActionCreator<ThunkAction<
51+
Promise<any>,
52+
ICompositeProductState,
53+
null,
54+
ICompositeProductGetAction
55+
>> = (opts) => {
56+
console.log("request recieved with data:", opts, JSON.stringify(opts));
57+
return async (dispatch: Dispatch) => {
58+
try {
59+
const response = await fetch(
60+
config.api_server_domain + "/composite-products",
61+
{
62+
headers: {
63+
"Content-Type": "application/json",
64+
},
65+
method: "post",
66+
body: JSON.stringify(opts),
67+
}
68+
);
69+
let result = await response.json();
70+
console.log("save request returned :", result);
71+
dispatch({
72+
status: "success",
73+
type: CompositeProductActionTypes.SAVE_COMPOSITE,
74+
});
75+
} catch (err) {
76+
console.error(err);
77+
}
78+
};
79+
};

0 commit comments

Comments
 (0)