diff --git a/client/.env.development b/client/.env.development deleted file mode 100644 index cba79f9..0000000 --- a/client/.env.development +++ /dev/null @@ -1,2 +0,0 @@ -REACT_APP_VERSION=$npm_package_version -REACT_APP_URL='http://127.0.0.1:4900' \ No newline at end of file diff --git a/client/.env.production b/client/.env.production deleted file mode 100644 index 4f79a0f..0000000 --- a/client/.env.production +++ /dev/null @@ -1 +0,0 @@ -GENERATE_SOURCEMAP=false \ No newline at end of file diff --git a/client/.eslintrc b/client/.eslintrc deleted file mode 100644 index bc1f11f..0000000 --- a/client/.eslintrc +++ /dev/null @@ -1,50 +0,0 @@ -{ - "root": true, - "env": { - "node": true, - "es6": true - }, - "parser": "babel-eslint", - "plugins": ["react"], - "parserOptions": { - "sourceType": "module", - "ecmaVersion": 6 - }, - "rules": { - "max-len": 0, - "semi": 0, - "curly": [2, "multi-line"], - "comma-dangle": [2, "always-multiline"], - "eol-last": [2, "always"], - "eqeqeq": [2, "allow-null"], - "no-shadow": 1, - "quotes": [ - 2, - "single", - { - "allowTemplateLiterals": true, - "avoidEscape": true - } - ], - // dog fooding - "import/no-extraneous-dependencies": 0, - "import/unambiguous": "off" - }, - - "settings": { - "import/resolver": { - "node": { - "paths": ["src"] - } - } - }, - - "overrides": [ - { - "files": "scripts/**", - "rules": { - "no-console": "off" - } - } - ] -} diff --git a/client/.gitignore b/client/.gitignore deleted file mode 100644 index 4d29575..0000000 --- a/client/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dependencies -/node_modules -/.pnp -.pnp.js - -# testing -/coverage - -# production -/build - -# misc -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local - -npm-debug.log* -yarn-debug.log* -yarn-error.log* diff --git a/client/README.md b/client/README.md deleted file mode 100644 index 02aac3f..0000000 --- a/client/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# Getting Started with Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `yarn start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.\ -You will also see any lint errors in the console. - -### `yarn test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `yarn build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `yarn eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -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. - -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. - -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. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) - -### Analyzing the Bundle Size - -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) - -### Making a Progressive Web App - -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) - -### Advanced Configuration - -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) - -### Deployment - -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `yarn build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/client/package.json b/client/package.json deleted file mode 100644 index 45ef20e..0000000 --- a/client/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "client", - "version": "0.1.0", - "private": true, - "dependencies": { - "@testing-library/jest-dom": "^5.11.4", - "@testing-library/react": "^11.1.0", - "@testing-library/user-event": "^12.1.10", - "axios": "^0.21.0", - "node-sass": "^4.0.0", - "react": "^17.0.1", - "react-dom": "^17.0.1", - "react-redux": "^7.2.2", - "react-router-dom": "^5.2.0", - "react-scripts": "4.0.1", - "redux": "^4.0.5", - "redux-form": "^8.3.7", - "redux-thunk": "^2.3.0", - "rxjs": "^6.6.3", - "web-vitals": "^0.2.4" - }, - "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" - }, - "eslintConfig": { - "extends": [ - "react-app", - "react-app/jest" - ] - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - } -} diff --git a/client/public/favicon.ico b/client/public/favicon.ico deleted file mode 100644 index a11777c..0000000 Binary files a/client/public/favicon.ico and /dev/null differ diff --git a/client/public/index.html b/client/public/index.html deleted file mode 100644 index ec85e88..0000000 --- a/client/public/index.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - Book - - - -
- - - diff --git a/client/public/logo192.png b/client/public/logo192.png deleted file mode 100644 index fc44b0a..0000000 Binary files a/client/public/logo192.png and /dev/null differ diff --git a/client/public/logo512.png b/client/public/logo512.png deleted file mode 100644 index a4e47a6..0000000 Binary files a/client/public/logo512.png and /dev/null differ diff --git a/client/public/manifest.json b/client/public/manifest.json deleted file mode 100644 index 080d6c7..0000000 --- a/client/public/manifest.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "short_name": "React App", - "name": "Create React App Sample", - "icons": [ - { - "src": "favicon.ico", - "sizes": "64x64 32x32 24x24 16x16", - "type": "image/x-icon" - }, - { - "src": "logo192.png", - "type": "image/png", - "sizes": "192x192" - }, - { - "src": "logo512.png", - "type": "image/png", - "sizes": "512x512" - } - ], - "start_url": ".", - "display": "standalone", - "theme_color": "#000000", - "background_color": "#ffffff" -} diff --git a/client/public/robots.txt b/client/public/robots.txt deleted file mode 100644 index e9e57dc..0000000 --- a/client/public/robots.txt +++ /dev/null @@ -1,3 +0,0 @@ -# https://www.robotstxt.org/robotstxt.html -User-agent: * -Disallow: diff --git a/client/setupProxy.js b/client/setupProxy.js deleted file mode 100644 index c0effe3..0000000 --- a/client/setupProxy.js +++ /dev/null @@ -1,13 +0,0 @@ -const proxy = require('http-proxy-middleware'); - -module.exports = function(app) { - app.use( - proxy('/api', { - target: 'http://127.0.0.1:4900', - changeOrigin: true, - pathRewrite: { - '^/api': '', - }, - }), - ); -}; diff --git a/client/src/App.css b/client/src/App.css deleted file mode 100644 index bfd2969..0000000 --- a/client/src/App.css +++ /dev/null @@ -1,43 +0,0 @@ - .row { - display: flex; - padding: 3px 10px; - } - .pageBody{ - min-width: 1000px; - max-width: 1000px; - } - - .col, - .col0, - .col1, - .col2, - .col3, - .col4, - .col5 { - padding: 3px; - } - - .col, - .col1 { - flex: 1; - } - - .col2 { - flex: 2; - } - - .col3 { - flex: 3; - } - - .col4 { - flex: 4; - } - - .col5 { - flex: 5; - } - - .align-center { - align-items: center; - } \ No newline at end of file diff --git a/client/src/App.js b/client/src/App.js deleted file mode 100644 index cad6c13..0000000 --- a/client/src/App.js +++ /dev/null @@ -1,45 +0,0 @@ -import {createBrowserHistory} from 'history'; -import {Router, Route, Switch} from 'react-router-dom'; - -import './App.css'; -import pageLogin from './pages/page.login'; -import pageDefault from './pages/page.default'; -import pageRelease from './pages/page.release'; -import pageBookDetail from './pages/page.book.detail'; -import pageSignup from './pages/page.signup'; -import pageRequestList from './pages/page.request.list'; -import pageBorrowList from './pages/page.borrow.list'; -import pageMyHome from './pages/page.my'; -import pageCategory from './pages/page.category'; -import Header from './components/component.header'; - -const history = createBrowserHistory(); - -function App() { - return ( -
- -
-
-
-
- - - - - - - - - - - -
-
-
-
-
- ); -} - -export default App; diff --git a/client/src/App.test.js b/client/src/App.test.js deleted file mode 100644 index 650c607..0000000 --- a/client/src/App.test.js +++ /dev/null @@ -1,17 +0,0 @@ -import App from './App'; -import {render, screen} from '@testing-library/react'; -import {createStore, applyMiddleware, compose} from 'redux'; -import reducers from './reducers'; -const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; -import {Provider} from 'react-redux'; -import reduxThunk from 'redux-thunk'; - -test('renders learn react link', () => { - render( - - - , - ); - const linkElement = screen.getByText(/WELCOME TO BORROW PLATFORM/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/client/src/actions/index.js b/client/src/actions/index.js deleted file mode 100644 index 937b9b1..0000000 --- a/client/src/actions/index.js +++ /dev/null @@ -1,505 +0,0 @@ -import axios from 'axios'; -import {Subject} from 'rxjs'; - -const ApiMap = { - development: 'http://127.0.0.1:4900', - production: '', -}; -// console.log('process.env.NODE_ENV:', process.env.NODE_ENV); -export const ApiService = ApiMap[process.env.NODE_ENV] || ''; - -export const TypeMap = { - LOADING: 'COMMON_LOADING', - LOADING_HIDE: 'COMMON_LOADING_HIDE', - USER_LOGIN: 'USER_LOGIN', - USER_401: 'USER_401', - USER_UPDATE: 'USER_UPDATE', - USER_SIGNUP: 'USER_SIGNUP', - CATEGORY_LIST: 'CATEGORY_LIST', - CATEGORY_LIST_ALL: 'CATEGORY_LIST_ALL', - CATEGORY_UPDATE: 'CATEGORY_PUT', - CATEGORY_DELETE: 'CATEGORY_DELETE', - CATEGORY_DETAIL: 'CATEGORY_DETAIL', - - BOOK_SEARCH_KEYWORD: 'BOOK_SEARCH_KEYWORD', - BOOK_SEARCH: 'BOOK_SEARCH', - BOOK_DETAIL: 'BOOK_DETAIL', - BOOK_MY_RELEASE: 'BOOK_MY_RELEASE', - BOOK_MY_UPDATE: 'BOOK_MY_UPDATE', - BOOK_MY_DELETE: 'BOOK_MY_DELETE', - BOOK_MY_LIST: 'BOOK_MY_LIST', - - BORROW_ADD: 'BORROW_ADD', - BORROW_DETAIL: 'BORROW_DETAIL', - BORROW_MY_LIST: 'BORROW_MY_LIST', - BORROW_REQUEST: 'BORROW_REQUEST', - BORROW_DELETE: 'BORROW_DELETE', - BORROW_CONFIRM: 'BORROW_CONFIRM', - BORROW_REQUEST_MSG: 'BORROW_REQUEST_MSG', - BORROW_REPLY_MSG: 'BORROW_REPLY_MSG', - BORROW_REFUSE: 'BORROW_REFUSE', - BORROW_RETURN: 'BORROW_RETURN', -}; - -export class Utility { - static NotifyUpdate = new Subject(); - static NotifyLogout = new Subject(); - - /** - * get token from localstorage - * - * @static - * @memberof Utility - */ - static get Token() { - return window.localStorage.getItem('token'); - } - - /** - * save token to localstorage - * - * @static - * @memberof Utility - */ - static set Token(val) { - if (!val) { - window.localStorage.removeItem('token'); - } else { - window.localStorage.setItem('token', val); - } - } - - /** - * sve user info to localstorage - * - * @static - * @memberof Utility - */ - static set UserInfo(val) { - const key = 'userinfo'; - if (!val) { - window.localStorage.removeItem(key); - } else { - window.localStorage.setItem(key, JSON.stringify(val)); - } - } - /** - * get user info from localstorage - * - * @static - * @memberof Utility - */ - static get UserInfo() { - const info = window.localStorage.getItem('userinfo'); - if (info) { - try { - return JSON.parse(info); - } catch (ex) { - return null; - } - } - return null; - } - - static Toast() {} - - static LoadingHide() {} - - static IsArray(obj) { - if (!obj || !Array.isArray(obj) || obj.length === 0) { - return false; - } - return Array.isArray(obj); - } -} - -export class Httphelper { - static async __request({method = 'get', url, headers, params, data, dispatch}) { - try { - if (!url) { - Utility.Toast('url not found'); - return Promise.reject('url not found'); - } - const _url = `${ApiService}${url}`; - const token = Utility.Token; - const _headers = Object.assign({}, headers); - if (token) { - _headers.token = token; - } - const opt = {method, url: _url, headers: _headers, params, data}; - const response = await axios(opt); - const {data: body} = response; - return body.data || body; - } catch (ex) { - const {response} = ex; - const {data: errData, status, statusText} = response || {}; - const {msg} = errData || {}; - if (status === 401) { - Utility.Token = null; - Utility.UserInfo = null; - alert(msg || statusText); - - if (dispatch) { - dispatch({type: TypeMap.USER_401, payload: ''}); - } - Utility.NotifyLogout.next({isLogin: true}); - console.log(statusText); - return Promise.reject(msg); - } - if (msg) { - alert(msg); - } - console.log('status:', msg); - return Promise.reject(msg); - } - } - - /** - * post request - * - * @param {*} { url, headers, params, data } - * @returns - * @memberof Httphelper - */ - static async onPost(url, {headers, params, data}, dispatch) { - return this.__request({method: 'post', url, headers, params, data, dispatch}); - } - - /** - * put request - * - * @param {*} { url, headers, params, data } - * @returns - * @memberof Httphelper - */ - static async onPut(url, {headers, params, data}, dispatch) { - return this.__request({method: 'put', url, headers, params, data, dispatch}); - } - - /** - * delete request - * - * @param {*} { url, headers, params, data } - * @returns - * @memberof Httphelper - */ - static async onDelete(url, {headers, params, data}, dispatch) { - return this.__request({method: 'delete', url, headers, params, data, dispatch}); - } - - /** - * get request - * - * @param {*} { url, headers, params } - * @returns - * @memberof Httphelper - */ - static async onGet(url, {headers, params}, dispatch) { - return this.__request({method: 'get', url, headers, params, dispatch}); - } -} - -// update user info -export const userUpdate = (userInfo) => { - return {type: TypeMap.USER_UPDATE, payload: userInfo}; -}; -/** - * user login - * @param {*} info - */ -export const userLogin = (info) => { - return async (dispatch) => { - const item = await Httphelper.onPost('/api/user/signin', {data: info}, dispatch); - Utility.Token = item.token; - Utility.UserInfo = item; - dispatch({type: TypeMap.USER_LOGIN, payload: item}); - }; -}; - -/** - * user signup - * @param {*} info - */ -export const userSignUp = (data) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onPost('/api/user/signup', {data}, dispatch); - dispatch({type: TypeMap.USER_SIGNUP, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -// get category list -export const categoryList = (params) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onGet('/api/category', {params}, dispatch); - dispatch({type: TypeMap.CATEGORY_LIST, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; -// get category list -export const categoryListAll = (params) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onGet('/api/category/all', {params}, dispatch); - dispatch({type: TypeMap.CATEGORY_LIST_ALL, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -// edit category by id -export const categoryEdit = (id, data) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onPut('/api/category/' + id, {data}, dispatch); - dispatch({type: TypeMap.CATEGORY_DELETE, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -// search book by keyword -export const bookSearch = (keyword, page = 1, size = 20) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - dispatch({type: TypeMap.BOOK_SEARCH_KEYWORD, payload: {keyword, page, size}}); - const item = await Httphelper.onGet('/api/book/search', {params: {page, size, keyword}}, dispatch); - - dispatch({type: TypeMap.BOOK_SEARCH, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -// search book by keyword -export const bookListByMy = () => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onGet('/api/book/my', {params: {}}, dispatch); - dispatch({type: TypeMap.BOOK_MY_LIST, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -// get book detail info by id -export const bookDetail = (id) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onGet('/api/book/' + id, {params: {}}, dispatch); - dispatch({type: TypeMap.BOOK_DETAIL, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -// delete book by id -export const bookDelete = (id, index) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onDelete('/api/book/' + id, {params: {}}, dispatch); - dispatch({type: TypeMap.BOOK_MY_DELETE, payload: {id, index}}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -// add book -export const bookAdd = (data) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - let formData = new FormData(); - for (let key in data) { - formData.append(key, data[key]); - } - const item = await Httphelper.onPost('/api/book/', {data: formData}); - dispatch({type: TypeMap.BOOK_MY_RELEASE, payload: item}, dispatch); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -// edit book -export const bookEdit = (id, data) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - let formData = new FormData(); - for (let key in data) { - formData.append(key, data[key]); - } - const item = await Httphelper.onPut('/api/book/' + id, {data: formData}); - dispatch({type: TypeMap.BOOK_MY_UPDATE, payload: item}, dispatch); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -// book search keyword -export const bookSearchKeyword = (keyword, page = 1, size = 20) => { - return {type: TypeMap.BOOK_SEARCH_KEYWORD, payload: {keyword, page, size}}; -}; - -export const borrowAdd = (data) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onPost('/api/borrow/', {data}, dispatch); - dispatch({type: TypeMap.BORROW_ADD, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -export const borrowDelete = (id, index) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onDelete('/api/borrow/' + id, {}, dispatch); - dispatch({type: TypeMap.BORROW_DELETE, payload: {id, index}}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; -export const borrowDetail = (id) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const detail = await Httphelper.onGet('/api/borrow/' + id, {}, dispatch); - dispatch({type: TypeMap.BORROW_DETAIL, payload: detail}); - return detail; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -export const borrowMyList = () => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onGet('/api/borrow/my', {params: {}}, dispatch); - dispatch({type: TypeMap.BORROW_MY_LIST, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -export const borrowRequest = () => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onGet('/api/borrow/request', {}, dispatch); - dispatch({type: TypeMap.BORROW_REQUEST, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -export const borrowRequestMsg = (id, content) => { - return async (dispatch) => { - //BORROW_REPLY_TO - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onPut('/api/borrow/request/msg/' + id, {data: {content}}, dispatch); - dispatch({type: TypeMap.BORROW_REQUEST_MSG, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; - -export const borrowReplyMsg = (id, content) => { - return async (dispatch) => { - //BORROW_REPLY_TO - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onPut('/api/borrow/reply/msg/' + id, {data: {content}}, dispatch); - dispatch({type: TypeMap.BORROW_REPLY_MSG, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; -// refuse borrow book -export const borrowRefuse = (id, content) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onPut('/api/borrow/refuse/' + id, {data: {content}}, dispatch); - dispatch({type: TypeMap.BORROW_REFUSE, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; -// confirm borrow book -export const borrowConfirm = (id, content) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onPut('/api/borrow/confirm/' + id, {data: {content}}, dispatch); - dispatch({type: TypeMap.BORROW_CONFIRM, payload: item}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; -// return borrow book -export const borrowReturn = (id, index) => { - return async (dispatch) => { - dispatch({type: TypeMap.LOADING}); - try { - const item = await Httphelper.onPut('/api/borrow/return/' + id, {data: {}}, dispatch); - dispatch({type: TypeMap.BORROW_RETURN, payload: {id, index}}); - return item; - } finally { - dispatch({type: TypeMap.LOADING_HIDE}); - } - }; -}; diff --git a/client/src/components/component.book.item.js b/client/src/components/component.book.item.js deleted file mode 100644 index e94d670..0000000 --- a/client/src/components/component.book.item.js +++ /dev/null @@ -1,47 +0,0 @@ -import React, { useState } from 'react'; -import styles from './component.module.scss'; -import { ApiService } from '../actions'; -import Confirm from './component.confirm'; - -export default ({ book, borrowAdd, history }) => { - const { image, book_name, price } = book || {}; - const [showConfirm, setShowConfirm] = useState(false); - - const toDetail = () => { - history.push('/book/detail/' + book.id); - }; - - return ( -
-
toDetail()}>
-
toDetail()}> - {book_name} -
-
-
toDetail()}> - Price ${price} -
-
- -
-
- {showConfirm && ( - setShowConfirm(false)} - onConfirm={async (message) => { - if (!message) { - alert('Please fill in the reason for borrowing the book'); - return; - } - const data = { ...book, message }; - if (borrowAdd) { - await borrowAdd(data); - alert('add success'); - } - setShowConfirm(false); - }} - /> - )} -
- ); -}; diff --git a/client/src/components/component.confirm.js b/client/src/components/component.confirm.js deleted file mode 100644 index c5eac6e..0000000 --- a/client/src/components/component.confirm.js +++ /dev/null @@ -1,21 +0,0 @@ -import React, {useState} from 'react'; -import styles from './component.module.scss'; - -export default ({onConfirm, onCancel}) => { - const [content, setContent] = useState(''); - - return ( -
-
-
Message
-
- -
-
-
onCancel && onCancel()}>Cancel
-
onConfirm && onConfirm(content)}>Confirm
-
-
-
- ); -}; diff --git a/client/src/components/component.header.js b/client/src/components/component.header.js deleted file mode 100644 index f776a16..0000000 --- a/client/src/components/component.header.js +++ /dev/null @@ -1,143 +0,0 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import { Link } from 'react-router-dom'; -import { userUpdate, Utility, categoryList, bookSearchKeyword } from '../actions'; -import styles from './component.module.scss'; - -class Header extends React.Component { - constructor(props) { - super(props); - - this.state = {}; - } - - componentDidMount() { - this.judgeLogin(); - this.getCategoryList(); - - Utility.NotifyUpdate.subscribe((item) => { - this.update(); - }); - - Utility.NotifyLogout.subscribe((args) => { - this.logout() - const { isLogin } = args || {}; - if (isLogin) { - this.props.history.push('/login'); - } - }) - } - - judgeLogin() { - const { user } = this.props; - const { info } = user || {}; - const { id } = info || {}; - if (id) { - console.log('user info exists'); - return; - } - const { id: user_id } = Utility.UserInfo || {}; - if (!user_id) { - return; - } - console.log(Utility.UserInfo); - this.props.userUpdate(Utility.UserInfo); - console.log('user info exists'); - this.update(); - } - - update() { - this.setState({ ts: new Date() }); - } - - // get category list - async getCategoryList() { - await this.props.categoryList(); - this.update(); - } - - searchCategory(keyword) { - if (keyword) { - this.props.history.push('/?keyword=' + keyword); - } else { - this.props.history.push('/'); - } - this.props.bookSearchKeyword(keyword, 1, 20); - } - - logout() { - this.props.userUpdate(null); - Utility.UserInfo = null; - Utility.Token = null; - this.update(); - this.props.history.push('/'); - } - - buildCategoryHtml() { - const { category } = this.props; - if (!Utility.IsArray(category.list)) { - return ''; - } - - const result = category.list.map((item) => { - return ( -
this.searchCategory(item.name)}> - {item.name} -
- ); - }); - return result; - } - - buildMyHtml() { - const { username, email } = this.props.user.info; - return ( -
-
this.props.history.push('/my/home')}> - Welcome {username || email} -
-
- Logout -
-
- ); - } - - render() { - const { id } = this.props.user.info || {}; - - return ( -
-
- {`welcome to borrow platform`.toUpperCase()} -
-
-
-
this.searchCategory('')}> - All -
- {this.buildCategoryHtml()} -
- {!id ? ( -
-
- Login -
-
- Sign Up -
-
- ) : ( - this.buildMyHtml() - )} -
-
- ); - } -} - -const mapStateToProps = (state) => { - return { state: state, ...state }; -}; - -export default connect(mapStateToProps, { userUpdate, categoryList, bookSearchKeyword })(Header); diff --git a/client/src/components/component.message.js b/client/src/components/component.message.js deleted file mode 100644 index b13716f..0000000 --- a/client/src/components/component.message.js +++ /dev/null @@ -1,90 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import { connect } from 'react-redux'; -import * as allAction from '../actions'; -import styles from './component.module.scss'; - -const Message = (props) => { - const { item } = props; - - const [message, setMessage] = useState([]); - const [content, setContent] = useState(''); - - const func = async (id) => { - const detail = await props.borrowDetail(id); - setMessage(detail.message); - setContent(''); - }; - - useEffect(() => { - const id = item.id; - func(id); - }, [props.item.id]); - - const processDetail = async (type) => { - const { id } = item; - switch (type) { - case 'reply': - if (props.isRequest) { - await props.borrowReplyMsg(id, content); - } else { - await props.borrowRequestMsg(id, content); - } - break; - case 'refuse': - const isRefuse = window.confirm('do you really want to refuse?'); - if (!isRefuse) { - return; - } - await props.borrowRefuse(id, content); - break; - case 'confirm': - await props.borrowConfirm(id, content) - break; - - } - func(id); - }; - - return ( -
-
- {allAction.Utility.IsArray(message) && - message.map((row, index) => { - const isMine = (props.isRequest && row.reply_msg) || (!props.isRequest && row.request_msg); - const isReply = (props.isRequest && row.request_msg) || (!props.isRequest && row.reply_msg); - return ( -
-
-
{isReply ? 'Reply' : ''}
-
{item.create_time}
-
{isMine ? 'Mine' : ''}
-
-
-
{row.msg || row.request_msg || row.reply_msg}
-
-
- ); - })} -
- {item.state === 1 && ( -
-
- -
-
- - - {props.isRequest && ( - <> - - - - )} -
-
- )} -
- ); -}; - -export default connect((state) => ({ ...state }), { ...allAction })(Message); diff --git a/client/src/components/component.module.scss b/client/src/components/component.module.scss deleted file mode 100644 index f1e32e2..0000000 --- a/client/src/components/component.module.scss +++ /dev/null @@ -1,231 +0,0 @@ -.header { - position: relative; -} - -.row { - display: flex; - padding: 3px 10px; -} - -.logo { - padding: 20px; - font-size: 36px; - text-align: center; - font-weight: bolder; - color: #4e4e4e; - text-shadow: 5px 5px 5px #f0f0f0; - border: 1px solid #f0f0f0; -} - -.nav { - padding-left: 0px; - padding-right: 0px; - - > div { - padding-left: 0px; - padding-right: 0px; - } -} - -.alignCenter { - align-items: center; -} - -.col, -.col0, -.col1, -.col2, -.col3, -.col4, -.col5 { - padding: 3px; -} - -.col0 { - flex: unset; -} - -.col, -.col1 { - flex: 1; -} - -.col2 { - flex: 2; -} - -.col3 { - flex: 3; -} - -.col4 { - flex: 4; -} - -.col5 { - flex: 5; -} - -div { - cursor: default; -} - -.categoryName { - border: 1px solid #f0f0f0; - margin: 0px 5px 5px 0px; - padding: 3px 10px; - border-radius: 5px; -} - -.username { - margin-bottom: 10px; - margin-right: 10px; - cursor: pointer; - border: 1px solid pink; - padding-right: 10px; - padding-left: 10px; - > span { - font-weight: bold; - text-shadow: 5px 5px 5px pink; - } -} - -.myNav { - .aLink { - margin: 0px 10px; - } -} - -.bookItemCss { - min-width: calc(20% - 12px); - max-width: calc(20% - 12px); - margin: 5px; - border: 1px solid #f0f0f0; - - .bookImage { - width: 100%; - height: 190px; - background-position: center; - background-repeat: no-repeat; - background-size: cover; - padding-bottom: 10px; - } - - .priceAndBorrow { - display: flex; - } - - .borrowFrom { - text-decoration: line-through; - } -} - -.gCenter { - display: -webkit-box; - -webkit-box-pack: center; - -webkit-box-align: center; -} - -.dialogCss { - background: rgba($color: #000000, $alpha: 0.2); - position: fixed; - top: 0px; - left: 0px; - width: 100vw; - height: 100vh; - - .dialogContent { - position: relative; - background: #fff; - border: 1px solid #f0f0f0; - border-radius: 5px; - min-width: 300px; - max-width: 400px; - - .title { - text-align: center; - padding: 10px; - } - - .content { - display: flex; - position: relative; - - textarea { - flex: 1; - height: 100px; - resize: none; - border: 1px solid #f0f0f0; - padding: 5px; - line-height: 1.78; - - &:focus { - outline-offset: unset; - outline: unset; - } - } - } - - .dBtns { - display: flex; - - > div { - flex: 1; - text-align: center; - padding: 10px; - } - - .bCancel { - flex: 1; - } - - .bConfirm { - flex: 1; - } - } - } -} - -.message { - position: relative; - - .label { - position: relative; - } - - textarea { - height: 50px; - border-radius: 5px; - resize: none; - } - - .reply { - margin-top: 30; - } - - .msgContent { - max-height: 300px; - overflow: auto; - } - - button { - width: 70px; - margin-right: 10px; - padding: 5px 10px; - } - - .mine { - text-align: right; - } -} - -.pageNavigation { - position: relative; - - button { - margin-right: 5px; - padding: 5px 10px; - font-size: 16px; - width: 60px; - } -} diff --git a/client/src/components/component.mynav.js b/client/src/components/component.mynav.js deleted file mode 100644 index f428105..0000000 --- a/client/src/components/component.mynav.js +++ /dev/null @@ -1,66 +0,0 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import { Link } from 'react-router-dom'; -import { userUpdate, categoryList, Utility } from '../actions'; -import styles from './component.module.scss'; - -class MyNav extends React.Component { - constructor(props) { - super(props); - - this.state = {}; - } - componentDidUpdate(props, state) { - this.judgeIsLogin(); - } - - componentDidMount() { - this.judgeIsLogin(); - - Utility.NotifyLogout.subscribe(() => { - this.judgeIsLogin(); - }) - } - - judgeIsLogin() { - const { id } = this.props.user.info || {}; - if (!!id) { - return; - } - this.props.history.push('/login'); - } - - update() { - this.setState({ ts: new Date() }); - } - - render() { - const { role } = this.props.user.info || {}; - // console.log('role:', role) - return ( -
-
- - My Book List - - - Release - - - Request List - - - Borrow List - - {role === 2 && ( - - Category - - )} -
-
- ); - } -} - -export default connect((state) => ({ ...state }), { userUpdate, categoryList })(MyNav); diff --git a/client/src/components/component.page.navigation.js b/client/src/components/component.page.navigation.js deleted file mode 100644 index 6d2e5f6..0000000 --- a/client/src/components/component.page.navigation.js +++ /dev/null @@ -1,45 +0,0 @@ -import React, {useContext, useEffect, useState} from 'react'; -import {connect} from 'react-redux'; -import * as allAction from '../actions'; -import styles from './component.module.scss'; - -const PageNavigation = (props) => { - // const [ts, setTs] = useState(0); - // useEffect(() => { - // setTs(props.ts); - // }, [props.ts]); - - const {page, size, total, totalPage} = props.book.search || {}; - - const toPage = (val) => { - props.bookSearchKeyword(props.book.keyword, val, size); - props.history.push(`/?keyword=${props.book.keyword}&page=${val}&size=${size}`); - }; - return ( -
-
- - - - - -
-
- ); -}; - -export default connect((state) => ({...state}), {...allAction})(PageNavigation); diff --git a/client/src/index.css b/client/src/index.css deleted file mode 100644 index 76f5c5f..0000000 --- a/client/src/index.css +++ /dev/null @@ -1,37 +0,0 @@ -body { - margin: 0; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", - "Droid Sans", "Helvetica Neue", sans-serif; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - - font-size: 14px; -} - -a { - text-decoration: none; - white-space: nowrap; -} - -table { - margin-bottom: 20px; - width: 100%; - font-size: 12px; - border-top: 1px solid #f0f0f0; - border-left: 1px solid #f0f0f0; - font-weight: lighter; -} - -table thead th { - border-right: 1px solid #f0f0f0; - border-bottom: 1px solid #f0f0f0; - font-weight: lighter; - height: 36px; - font-size: 16px; -} - -table tbody tr td { - border-bottom: 1px solid #f0f0f0; - border-right: 1px solid #f0f0f0; - text-align: center; -} diff --git a/client/src/index.js b/client/src/index.js deleted file mode 100644 index e051708..0000000 --- a/client/src/index.js +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import './index.css'; -import App from './App'; -import {Provider} from 'react-redux'; -import {createStore, applyMiddleware, compose} from 'redux'; -import reduxThunk from 'redux-thunk'; -import reportWebVitals from './reportWebVitals'; -import reducers from './reducers'; - -const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; - -ReactDOM.render( - - - - - , - document.getElementById('root'), -); - -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); diff --git a/client/src/logo.svg b/client/src/logo.svg deleted file mode 100644 index 9dfc1c0..0000000 --- a/client/src/logo.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/client/src/pages/page.book.detail.js b/client/src/pages/page.book.detail.js deleted file mode 100644 index 74d966c..0000000 --- a/client/src/pages/page.book.detail.js +++ /dev/null @@ -1,99 +0,0 @@ -import React from 'react'; -import {connect} from 'react-redux'; -import styles from './pages.module.scss'; -import {ApiService, borrowAdd, bookDetail} from '../actions'; -import Confirm from '../components/component.confirm'; - -class PageBookDetail extends React.Component { - constructor(props) { - super(props); - this.state = {showConfirmDialog: false}; - } - - componentDidMount() { - this.getDetail(); - } - - update() { - this.setState({ts: new Date()}); - } - - async getDetail() { - const id = this.props.match.params.id; - await this.props.bookDetail(id); - this.update(); - } - - setShowConfirm(val) { - this.state.showConfirmDialog = val; - this.update(); - } - - render() { - const {image, book_name, price, ISBN, author, category, describe, is_borrow = false} = this.props.book.detail || {}; - - return ( -
-
-
-
-
-
-
Category:
-
{category}
-
-
-
Name:
-
{book_name}
-
-
-
Price:
-
${price}
-
-
-
ISBN:
-
{ISBN}
-
-
-
Author:
-
{author}
-
-
-
Describe:
-
{describe}
-
- -
-
-
- -
-
-
-
-
this.props.history.goBack()}>back
- - {this.state.showConfirmDialog && ( - this.setShowConfirm(false)} - onConfirm={async (message) => { - if (!message) { - alert('Please fill in the reason for borrowing the book'); - return; - } - const data = {...this.props.book.detail, message}; - await this.props.borrowAdd(data); - this.setShowConfirm(false); - alert('add success'); - }} - /> - )} -
-
- ); - } -} - -export default connect((state) => ({...state}), {bookDetail, borrowAdd})(PageBookDetail); diff --git a/client/src/pages/page.borrow.list.js b/client/src/pages/page.borrow.list.js deleted file mode 100644 index 87581d2..0000000 --- a/client/src/pages/page.borrow.list.js +++ /dev/null @@ -1,103 +0,0 @@ -import React from 'react'; -import {connect} from 'react-redux'; -import * as allAction from '../actions'; -import MyNav from '../components/component.mynav'; -import Message from '../components/component.message'; -import styles from './pages.module.scss'; -import {config} from 'rxjs'; - -class BorrowList extends React.Component { - constructor(props) { - super(props); - this.state = {currentItem: null}; - } - - componentDidMount() { - this.init(); - } - - update() { - this.setState({ts: new Date()}); - } - - async init() { - await this.props.borrowMyList(); - this.update(); - } - - buildRowHtml() { - const {mylist} = this.props.borrow; - if (!allAction.Utility.IsArray(mylist)) { - return ( - - - - ); - } - return mylist.map((item, index) => { - const stateMap = {1: 'Normal', 2: 'Confirm', 3: 'Refuse', 4: 'Return'}; - return ( - - {item.book_username} - {item.book_name} - ${item.book_price} - {item.book_address} - {stateMap[item.state] || stateMap['1']} - - - - - - ); - }); - } - - render() { - return ( -
- -
-
- - - - - - - - - - - - {this.buildRowHtml()} -
Username BookName Price Address State
-
- -
{this.state.currentItem && }
-
-
- ); - } -} - -export default connect((state) => ({...state}), {...allAction})(BorrowList); diff --git a/client/src/pages/page.category.js b/client/src/pages/page.category.js deleted file mode 100644 index 44992a4..0000000 --- a/client/src/pages/page.category.js +++ /dev/null @@ -1,142 +0,0 @@ -import React from 'react'; -import {connect} from 'react-redux'; -import MyNav from '../components/component.mynav'; -import styles from './pages.module.scss'; -import * as allAction from '../actions'; - -class Category extends React.Component { - constructor(props) { - super(props); - this.state = {}; - } - - componentDidMount() { - this.getCategoryAll(); - } - - update() { - this.setState({ts: new Date()}); - } - - async getCategoryAll() { - await this.props.categoryListAll(); - this.update(); - } - - async getCategory() { - await this.props.categoryList(); - allAction.Utility.NotifyUpdate.next(true); - } - - async handleEdit(item) { - const data = {...item}; - data.name = item.newValue; - await this.props.categoryEdit(item.id, data); - this.getCategoryAll() - this.getCategory(); - } - - buildRowHtml() { - const {all} = this.props.category; - if (!allAction.Utility.IsArray(all)) { - return ( - - - - ); - } - return all.map((item, index) => { - return ( - - {index + 1} - - {item.isEdit ? ( - { - item.newValue = e.target.value; - this.update(); - }} - /> - ) : ( - item.name - )} - - - { - item.state = !item.state; - await this.props.categoryEdit(item.id, item); - this.getCategory(); - this.update(); - }} - /> - - - - - - ); - }); - } - - render() { - return ( -
- -
- - - - - - - - - - {this.buildRowHtml()} -
ID Name State
-
-
- ); - } -} - -export default connect((state) => ({...state}), {...allAction})(Category); - -// return all.map((item, index) => { -// return ( -// -// {index + 1} -// - -// -// -// { -// item.state = !item.state; -// await this.props.categoryEdit(item.id, item); -// this.update(); -// }} -// /> -// -// - -// -// -// ); -// }); diff --git a/client/src/pages/page.default.js b/client/src/pages/page.default.js deleted file mode 100644 index d3f87b7..0000000 --- a/client/src/pages/page.default.js +++ /dev/null @@ -1,77 +0,0 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import styles from './pages.module.scss'; -import { bookSearch, bookSearchKeyword, borrowAdd, Utility } from '../actions'; -import PageNavigation from '../components/component.page.navigation'; -import BookItem from '../components/component.book.item'; - -class Default extends React.Component { - constructor(props) { - super(props); - this.state = { keyword: '', isLoading: false, size: 20 }; - } - - componentDidUpdate(props, state) { - this.handleSearch(); - } - - componentDidMount() { - this.handleSearch(); - } - - update() { - this.setState({ ts: new Date() }); - } - - handleKeyword(source) { - this.state.keyword = source.target.value.trim(); - } - - async handleSearch() { - if (!!this.state.isLoading) { - return; - } - - this.state.isLoading = true; - const { keyword, page = 1, size = 20 } = this.props.book; - this.state.keyword = keyword; - await this.props.bookSearch(keyword, page, size); - this.update(); - this.state.isLoading = false; - } - - buildSearchHtml() { - const { list } = this.props.book.search || {}; - if (!Utility.IsArray(list)) { - return; - } - return list.map((item) => { - return ; - }); - } - - render() { - return ( -
-
- - -
-
{this.buildSearchHtml()}
-
- {this.props.book.search && Utility.IsArray(this.props.book.search.list) && } -
-
- ); - } -} - -export default connect((state) => ({ ...state }), { bookSearch, bookSearchKeyword, borrowAdd })(Default); diff --git a/client/src/pages/page.login.js b/client/src/pages/page.login.js deleted file mode 100644 index 4634e11..0000000 --- a/client/src/pages/page.login.js +++ /dev/null @@ -1,50 +0,0 @@ -import React from 'react'; -import {connect} from 'react-redux'; -import styles from './pages.module.scss'; -import {userLogin, Utility} from '../actions/index'; - -class Login extends React.Component { - constructor(props) { - super(props); - this.state = {info: {}}; - } - - handleChange(field, source) { - this.state.info[field] = source.target.value; - } - - async handleLogin() { - const user = await this.props.userLogin(this.state.info); - Utility.NotifyUpdate.next(user); - this.props.history.push('/my/home'); - } - - render() { - return ( -
-
-
-
Email:
-
- -
-
-
-
Password:
-
- -
-
-
-
-
- -
-
-
-
- ); - } -} - -export default connect((state) => ({...state}), {userLogin})(Login); diff --git a/client/src/pages/page.my.js b/client/src/pages/page.my.js deleted file mode 100644 index 3b45417..0000000 --- a/client/src/pages/page.my.js +++ /dev/null @@ -1,99 +0,0 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import MyNav from '../components/component.mynav'; -import styles from './pages.module.scss'; -import { ApiService, bookListByMy, bookDelete, Utility, bookEdit } from '../actions'; - -class MyHome extends React.Component { - constructor(props) { - super(props); - this.state = {}; - } - - componentDidMount() { - this.initMyList(); - } - - update() { - this.setState({ ts: new Date() }); - } - - async initMyList() { - await this.props.bookListByMy(); - this.update(); - } - - async handleUpdateState(item, source) { - item.state = source.target.checked; - await this.props.bookEdit(item.id, item); - this.update(); - alert('update success'); - } - - buildList() { - const { mylist } = this.props.book; - if (!Utility.IsArray(mylist)) { - return ( - - - - ); - } - return mylist.map((item, index) => { - return ( - - -
- - {item.book_name} - {item.price} - {item.ISBN} - - - - - - - - - - ); - }); - } - - render() { - return ( -
- -
- - - - - - - - - - - - {this.buildList()} -
ImageBook NamePriceISBNstate
-
-
- ); - } -} - -export default connect((state) => ({ ...state }), { bookEdit, bookListByMy, bookDelete })(MyHome); diff --git a/client/src/pages/page.release.js b/client/src/pages/page.release.js deleted file mode 100644 index c450ff2..0000000 --- a/client/src/pages/page.release.js +++ /dev/null @@ -1,151 +0,0 @@ -import React from 'react'; -import {connect} from 'react-redux'; -import {Utility, bookAdd, bookEdit, bookDetail, ApiService} from '../actions'; -import MyNav from '../components/component.mynav'; -import styles from './pages.module.scss'; - -class Release extends React.Component { - constructor(props) { - super(props); - this.state = {isLoading: false, info: {}}; - } - - update() { - this.setState({ts: new Date()}); - } - componentDidMount() { - this.getDetail(); - } - - async getDetail() { - const {search} = this.props.location; - if (!search) { - return; - } - const queryArray = search.substring(1).split('='); - if (!Utility.IsArray(queryArray)) { - return; - } - - if (!!this.state.isLoading) { - return; - } - this.state.isLoading = true; - const id = queryArray[1]; - const detail = await this.props.bookDetail(id); - this.state.info = detail; - this.update(); - this.state.isLoading = false; - } - - handleChange(field, source) { - if (field === 'state') { - this.state.info[field] = source.target.checked; - } else if (field === 'file') { - this.state.info[field] = source.target.files[0]; - if (this.state.info[field]) { - this.state.image = URL.createObjectURL(source.target.files[0]); - } - this.update(); - } else { - this.state.info[field] = source.target.value; - } - this.update(); - console.log(this.state.info); - } - - async handleSubmit() { - if (this.state.info.id) { - await this.props.bookEdit(this.state.info.id, this.state.info); - alert('update success'); - return; - } - - await this.props.bookAdd(this.state.info); - this.state.info = {}; - this.update(); - alert('add success'); - } - - buildSelect() { - const {list} = this.props.category; - - if (!Utility.IsArray(list)) { - return; - } - return list.map((item) => { - return ( - - ); - }); - } - - render() { - const image = this.state.image || `${ApiService}${this.state.info.image}`; - return ( -
- -
-
-
-
-
-
-
Image
- -
-
-
Category
- -
-
-
Name
- -
-
-
Price
- -
-
-
Author
- -
-
-
ISBN
- -
-
-
State
- -
-
-
Describe
-