Skip to content

Commit 76774c8

Browse files
feat: First commit
1 parent de9c45b commit 76774c8

File tree

13 files changed

+929
-84
lines changed

13 files changed

+929
-84
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
25+
.env

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@material-ui/core": "^4.11.3",
67
"@testing-library/jest-dom": "^5.11.4",
78
"@testing-library/react": "^11.1.0",
89
"@testing-library/user-event": "^12.1.10",
10+
"ra-data-lb4": "^0.3.0",
11+
"ra-data-simple-rest": "^3.13.4",
912
"react": "^17.0.2",
13+
"react-admin": "^3.14.1",
14+
"react-admin-lb4": "^1.0.3",
1015
"react-dom": "^17.0.2",
1116
"react-scripts": "4.0.3",
1217
"web-vitals": "^1.0.1"
1318
},
1419
"scripts": {
1520
"start": "react-scripts start",
16-
"build": "react-scripts build",
21+
"build": "react-scripts build && echo '/* /index.html 200' | cat >build/_redirects ",
1722
"test": "react-scripts test",
1823
"eject": "react-scripts eject"
1924
},

src/App.css

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/App.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import logo from './logo.svg';
2-
import './App.css';
1+
import React from 'react';
2+
import { Admin, Resource } from 'react-admin';
3+
import OrderList from './components/OrderList';
4+
import OrderListEdit from './components/OrderListEdit';
5+
import lb4Provider from 'react-admin-lb4';
6+
//import lb4Provider from 'ra-data-lb4';
7+
8+
import ProductList from './components/ProductList';
9+
import ProductListEdit from './components/ProductListEdit';
10+
import { authProvider, httpClient } from './Auth';
311

412
function App() {
513
return (
6-
<div className="App">
7-
<header className="App-header">
8-
<img src={logo} className="App-logo" alt="logo" />
9-
<p>
10-
Edit <code>src/App.js</code> and save to reload.
11-
</p>
12-
<a
13-
className="App-link"
14-
href="https://reactjs.org"
15-
target="_blank"
16-
rel="noopener noreferrer"
17-
>
18-
Learn React
19-
</a>
20-
</header>
21-
</div>
14+
<Admin
15+
dataProvider={lb4Provider(process.env.REACT_APP_API_URL, httpClient)}
16+
authProvider={authProvider}
17+
>
18+
<Resource name='orders' list={OrderList} edit={OrderListEdit} />
19+
<Resource name='products' list={ProductList} edit={ProductListEdit} />
20+
</Admin>
2221
);
2322
}
2423

src/App.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Auth.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
export const httpClient = () => {
2+
const { token } = JSON.parse(localStorage.getItem('auth')) || {};
3+
return { Authorization: `Bearer ${token}` };
4+
};
5+
6+
export const authProvider = {
7+
// authentication
8+
login: ({ username, password }) => {
9+
const request = new Request(
10+
process.env.REACT_APP_API_URL + '/users/login',
11+
{
12+
method: 'POST',
13+
body: JSON.stringify({ email: username, password }),
14+
headers: new Headers({ 'Content-Type': 'application/json' }),
15+
}
16+
);
17+
return fetch(request)
18+
.then((response) => {
19+
if (response.status < 200 || response.status >= 300) {
20+
throw new Error(response.statusText);
21+
}
22+
return response.json();
23+
})
24+
.then((auth) => {
25+
localStorage.setItem(
26+
'auth',
27+
JSON.stringify({ ...auth, fullName: username })
28+
);
29+
})
30+
.catch(() => {
31+
throw new Error('Network error');
32+
});
33+
},
34+
checkError: (error) => {
35+
const status = error.status;
36+
if (status === 401 || status === 403) {
37+
localStorage.removeItem('auth');
38+
return Promise.reject();
39+
}
40+
// other error code (404, 500, etc): no need to log out
41+
return Promise.resolve();
42+
},
43+
checkAuth: () =>
44+
localStorage.getItem('auth')
45+
? Promise.resolve()
46+
: Promise.reject({ message: 'login required' }),
47+
logout: () => {
48+
localStorage.removeItem('auth');
49+
return Promise.resolve();
50+
},
51+
getIdentity: () => {
52+
try {
53+
const { id, fullName, avatar } = JSON.parse(localStorage.getItem('auth'));
54+
return Promise.resolve({ id, fullName, avatar });
55+
} catch (error) {
56+
return Promise.reject(error);
57+
}
58+
},
59+
getPermissions: (params) => Promise.resolve(),
60+
};

