@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.
Files changed (79) hide show
  1. package/dist/auth/Auth.js +19 -36
  2. package/dist/auth/AuthButtons.d.ts +18 -0
  3. package/dist/auth/AuthButtons.js +29 -0
  4. package/dist/auth/AuthFooterLinks.js +9 -25
  5. package/dist/auth/AuthModal.d.ts +9 -0
  6. package/dist/auth/AuthModal.js +5 -0
  7. package/dist/auth/Forgot.js +48 -56
  8. package/dist/auth/Login.js +33 -48
  9. package/dist/auth/LoginForm.js +18 -47
  10. package/dist/auth/LogoutButton.d.ts +3 -0
  11. package/dist/auth/LogoutButton.js +39 -0
  12. package/dist/auth/RecoverPassword.js +64 -76
  13. package/dist/auth/Register.js +47 -55
  14. package/dist/auth/ResendLinkButton.d.ts +3 -4
  15. package/dist/auth/ResendLinkButton.js +41 -39
  16. package/dist/auth/__tests__/Login.test.d.ts +1 -0
  17. package/dist/auth/__tests__/Login.test.js +75 -0
  18. package/dist/auth/index.d.ts +3 -0
  19. package/dist/auth/index.js +11 -22
  20. package/dist/graphql/ForgotMutation.graphql.d.ts +24 -0
  21. package/dist/graphql/{ForgotPasswordMutation.graphql.js → ForgotMutation.graphql.js} +11 -13
  22. package/dist/graphql/LoginMutation.graphql.d.ts +5 -5
  23. package/dist/graphql/LoginMutation.graphql.js +6 -8
  24. package/dist/graphql/LogoutButtonMutation.graphql.d.ts +18 -0
  25. package/dist/graphql/LogoutButtonMutation.graphql.js +55 -0
  26. package/dist/graphql/RecoverPasswordMutation.graphql.d.ts +24 -0
  27. package/dist/graphql/{recoveryMutation.graphql.js → RecoverPasswordMutation.graphql.js} +13 -13
  28. package/dist/graphql/RegisterMutation.graphql.d.ts +7 -6
  29. package/dist/graphql/RegisterMutation.graphql.js +15 -10
  30. package/dist/graphql/ResendLinkButtonMutation.graphql.d.ts +5 -6
  31. package/dist/graphql/ResendLinkButtonMutation.graphql.js +9 -11
  32. package/dist/index.d.ts +0 -1
  33. package/dist/index.js +3 -20
  34. package/dist/ui/AreYouSure.js +9 -23
  35. package/dist/ui/FormError.js +9 -14
  36. package/dist/ui/FormItem.js +8 -22
  37. package/dist/ui/H.d.ts +1 -1
  38. package/dist/ui/H.js +15 -32
  39. package/dist/ui/Panel.d.ts +1 -1
  40. package/dist/ui/Panel.js +6 -23
  41. package/dist/ui/SeoHead.js +7 -13
  42. package/dist/ui/index.js +6 -18
  43. package/dist/utils/FrontendContext.js +6 -25
  44. package/dist/utils/getError.js +12 -20
  45. package/dist/utils/handleFormErrors.js +20 -29
  46. package/dist/utils/index.js +5 -28
  47. package/dist/utils/isObject.js +2 -6
  48. package/dist/utils/limitExpiresAt.js +9 -12
  49. package/package.json +8 -6
  50. package/src/auth/Auth.tsx +2 -2
  51. package/src/auth/AuthButtons.tsx +119 -0
  52. package/src/auth/AuthModal.tsx +28 -0
  53. package/src/auth/Forgot.tsx +32 -21
  54. package/src/auth/Login.tsx +25 -10
  55. package/src/auth/LoginForm.tsx +4 -4
  56. package/src/auth/LogoutButton.tsx +53 -0
  57. package/src/auth/RecoverPassword.tsx +37 -23
  58. package/src/auth/Register.tsx +29 -13
  59. package/src/auth/ResendLinkButton.tsx +34 -18
  60. package/src/auth/__tests__/Login.test.tsx +99 -0
  61. package/src/auth/index.ts +3 -0
  62. package/src/graphql/ForgotMutation.graphql.ts +100 -0
  63. package/src/graphql/LoginMutation.graphql.ts +73 -73
  64. package/src/graphql/LogoutButtonMutation.graphql.ts +74 -0
  65. package/src/graphql/RecoverPasswordMutation.graphql.ts +93 -0
  66. package/src/graphql/RegisterMutation.graphql.ts +81 -73
  67. package/src/graphql/ResendLinkButtonMutation.graphql.ts +78 -79
  68. package/src/index.ts +0 -1
  69. package/src/locales/ru/common.json +8 -190
  70. package/src/ui/H.tsx +1 -1
  71. package/src/ui/Panel.tsx +1 -1
  72. package/src/utils/limitExpiresAt.ts +3 -1
  73. package/dist/graphql/ForgotPasswordMutation.graphql.d.ts +0 -24
  74. package/dist/graphql/index.d.ts +0 -5
  75. package/dist/graphql/index.js +0 -16
  76. package/dist/graphql/recoveryMutation.graphql.d.ts +0 -19
  77. package/src/graphql/ForgotPasswordMutation.graphql.ts +0 -100
  78. package/src/graphql/index.ts +0 -5
  79. package/src/graphql/recoveryMutation.graphql.ts +0 -91
