@skroz/frontend 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/Auth.js +19 -36
- package/dist/auth/AuthButtons.d.ts +18 -0
- package/dist/auth/AuthButtons.js +29 -0
- package/dist/auth/AuthFooterLinks.js +9 -25
- package/dist/auth/AuthModal.d.ts +9 -0
- package/dist/auth/AuthModal.js +5 -0
- package/dist/auth/Forgot.js +48 -56
- package/dist/auth/Login.js +33 -48
- package/dist/auth/LoginForm.js +18 -47
- package/dist/auth/LogoutButton.d.ts +3 -0
- package/dist/auth/LogoutButton.js +39 -0
- package/dist/auth/RecoverPassword.js +64 -76
- package/dist/auth/Register.js +47 -55
- package/dist/auth/ResendLinkButton.d.ts +3 -4
- package/dist/auth/ResendLinkButton.js +41 -39
- package/dist/auth/__tests__/Login.test.d.ts +1 -0
- package/dist/auth/__tests__/Login.test.js +75 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.js +11 -22
- package/dist/graphql/ForgotMutation.graphql.d.ts +24 -0
- package/dist/graphql/{ForgotPasswordMutation.graphql.js → ForgotMutation.graphql.js} +11 -13
- package/dist/graphql/LoginMutation.graphql.d.ts +5 -5
- package/dist/graphql/LoginMutation.graphql.js +6 -8
- package/dist/graphql/LogoutButtonMutation.graphql.d.ts +18 -0
- package/dist/graphql/LogoutButtonMutation.graphql.js +55 -0
- package/dist/graphql/RecoverPasswordMutation.graphql.d.ts +24 -0
- package/dist/graphql/{recoveryMutation.graphql.js → RecoverPasswordMutation.graphql.js} +13 -13
- package/dist/graphql/RegisterMutation.graphql.d.ts +7 -6
- package/dist/graphql/RegisterMutation.graphql.js +15 -10
- package/dist/graphql/ResendLinkButtonMutation.graphql.d.ts +5 -6
- package/dist/graphql/ResendLinkButtonMutation.graphql.js +9 -11
- package/dist/index.d.ts +0 -1
- package/dist/index.js +3 -20
- package/dist/ui/AreYouSure.js +9 -23
- package/dist/ui/FormError.js +9 -14
- package/dist/ui/FormItem.js +8 -22
- package/dist/ui/H.d.ts +1 -1
- package/dist/ui/H.js +15 -32
- package/dist/ui/Panel.d.ts +1 -1
- package/dist/ui/Panel.js +6 -23
- package/dist/ui/SeoHead.js +7 -13
- package/dist/ui/index.js +6 -18
- package/dist/utils/FrontendContext.js +6 -25
- package/dist/utils/getError.js +12 -20
- package/dist/utils/handleFormErrors.js +20 -29
- package/dist/utils/index.js +5 -28
- package/dist/utils/isObject.js +2 -6
- package/dist/utils/limitExpiresAt.js +9 -12
- package/package.json +8 -6
- package/src/auth/Auth.tsx +2 -2
- package/src/auth/AuthButtons.tsx +119 -0
- package/src/auth/AuthModal.tsx +28 -0
- package/src/auth/Forgot.tsx +32 -21
- package/src/auth/Login.tsx +25 -10
- package/src/auth/LoginForm.tsx +4 -4
- package/src/auth/LogoutButton.tsx +53 -0
- package/src/auth/RecoverPassword.tsx +37 -23
- package/src/auth/Register.tsx +29 -13
- package/src/auth/ResendLinkButton.tsx +34 -18
- package/src/auth/__tests__/Login.test.tsx +99 -0
- package/src/auth/index.ts +3 -0
- package/src/graphql/ForgotMutation.graphql.ts +100 -0
- package/src/graphql/LoginMutation.graphql.ts +73 -73
- package/src/graphql/LogoutButtonMutation.graphql.ts +74 -0
- package/src/graphql/RecoverPasswordMutation.graphql.ts +93 -0
- package/src/graphql/RegisterMutation.graphql.ts +81 -73
- package/src/graphql/ResendLinkButtonMutation.graphql.ts +78 -79
- package/src/index.ts +0 -1
- package/src/locales/ru/common.json +8 -190
- package/src/ui/H.tsx +1 -1
- package/src/ui/Panel.tsx +1 -1
- package/src/utils/limitExpiresAt.ts +3 -1
- package/dist/graphql/ForgotPasswordMutation.graphql.d.ts +0 -24
- package/dist/graphql/index.d.ts +0 -5
- package/dist/graphql/index.js +0 -16
- package/dist/graphql/recoveryMutation.graphql.d.ts +0 -19
- package/src/graphql/ForgotPasswordMutation.graphql.ts +0 -100
- package/src/graphql/index.ts +0 -5
- package/src/graphql/recoveryMutation.graphql.ts +0 -91
|
@@ -1,96 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var link_1 = __importDefault(require("next/link"));
|
|
25
|
-
var use_interval_1 = __importDefault(require("@os-design/use-interval"));
|
|
26
|
-
var handleFormErrors_1 = __importDefault(require("../utils/handleFormErrors"));
|
|
27
|
-
var FrontendContext_1 = require("../utils/FrontendContext");
|
|
28
|
-
var recoveryMutation_graphql_1 = __importDefault(require("../graphql/recoveryMutation.graphql"));
|
|
29
|
-
var H_1 = __importDefault(require("../ui/H"));
|
|
30
|
-
var Panel_1 = __importDefault(require("../ui/Panel"));
|
|
31
|
-
var FormItem_1 = __importDefault(require("../ui/FormItem"));
|
|
32
|
-
var FormError_1 = __importDefault(require("../ui/FormError"));
|
|
33
|
-
var ResendLinkButton_1 = __importDefault(require("./ResendLinkButton"));
|
|
34
|
-
var limitExpiresAt_1 = require("../utils/limitExpiresAt");
|
|
35
|
-
var RecoverPassword = function () {
|
|
36
|
-
var router = (0, router_1.useRouter)();
|
|
37
|
-
var t = (0, next_i18next_1.useTranslation)(['common']).t;
|
|
38
|
-
var config = (0, FrontendContext_1.useFrontendConfig)();
|
|
39
|
-
var email = router.query.email;
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Form, Input, message } from 'antd';
|
|
3
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
4
|
+
import { useRouter } from 'next/router';
|
|
5
|
+
import { useTranslation } from 'next-i18next';
|
|
6
|
+
import { FormProvider, useForm } from '@os-design/form';
|
|
7
|
+
import { useMutation } from 'react-relay';
|
|
8
|
+
import Link from 'next/link';
|
|
9
|
+
import useInterval from '@os-design/use-interval';
|
|
10
|
+
import handleFormErrors from '../utils/handleFormErrors';
|
|
11
|
+
import { useFrontendConfig } from '../utils/FrontendContext';
|
|
12
|
+
import RecoverPasswordMutationNode from '../graphql/RecoverPasswordMutation.graphql';
|
|
13
|
+
import H from '../ui/H';
|
|
14
|
+
import Panel from '../ui/Panel';
|
|
15
|
+
import FormItem from '../ui/FormItem';
|
|
16
|
+
import FormError from '../ui/FormError';
|
|
17
|
+
import ResendLinkButton from './ResendLinkButton';
|
|
18
|
+
import { getLimitExpiresIn, setLimitExpiresAt } from '../utils/limitExpiresAt';
|
|
19
|
+
const RecoverPassword = () => {
|
|
20
|
+
const router = useRouter();
|
|
21
|
+
const { t } = useTranslation('common');
|
|
22
|
+
const config = useFrontendConfig();
|
|
23
|
+
let { email } = router.query;
|
|
40
24
|
if (typeof email !== 'string' || !email)
|
|
41
25
|
email = '';
|
|
42
|
-
|
|
26
|
+
const { form, Field } = useForm({
|
|
43
27
|
token: '',
|
|
44
28
|
password: '',
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
|
|
29
|
+
});
|
|
30
|
+
/*
|
|
31
|
+
SKROZ_PROTECTION NOTE:
|
|
32
|
+
The Relay compiler has generated artifacts for this mutation.
|
|
33
|
+
Explicit import of RecoverPasswordMutationNode is used.
|
|
34
|
+
|
|
35
|
+
Mutation definition (for reference/regeneration):
|
|
36
|
+
graphql`
|
|
37
|
+
mutation RecoverPasswordMutation($input: RecoverPasswordInput!) {
|
|
38
|
+
recoverPassword(input: $input) {
|
|
39
|
+
ok
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`
|
|
43
|
+
*/
|
|
44
|
+
const [commit, loading] = useMutation(RecoverPasswordMutationNode);
|
|
45
|
+
const recoverPasswordHandler = useCallback(() => {
|
|
48
46
|
commit({
|
|
49
47
|
variables: {
|
|
50
|
-
input:
|
|
48
|
+
input: {
|
|
49
|
+
...form.values.getAll(),
|
|
50
|
+
},
|
|
51
51
|
},
|
|
52
|
-
onError:
|
|
53
|
-
onCompleted:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
?
|
|
52
|
+
onError: (error) => handleFormErrors(form, error),
|
|
53
|
+
onCompleted: () => {
|
|
54
|
+
message.success(t('auth.recoverySuccess'));
|
|
55
|
+
const profilePath = config.defaultPath
|
|
56
|
+
? `${config.defaultPath === '/' ? '' : config.defaultPath}/profile`
|
|
57
57
|
: '/profile';
|
|
58
58
|
router.push(profilePath);
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
}, [commit, form, router, t, config.defaultPath]);
|
|
62
|
-
|
|
62
|
+
const [limitExpiresIn, setLimitExpiresIn] = useState(0);
|
|
63
63
|
// Update limitExpiresIn
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
(
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
const updateLimitExpiresIn = useCallback(() => setLimitExpiresIn(getLimitExpiresIn()), []);
|
|
65
|
+
useEffect(updateLimitExpiresIn, [updateLimitExpiresIn]); // Initial update
|
|
66
|
+
useInterval(updateLimitExpiresIn, limitExpiresIn > 0 ? 1000 : null); // Update every second
|
|
67
|
+
const resendIsDenied = limitExpiresIn > 0;
|
|
68
|
+
const getResendButtonTitle = () => {
|
|
69
69
|
if (resendIsDenied) {
|
|
70
|
-
return
|
|
70
|
+
return `${t('auth.openEmailResendDenied')} ${Math.ceil(limitExpiresIn / 1000)} ${t('sec')}`;
|
|
71
71
|
}
|
|
72
|
-
return t('
|
|
72
|
+
return t('auth.openEmailResend');
|
|
73
73
|
};
|
|
74
|
-
return ((
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return ((0, jsx_runtime_1.jsx)(FormItem_1.default, __assign({ label: '\u041A\u043E\u0434 \u0438\u0437 \u043F\u0438\u0441\u044C\u043C\u0430', error: error, style: { marginBottom: 0 } }, { children: (0, jsx_runtime_1.jsx)(antd_1.Input, { placeholder: '------', value: value, onChange: function (e) {
|
|
78
|
-
return onChange(e.target.value);
|
|
79
|
-
} }) })));
|
|
80
|
-
} }), (0, jsx_runtime_1.jsx)("div", __assign({ style: { marginBottom: 25 } }, { children: (0, jsx_runtime_1.jsx)(ResendLinkButton_1.default, __assign({ email: email, type: 'recovery', disabled: resendIsDenied, onError: function (error) { return (0, handleFormErrors_1.default)(form, error); }, onCompleted: function (res) {
|
|
81
|
-
(0, limitExpiresAt_1.setLimitExpiresAt)(res.resendLink.limitExpiresAt);
|
|
82
|
-
setLimitExpiresIn((0, limitExpiresAt_1.getLimitExpiresIn)());
|
|
74
|
+
return (_jsxs("div", { className: 'recovery', children: [_jsx("div", { className: 'recovery-header', children: t('auth.setNewPassword') }), email.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("div", { style: { color: 'red', marginBottom: 15 }, children: t('auth.findCodeOnEmail') }), _jsx(FormProvider, { form: form, children: _jsxs(Form, { layout: 'vertical', size: 'large', children: [_jsx(FormError, {}), _jsx(Field, { name: 'token', render: ({ value, onChange, }, { error }) => (_jsx(FormItem, { label: t('auth.setNewCodeLabel'), error: error, style: { marginBottom: 0 }, children: _jsx(Input, { placeholder: '------', value: value, onChange: (e) => onChange(e.target.value) }) })) }), _jsx("div", { style: { marginBottom: 25 }, children: _jsx(ResendLinkButton, { email: email, disabled: resendIsDenied, onError: (error) => handleFormErrors(form, error), onCompleted: (res) => {
|
|
75
|
+
setLimitExpiresAt(res.resendLink.limitExpiresAt);
|
|
76
|
+
setLimitExpiresIn(getLimitExpiresIn());
|
|
83
77
|
// Отображаем сообщение
|
|
84
78
|
if (res.resendLink.ok)
|
|
85
|
-
|
|
79
|
+
message.success(t('auth.openEmailResendOk'));
|
|
86
80
|
else
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
var value = _a.value, onChange = _a.onChange;
|
|
90
|
-
var error = _b.error;
|
|
91
|
-
return ((0, jsx_runtime_1.jsx)(FormItem_1.default, __assign({ label: t('common:auth.setNewPassword'), error: error }, { children: (0, jsx_runtime_1.jsx)(antd_1.Input.Password, { value: value, onChange: function (e) {
|
|
92
|
-
return onChange(e.target.value);
|
|
93
|
-
}, placeholder: t('common:auth.newPassword') }) })));
|
|
94
|
-
} }), (0, jsx_runtime_1.jsx)(antd_1.Button, __assign({ loading: loading, onClick: recoverPasswordHandler, type: 'primary' }, { children: t('common:auth.saveNewPassword') }))] }))] })) }))] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(H_1.default, __assign({ type: 'h2', subHeader: '\u0412\u044B \u043F\u0435\u0440\u0435\u0448\u043B\u0438 \u043D\u0430 \u044D\u0442\u0443 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0443 \u0441 \u043D\u0435\u0432\u0435\u0440\u043D\u044B\u043C\u0438 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\u043C\u0438, \u0432\u0435\u0440\u043D\u0438\u0442\u0435\u0441\u044C \u043D\u0430\u0437\u0430\u0434, \u0447\u0442\u043E\u0431\u044B \u0438\u0441\u043F\u0440\u0430\u0432\u0438\u0442\u044C \u043E\u0448\u0438\u0431\u043A\u0443', textAlign: 'center' }, { children: "\u041E\u0448\u0438\u0431\u043E\u0447\u043D\u044B\u0435 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B" })), (0, jsx_runtime_1.jsx)("div", __assign({ style: { textAlign: 'center' } }, { children: (0, jsx_runtime_1.jsx)(link_1.default, __assign({ href: config.forgotPasswordPath || '/forgot' }, { children: (0, jsx_runtime_1.jsx)(antd_1.Button, __assign({ type: 'primary', shape: 'round', size: 'large' }, { children: "\u0412\u0435\u0440\u043D\u0443\u0442\u044C\u0441\u044F \u043D\u0430\u0437\u0430\u0434" })) })) }))] }))] })));
|
|
81
|
+
message.error(t('auth.openEmailResendError'));
|
|
82
|
+
}, children: getResendButtonTitle() }) }), _jsxs(Panel, { bg: 'secondary', children: [_jsx(Field, { name: 'password', render: ({ value, onChange, }, { error }) => (_jsx(FormItem, { label: t('auth.setNewPassword'), error: error, children: _jsx(Input.Password, { value: value, onChange: (e) => onChange(e.target.value), placeholder: t('auth.newPassword') }) })) }), _jsx(Button, { loading: loading, onClick: recoverPasswordHandler, type: 'primary', children: t('auth.saveNewPassword') })] })] }) })] })) : (_jsxs(_Fragment, { children: [_jsx(H, { type: 'h2', subHeader: t('auth.wrongParamsSubtitle'), textAlign: 'center', children: t('auth.wrongParamsTitle') }), _jsx("div", { style: { textAlign: 'center' }, children: _jsx(Link, { href: config.forgotPasswordPath || '/forgot', children: _jsx(Button, { type: 'primary', shape: 'round', size: 'large', children: t('auth.goBack') }) }) })] }))] }));
|
|
95
83
|
};
|
|
96
|
-
|
|
84
|
+
export default RecoverPassword;
|
package/dist/auth/Register.js
CHANGED
|
@@ -1,64 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var _c = (0, react_relay_1.useMutation)(RegisterMutation_graphql_1.default), commit = _c[0], loading = _c[1];
|
|
39
|
-
var registerHandler = (0, react_1.useCallback)(function () {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { Button, Checkbox, message } from 'antd';
|
|
4
|
+
import { useRouter } from 'next/router';
|
|
5
|
+
import { useTranslation } from 'next-i18next';
|
|
6
|
+
import Link from 'next/link';
|
|
7
|
+
import { useExistingForm } from '@os-design/form';
|
|
8
|
+
import { useMutation } from 'react-relay';
|
|
9
|
+
import handleFormErrors from '../utils/handleFormErrors';
|
|
10
|
+
import AuthFooterLinks from './AuthFooterLinks';
|
|
11
|
+
import H from '../ui/H';
|
|
12
|
+
import { useFrontendConfig } from '../utils/FrontendContext';
|
|
13
|
+
import RegisterMutationNode from '../graphql/RegisterMutation.graphql';
|
|
14
|
+
import LoginForm from './LoginForm';
|
|
15
|
+
import FormItem from '../ui/FormItem';
|
|
16
|
+
const Register = ({ onFinish, isModal, onForgotClick, }) => {
|
|
17
|
+
const { t } = useTranslation('common');
|
|
18
|
+
const router = useRouter();
|
|
19
|
+
const config = useFrontendConfig();
|
|
20
|
+
const { form, Field } = useExistingForm();
|
|
21
|
+
/*
|
|
22
|
+
SKROZ_PROTECTION NOTE:
|
|
23
|
+
The Relay compiler has generated artifacts for this mutation.
|
|
24
|
+
Explicit import of RegisterMutationNode is used.
|
|
25
|
+
|
|
26
|
+
Mutation definition (for reference/regeneration):
|
|
27
|
+
graphql`
|
|
28
|
+
mutation RegisterMutation($input: AuthInput!) {
|
|
29
|
+
register(input: $input) {
|
|
30
|
+
id
|
|
31
|
+
email
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`
|
|
35
|
+
*/
|
|
36
|
+
const [commit, loading] = useMutation(RegisterMutationNode);
|
|
37
|
+
const registerHandler = useCallback(() => {
|
|
40
38
|
commit({
|
|
41
39
|
variables: {
|
|
42
|
-
input:
|
|
40
|
+
input: {
|
|
41
|
+
...form.values.getAll(),
|
|
42
|
+
},
|
|
43
43
|
},
|
|
44
|
-
onError:
|
|
45
|
-
onCompleted:
|
|
44
|
+
onError: (error) => handleFormErrors(form, error),
|
|
45
|
+
onCompleted: () => {
|
|
46
46
|
onFinish();
|
|
47
47
|
router.push(config.defaultPath || '/');
|
|
48
|
-
|
|
48
|
+
message.success(t('auth.successRegister'));
|
|
49
49
|
},
|
|
50
50
|
});
|
|
51
51
|
}, [commit, form, onFinish, router, t, config.defaultPath]);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return ((
|
|
55
|
-
var value = _a.value, onChange = _a.onChange;
|
|
56
|
-
var error = _b.error;
|
|
57
|
-
return ((0, jsx_runtime_1.jsx)(FormItem_1.default, __assign({ error: error, style: { marginBottom: 0 } }, { children: (0, jsx_runtime_1.jsxs)(antd_1.Checkbox, __assign({ style: { fontSize: '16px' }, checked: value || false, onChange: function (e) { return onChange(e.target.checked); } }, { children: [t('common:auth.acceptUserAgreement'), ' ', (0, jsx_runtime_1.jsx)(link_1.default, __assign({ href: '/docs/user-agreement' }, { children: t('common:links.userAgreement') }))] })) })));
|
|
58
|
-
} }), (0, jsx_runtime_1.jsx)(Field, { name: 'isPrivacyPolicyAgree', render: function (_a, _b) {
|
|
59
|
-
var value = _a.value, onChange = _a.onChange;
|
|
60
|
-
var error = _b.error;
|
|
61
|
-
return ((0, jsx_runtime_1.jsx)(FormItem_1.default, __assign({ error: error }, { children: (0, jsx_runtime_1.jsxs)(antd_1.Checkbox, __assign({ checked: value || false, onChange: function (e) { return onChange(e.target.checked); }, style: { fontSize: '16px' } }, { children: [t('common:auth.acceptPrivacyPolicy'), ' ', (0, jsx_runtime_1.jsx)(link_1.default, __assign({ href: '/docs/privacy-policy' }, { children: t('common:links.privacyPolicy') }))] })) })));
|
|
62
|
-
} })] }), (0, jsx_runtime_1.jsx)("div", __assign({ className: 'auth-button' }, { children: (0, jsx_runtime_1.jsx)(antd_1.Button, __assign({ type: 'primary', shape: 'round', size: 'large', loading: loading, onClick: registerHandler }, { children: t('common:buttons.register') })) })), (0, jsx_runtime_1.jsxs)("div", __assign({ className: 'auth-footer' }, { children: [(0, jsx_runtime_1.jsx)("div", { children: onForgotClick ? (forgotButton) : ((0, jsx_runtime_1.jsx)(link_1.default, __assign({ href: config.forgotPasswordPath || '/forgot', passHref: true }, { children: forgotButton }))) }), (0, jsx_runtime_1.jsx)(AuthFooterLinks_1.default, {})] }))] })));
|
|
52
|
+
const forgotButton = (_jsx(Button, { type: 'link', onClick: onForgotClick, children: t('auth.forgot') }));
|
|
53
|
+
const loginButton = (_jsx(Button, { type: 'link', shape: 'round', children: t('buttons.login') }));
|
|
54
|
+
return (_jsxs("div", { className: 'auth no-text-selection', children: [_jsx(H, { type: 'h1', textAlign: 'center', children: t('auth.registerTitle') }), !isModal && (_jsxs("div", { className: 'auth-subtitle', children: [t('auth.registerSubtitle'), ' ', _jsx(Link, { href: config.loginPath || '/login', passHref: true, children: loginButton })] })), _jsx(LoginForm, { onPressEnter: registerHandler }), _jsxs("div", { children: [_jsx(Field, { name: 'isUserAgreementAgree', render: ({ value, onChange, }, { error }) => (_jsx(FormItem, { error: error, style: { marginBottom: 0 }, children: _jsxs(Checkbox, { style: { fontSize: '16px' }, checked: value || false, onChange: (e) => onChange(e.target.checked), children: [t('auth.acceptUserAgreement'), ' ', _jsx(Link, { href: '/docs/user-agreement', children: t('links.userAgreement') })] }) })) }), _jsx(Field, { name: 'isPrivacyPolicyAgree', render: ({ value, onChange, }, { error }) => (_jsx(FormItem, { error: error, children: _jsxs(Checkbox, { checked: value || false, onChange: (e) => onChange(e.target.checked), style: { fontSize: '16px' }, children: [t('auth.acceptPrivacyPolicy'), ' ', _jsx(Link, { href: '/docs/privacy-policy', children: t('links.privacyPolicy') })] }) })) })] }), _jsx("div", { className: 'auth-button', children: _jsx(Button, { type: 'primary', shape: 'round', size: 'large', loading: loading, onClick: registerHandler, children: t('buttons.register') }) }), _jsxs("div", { className: 'auth-footer', children: [_jsx("div", { children: onForgotClick ? (forgotButton) : (_jsx(Link, { href: config.forgotPasswordPath || '/forgot', passHref: true, children: forgotButton })) }), _jsx(AuthFooterLinks, {})] })] }));
|
|
63
55
|
};
|
|
64
|
-
|
|
56
|
+
export default Register;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
interface ResendLinkButtonProps {
|
|
3
|
-
type: string;
|
|
4
3
|
email: string;
|
|
5
|
-
|
|
4
|
+
onCompleted?: (res: any) => void;
|
|
5
|
+
onError?: (error: any) => void;
|
|
6
6
|
disabled?: boolean;
|
|
7
|
-
|
|
8
|
-
onError: (res: any) => void;
|
|
7
|
+
children: React.ReactNode;
|
|
9
8
|
}
|
|
10
9
|
declare const ResendLinkButton: React.FC<ResendLinkButtonProps>;
|
|
11
10
|
export default ResendLinkButton;
|
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var _b = (0, react_relay_1.useMutation)(ResendLinkButtonMutation_graphql_1.default), commit = _b[0], loading = _b[1];
|
|
27
|
-
var resendLinkHandler = (0, react_1.useCallback)(function () {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useMutation } from 'react-relay';
|
|
4
|
+
import { Button, message } from 'antd';
|
|
5
|
+
import { useTranslation } from 'next-i18next';
|
|
6
|
+
import ResendLinkButtonMutationNode from '../graphql/ResendLinkButtonMutation.graphql';
|
|
7
|
+
const ResendLinkButton = ({ email, onCompleted, onError, disabled, children, }) => {
|
|
8
|
+
const { t } = useTranslation('common');
|
|
9
|
+
/*
|
|
10
|
+
SKROZ_PROTECTION NOTE:
|
|
11
|
+
The Relay compiler has generated artifacts for this mutation.
|
|
12
|
+
Explicit import of ResendLinkButtonMutationNode is used.
|
|
13
|
+
|
|
14
|
+
Mutation definition (for reference/regeneration):
|
|
15
|
+
graphql`
|
|
16
|
+
mutation ResendLinkButtonMutation($input: SendTokenInput!) {
|
|
17
|
+
sendToken(input: $input) {
|
|
18
|
+
codeIsSent
|
|
19
|
+
limitExpiresAt
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`
|
|
23
|
+
*/
|
|
24
|
+
const [commit, loading] = useMutation(ResendLinkButtonMutationNode);
|
|
25
|
+
const resendLinkHandler = useCallback(() => {
|
|
28
26
|
if (!email) {
|
|
29
|
-
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (!type) {
|
|
33
|
-
antd_1.message.error(t('error.typeNotProvided'));
|
|
27
|
+
message.error(t('error.emailNotProvided'));
|
|
34
28
|
return;
|
|
35
29
|
}
|
|
36
30
|
commit({
|
|
37
31
|
variables: {
|
|
38
32
|
input: {
|
|
39
|
-
email
|
|
40
|
-
type: type,
|
|
33
|
+
email,
|
|
41
34
|
},
|
|
42
35
|
},
|
|
43
|
-
onError
|
|
44
|
-
onCompleted:
|
|
36
|
+
onError,
|
|
37
|
+
onCompleted: (res) => {
|
|
38
|
+
if (onCompleted) {
|
|
39
|
+
onCompleted({
|
|
40
|
+
resendLink: {
|
|
41
|
+
ok: res.sendToken.codeIsSent,
|
|
42
|
+
limitExpiresAt: res.sendToken.limitExpiresAt,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
},
|
|
45
47
|
});
|
|
46
|
-
}, [commit, email, onCompleted, onError, t
|
|
47
|
-
return ((
|
|
48
|
+
}, [commit, email, onCompleted, onError, t]);
|
|
49
|
+
return (_jsx(Button, { type: 'link', disabled: disabled, onClick: resendLinkHandler, loading: loading, size: 'large', children: children }));
|
|
48
50
|
};
|
|
49
|
-
|
|
51
|
+
export default ResendLinkButton;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { useRouter } from 'next/router';
|
|
4
|
+
import { useMutation } from 'react-relay';
|
|
5
|
+
import { useExistingForm } from '@os-design/form';
|
|
6
|
+
import Login from '../Login';
|
|
7
|
+
// Mocking dependencies with verified relative paths
|
|
8
|
+
jest.mock('next/router', () => ({
|
|
9
|
+
useRouter: jest.fn(),
|
|
10
|
+
}));
|
|
11
|
+
jest.mock('next/link', () => ({
|
|
12
|
+
__esModule: true,
|
|
13
|
+
default: ({ children, href }) => _jsx("a", { href: href, children: children }),
|
|
14
|
+
}));
|
|
15
|
+
jest.mock('next-i18next', () => ({
|
|
16
|
+
useTranslation: () => ({
|
|
17
|
+
t: (key) => key,
|
|
18
|
+
}),
|
|
19
|
+
}));
|
|
20
|
+
jest.mock('antd', () => ({
|
|
21
|
+
Button: ({ children, onClick }) => _jsx("button", { onClick: onClick, children: children }),
|
|
22
|
+
message: {
|
|
23
|
+
success: jest.fn(),
|
|
24
|
+
error: jest.fn(),
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
jest.mock('react-relay', () => ({
|
|
28
|
+
useMutation: jest.fn(),
|
|
29
|
+
graphql: jest.fn(),
|
|
30
|
+
}));
|
|
31
|
+
jest.mock('../../graphql/LoginMutation.graphql', () => ({
|
|
32
|
+
__esModule: true,
|
|
33
|
+
default: {},
|
|
34
|
+
}));
|
|
35
|
+
jest.mock('@os-design/form', () => ({
|
|
36
|
+
useExistingForm: jest.fn(),
|
|
37
|
+
}));
|
|
38
|
+
jest.mock('../../ui/H', () => ({ children }) => _jsx("h1", { children: children }));
|
|
39
|
+
jest.mock('../LoginForm', () => () => _jsx("div", { "data-testid": "login-form" }));
|
|
40
|
+
jest.mock('../AuthFooterLinks', () => () => _jsx("div", { "data-testid": "auth-footer-links" }));
|
|
41
|
+
jest.mock('../../utils/FrontendContext', () => ({
|
|
42
|
+
useFrontendConfig: () => ({
|
|
43
|
+
loginPath: '/login',
|
|
44
|
+
registerPath: '/register',
|
|
45
|
+
forgotPasswordPath: '/forgot',
|
|
46
|
+
defaultPath: '/',
|
|
47
|
+
}),
|
|
48
|
+
}));
|
|
49
|
+
jest.mock('../../utils/handleFormErrors', () => jest.fn());
|
|
50
|
+
describe('Login Component', () => {
|
|
51
|
+
const mockOnFinish = jest.fn();
|
|
52
|
+
const mockOnForgotClick = jest.fn();
|
|
53
|
+
const mockCommit = jest.fn();
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
useRouter.mockReturnValue({
|
|
56
|
+
reload: jest.fn(),
|
|
57
|
+
});
|
|
58
|
+
useMutation.mockReturnValue([mockCommit, false]);
|
|
59
|
+
useExistingForm.mockReturnValue({
|
|
60
|
+
form: {
|
|
61
|
+
values: {
|
|
62
|
+
getAll: jest.fn().mockReturnValue({}),
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it('should render the login title', () => {
|
|
68
|
+
const { getByText } = render(_jsx(Login, { onFinish: mockOnFinish, onForgotClick: mockOnForgotClick, isModal: false }));
|
|
69
|
+
expect(getByText('common:auth.loginTitle')).toBeDefined();
|
|
70
|
+
});
|
|
71
|
+
it('should render the login form', () => {
|
|
72
|
+
const { getByTestId } = render(_jsx(Login, { onFinish: mockOnFinish, onForgotClick: mockOnForgotClick, isModal: false }));
|
|
73
|
+
expect(getByTestId('login-form')).toBeDefined();
|
|
74
|
+
});
|
|
75
|
+
});
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -6,3 +6,6 @@ export { default as RecoverPassword } from './RecoverPassword';
|
|
|
6
6
|
export { default as AuthFooterLinks } from './AuthFooterLinks';
|
|
7
7
|
export { default as LoginForm } from './LoginForm';
|
|
8
8
|
export { default as ResendLinkButton } from './ResendLinkButton';
|
|
9
|
+
export { default as LogoutButton } from './LogoutButton';
|
|
10
|
+
export { default as AuthModal } from './AuthModal';
|
|
11
|
+
export { default as AuthButtons } from './AuthButtons';
|
package/dist/auth/index.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, "Register", { enumerable: true, get: function () { return __importDefault(Register_1).default; } });
|
|
13
|
-
var Forgot_1 = require("./Forgot");
|
|
14
|
-
Object.defineProperty(exports, "Forgot", { enumerable: true, get: function () { return __importDefault(Forgot_1).default; } });
|
|
15
|
-
var RecoverPassword_1 = require("./RecoverPassword");
|
|
16
|
-
Object.defineProperty(exports, "RecoverPassword", { enumerable: true, get: function () { return __importDefault(RecoverPassword_1).default; } });
|
|
17
|
-
var AuthFooterLinks_1 = require("./AuthFooterLinks");
|
|
18
|
-
Object.defineProperty(exports, "AuthFooterLinks", { enumerable: true, get: function () { return __importDefault(AuthFooterLinks_1).default; } });
|
|
19
|
-
var LoginForm_1 = require("./LoginForm");
|
|
20
|
-
Object.defineProperty(exports, "LoginForm", { enumerable: true, get: function () { return __importDefault(LoginForm_1).default; } });
|
|
21
|
-
var ResendLinkButton_1 = require("./ResendLinkButton");
|
|
22
|
-
Object.defineProperty(exports, "ResendLinkButton", { enumerable: true, get: function () { return __importDefault(ResendLinkButton_1).default; } });
|
|
1
|
+
export { default as Auth } from './Auth';
|
|
2
|
+
export { default as Login } from './Login';
|
|
3
|
+
export { default as Register } from './Register';
|
|
4
|
+
export { default as Forgot } from './Forgot';
|
|
5
|
+
export { default as RecoverPassword } from './RecoverPassword';
|
|
6
|
+
export { default as AuthFooterLinks } from './AuthFooterLinks';
|
|
7
|
+
export { default as LoginForm } from './LoginForm';
|
|
8
|
+
export { default as ResendLinkButton } from './ResendLinkButton';
|
|
9
|
+
export { default as LogoutButton } from './LogoutButton';
|
|
10
|
+
export { default as AuthModal } from './AuthModal';
|
|
11
|
+
export { default as AuthButtons } from './AuthButtons';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<0f3dfefe3a2565ec72f2043bace633b9>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
* @nogrep
|
|
5
|
+
*/
|
|
6
|
+
import { ConcreteRequest } from 'relay-runtime';
|
|
7
|
+
export type SendTokenInput = {
|
|
8
|
+
email: string;
|
|
9
|
+
};
|
|
10
|
+
export type ForgotMutation$variables = {
|
|
11
|
+
input: SendTokenInput;
|
|
12
|
+
};
|
|
13
|
+
export type ForgotMutation$data = {
|
|
14
|
+
readonly sendToken: {
|
|
15
|
+
readonly codeIsSent: boolean;
|
|
16
|
+
readonly limitExpiresAt: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export type ForgotMutation = {
|
|
20
|
+
response: ForgotMutation$data;
|
|
21
|
+
variables: ForgotMutation$variables;
|
|
22
|
+
};
|
|
23
|
+
declare const node: ConcreteRequest;
|
|
24
|
+
export default node;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
|
-
* @generated SignedSource<<
|
|
2
|
+
* @generated SignedSource<<0f3dfefe3a2565ec72f2043bace633b9>>
|
|
4
3
|
* @lightSyntaxTransform
|
|
5
4
|
* @nogrep
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
var node = (function () {
|
|
6
|
+
const node = (function () {
|
|
9
7
|
var v0 = [
|
|
10
8
|
{
|
|
11
9
|
"defaultValue": null,
|
|
@@ -22,9 +20,9 @@ var node = (function () {
|
|
|
22
20
|
"variableName": "input"
|
|
23
21
|
}
|
|
24
22
|
],
|
|
25
|
-
"concreteType": "
|
|
23
|
+
"concreteType": "SendTokenPayload",
|
|
26
24
|
"kind": "LinkedField",
|
|
27
|
-
"name": "
|
|
25
|
+
"name": "sendToken",
|
|
28
26
|
"plural": false,
|
|
29
27
|
"selections": [
|
|
30
28
|
{
|
|
@@ -50,7 +48,7 @@ var node = (function () {
|
|
|
50
48
|
"argumentDefinitions": (v0 /*: any*/),
|
|
51
49
|
"kind": "Fragment",
|
|
52
50
|
"metadata": null,
|
|
53
|
-
"name": "
|
|
51
|
+
"name": "ForgotMutation",
|
|
54
52
|
"selections": (v1 /*: any*/),
|
|
55
53
|
"type": "Mutation",
|
|
56
54
|
"abstractKey": null
|
|
@@ -59,18 +57,18 @@ var node = (function () {
|
|
|
59
57
|
"operation": {
|
|
60
58
|
"argumentDefinitions": (v0 /*: any*/),
|
|
61
59
|
"kind": "Operation",
|
|
62
|
-
"name": "
|
|
60
|
+
"name": "ForgotMutation",
|
|
63
61
|
"selections": (v1 /*: any*/)
|
|
64
62
|
},
|
|
65
63
|
"params": {
|
|
66
|
-
"cacheID": "
|
|
64
|
+
"cacheID": "0a93b8a190804d04b6fb46be655df5d1",
|
|
67
65
|
"id": null,
|
|
68
66
|
"metadata": {},
|
|
69
|
-
"name": "
|
|
67
|
+
"name": "ForgotMutation",
|
|
70
68
|
"operationKind": "mutation",
|
|
71
|
-
"text": "mutation
|
|
69
|
+
"text": "mutation ForgotMutation(\n $input: SendTokenInput!\n) {\n sendToken(input: $input) {\n codeIsSent\n limitExpiresAt\n }\n}\n"
|
|
72
70
|
}
|
|
73
71
|
};
|
|
74
72
|
})();
|
|
75
|
-
node.hash = "
|
|
76
|
-
|
|
73
|
+
node.hash = "45c1fe91d41e8ab4b3aaadcfe395e427";
|
|
74
|
+
export default node;
|