Skip to content

Commit eb407bd

Browse files
committed
Added react-hook-form
1 parent a6bac27 commit eb407bd

File tree

37 files changed

+468
-651
lines changed

37 files changed

+468
-651
lines changed

package-lock.json

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@hookform/resolvers": "^0.1.0",
67
"bulma": "^0.9.0",
78
"classnames": "^2.2.6",
89
"date-fns": "^2.15.0",
910
"firebase": "^7.18",
11+
"mutationobserver-shim": "^0.3.7",
1012
"prop-types": "^15.7.2",
1113
"react": "^16.13.1",
1214
"react-datepicker": "^3.0.0",
1315
"react-dom": "^16.13.1",
1416
"react-firebaseui": "^4.1.0",
17+
"react-hook-form": "^6.7.0",
1518
"react-intl": "^5.6.5",
1619
"react-redux": "^7.2.1",
1720
"react-redux-toastr": "^7.6.4",
@@ -22,7 +25,8 @@
2225
"redux": "^4.0.5",
2326
"redux-act": "^1.8.0",
2427
"redux-persist": "^6.0.0",
25-
"redux-thunk": "^2.3.0"
28+
"redux-thunk": "^2.3.0",
29+
"yup": "^0.29.3"
2630
},
2731
"scripts": {
2832
"start": "react-scripts start",

src/components/DatePicker/DatePicker.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import DatePicker from 'react-datepicker';
44
import DatePickerStyled from '.';
55

66
describe('<DatePickerStyled /> rendering', () => {
7-
const setState = jest.fn();
7+
const onChange = jest.fn();
88

99
it('should render without crashing', () => {
1010
const { component } = shallowWithProviders(
1111
<DatePickerStyled
1212
name="test"
1313
dateFormat="en-US"
1414
date={new Date('Thu Nov 12 2020 00:00:00 GMT-0000')}
15-
setState={setState}
15+
onChange={onChange}
1616
/>
1717
)({});
1818

@@ -25,7 +25,7 @@ describe('<DatePickerStyled /> rendering', () => {
2525
name="test"
2626
dateFormat="en-US"
2727
date={new Date('11/12/2020')}
28-
setState={setState}
28+
onChange={onChange}
2929
/>
3030
)({});
3131

@@ -38,7 +38,7 @@ describe('<DatePickerStyled /> rendering', () => {
3838
name="test"
3939
dateFormat="en-US"
4040
date={new Date('11/12/2020')}
41-
setState={setState}
41+
onChange={onChange}
4242
/>
4343
)({});
4444

src/components/DatePicker/__snapshots__/DatePicker.test.js.snap

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@ exports[`<DatePickerStyled /> rendering should render without crashing 1`] = `
4545
"ChangePassword.safePassword": "Safe password",
4646
"ChangePassword.samePassword": "The new password and the current one cannot be the same",
4747
"ChangePassword.submits": "Submit",
48+
"ErrorMessage.defaultMessage": "This field is required",
4849
"Home.content": "Home content",
4950
"Home.home": "Home",
5051
"Login.email": "E-mail Address",
5152
"Login.facebook": "Continue with Facebook",
5253
"Login.forgotPassword": "Forgot Password?",
5354
"Login.google": "Continue with Google",
55+
"Login.invalidEmail": "Invalid email",
5456
"Login.login": "Login",
5557
"Login.microsoft": "Continue with Microsoft",
5658
"Login.password": "Password",
59+
"Login.safePassword": "Safe password",
5760
"Login.setNewPassword": "Set your new password",
5861
"Login.setPassword": "Set Password",
62+
"Login.unsafePassword": "Unsafe password",
5963
"NavBar.Language": "English",
6064
"NavBar.logOut": "Log Out",
6165
"NavBar.profile": "Profile",
@@ -112,13 +116,11 @@ exports[`<DatePickerStyled /> rendering should render without crashing 1`] = `
112116
"auth/too-many-requests": "Too many attempts made, try again later",
113117
"auth/user-disabled": "User disabled",
114118
"auth/wrong-password": "Invalid credentials",
119+
"invalidEmail": "Invalid E-mail",
115120
"storage/quota-exceeded": "Internal server error, get in touch with your administrator",
116121
"storage/unauthenticated": "Unauthenticated, please authenticate and try again",
117122
"storage/unauthorized": "Unauthorized, you are not authorized to perform this action",
118123
"utils.default": "Unknown error, get in touch with your administrator",
119-
"utils.invalidEmail": "Invalid email",
120-
"utils.safePassword": "Safe password",
121-
"utils.unsafePassword": "Unsafe password",
122124
},
123125
"onError": [Function],
124126
"textComponent": Symbol(react.fragment),
@@ -146,7 +148,7 @@ exports[`<DatePickerStyled /> rendering should render without crashing 1`] = `
146148
date={2020-11-12T00:00:00.000Z}
147149
dateFormat="en-US"
148150
name="test"
149-
setState={[MockFunction]}
151+
onChange={[MockFunction]}
150152
/>
151153
</Provider>
152154
</BrowserRouter>

src/components/DatePicker/index.jsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import './DatePicker.scss';
1111
registerLocale('en', en);
1212
registerLocale('es', es);
1313

14-
const dateFormat = locale => {
14+
const dateFormat = (locale) => {
1515
switch (locale) {
1616
case 'en':
1717
return 'MM-dd-yy';
@@ -22,16 +22,13 @@ const dateFormat = locale => {
2222
}
2323
};
2424

25-
const DatePickerStyled = ({ name, date, setState }) => {
26-
const onDateChangedHandler = value =>
27-
setState(prevState => ({
28-
...prevState,
29-
[name]: value.toDateString()
30-
}));
25+
const DatePickerStyled = ({ date, onChange }) => {
26+
const onDateChangedHandler = (value) =>
27+
onChange(value ? value.toDateString() : new Date().toDateString());
3128

3229
const { locale } = useSelector(
33-
state => ({
34-
locale: state.preferences.locale
30+
(state) => ({
31+
locale: state.preferences.locale,
3532
}),
3633
shallowEqual
3734
);
@@ -47,9 +44,8 @@ const DatePickerStyled = ({ name, date, setState }) => {
4744
};
4845

4946
DatePickerStyled.propTypes = {
50-
name: PropTypes.string.isRequired,
5147
date: PropTypes.instanceOf(Date).isRequired,
52-
setState: PropTypes.func.isRequired
48+
onChange: PropTypes.func.isRequired,
5349
};
5450

5551
export default DatePickerStyled;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { useFormatMessage } from 'hooks';
3+
4+
const ErrorMessage = (text = '') => {
5+
const defaultText = useFormatMessage('ErrorMessage.defaultMessage');
6+
return <p className="error">{text || defaultText}</p>;
7+
};
8+
9+
export default ErrorMessage;

src/components/Layout/__snapshots__/Layout.test.js.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@ exports[`<Layout /> rendering should render without crashing 1`] = `
4545
"ChangePassword.safePassword": "Safe password",
4646
"ChangePassword.samePassword": "The new password and the current one cannot be the same",
4747
"ChangePassword.submits": "Submit",
48+
"ErrorMessage.defaultMessage": "This field is required",
4849
"Home.content": "Home content",
4950
"Home.home": "Home",
5051
"Login.email": "E-mail Address",
5152
"Login.facebook": "Continue with Facebook",
5253
"Login.forgotPassword": "Forgot Password?",
5354
"Login.google": "Continue with Google",
55+
"Login.invalidEmail": "Invalid email",
5456
"Login.login": "Login",
5557
"Login.microsoft": "Continue with Microsoft",
5658
"Login.password": "Password",
59+
"Login.safePassword": "Safe password",
5760
"Login.setNewPassword": "Set your new password",
5861
"Login.setPassword": "Set Password",
62+
"Login.unsafePassword": "Unsafe password",
5963
"NavBar.Language": "English",
6064
"NavBar.logOut": "Log Out",
6165
"NavBar.profile": "Profile",
@@ -112,13 +116,11 @@ exports[`<Layout /> rendering should render without crashing 1`] = `
112116
"auth/too-many-requests": "Too many attempts made, try again later",
113117
"auth/user-disabled": "User disabled",
114118
"auth/wrong-password": "Invalid credentials",
119+
"invalidEmail": "Invalid E-mail",
115120
"storage/quota-exceeded": "Internal server error, get in touch with your administrator",
116121
"storage/unauthenticated": "Unauthenticated, please authenticate and try again",
117122
"storage/unauthorized": "Unauthorized, you are not authorized to perform this action",
118123
"utils.default": "Unknown error, get in touch with your administrator",
119-
"utils.invalidEmail": "Invalid email",
120-
"utils.safePassword": "Safe password",
121-
"utils.unsafePassword": "Unsafe password",
122124
},
123125
"onError": [Function],
124126
"textComponent": Symbol(react.fragment),

src/components/Navigation/Aside/__snapshots__/Aside.test.js.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,21 @@ Object {
4646
"ChangePassword.safePassword": "Safe password",
4747
"ChangePassword.samePassword": "The new password and the current one cannot be the same",
4848
"ChangePassword.submits": "Submit",
49+
"ErrorMessage.defaultMessage": "This field is required",
4950
"Home.content": "Home content",
5051
"Home.home": "Home",
5152
"Login.email": "E-mail Address",
5253
"Login.facebook": "Continue with Facebook",
5354
"Login.forgotPassword": "Forgot Password?",
5455
"Login.google": "Continue with Google",
56+
"Login.invalidEmail": "Invalid email",
5557
"Login.login": "Login",
5658
"Login.microsoft": "Continue with Microsoft",
5759
"Login.password": "Password",
60+
"Login.safePassword": "Safe password",
5861
"Login.setNewPassword": "Set your new password",
5962
"Login.setPassword": "Set Password",
63+
"Login.unsafePassword": "Unsafe password",
6064
"NavBar.Language": "English",
6165
"NavBar.logOut": "Log Out",
6266
"NavBar.profile": "Profile",
@@ -113,13 +117,11 @@ Object {
113117
"auth/too-many-requests": "Too many attempts made, try again later",
114118
"auth/user-disabled": "User disabled",
115119
"auth/wrong-password": "Invalid credentials",
120+
"invalidEmail": "Invalid E-mail",
116121
"storage/quota-exceeded": "Internal server error, get in touch with your administrator",
117122
"storage/unauthenticated": "Unauthenticated, please authenticate and try again",
118123
"storage/unauthorized": "Unauthorized, you are not authorized to perform this action",
119124
"utils.default": "Unknown error, get in touch with your administrator",
120-
"utils.invalidEmail": "Invalid email",
121-
"utils.safePassword": "Safe password",
122-
"utils.unsafePassword": "Unsafe password",
123125
},
124126
"onError": [Function],
125127
"textComponent": Symbol(react.fragment),

src/components/Navigation/NavBar/__snapshots__/NavBar.test.js.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@ exports[`<NavBar /> rendering should render without crashing 1`] = `
4545
"ChangePassword.safePassword": "Safe password",
4646
"ChangePassword.samePassword": "The new password and the current one cannot be the same",
4747
"ChangePassword.submits": "Submit",
48+
"ErrorMessage.defaultMessage": "This field is required",
4849
"Home.content": "Home content",
4950
"Home.home": "Home",
5051
"Login.email": "E-mail Address",
5152
"Login.facebook": "Continue with Facebook",
5253
"Login.forgotPassword": "Forgot Password?",
5354
"Login.google": "Continue with Google",
55+
"Login.invalidEmail": "Invalid email",
5456
"Login.login": "Login",
5557
"Login.microsoft": "Continue with Microsoft",
5658
"Login.password": "Password",
59+
"Login.safePassword": "Safe password",
5760
"Login.setNewPassword": "Set your new password",
5861
"Login.setPassword": "Set Password",
62+
"Login.unsafePassword": "Unsafe password",
5963
"NavBar.Language": "English",
6064
"NavBar.logOut": "Log Out",
6165
"NavBar.profile": "Profile",
@@ -112,13 +116,11 @@ exports[`<NavBar /> rendering should render without crashing 1`] = `
112116
"auth/too-many-requests": "Too many attempts made, try again later",
113117
"auth/user-disabled": "User disabled",
114118
"auth/wrong-password": "Invalid credentials",
119+
"invalidEmail": "Invalid E-mail",
115120
"storage/quota-exceeded": "Internal server error, get in touch with your administrator",
116121
"storage/unauthenticated": "Unauthenticated, please authenticate and try again",
117122
"storage/unauthorized": "Unauthorized, you are not authorized to perform this action",
118123
"utils.default": "Unknown error, get in touch with your administrator",
119-
"utils.invalidEmail": "Invalid email",
120-
"utils.safePassword": "Safe password",
121-
"utils.unsafePassword": "Unsafe password",
122124
},
123125
"onError": [Function],
124126
"textComponent": Symbol(react.fragment),

0 commit comments

Comments
 (0)