@@ -1,96 +1,84 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- var jsx_runtime_1 = require("react/jsx-runtime");
18
- var antd_1 = require("antd");
19
- var react_1 = require("react");
20
- var router_1 = require("next/router");
21
- var next_i18next_1 = require("next-i18next");
22
- var form_1 = require("@os-design/form");
23
- var react_relay_1 = require("react-relay");
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
- var _a = (0, form_1.useForm)({
26
+ const { form, Field } = useForm({
43
27
  token: '',
44
28
  password: '',
45
- }), form = _a.form, Field = _a.Field;
46
- var _b = (0, react_relay_1.useMutation)(recoveryMutation_graphql_1.default), commit = _b[0], loading = _b[1];
47
- var recoverPasswordHandler = (0, react_1.useCallback)(function () {
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: __assign({}, form.values.getAll()),
48
+ input: {
49
+ ...form.values.getAll(),
50
+ },
51
51
  },
52
- onError: function (error) { return (0, handleFormErrors_1.default)(form, error); },
53
- onCompleted: function () {
54
- antd_1.message.success(t('common:auth.recoverySuccess'));
55
- var profilePath = config.defaultPath
56
- ? "".concat(config.defaultPath === '/' ? '' : config.defaultPath, "/profile")
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
- var _c = (0, react_1.useState)(0), limitExpiresIn = _c[0], setLimitExpiresIn = _c[1];
62
+ const [limitExpiresIn, setLimitExpiresIn] = useState(0);
63
63
  // Update limitExpiresIn
64
- var updateLimitExpiresIn = (0, react_1.useCallback)(function () { return setLimitExpiresIn((0, limitExpiresAt_1.getLimitExpiresIn)()); }, []);
65
- (0, react_1.useEffect)(updateLimitExpiresIn, [updateLimitExpiresIn]); // Initial update
66
- (0, use_interval_1.default)(updateLimitExpiresIn, limitExpiresIn > 0 ? 1000 : null); // Update every second
67
- var resendIsDenied = limitExpiresIn > 0;
68
- var getResendButtonTitle = function () {
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 "".concat(t('common:auth.openEmailResendDenied'), " ").concat(Math.ceil(limitExpiresIn / 1000), " ").concat(t('common:sec'));
70
+ return `${t('auth.openEmailResendDenied')} ${Math.ceil(limitExpiresIn / 1000)} ${t('sec')}`;
71
71
  }
72
- return t('common:auth.openEmailResend');
72
+ return t('auth.openEmailResend');
73
73
  };
74
- return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: 'recovery' }, { children: [(0, jsx_runtime_1.jsx)("div", __assign({ className: 'recovery-header' }, { children: t('common:auth.setNewPassword') })), email.length > 0 ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", __assign({ style: { color: 'red', marginBottom: 15 } }, { children: t('common:auth.findCodeOnEmail') })), (0, jsx_runtime_1.jsx)(form_1.FormProvider, __assign({ form: form }, { children: (0, jsx_runtime_1.jsxs)(antd_1.Form, __assign({ layout: 'vertical', size: 'large' }, { children: [(0, jsx_runtime_1.jsx)(FormError_1.default, {}), (0, jsx_runtime_1.jsx)(Field, { name: 'token', render: function (_a, _b) {
75
- var value = _a.value, onChange = _a.onChange;
76
- var error = _b.error;
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
- antd_1.message.success(t('common:auth.openEmailResendOk'));
79
+ message.success(t('auth.openEmailResendOk'));
86
80
  else
87
- antd_1.message.error(t('common:auth.openEmailResendError'));
88
- } }, { children: getResendButtonTitle() })) })), (0, jsx_runtime_1.jsxs)(Panel_1.default, __assign({ bg: 'secondary' }, { children: [(0, jsx_runtime_1.jsx)(Field, { name: 'password', render: function (_a, _b) {
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
- exports.default = RecoverPassword;
84
+ export default RecoverPassword;
@@ -1,64 +1,56 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- var jsx_runtime_1 = require("react/jsx-runtime");
18
- var react_1 = require("react");
19
- var antd_1 = require("antd");
20
- var router_1 = require("next/router");
21
- var next_i18next_1 = require("next-i18next");
22
- var link_1 = __importDefault(require("next/link"));
23
- var form_1 = require("@os-design/form");
24
- var react_relay_1 = require("react-relay");
25
- var handleFormErrors_1 = __importDefault(require("../utils/handleFormErrors"));
26
- var AuthFooterLinks_1 = __importDefault(require("./AuthFooterLinks"));
27
- var H_1 = __importDefault(require("../ui/H"));
28
- var FrontendContext_1 = require("../utils/FrontendContext");
29
- var RegisterMutation_graphql_1 = __importDefault(require("../graphql/RegisterMutation.graphql"));
30
- var LoginForm_1 = __importDefault(require("./LoginForm"));
31
- var FormItem_1 = __importDefault(require("../ui/FormItem"));
32
- var Register = function (_a) {
33
- var onFinish = _a.onFinish, isModal = _a.isModal, onForgotClick = _a.onForgotClick;
34
- var t = (0, next_i18next_1.useTranslation)().t;
35
- var router = (0, router_1.useRouter)();
36
- var config = (0, FrontendContext_1.useFrontendConfig)();
37
- var _b = (0, form_1.useExistingForm)(), form = _b.form, Field = _b.Field;
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: __assign({}, form.values.getAll()),
40
+ input: {
41
+ ...form.values.getAll(),
42
+ },
43
43
  },
44
- onError: function (error) { return (0, handleFormErrors_1.default)(form, error); },
45
- onCompleted: function () {
44
+ onError: (error) => handleFormErrors(form, error),
45
+ onCompleted: () => {
46
46
  onFinish();
47
47
  router.push(config.defaultPath || '/');
48
- antd_1.message.success(t('common:auth.successRegister'));
48
+ message.success(t('auth.successRegister'));
49
49
  },
50
50
  });
51
51
  }, [commit, form, onFinish, router, t, config.defaultPath]);
52
- var forgotButton = ((0, jsx_runtime_1.jsx)(antd_1.Button, __assign({ type: 'link', onClick: onForgotClick }, { children: t('common:auth.forgot') })));
53
- var loginButton = ((0, jsx_runtime_1.jsx)(antd_1.Button, __assign({ type: 'link', shape: 'round' }, { children: t('common:buttons.login') })));
54
- return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: 'auth no-text-selection' }, { children: [(0, jsx_runtime_1.jsx)(H_1.default, __assign({ type: 'h1', textAlign: 'center' }, { children: t('common:auth.registerTitle') })), !isModal && ((0, jsx_runtime_1.jsxs)("div", __assign({ className: 'auth-subtitle' }, { children: [t('common:auth.registerSubtitle'), ' ', (0, jsx_runtime_1.jsx)(link_1.default, __assign({ href: config.loginPath || '/login', passHref: true }, { children: loginButton }))] }))), (0, jsx_runtime_1.jsx)(LoginForm_1.default, { onPressEnter: registerHandler }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(Field, { name: 'isUserAgreementAgree', render: function (_a, _b) {
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
- exports.default = Register;
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
- children: React.ReactNode;
4
+ onCompleted?: (res: any) => void;
5
+ onError?: (error: any) => void;
6
6
  disabled?: boolean;
7
- onCompleted: (res: any) => void;
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
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- var jsx_runtime_1 = require("react/jsx-runtime");
18
- var react_1 = require("react");
19
- var react_relay_1 = require("react-relay");
20
- var antd_1 = require("antd");
21
- var next_i18next_1 = require("next-i18next");
22
- var ResendLinkButtonMutation_graphql_1 = __importDefault(require("../graphql/ResendLinkButtonMutation.graphql"));
23
- var ResendLinkButton = function (_a) {
24
- var type = _a.type, email = _a.email, children = _a.children, disabled = _a.disabled, onCompleted = _a.onCompleted, onError = _a.onError;
25
- var t = (0, next_i18next_1.useTranslation)().t;
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
- antd_1.message.error(t('error.emailNotProvided'));
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: email,
40
- type: type,
33
+ email,
41
34
  },
42
35
  },
43
- onError: onError,
44
- onCompleted: 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, type]);
47
- return ((0, jsx_runtime_1.jsx)(antd_1.Button, __assign({ type: 'link', disabled: disabled, onClick: resendLinkHandler, loading: loading, size: 'large' }, { children: children })));
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
- exports.default = ResendLinkButton;
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
+ });
@@ -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';
@@ -1,22 +1,11 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ResendLinkButton = exports.LoginForm = exports.AuthFooterLinks = exports.RecoverPassword = exports.Forgot = exports.Register = exports.Login = exports.Auth = void 0;
7
- var Auth_1 = require("./Auth");
8
- Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return __importDefault(Auth_1).default; } });
9
- var Login_1 = require("./Login");
10
- Object.defineProperty(exports, "Login", { enumerable: true, get: function () { return __importDefault(Login_1).default; } });
11
- var Register_1 = require("./Register");
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<<fa5d43293d27c101facae2d958971c83>>
2
+ * @generated SignedSource<<0f3dfefe3a2565ec72f2043bace633b9>>
4
3
  * @lightSyntaxTransform
5
4
  * @nogrep
6
5
  */
7
- Object.defineProperty(exports, "__esModule", { value: true });
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": "ForgotPasswordPayload",
23
+ "concreteType": "SendTokenPayload",
26
24
  "kind": "LinkedField",
27
- "name": "forgotPassword",
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": "ForgotPasswordMutation",
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": "ForgotPasswordMutation",
60
+ "name": "ForgotMutation",
63
61
  "selections": (v1 /*: any*/)
64
62
  },
65
63
  "params": {
66
- "cacheID": "5e5512b2a837741f90fc5a83dacf437f",
64
+ "cacheID": "0a93b8a190804d04b6fb46be655df5d1",
67
65
  "id": null,
68
66
  "metadata": {},
69
- "name": "ForgotPasswordMutation",
67
+ "name": "ForgotMutation",
70
68
  "operationKind": "mutation",
71
- "text": "mutation ForgotPasswordMutation(\n $input: ForgotPasswordInput!\n) {\n forgotPassword(input: $input) {\n codeIsSent\n limitExpiresAt\n }\n}\n"
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 = "13b4d04002f461d3c131f16f81e940a0";
76
- exports.default = node;
73
+ node.hash = "45c1fe91d41e8ab4b3aaadcfe395e427";
74
+ export default node;