src/components/OrderList.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import {List, Datagrid, TextField, DateField, EditButton} from 'react-admin';
3+
4+
const OrderList = (props) => {
5+
return (
6+
<List {...props}>
7+
<Datagrid>
8+
<TextField source='id' />
9+
<TextField source='order_status' />
10+
<DateField source='order_purchase_timestamp' />
11+
<DateField source='order_approved_at' />
12+
<DateField source='order_delivered_carrier_date'/>
13+
<DateField source='order_delivered_customer_date' />
14+
<DateField source='order_estimated_delivery_date' />
15+
16+
<EditButton basePath='/orders' />
17+
</Datagrid>
18+
</List>
19+
);
20+
}
21+
22+
export default OrderList;

src/components/OrderListEdit.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import {
3+
Edit,
4+
SimpleForm,
5+
TextInput,
6+
DateTimeInput,
7+
SelectInput,
8+
} from 'react-admin';
9+
10+
const OrderListEdit = (props) => {
11+
return (
12+
<Edit title='Update shipping limit date' {...props}>
13+
<SimpleForm>
14+
<TextInput disabled source='id' />
15+
<SelectInput
16+
source='order_status'
17+
choices={[
18+
{
19+
id: 'invoiced',
20+
name: 'invoiced',
21+
},
22+
{
23+
id: 'delivered',
24+
name: 'delivered',
25+
},
26+
{
27+
id: 'shipped',
28+
name: 'shipped',
29+
},
30+
{
31+
id: 'unavailable',
32+
name: 'unavailable',
33+
},
34+
]}
35+
/>
36+
37+
<DateTimeInput label='Approved' source='order_approved_at' />
38+
<DateTimeInput
39+
label='Est Delivery'
40+
source='order_estimated_delivery_date'
41+
/>
42+
<DateTimeInput label='Carrier' source='order_delivered_carrier_date' />
43+
</SimpleForm>
44+
</Edit>
45+
);
46+
};
47+
48+
export default OrderListEdit;

src/components/ProductList.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import {List, Datagrid, TextField, EditButton } from 'react-admin';
3+
4+
const ProductList = (props) => {
5+
return (
6+
<List {...props}>
7+
<Datagrid>
8+
<TextField source='id' />
9+
<TextField source='product_category_name' />
10+
<TextField source='product_name_lenght' />
11+
<TextField source='product_height_cm' />
12+
<TextField source='product_length_cm' />
13+
<TextField source='product_width_cm' />
14+
<TextField source='product_weight_g' />
15+
<TextField source='product_photos_qty' />
16+
<TextField source='product_description_lenght' />
17+
18+
<EditButton basePath='/products' />
19+
</Datagrid>
20+
</List>
21+
);
22+
}
23+
24+
export default ProductList;

src/components/ProductListEdit.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import {
3+
Edit,
4+
SimpleForm,
5+
TextInput,
6+
NumberInput,
7+
} from 'react-admin';
8+
9+
const ProductListEdit = (props) => {
10+
return (
11+
<Edit title='Update shipping limit date' {...props}>
12+
<SimpleForm>
13+
<TextInput disabled source='id' />
14+
<TextInput title='Name' source='product_category_name' />
15+
<NumberInput title='Height' source='product_height_cm' />
16+
<NumberInput title='Length' source='product_length_cm' />
17+
<NumberInput title='Width' source='product_width_cm' />
18+
</SimpleForm>
19+
</Edit>
20+
);
21+
};
22+
23+
export default ProductListEdit;

0 commit comments

Comments
 (0)