Skip to content

Commit c940328

Browse files
committed
ref: #187 update 14 form validation
1 parent 57d15cf commit c940328

3 files changed

Lines changed: 51 additions & 48 deletions

File tree

hooks/14_FormValidation/package.json

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,35 @@
1515
"author": "Braulio Diez Botella",
1616
"license": "MIT",
1717
"devDependencies": {
18-
"@babel/cli": "^7.2.3",
19-
"@babel/core": "^7.2.2",
20-
"@babel/polyfill": "^7.2.5",
21-
"@babel/preset-env": "^7.3.1",
22-
"@types/react": "^16.8.3",
23-
"@types/react-dom": "^16.8.1",
24-
"@types/react-router-dom": "^4.3.1",
18+
"@babel/cli": "^7.10.5",
19+
"@babel/core": "^7.10.5",
20+
"@babel/polyfill": "^7.10.4",
21+
"@babel/preset-env": "^7.10.4",
22+
"@babel/preset-react": "^7.10.4",
23+
"@babel/preset-typescript": "^7.10.4",
24+
"@types/node": "^14.0.24",
25+
"@types/react": "^16.9.43",
26+
"@types/react-dom": "^16.9.8",
27+
"@types/react-router-dom": "^5.1.5",
2528
"awesome-typescript-loader": "^5.2.1",
26-
"babel-loader": "^8.0.5",
27-
"css-loader": "^2.1.0",
28-
"file-loader": "^3.0.1",
29-
"html-webpack-plugin": "^3.2.0",
30-
"mini-css-extract-plugin": "^0.5.0",
31-
"style-loader": "^0.23.1",
32-
"typescript": "^3.3.3",
33-
"url-loader": "^1.1.2",
34-
"webpack": "^4.29.3",
35-
"webpack-cli": "^3.2.3",
36-
"webpack-dev-server": "^3.1.14"
29+
"babel-loader": "^8.1.0",
30+
"css-loader": "^3.6.0",
31+
"file-loader": "^6.0.0",
32+
"html-webpack-plugin": "^4.3.0",
33+
"mini-css-extract-plugin": "^0.9.0",
34+
"style-loader": "^1.2.1",
35+
"typescript": "^3.9.7",
36+
"url-loader": "^4.1.0",
37+
"webpack": "^4.43.0",
38+
"webpack-cli": "^3.3.12",
39+
"webpack-dev-server": "^3.11.0"
3740
},
3841
"dependencies": {
39-
"@material-ui/core": "^4.0.1",
40-
"@material-ui/icons": "^4.0.1",
42+
"@material-ui/core": "^4.11.0",
43+
"@material-ui/icons": "^4.9.1",
4144
"lc-form-validation": "^2.0.0",
42-
"react": "^16.8.2",
43-
"react-dom": "^16.8.2",
44-
"react-router-dom": "^4.3.1"
45+
"react": "^16.13.1",
46+
"react-dom": "^16.13.1",
47+
"react-router-dom": "^5.2.0"
4548
}
4649
}

hooks/14_FormValidation/src/pages/loginPage.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react";
22
import { Link } from "react-router-dom";
3-
import { withRouter, RouteComponentProps } from "react-router-dom";
3+
import { useHistory } from "react-router-dom";
44
import makeStyles from "@material-ui/styles/makeStyles";
55
import createStyles from "@material-ui/styles/createStyles";
66
import Card from "@material-ui/core/Card";
@@ -29,9 +29,9 @@ const useStyles = makeStyles(theme =>
2929
})
3030
);
3131

32-
interface Props extends RouteComponentProps {}
32+
interface Props {}
3333

34-
const LoginPageInner = (props: Props) => {
34+
export const LoginPage = (props: Props) => {
3535
const [loginInfo, setLoginInfo] = React.useState<LoginEntity>(
3636
createEmptyLogin()
3737
);
@@ -40,12 +40,13 @@ const LoginPageInner = (props: Props) => {
4040
);
4141
const [showLoginFailedMsg, setShowLoginFailedMsg] = React.useState(false);
4242
const classes = useStyles();
43+
const history = useHistory();
4344

4445
const onLogin = () => {
4546
loginFormValidation.validateForm(loginInfo).then(formValidationResult => {
4647
if (formValidationResult.succeeded) {
4748
if (isValidLogin(loginInfo)) {
48-
props.history.push("/pageB");
49+
history.push("/pageB");
4950
} else {
5051
setShowLoginFailedMsg(true);
5152
}
@@ -98,8 +99,6 @@ const LoginPageInner = (props: Props) => {
9899
);
99100
};
100101

101-
export const LoginPage = withRouter<Props>(LoginPageInner);
102-
103102
interface PropsForm {
104103
onLogin: () => void;
105104
onUpdateField: (string, any) => void;
Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
var HtmlWebpackPlugin = require("html-webpack-plugin");
2-
var MiniCssExtractPlugin = require("mini-css-extract-plugin");
3-
var webpack = require("webpack");
4-
var path = require("path");
1+
const HtmlWebpackPlugin = require("html-webpack-plugin");
2+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
3+
const webpack = require("webpack");
4+
const path = require("path");
55

6-
var basePath = __dirname;
6+
const basePath = __dirname;
77

88
module.exports = {
99
context: path.join(basePath, "src"),
1010
resolve: {
11-
extensions: [".js", ".ts", ".tsx"]
11+
extensions: [".js", ".ts", ".tsx"],
1212
},
1313
entry: ["@babel/polyfill", "./index.tsx"],
1414
output: {
1515
path: path.join(basePath, "dist"),
16-
filename: "bundle.js"
16+
filename: "bundle.js",
1717
},
1818
devtool: "source-map",
1919
devServer: {
2020
contentBase: "./dist", // Content base
2121
inline: true, // Enable watch and live reload
2222
host: "localhost",
2323
port: 8080,
24-
stats: "errors-only"
24+
stats: "errors-only",
2525
},
2626
module: {
2727
rules: [
@@ -31,32 +31,33 @@ module.exports = {
3131
loader: "awesome-typescript-loader",
3232
options: {
3333
useBabel: true,
34-
babelCore: "@babel/core" // needed for Babel v7
35-
}
34+
babelCore: "@babel/core", // needed for Babel v7
35+
},
3636
},
3737
{
3838
test: /\.css$/,
39-
use: [MiniCssExtractPlugin.loader, "css-loader"]
39+
use: [MiniCssExtractPlugin.loader, "css-loader"],
4040
},
4141
{
4242
test: /\.(png|jpg|gif|svg)$/,
4343
loader: "file-loader",
4444
options: {
45-
name: "assets/img/[name].[ext]?[hash]"
46-
}
47-
}
48-
]
45+
name: "assets/img/[name].[ext]?[hash]",
46+
esModule: false,
47+
},
48+
},
49+
],
4950
},
5051
plugins: [
5152
//Generate index.html in /dist => https://github.com/ampedandwired/html-webpack-plugin
5253
new HtmlWebpackPlugin({
5354
filename: "index.html", //Name of file in ./dist/
5455
template: "index.html", //Name of template in ./src
55-
hash: true
56+
hash: true,
5657
}),
5758
new MiniCssExtractPlugin({
5859
filename: "[name].css",
59-
chunkFilename: "[id].css"
60-
})
61-
]
60+
chunkFilename: "[id].css",
61+
}),
62+
],
6263
};

0 commit comments

Comments
 (0)