UNPKG

4.8 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _regenerator = require('babel-runtime/regenerator');
8
9var _regenerator2 = _interopRequireDefault(_regenerator);
10
11var _stringify = require('babel-runtime/core-js/json/stringify');
12
13var _stringify2 = _interopRequireDefault(_stringify);
14
15var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
16
17var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
18
19var _react = require('react');
20
21var _react2 = _interopRequireDefault(_react);
22
23var _formik = require('formik');
24
25var _recompose = require('recompose');
26
27var _Form = require('./Form');
28
29var _Form2 = _interopRequireDefault(_Form);
30
31var _yup = require('yup');
32
33var Yup = _interopRequireWildcard(_yup);
34
35function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
36
37function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
39var CreateUserWithEmailAndPasswordForm = function CreateUserWithEmailAndPasswordForm(props) {
40 var labels = props.labels;
41
42 return _react2.default.createElement(
43 _Form2.default,
44 props,
45 function (_ref) {
46 var renderTextInputSocket = _ref.renderTextInputSocket,
47 renderSubmitButton = _ref.renderSubmitButton;
48 return _react2.default.createElement(
49 _react.Fragment,
50 null,
51 renderTextInputSocket({ type: 'email', label: labels.email }),
52 renderTextInputSocket({ type: 'password', label: labels.password }),
53 renderTextInputSocket({
54 type: 'passwordConfirmation',
55 label: labels.passwordConfirmation
56 }),
57 renderSubmitButton({ label: labels.submit })
58 );
59 }
60 );
61};
62
63var enhance = (0, _recompose.compose)((0, _recompose.defaultProps)({
64 handleCreateUserWithEmailAndPassword: function handleCreateUserWithEmailAndPassword(email, password) {
65 return console.log('handleCreateUserWithEmailAndPassword', email, password);
66 },
67 labels: {
68 submit: 'submit',
69 email: 'email',
70 emailRequired: 'emailRequired',
71 emailInvalid: 'emailInvalid',
72 password: 'password',
73 passwordRequired: 'passwordRequired',
74 passwordMinLength: 'passwordMinLength',
75 passwordConfirmation: 'passwordConfirmation',
76 passwordConfirmationRequired: 'passwordConfirmationRequired',
77 passwordConfirmationMismatch: 'passwordConfirmationMismatch'
78 }
79}), (0, _formik.withFormik)({
80 mapPropsToValues: function mapPropsToValues() {
81 return { email: '', password: '', passwordConfirmation: '' };
82 },
83 validationSchema: function validationSchema(_ref2) {
84 var labels = _ref2.labels;
85
86 return Yup.object().shape({
87 email: Yup.string().required(labels.emailRequired).email(labels.emailInvalid),
88 password: Yup.string().required(labels.passwordRequired).min(8, labels.passwordMinLength),
89 passwordConfirmation: Yup.string().required(labels.passwordConfirmationRequired).oneOf([Yup.ref('password'), null], labels.passwordConfirmationMismatch)
90 });
91 },
92 handleSubmit: function () {
93 var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(values, _ref3) {
94 var handleCreateUserWithEmailAndPassword = _ref3.props.handleCreateUserWithEmailAndPassword,
95 setSubmitting = _ref3.setSubmitting,
96 setFieldError = _ref3.setFieldError;
97 return _regenerator2.default.wrap(function _callee$(_context) {
98 while (1) {
99 switch (_context.prev = _context.next) {
100 case 0:
101 _context.prev = 0;
102
103 console.log('Submit', (0, _stringify2.default)(values, null, 2));
104 _context.next = 4;
105 return handleCreateUserWithEmailAndPassword(values);
106
107 case 4:
108 _context.next = 11;
109 break;
110
111 case 6:
112 _context.prev = 6;
113 _context.t0 = _context['catch'](0);
114
115 console.error(_context.t0);
116 _context.next = 11;
117 return setFieldError('firebase', _context.t0.message);
118
119 case 11:
120 _context.next = 13;
121 return setSubmitting(false);
122
123 case 13:
124 case 'end':
125 return _context.stop();
126 }
127 }
128 }, _callee, undefined, [[0, 6]]);
129 }));
130
131 function handleSubmit(_x, _x2) {
132 return _ref4.apply(this, arguments);
133 }
134
135 return handleSubmit;
136 }(),
137 displayName: 'CreateUserWithEmailAndPasswordForm'
138}));
139
140CreateUserWithEmailAndPasswordForm.propTypes = {};
141
142exports.default = enhance(CreateUserWithEmailAndPasswordForm);
\No newline at end of file