@os-team/profile 1.0.48 → 1.0.50
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/cjs/components/profile/ProfileDrawerContent.js +6 -11
- package/dist/cjs/components/profile/ProfileDrawerContent.js.map +1 -1
- package/dist/cjs/components/profile/ProfileUpdateNameModal.js +44 -46
- package/dist/cjs/components/profile/ProfileUpdateNameModal.js.map +1 -1
- package/dist/cjs/components/profile/ProfileUpdatePasswordModal.js +45 -46
- package/dist/cjs/components/profile/ProfileUpdatePasswordModal.js.map +1 -1
- package/dist/cjs/components/session/SessionList.js +4 -4
- package/dist/cjs/components/session/SessionList.js.map +1 -1
- package/dist/cjs/components/session/SessionListItem.js +2 -2
- package/dist/cjs/components/shared/ErrorResult.js +3 -5
- package/dist/cjs/components/shared/ErrorResult.js.map +1 -1
- package/dist/cjs/components/shared/FormError.js +21 -0
- package/dist/cjs/components/shared/FormError.js.map +1 -0
- package/dist/cjs/utils/getErrorMessage.js +43 -0
- package/dist/cjs/utils/getErrorMessage.js.map +1 -0
- package/dist/cjs/utils/handleFormErrors.js +47 -0
- package/dist/cjs/utils/handleFormErrors.js.map +1 -0
- package/dist/esm/components/profile/ProfileDrawerContent.js +4 -15
- package/dist/esm/components/profile/ProfileDrawerContent.js.map +1 -1
- package/dist/esm/components/profile/ProfileUpdateNameModal.js +40 -36
- package/dist/esm/components/profile/ProfileUpdateNameModal.js.map +1 -1
- package/dist/esm/components/profile/ProfileUpdatePasswordModal.js +43 -36
- package/dist/esm/components/profile/ProfileUpdatePasswordModal.js.map +1 -1
- package/dist/esm/components/session/SessionList.js +2 -2
- package/dist/esm/components/session/SessionList.js.map +1 -1
- package/dist/esm/components/shared/ErrorResult.js +3 -5
- package/dist/esm/components/shared/ErrorResult.js.map +1 -1
- package/dist/esm/components/shared/FormError.js +14 -0
- package/dist/esm/components/shared/FormError.js.map +1 -0
- package/dist/esm/utils/getErrorMessage.js +36 -0
- package/dist/esm/utils/getErrorMessage.js.map +1 -0
- package/dist/esm/utils/handleFormErrors.js +32 -0
- package/dist/esm/utils/handleFormErrors.js.map +1 -0
- package/dist/types/src/lib/components/profile/ProfileDrawer.d.ts +1 -1
- package/dist/types/src/lib/components/profile/ProfileDrawer.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/ProfileDrawerContent.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/ProfileUpdateNameModal.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/ProfileUpdatePasswordModal.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.d.ts +3 -3
- package/dist/types/src/lib/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql.d.ts +4 -4
- package/dist/types/src/lib/components/profile/__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/__generated__/ProfileDrawerSignOutMutation.graphql.d.ts +3 -3
- package/dist/types/src/lib/components/profile/__generated__/ProfileDrawerSignOutMutation.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/__generated__/ProfileDrawerUpdateAvatarMutation.graphql.d.ts +4 -4
- package/dist/types/src/lib/components/profile/__generated__/ProfileDrawerUpdateAvatarMutation.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/__generated__/ProfileUpdateNameModalMutation.graphql.d.ts +4 -4
- package/dist/types/src/lib/components/profile/__generated__/ProfileUpdateNameModalMutation.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/__generated__/ProfileUpdatePasswordModalMutation.graphql.d.ts +4 -4
- package/dist/types/src/lib/components/profile/__generated__/ProfileUpdatePasswordModalMutation.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/profile/__generated__/ProtectedWrapperQuery.graphql.d.ts +3 -3
- package/dist/types/src/lib/components/profile/__generated__/ProtectedWrapperQuery.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/session/__generated__/SessionDrawerContentQuery.graphql.d.ts +3 -3
- package/dist/types/src/lib/components/session/__generated__/SessionDrawerContentQuery.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/session/__generated__/SessionListDestroyAllOtherSessionsMutation.graphql.d.ts +3 -3
- package/dist/types/src/lib/components/session/__generated__/SessionListDestroyAllOtherSessionsMutation.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/session/__generated__/SessionListItemDestroySessionMutation.graphql.d.ts +4 -4
- package/dist/types/src/lib/components/session/__generated__/SessionListItemDestroySessionMutation.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/session/__generated__/SessionListItem_session.graphql.d.ts +2 -2
- package/dist/types/src/lib/components/session/__generated__/SessionListItem_session.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/session/__generated__/SessionListRefetchQuery.graphql.d.ts +3 -3
- package/dist/types/src/lib/components/session/__generated__/SessionListRefetchQuery.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/session/__generated__/SessionList_sessions.graphql.d.ts +2 -2
- package/dist/types/src/lib/components/session/__generated__/SessionList_sessions.graphql.d.ts.map +1 -1
- package/dist/types/src/lib/components/shared/ErrorResult.d.ts.map +1 -1
- package/dist/types/src/lib/components/shared/FormError.d.ts +4 -0
- package/dist/types/src/lib/components/shared/FormError.d.ts.map +1 -0
- package/dist/types/src/lib/utils/getErrorMessage.d.ts +3 -0
- package/dist/types/src/lib/utils/getErrorMessage.d.ts.map +1 -0
- package/dist/types/src/lib/utils/handleFormErrors.d.ts +9 -0
- package/dist/types/src/lib/utils/handleFormErrors.d.ts.map +1 -0
- package/package.json +31 -31
- package/dist/cjs/components/profile/ProfileUpdateNameForm.js +0 -35
- package/dist/cjs/components/profile/ProfileUpdateNameForm.js.map +0 -1
- package/dist/cjs/components/profile/ProfileUpdatePasswordForm.js +0 -39
- package/dist/cjs/components/profile/ProfileUpdatePasswordForm.js.map +0 -1
- package/dist/esm/components/profile/ProfileUpdateNameForm.js +0 -30
- package/dist/esm/components/profile/ProfileUpdateNameForm.js.map +0 -1
- package/dist/esm/components/profile/ProfileUpdatePasswordForm.js +0 -34
- package/dist/esm/components/profile/ProfileUpdatePasswordForm.js.map +0 -1
- package/dist/types/src/lib/components/profile/ProfileUpdateNameForm.d.ts +0 -11
- package/dist/types/src/lib/components/profile/ProfileUpdateNameForm.d.ts.map +0 -1
- package/dist/types/src/lib/components/profile/ProfileUpdatePasswordForm.d.ts +0 -11
- package/dist/types/src/lib/components/profile/ProfileUpdatePasswordForm.d.ts.map +0 -1
|
@@ -9,20 +9,18 @@ var _icons = require("@os-design/icons");
|
|
|
9
9
|
var _core = require("@os-design/core");
|
|
10
10
|
var _reactI18next = require("react-i18next");
|
|
11
11
|
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
12
|
+
var _getErrorMessage = _interopRequireDefault(require("../../utils/getErrorMessage"));
|
|
12
13
|
var _templateObject;
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
15
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
15
16
|
var StyledResult = (0, _styled.default)(_core.Result)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n margin: 0 1em;\n"])));
|
|
16
17
|
var ErrorResult = function ErrorResult(_ref) {
|
|
17
|
-
var _source, _source$errors, _source$errors$;
|
|
18
18
|
var error = _ref.error;
|
|
19
19
|
var _useTranslation = (0, _reactI18next.useTranslation)(['common']),
|
|
20
20
|
t = _useTranslation.t;
|
|
21
21
|
return /*#__PURE__*/_react.default.createElement(StyledResult, {
|
|
22
|
-
title: t('common:errorTitle')
|
|
23
|
-
|
|
24
|
-
,
|
|
25
|
-
description: (_source = error.source) === null || _source === void 0 ? void 0 : (_source$errors = _source.errors) === null || _source$errors === void 0 ? void 0 : (_source$errors$ = _source$errors[0]) === null || _source$errors$ === void 0 ? void 0 : _source$errors$.message,
|
|
22
|
+
title: t('common:errorTitle'),
|
|
23
|
+
description: (0, _getErrorMessage.default)(error),
|
|
26
24
|
icon: /*#__PURE__*/_react.default.createElement(_icons.CloseCircle, null)
|
|
27
25
|
});
|
|
28
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorResult.js","names":["StyledResult","styled","Result","ErrorResult","error","useTranslation","t","
|
|
1
|
+
{"version":3,"file":"ErrorResult.js","names":["StyledResult","styled","Result","ErrorResult","error","useTranslation","t","getErrorMessage"],"sources":["../../../../src/lib/components/shared/ErrorResult.tsx"],"sourcesContent":["import React from 'react';\nimport { CloseCircle } from '@os-design/icons';\nimport { Result } from '@os-design/core';\nimport { useTranslation } from 'react-i18next';\nimport styled from '@emotion/styled';\nimport getErrorMessage from '../../utils/getErrorMessage';\n\ninterface ErrorResultProps {\n error: Error;\n}\n\nconst StyledResult = styled(Result)`\n margin: 0 1em;\n`;\n\nconst ErrorResult: React.FC<ErrorResultProps> = ({ error }) => {\n const { t } = useTranslation(['common']);\n\n return (\n <StyledResult\n title={t('common:errorTitle')}\n description={getErrorMessage(error)}\n icon={<CloseCircle />}\n />\n );\n};\n\nexport default ErrorResult;\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAA0D;AAAA;AAAA;AAM1D,IAAMA,YAAY,GAAG,IAAAC,eAAM,EAACC,YAAM,CAAC,yFAElC;AAED,IAAMC,WAAuC,GAAG,SAA1CA,WAAuC,OAAkB;EAAA,IAAZC,KAAK,QAALA,KAAK;EACtD,sBAAc,IAAAC,4BAAc,EAAC,CAAC,QAAQ,CAAC,CAAC;IAAhCC,CAAC,mBAADA,CAAC;EAET,oBACE,6BAAC,YAAY;IACX,KAAK,EAAEA,CAAC,CAAC,mBAAmB,CAAE;IAC9B,WAAW,EAAE,IAAAC,wBAAe,EAACH,KAAK,CAAE;IACpC,IAAI,eAAE,6BAAC,kBAAW;EAAI,EACtB;AAEN,CAAC;AAAC,eAEaD,WAAW;AAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _core = require("@os-design/core");
|
|
8
|
+
var _form = require("@os-design/form");
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
var FormError = function FormError() {
|
|
12
|
+
var _useExistingForm = (0, _form.useExistingForm)(),
|
|
13
|
+
useError = _useExistingForm.useError;
|
|
14
|
+
var error = useError('_error');
|
|
15
|
+
return error ? /*#__PURE__*/_react.default.createElement(_core.Alert, {
|
|
16
|
+
type: "error"
|
|
17
|
+
}, error) : null;
|
|
18
|
+
};
|
|
19
|
+
var _default = FormError;
|
|
20
|
+
exports.default = _default;
|
|
21
|
+
//# sourceMappingURL=FormError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormError.js","names":["FormError","useExistingForm","useError","error"],"sources":["../../../../src/lib/components/shared/FormError.tsx"],"sourcesContent":["import { Alert } from '@os-design/core';\nimport { useExistingForm } from '@os-design/form';\nimport React from 'react';\n\nconst FormError: React.FC = () => {\n const { useError } = useExistingForm();\n const error = useError('_error');\n return error ? <Alert type='error'>{error}</Alert> : null;\n};\n\nexport default FormError;\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAA0B;AAE1B,IAAMA,SAAmB,GAAG,SAAtBA,SAAmB,GAAS;EAChC,uBAAqB,IAAAC,qBAAe,GAAE;IAA9BC,QAAQ,oBAARA,QAAQ;EAChB,IAAMC,KAAK,GAAGD,QAAQ,CAAC,QAAQ,CAAC;EAChC,OAAOC,KAAK,gBAAG,6BAAC,WAAK;IAAC,IAAI,EAAC;EAAO,GAAEA,KAAK,CAAS,GAAG,IAAI;AAC3D,CAAC;AAAC,eAEaH,SAAS;AAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
|
+
|
|
10
|
+
var isObject = function isObject(value) {
|
|
11
|
+
return _typeof(value) === 'object' && !Array.isArray(value) && value !== null;
|
|
12
|
+
};
|
|
13
|
+
var DEFAULT_MESSAGE = 'Error';
|
|
14
|
+
var getErrorMessage = function getErrorMessage(error) {
|
|
15
|
+
if (!isObject(error)) return DEFAULT_MESSAGE;
|
|
16
|
+
var source = error.source;
|
|
17
|
+
var _error$message = error.message,
|
|
18
|
+
message = _error$message === void 0 ? DEFAULT_MESSAGE : _error$message;
|
|
19
|
+
if (!isObject(source) || !Array.isArray(source.errors) || source.errors.length === 0) {
|
|
20
|
+
return message;
|
|
21
|
+
}
|
|
22
|
+
var firstError = source.errors[0];
|
|
23
|
+
if (!isObject(firstError)) {
|
|
24
|
+
return message;
|
|
25
|
+
}
|
|
26
|
+
message = firstError.message || message;
|
|
27
|
+
if (!isObject(firstError.extensions) || !isObject(firstError.extensions.constraints)) {
|
|
28
|
+
return message;
|
|
29
|
+
}
|
|
30
|
+
var constraintKeys = Object.keys(firstError.extensions.constraints);
|
|
31
|
+
if (constraintKeys.length === 0) {
|
|
32
|
+
return message;
|
|
33
|
+
}
|
|
34
|
+
var firstKey = constraintKeys[0];
|
|
35
|
+
var firstConstraint = firstError.extensions.constraints[firstKey];
|
|
36
|
+
if (!isObject(firstConstraint) || typeof firstConstraint.message !== 'string') {
|
|
37
|
+
return message;
|
|
38
|
+
}
|
|
39
|
+
return firstConstraint.message;
|
|
40
|
+
};
|
|
41
|
+
var _default = getErrorMessage;
|
|
42
|
+
exports.default = _default;
|
|
43
|
+
//# sourceMappingURL=getErrorMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getErrorMessage.js","names":["isObject","value","Array","isArray","DEFAULT_MESSAGE","getErrorMessage","error","source","message","errors","length","firstError","extensions","constraints","constraintKeys","Object","keys","firstKey","firstConstraint"],"sources":["../../../src/lib/utils/getErrorMessage.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nconst isObject = (value: any) =>\n typeof value === 'object' && !Array.isArray(value) && value !== null;\n\nconst DEFAULT_MESSAGE = 'Error';\n\nconst getErrorMessage = (error: any) => {\n if (!isObject(error)) return DEFAULT_MESSAGE;\n\n const { source } = error;\n let { message = DEFAULT_MESSAGE } = error;\n if (\n !isObject(source) ||\n !Array.isArray(source.errors) ||\n source.errors.length === 0\n ) {\n return message;\n }\n\n const firstError = source.errors[0];\n if (!isObject(firstError)) {\n return message;\n }\n\n message = firstError.message || message;\n if (\n !isObject(firstError.extensions) ||\n !isObject(firstError.extensions.constraints)\n ) {\n return message;\n }\n\n const constraintKeys = Object.keys(firstError.extensions.constraints);\n if (constraintKeys.length === 0) {\n return message;\n }\n\n const firstKey = constraintKeys[0];\n const firstConstraint = firstError.extensions.constraints[firstKey];\n if (\n !isObject(firstConstraint) ||\n typeof firstConstraint.message !== 'string'\n ) {\n return message;\n }\n\n return firstConstraint.message;\n};\n\nexport default getErrorMessage;\n"],"mappings":";;;;;;;AAAA;;AAEA,IAAMA,QAAQ,GAAG,SAAXA,QAAQ,CAAIC,KAAU;EAAA,OAC1B,QAAOA,KAAK,MAAK,QAAQ,IAAI,CAACC,KAAK,C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,EAC3C;IACA,OAAOA,OAAO;EAChB;EAEA,OAAOU,eAAe,CAACV,OAAO;AAChC,CAAC;AAAC,eAEaH,eAAe;AAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getErrorConstraints = exports.default = void 0;
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
|
+
|
|
15
|
+
var NO_CONSTRAINTS = {};
|
|
16
|
+
var getErrorConstraints = function getErrorConstraints(error) {
|
|
17
|
+
var e = error;
|
|
18
|
+
if (!e.source || !Array.isArray(e.source.errors) || e.source.errors.length === 0 || !e.source.errors[0].extensions || !e.source.errors[0].extensions.code) {
|
|
19
|
+
return NO_CONSTRAINTS;
|
|
20
|
+
}
|
|
21
|
+
if (e.source.errors[0].extensions.code !== 'BAD_ARGUMENTS') {
|
|
22
|
+
return NO_CONSTRAINTS;
|
|
23
|
+
}
|
|
24
|
+
return e.source.errors[0].extensions.constraints;
|
|
25
|
+
};
|
|
26
|
+
exports.getErrorConstraints = getErrorConstraints;
|
|
27
|
+
var handleFormErrors = function handleFormErrors(form, error) {
|
|
28
|
+
var e = error;
|
|
29
|
+
if (!e.source || !Array.isArray(e.source.errors) || e.source.errors.length === 0 || !e.source.errors[0].extensions || !e.source.errors[0].extensions.code) {
|
|
30
|
+
form.errors.set('_error', e.message);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (e.source.errors[0].extensions.code === 'BAD_ARGUMENTS') {
|
|
34
|
+
var constraints = getErrorConstraints(error);
|
|
35
|
+
Object.entries(constraints).forEach(function (_ref) {
|
|
36
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
37
|
+
fieldName = _ref2[0],
|
|
38
|
+
message = _ref2[1].message;
|
|
39
|
+
form.errors.set(fieldName, message);
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
form.errors.set('_error', e.source.errors[0].message);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var _default = handleFormErrors;
|
|
46
|
+
exports.default = _default;
|
|
47
|
+
//# sourceMappingURL=handleFormErrors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleFormErrors.js","names":["NO_CONSTRAINTS","getErrorConstraints","error","e","source","Array","isArray","errors","length","extensions","code","constraints","handleFormErrors","form","set","message","Object","entries","forEach","fieldName"],"sources":["../../../src/lib/utils/handleFormErrors.ts"],"sourcesContent":["import { Form } from '@os-design/form';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\ninterface Constraint {\n name: string;\n message: string;\n}\n\nconst NO_CONSTRAINTS = {};\n\nexport const getErrorConstraints = (\n error: Error\n): Record<string, Constraint> => {\n const e = error as any;\n\n if (\n !e.source ||\n !Array.isArray(e.source.errors) ||\n e.source.errors.length === 0 ||\n !e.source.errors[0].extensions ||\n !e.source.errors[0].extensions.code\n ) {\n return NO_CONSTRAINTS;\n }\n if (e.source.errors[0].extensions.code !== 'BAD_ARGUMENTS') {\n return NO_CONSTRAINTS;\n }\n\n return e.source.errors[0].extensions.constraints;\n};\n\nconst handleFormErrors = (form: Form<any>, error: Error): void => {\n const e = error as any;\n\n if (\n !e.source ||\n !Array.isArray(e.source.errors) ||\n e.source.errors.length === 0 ||\n !e.source.errors[0].extensions ||\n !e.source.errors[0].extensions.code\n ) {\n form.errors.set('_error', e.message);\n return;\n }\n\n if (e.source.errors[0].extensions.code === 'BAD_ARGUMENTS') {\n const constraints = getErrorConstraints(error);\n Object.entries(constraints).forEach(([fieldName, { message }]) => {\n form.errors.set(fieldName, message);\n });\n } else {\n form.errors.set('_error', e.source.errors[0].message);\n }\n};\n\nexport default handleFormErrors;\n"],"mappings":";;;;;;;;;;;;AAEA;;AAOA,IAAMA,cAAc,GAAG,CAAC,CAAC;AAElB,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAmB,CAC9BC,KAAY,EACmB;EAC/B,IAAMC,CAAC,GAAGD,KAAY;EAEtB,IACE,CAACC,CAAC,CAACC,MAAM,IACT,CAACC,KAAK,CAACC,OAAO,CAACH,CAAC,CAACC,MAAM,CAACG,MAAM,CAAC,IAC/BJ,CAAC,CAACC,MAAM,CAACG,MAAM,CAACC,MAAM,KAAK,CAAC,IAC5B,CAAC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,IAAI,CAACN,MAAM,CAACO,GAAG,CAACK,SAAS,EAAEJ,OAAO,CAAC;IACrC,CAAC,CAAC;EACJ,CAAC,MAAM;IACLF,IAAI,CAACN,MAAM,CAACO,GAAG,CAAC,QAAQ,EAAEX,CAAC,CAACC,MAAM,CAACG,MAAM,CAAC,CAAC,CAAC,CAACQ,OAAO,CAAC;EACvD;AACF,CAAC;AAAC,eAEaH,gBAAgB;AAAA"}
|
|
@@ -10,6 +10,7 @@ import { useProfile } from './ProfileContext';
|
|
|
10
10
|
import ProfileButton from './ProfileButton';
|
|
11
11
|
import ProfileUpdateNameModal from './ProfileUpdateNameModal';
|
|
12
12
|
import ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';
|
|
13
|
+
import getErrorMessage from '../../utils/getErrorMessage';
|
|
13
14
|
const AvatarContainer = styled.div`
|
|
14
15
|
display: flex;
|
|
15
16
|
flex-direction: column;
|
|
@@ -55,11 +56,7 @@ const DeleteAvatarButton = () => {
|
|
|
55
56
|
avatar: null
|
|
56
57
|
}
|
|
57
58
|
},
|
|
58
|
-
onError: error =>
|
|
59
|
-
var _source, _source$errors, _source$errors$;
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
-
message.error((_source = error.source) === null || _source === void 0 ? void 0 : (_source$errors = _source.errors) === null || _source$errors === void 0 ? void 0 : (_source$errors$ = _source$errors[0]) === null || _source$errors$ === void 0 ? void 0 : _source$errors$.message);
|
|
62
|
-
},
|
|
59
|
+
onError: error => message.error(getErrorMessage(error)),
|
|
63
60
|
onCompleted: () => {
|
|
64
61
|
message.success(t('profile:updated'));
|
|
65
62
|
}
|
|
@@ -93,11 +90,7 @@ const UpdateAvatarButton = ({
|
|
|
93
90
|
uploadables: {
|
|
94
91
|
avatar: file
|
|
95
92
|
},
|
|
96
|
-
onError: error =>
|
|
97
|
-
var _source2, _source2$errors, _source2$errors$;
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
-
message.error((_source2 = error.source) === null || _source2 === void 0 ? void 0 : (_source2$errors = _source2.errors) === null || _source2$errors === void 0 ? void 0 : (_source2$errors$ = _source2$errors[0]) === null || _source2$errors$ === void 0 ? void 0 : _source2$errors$.message);
|
|
100
|
-
},
|
|
93
|
+
onError: error => message.error(getErrorMessage(error)),
|
|
101
94
|
onCompleted: () => {
|
|
102
95
|
message.success(t('profile:updated'));
|
|
103
96
|
}
|
|
@@ -151,11 +144,7 @@ const SignOutButton = () => {
|
|
|
151
144
|
const handler = useCallback(() => {
|
|
152
145
|
commit({
|
|
153
146
|
variables: {},
|
|
154
|
-
onError: error =>
|
|
155
|
-
var _source3, _source3$errors, _source3$errors$;
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
|
-
message.error((_source3 = error.source) === null || _source3 === void 0 ? void 0 : (_source3$errors = _source3.errors) === null || _source3$errors === void 0 ? void 0 : (_source3$errors$ = _source3$errors[0]) === null || _source3$errors$ === void 0 ? void 0 : _source3$errors$.message);
|
|
158
|
-
},
|
|
147
|
+
onError: error => message.error(getErrorMessage(error)),
|
|
159
148
|
onCompleted: () => {
|
|
160
149
|
window.location.href = '/auth/';
|
|
161
150
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileDrawerContent.js","names":["React","useCallback","useMemo","useRef","useState","message","ThemeSwitcher","styled","clr","useTranslation","useMutation","UserAvatar","useProfile","ProfileButton","ProfileUpdateNameModal","ProfileUpdatePasswordModal","AvatarContainer","div","UserContent","FullName","p","theme","sizes","large","Email","inputColorPlaceholder","ActionsContainer","Footer","HiddenInput","input","profileDrawerContentUpdateAvatarMutation","DeleteAvatarButton","t","commit","loading","handler","variables","avatar","onError","error","source","errors","onCompleted","success","UpdateAvatarButton","hasAvatar","fileInputRef","e","target","files","file","uploadables","current","value","click","UpdateNameButton","hasName","modalVisibility","setModalVisibility","ChangePasswordButton","SignOutButton","window","location","href","ProfileDrawerContent","actions","children","email","firstName","lastName","fullName","filter","i","join"],"sources":["../../../../src/lib/components/profile/ProfileDrawerContent.tsx"],"sourcesContent":["import React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { message, ThemeSwitcher } from '@os-design/core';\nimport styled from '@emotion/styled';\nimport { clr } from '@os-design/theming';\nimport { useTranslation } from 'react-i18next';\nimport { useMutation } from 'react-relay/hooks';\nimport { graphql } from 'babel-plugin-relay/macro';\nimport UserAvatar from './UserAvatar';\nimport { useProfile } from './ProfileContext';\nimport ProfileButton from './ProfileButton';\nimport ProfileUpdateNameModal from './ProfileUpdateNameModal';\nimport ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';\nimport { ProfileDrawerContentSignOutMutation } from './__generated__/ProfileDrawerContentSignOutMutation.graphql';\nimport { ProfileDrawerContentUpdateAvatarMutation } from './__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql';\n\nexport interface ProfileDrawerContentProps {\n /**\n * Additional actions placed under the avatar.\n * @default undefined\n */\n actions?: React.ReactNode;\n /**\n * The children.\n */\n children?: React.ReactNode;\n}\n\nconst AvatarContainer = styled.div`\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n`;\n\nconst UserContent = styled.div`\n margin-top: 1em;\n`;\n\nconst FullName = styled.div`\n font-size: ${(p) => p.theme.sizes.large}em;\n font-weight: 500;\n text-align: center;\n line-height: 1.2;\n`;\n\nconst Email = styled.div`\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n margin-top: 0.2em;\n text-align: center;\n`;\n\nconst ActionsContainer = styled.div`\n margin-top: 1.5em;\n`;\n\nconst Footer = styled.div`\n display: flex;\n justify-content: center;\n margin-top: auto;\n padding-top: 1.5em;\n`;\n\nconst HiddenInput = styled.input`\n display: none;\n`;\n\nconst profileDrawerContentUpdateAvatarMutation = graphql`\n mutation ProfileDrawerContentUpdateAvatarMutation(\n $input: UpdateAvatarInput!\n ) {\n updateAvatar(input: $input) {\n id\n avatar\n }\n }\n`;\n\nconst DeleteAvatarButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n\n const [commit, loading] =\n useMutation<ProfileDrawerContentUpdateAvatarMutation>(\n profileDrawerContentUpdateAvatarMutation\n );\n\n const handler = useCallback(() => {\n commit({\n variables: {\n input: { avatar: null },\n },\n onError: (error) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n message.error((error as any).source?.errors?.[0]?.message);\n },\n onCompleted: () => {\n message.success(t('profile:updated'));\n },\n });\n }, [commit, t]);\n\n return (\n <ProfileButton loading={loading} onClick={handler}>\n {t('profile:deleteAvatar')}\n </ProfileButton>\n );\n};\n\ninterface UpdateAvatarButtonProps {\n hasAvatar: boolean;\n}\n\nconst UpdateAvatarButton: React.FC<UpdateAvatarButtonProps> = ({\n hasAvatar,\n}) => {\n const { t } = useTranslation(['profile']);\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n const [commit, loading] =\n useMutation<ProfileDrawerContentUpdateAvatarMutation>(\n profileDrawerContentUpdateAvatarMutation\n );\n\n const handler = useCallback(\n (e) => {\n const target = e.target as HTMLInputElement | null;\n if (!target) return;\n\n const { files } = target;\n if (!files) return;\n\n const file = files[0];\n\n commit({\n variables: {\n input: {},\n },\n uploadables: { avatar: file },\n onError: (error) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n message.error((error as any).source?.errors?.[0]?.message);\n },\n onCompleted: () => {\n message.success(t('profile:updated'));\n },\n });\n },\n [commit, t]\n );\n\n return (\n <>\n <ProfileButton\n loading={loading}\n onClick={() => {\n if (!fileInputRef.current) return;\n fileInputRef.current.value = '';\n fileInputRef.current.click();\n }}\n >\n {t(`profile:${hasAvatar ? 'changeAvatar' : 'setAvatar'}`)}\n </ProfileButton>\n\n <HiddenInput\n type='file'\n accept='image/jpeg,image/png,image/webp'\n onChange={handler}\n ref={fileInputRef}\n />\n </>\n );\n};\n\ninterface UpdateNameButtonProps {\n hasName: boolean;\n}\n\nconst UpdateNameButton: React.FC<UpdateNameButtonProps> = ({ hasName }) => {\n const { t } = useTranslation(['profile']);\n const [modalVisibility, setModalVisibility] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisibility(true)}>\n {t(`profile:${hasName ? 'changeName' : 'setName'}`)}\n </ProfileButton>\n\n <ProfileUpdateNameModal\n visibility={modalVisibility}\n onClose={() => setModalVisibility(false)}\n />\n </>\n );\n};\n\nconst ChangePasswordButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n const [modalVisibility, setModalVisibility] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisibility(true)}>\n {t('profile:changePassword')}\n </ProfileButton>\n\n <ProfileUpdatePasswordModal\n visibility={modalVisibility}\n onClose={() => setModalVisibility(false)}\n />\n </>\n );\n};\n\nconst SignOutButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n\n const [commit, loading] =\n useMutation<ProfileDrawerContentSignOutMutation>(graphql`\n mutation ProfileDrawerContentSignOutMutation {\n signOut {\n ok\n }\n }\n `);\n\n const handler = useCallback(() => {\n commit({\n variables: {},\n onError: (error) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n message.error((error as any).source?.errors?.[0]?.message);\n },\n onCompleted: () => {\n window.location.href = '/auth/';\n },\n });\n }, [commit]);\n\n return (\n <ProfileButton danger loading={loading} onClick={handler}>\n {t('profile:signOut')}\n </ProfileButton>\n );\n};\n\nconst ProfileDrawerContent: React.FC<ProfileDrawerContentProps> = ({\n actions,\n children,\n}) => {\n const { email, firstName, lastName, avatar } = useProfile();\n\n const fullName = useMemo(\n () => [firstName, lastName].filter((i) => i).join(' '),\n [firstName, lastName]\n );\n\n return (\n <>\n <AvatarContainer>\n <UserAvatar size='10em' />\n <UserContent>\n {fullName && <FullName>{fullName}</FullName>}\n <Email>{email}</Email>\n </UserContent>\n </AvatarContainer>\n\n <ActionsContainer>\n {avatar && <DeleteAvatarButton />}\n\n <UpdateAvatarButton hasAvatar={!!avatar} />\n <UpdateNameButton hasName={!!fullName} />\n <ChangePasswordButton />\n\n {actions}\n\n <SignOutButton />\n\n {children}\n </ActionsContainer>\n\n <Footer>\n <ThemeSwitcher />\n </Footer>\n </>\n );\n};\n\nexport default ProfileDrawerContent;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACrE,SAASC,OAAO,EAAEC,aAAa,QAAQ,iBAAiB;AACxD,OAAOC,MAAM,MAAM,iBAAiB;AACpC,SAASC,GAAG,QAAQ,oBAAoB;AACxC,SAASC,cAAc,QAAQ,eAAe;AAC9C,SAASC,WAAW,QAAQ,mBAAmB;AAE/C,OAAOC,UAAU,MAAM,cAAc;AACrC,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,sBAAsB,MAAM,0BAA0B;AAC7D,OAAOC,0BAA0B,MAAM,8BAA8B;AAgBrE,MAAMC,eAAe,GAAGT,MAAM,CAACU,GAAI;AACnC;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAGX,MAAM,CAACU,GAAI;AAC/B;AACA,CAAC;AAED,MAAME,QAAQ,GAAGZ,MAAM,CAACU,GAAI;AAC5B,eAAgBG,CAAC,IAAKA,CAAC,CAACC,KAAK,CAACC,KAAK,CAACC,KAAM;AAC1C;AACA;AACA;AACA,CAAC;AAED,MAAMC,KAAK,GAAGjB,MAAM,CAACU,GAAI;AACzB,WAAYG,CAAC,IAAKZ,GAAG,CAACY,CAAC,CAACC,KAAK,CAACI,qBAAqB,CAAE;AACrD;AACA;AACA,CAAC;AAED,MAAMC,gBAAgB,GAAGnB,MAAM,CAACU,GAAI;AACpC;AACA,CAAC;AAED,MAAMU,MAAM,GAAGpB,MAAM,CAACU,GAAI;AAC1B;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMW,WAAW,GAAGrB,MAAM,CAACsB,KAAM;AACjC;AACA,CAAC;AAED,MAAMC,wCAAwC,8kBAS7C;AAED,MAAMC,k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":3,"file":"ProfileDrawerContent.js","names":["React","useCallback","useMemo","useRef","useState","message","ThemeSwitcher","styled","clr","useTranslation","useMutation","UserAvatar","useProfile","ProfileButton","ProfileUpdateNameModal","ProfileUpdatePasswordModal","getErrorMessage","AvatarContainer","div","UserContent","FullName","p","theme","sizes","large","Email","inputColorPlaceholder","ActionsContainer","Footer","HiddenInput","input","profileDrawerContentUpdateAvatarMutation","DeleteAvatarButton","t","commit","loading","handler","variables","avatar","onError","error","onCompleted","success","UpdateAvatarButton","hasAvatar","fileInputRef","e","target","files","file","uploadables","current","value","click","UpdateNameButton","hasName","modalVisibility","setModalVisibility","ChangePasswordButton","SignOutButton","window","location","href","ProfileDrawerContent","actions","children","email","firstName","lastName","fullName","filter","i","join"],"sources":["../../../../src/lib/components/profile/ProfileDrawerContent.tsx"],"sourcesContent":["import React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { message, ThemeSwitcher } from '@os-design/core';\nimport styled from '@emotion/styled';\nimport { clr } from '@os-design/theming';\nimport { useTranslation } from 'react-i18next';\nimport { useMutation } from 'react-relay/hooks';\nimport { graphql } from 'babel-plugin-relay/macro';\nimport UserAvatar from './UserAvatar';\nimport { useProfile } from './ProfileContext';\nimport ProfileButton from './ProfileButton';\nimport ProfileUpdateNameModal from './ProfileUpdateNameModal';\nimport ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';\nimport { ProfileDrawerContentSignOutMutation } from './__generated__/ProfileDrawerContentSignOutMutation.graphql';\nimport { ProfileDrawerContentUpdateAvatarMutation } from './__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql';\nimport getErrorMessage from '../../utils/getErrorMessage';\n\nexport interface ProfileDrawerContentProps {\n /**\n * Additional actions placed under the avatar.\n * @default undefined\n */\n actions?: React.ReactNode;\n /**\n * The children.\n */\n children?: React.ReactNode;\n}\n\nconst AvatarContainer = styled.div`\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n`;\n\nconst UserContent = styled.div`\n margin-top: 1em;\n`;\n\nconst FullName = styled.div`\n font-size: ${(p) => p.theme.sizes.large}em;\n font-weight: 500;\n text-align: center;\n line-height: 1.2;\n`;\n\nconst Email = styled.div`\n color: ${(p) => clr(p.theme.inputColorPlaceholder)};\n margin-top: 0.2em;\n text-align: center;\n`;\n\nconst ActionsContainer = styled.div`\n margin-top: 1.5em;\n`;\n\nconst Footer = styled.div`\n display: flex;\n justify-content: center;\n margin-top: auto;\n padding-top: 1.5em;\n`;\n\nconst HiddenInput = styled.input`\n display: none;\n`;\n\nconst profileDrawerContentUpdateAvatarMutation = graphql`\n mutation ProfileDrawerContentUpdateAvatarMutation(\n $input: UpdateAvatarInput!\n ) {\n updateAvatar(input: $input) {\n id\n avatar\n }\n }\n`;\n\nconst DeleteAvatarButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n\n const [commit, loading] =\n useMutation<ProfileDrawerContentUpdateAvatarMutation>(\n profileDrawerContentUpdateAvatarMutation\n );\n\n const handler = useCallback(() => {\n commit({\n variables: {\n input: { avatar: null },\n },\n onError: (error) => message.error(getErrorMessage(error)),\n onCompleted: () => {\n message.success(t('profile:updated'));\n },\n });\n }, [commit, t]);\n\n return (\n <ProfileButton loading={loading} onClick={handler}>\n {t('profile:deleteAvatar')}\n </ProfileButton>\n );\n};\n\ninterface UpdateAvatarButtonProps {\n hasAvatar: boolean;\n}\n\nconst UpdateAvatarButton: React.FC<UpdateAvatarButtonProps> = ({\n hasAvatar,\n}) => {\n const { t } = useTranslation(['profile']);\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n const [commit, loading] =\n useMutation<ProfileDrawerContentUpdateAvatarMutation>(\n profileDrawerContentUpdateAvatarMutation\n );\n\n const handler = useCallback(\n (e) => {\n const target = e.target as HTMLInputElement | null;\n if (!target) return;\n\n const { files } = target;\n if (!files) return;\n\n const file = files[0];\n\n commit({\n variables: {\n input: {},\n },\n uploadables: { avatar: file },\n onError: (error) => message.error(getErrorMessage(error)),\n onCompleted: () => {\n message.success(t('profile:updated'));\n },\n });\n },\n [commit, t]\n );\n\n return (\n <>\n <ProfileButton\n loading={loading}\n onClick={() => {\n if (!fileInputRef.current) return;\n fileInputRef.current.value = '';\n fileInputRef.current.click();\n }}\n >\n {t(`profile:${hasAvatar ? 'changeAvatar' : 'setAvatar'}`)}\n </ProfileButton>\n\n <HiddenInput\n type='file'\n accept='image/jpeg,image/png,image/webp'\n onChange={handler}\n ref={fileInputRef}\n />\n </>\n );\n};\n\ninterface UpdateNameButtonProps {\n hasName: boolean;\n}\n\nconst UpdateNameButton: React.FC<UpdateNameButtonProps> = ({ hasName }) => {\n const { t } = useTranslation(['profile']);\n const [modalVisibility, setModalVisibility] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisibility(true)}>\n {t(`profile:${hasName ? 'changeName' : 'setName'}`)}\n </ProfileButton>\n\n <ProfileUpdateNameModal\n visibility={modalVisibility}\n onClose={() => setModalVisibility(false)}\n />\n </>\n );\n};\n\nconst ChangePasswordButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n const [modalVisibility, setModalVisibility] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisibility(true)}>\n {t('profile:changePassword')}\n </ProfileButton>\n\n <ProfileUpdatePasswordModal\n visibility={modalVisibility}\n onClose={() => setModalVisibility(false)}\n />\n </>\n );\n};\n\nconst SignOutButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n\n const [commit, loading] =\n useMutation<ProfileDrawerContentSignOutMutation>(graphql`\n mutation ProfileDrawerContentSignOutMutation {\n signOut {\n ok\n }\n }\n `);\n\n const handler = useCallback(() => {\n commit({\n variables: {},\n onError: (error) => message.error(getErrorMessage(error)),\n onCompleted: () => {\n window.location.href = '/auth/';\n },\n });\n }, [commit]);\n\n return (\n <ProfileButton danger loading={loading} onClick={handler}>\n {t('profile:signOut')}\n </ProfileButton>\n );\n};\n\nconst ProfileDrawerContent: React.FC<ProfileDrawerContentProps> = ({\n actions,\n children,\n}) => {\n const { email, firstName, lastName, avatar } = useProfile();\n\n const fullName = useMemo(\n () => [firstName, lastName].filter((i) => i).join(' '),\n [firstName, lastName]\n );\n\n return (\n <>\n <AvatarContainer>\n <UserAvatar size='10em' />\n <UserContent>\n {fullName && <FullName>{fullName}</FullName>}\n <Email>{email}</Email>\n </UserContent>\n </AvatarContainer>\n\n <ActionsContainer>\n {avatar && <DeleteAvatarButton />}\n\n <UpdateAvatarButton hasAvatar={!!avatar} />\n <UpdateNameButton hasName={!!fullName} />\n <ChangePasswordButton />\n\n {actions}\n\n <SignOutButton />\n\n {children}\n </ActionsContainer>\n\n <Footer>\n <ThemeSwitcher />\n </Footer>\n </>\n );\n};\n\nexport default ProfileDrawerContent;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACrE,SAASC,OAAO,EAAEC,aAAa,QAAQ,iBAAiB;AACxD,OAAOC,MAAM,MAAM,iBAAiB;AACpC,SAASC,GAAG,QAAQ,oBAAoB;AACxC,SAASC,cAAc,QAAQ,eAAe;AAC9C,SAASC,WAAW,QAAQ,mBAAmB;AAE/C,OAAOC,UAAU,MAAM,cAAc;AACrC,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,sBAAsB,MAAM,0BAA0B;AAC7D,OAAOC,0BAA0B,MAAM,8BAA8B;AAGrE,OAAOC,eAAe,MAAM,6BAA6B;AAczD,MAAMC,eAAe,GAAGV,MAAM,CAACW,GAAI;AACnC;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAGZ,MAAM,CAACW,GAAI;AAC/B;AACA,CAAC;AAED,MAAME,QAAQ,GAAGb,MAAM,CAACW,GAAI;AAC5B,eAAgBG,CAAC,IAAKA,CAAC,CAACC,KAAK,CAACC,KAAK,CAACC,KAAM;AAC1C;AACA;AACA;AACA,CAAC;AAED,MAAMC,KAAK,GAAGlB,MAAM,C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AAG,CACV,CACR;AAEP,CAAC;AAED,eAAeF,oBAAoB"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
var _ProfileUpdateNameModalMutation;
|
|
2
|
-
|
|
3
|
-
import { message, Modal } from '@os-design/core';
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
import { Form, FormItem, Input, message, Modal } from '@os-design/core';
|
|
4
|
+
import { FormProvider, useForm } from '@os-design/form';
|
|
5
|
+
import React, { useCallback, useEffect, useMemo } from 'react';
|
|
4
6
|
import { useTranslation } from 'react-i18next';
|
|
5
|
-
import { handleFormErrors, FormContext } from '@os-team/form-utils';
|
|
6
7
|
import { useMutation } from 'react-relay/hooks';
|
|
7
|
-
import
|
|
8
|
+
import handleFormErrors from '../../utils/handleFormErrors';
|
|
9
|
+
import FormError from '../shared/FormError';
|
|
8
10
|
import { useProfile } from './ProfileContext';
|
|
9
11
|
const ProfileUpdateNameModal = ({
|
|
10
12
|
visibility,
|
|
@@ -17,50 +19,32 @@ const ProfileUpdateNameModal = ({
|
|
|
17
19
|
firstName,
|
|
18
20
|
lastName
|
|
19
21
|
} = useProfile();
|
|
20
|
-
const
|
|
21
|
-
const [formError, setFormError] = useState();
|
|
22
|
-
const [data, setData] = useState({
|
|
22
|
+
const initValues = useMemo(() => ({
|
|
23
23
|
firstName: firstName || '',
|
|
24
24
|
lastName: lastName || ''
|
|
25
|
-
});
|
|
25
|
+
}), [firstName, lastName]);
|
|
26
|
+
const {
|
|
27
|
+
form,
|
|
28
|
+
Field
|
|
29
|
+
} = useForm(initValues);
|
|
26
30
|
const [commit, loading] = useMutation(_ProfileUpdateNameModalMutation !== void 0 ? _ProfileUpdateNameModalMutation : (_ProfileUpdateNameModalMutation = require("./__generated__/ProfileUpdateNameModalMutation.graphql"), _ProfileUpdateNameModalMutation.hash && _ProfileUpdateNameModalMutation.hash !== "7264a05b6738d5417df9f1dc462486aa" && console.error("The definition of 'ProfileUpdateNameModalMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _ProfileUpdateNameModalMutation));
|
|
27
31
|
|
|
28
32
|
// Reset the data if the modal is visible
|
|
29
33
|
useEffect(() => {
|
|
30
|
-
if (visibility)
|
|
31
|
-
|
|
32
|
-
firstName: firstName || '',
|
|
33
|
-
lastName: lastName || ''
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}, [firstName, lastName, visibility]);
|
|
34
|
+
if (visibility) form.reset();
|
|
35
|
+
}, [form, visibility]);
|
|
37
36
|
const onSubmit = useCallback(() => {
|
|
38
37
|
commit({
|
|
39
38
|
variables: {
|
|
40
|
-
input:
|
|
41
|
-
},
|
|
42
|
-
onError: error => {
|
|
43
|
-
handleFormErrors(error, {
|
|
44
|
-
setFieldErrors,
|
|
45
|
-
setFormError
|
|
46
|
-
});
|
|
39
|
+
input: form.values.getAll()
|
|
47
40
|
},
|
|
41
|
+
onError: error => handleFormErrors(form, error),
|
|
48
42
|
onCompleted: () => {
|
|
49
|
-
setFieldErrors({});
|
|
50
|
-
setFormError(undefined);
|
|
51
43
|
message.success(t('profile:updated'));
|
|
52
44
|
onClose();
|
|
53
45
|
}
|
|
54
46
|
});
|
|
55
|
-
}, [commit,
|
|
56
|
-
const formContext = useMemo(() => ({
|
|
57
|
-
data,
|
|
58
|
-
setData,
|
|
59
|
-
fieldErrors,
|
|
60
|
-
setFieldErrors,
|
|
61
|
-
formError,
|
|
62
|
-
setFormError
|
|
63
|
-
}), [data, fieldErrors, formError]);
|
|
47
|
+
}, [commit, form, onClose, t]);
|
|
64
48
|
return /*#__PURE__*/React.createElement(Modal, {
|
|
65
49
|
title: t('profile:updateNameModal.title'),
|
|
66
50
|
visible: visibility,
|
|
@@ -68,9 +52,29 @@ const ProfileUpdateNameModal = ({
|
|
|
68
52
|
okLoading: loading,
|
|
69
53
|
onOk: onSubmit,
|
|
70
54
|
onClose: onClose
|
|
71
|
-
}, /*#__PURE__*/React.createElement(
|
|
72
|
-
|
|
73
|
-
}, /*#__PURE__*/React.createElement(
|
|
55
|
+
}, /*#__PURE__*/React.createElement(FormProvider, {
|
|
56
|
+
form: form
|
|
57
|
+
}, /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Field, {
|
|
58
|
+
name: "firstName",
|
|
59
|
+
render: (props, {
|
|
60
|
+
error
|
|
61
|
+
}) => /*#__PURE__*/React.createElement(FormItem, {
|
|
62
|
+
label: t('profile:updateNameModal.firstName.label'),
|
|
63
|
+
error: error
|
|
64
|
+
}, /*#__PURE__*/React.createElement(Input, _extends({
|
|
65
|
+
placeholder: t('profile:updateNameModal.firstName.placeholder')
|
|
66
|
+
}, props)))
|
|
67
|
+
}), /*#__PURE__*/React.createElement(Field, {
|
|
68
|
+
name: "lastName",
|
|
69
|
+
render: (props, {
|
|
70
|
+
error
|
|
71
|
+
}) => /*#__PURE__*/React.createElement(FormItem, {
|
|
72
|
+
label: t('profile:updateNameModal.lastName.label'),
|
|
73
|
+
error: error
|
|
74
|
+
}, /*#__PURE__*/React.createElement(Input, _extends({
|
|
75
|
+
placeholder: t('profile:updateNameModal.lastName.placeholder')
|
|
76
|
+
}, props)))
|
|
77
|
+
}), /*#__PURE__*/React.createElement(FormError, null))));
|
|
74
78
|
};
|
|
75
79
|
export default ProfileUpdateNameModal;
|
|
76
80
|
//# sourceMappingURL=ProfileUpdateNameModal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileUpdateNameModal.js","names":["
|
|
1
|
+
{"version":3,"file":"ProfileUpdateNameModal.js","names":["Form","FormItem","Input","message","Modal","FormProvider","useForm","React","useCallback","useEffect","useMemo","useTranslation","useMutation","handleFormErrors","FormError","useProfile","ProfileUpdateNameModal","visibility","onClose","t","firstName","lastName","initValues","form","Field","commit","loading","reset","onSubmit","variables","input","values","getAll","onError","error","onCompleted","success","props"],"sources":["../../../../src/lib/components/profile/ProfileUpdateNameModal.tsx"],"sourcesContent":["import { Form, FormItem, Input, message, Modal } from '@os-design/core';\nimport { FormProvider, useForm } from '@os-design/form';\nimport { graphql } from 'babel-plugin-relay/macro';\nimport React, { useCallback, useEffect, useMemo } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { useMutation } from 'react-relay/hooks';\nimport handleFormErrors from '../../utils/handleFormErrors';\nimport FormError from '../shared/FormError';\nimport { useProfile } from './ProfileContext';\nimport { ProfileUpdateNameModalMutation } from './__generated__/ProfileUpdateNameModalMutation.graphql';\n\ninterface ProfileUpdateNameFormData {\n firstName: string;\n lastName: string;\n}\n\ninterface ProfileUpdateNameModalProps {\n visibility: boolean;\n onClose: () => void;\n}\n\nconst ProfileUpdateNameModal: React.FC<ProfileUpdateNameModalProps> = ({\n visibility,\n onClose,\n}) => {\n const { t } = useTranslation(['profile']);\n const { firstName, lastName } = useProfile();\n\n const initValues = useMemo(\n () => ({ firstName: firstName || '', lastName: lastName || '' }),\n [firstName, lastName]\n );\n\n const { form, Field } = useForm<ProfileUpdateNameFormData>(initValues);\n\n const [commit, loading] = useMutation<ProfileUpdateNameModalMutation>(graphql`\n mutation ProfileUpdateNameModalMutation($input: UpdateProfileInput!) {\n updateProfile(input: $input) {\n firstName\n lastName\n }\n }\n `);\n\n // Reset the data if the modal is visible\n useEffect(() => {\n if (visibility) form.reset();\n }, [form, visibility]);\n\n const onSubmit = useCallback(() => {\n commit({\n variables: {\n input: form.values.getAll(),\n },\n onError: (error) => handleFormErrors(form, error),\n onCompleted: () => {\n message.success(t('profile:updated'));\n onClose();\n },\n });\n }, [commit, form, onClose, t]);\n\n return (\n <Modal\n title={t('profile:updateNameModal.title')}\n visible={visibility}\n okText={t('profile:update')}\n okLoading={loading}\n onOk={onSubmit}\n onClose={onClose}\n >\n <FormProvider form={form}>\n <Form>\n <Field\n name='firstName'\n render={(props, { error }) => (\n <FormItem\n label={t('profile:updateNameModal.firstName.label')}\n error={error}\n >\n <Input\n placeholder={t(\n 'profile:updateNameModal.firstName.placeholder'\n )}\n {...props}\n />\n </FormItem>\n )}\n />\n\n <Field\n name='lastName'\n render={(props, { error }) => (\n <FormItem\n label={t('profile:updateNameModal.lastName.label')}\n error={error}\n >\n <Input\n placeholder={t(\n 'profile:updateNameModal.lastName.placeholder'\n )}\n {...props}\n />\n </FormItem>\n )}\n />\n\n <FormError />\n </Form>\n </FormProvider>\n </Modal>\n );\n};\n\nexport default ProfileUpdateNameModal;\n"],"mappings":";;AAAA,SAASA,IAAI,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,KAAK,QAAQ,iBAAiB;AACvE,SAASC,YAAY,EAAEC,OAAO,QAAQ,iBAAiB;AAEvD,OAAOC,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAC9D,SAASC,cAAc,QAAQ,eAAe;AAC9C,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,gBAAgB,MAAM,8BAA8B;AAC3D,OAAOC,SAAS,MAAM,qBAAqB;AAC3C,SAASC,UAAU,QAAQ,kBAAkB;AAa7C,MAAMC,sBAA6D,GAAG,CAAC;EACrEC,UAAU;EACVC;AACF,CAAC,KAAK;EACJ,MAAM;IAAEC;EAAE,CAAC,GAAGR,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC;EACzC,MAAM;IAAES,SAAS;IAAEC;EAAS,CAAC,GAAGN,UAAU,EAAE;EAE5C,MAAMO,UAAU,GAAGZ,OAAO,CACxB,OAAO;IAAEU,SAAS,EAAEA,SAAS,IAAI,EAAE;IAAEC,QAAQ,EAAEA,QAAQ,IAAI;EAAG,CAAC,CAAC,EAChE,CAACD,SAAS,EAAEC,QAAQ,CAAC,CACtB;EAED,MAAM;IAAEE,IAAI;IAAEC;EAAM,CAAC,GAAGlB,OAAO,CAA4BgB,UAAU,CAAC;EAEtE,MAAM,CAACG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AI,EAAC,UAAU;IACf,MAAM,EAAE,CAACA,KAAK,EAAE;MAAEH;IAAM,CAAC,kBACvB,oBAAC,QAAQ;MACP,KAAK,EAAEf,CAAC,CAAC,wCAAwC,CAAE;MACnD,KAAK,EAAEe;IAAM,gBAEb,oBAAC,KAAK;MACJ,WAAW,EAAEf,CAAC,CACZ,8CAA8C;IAC9C,GACEkB,KAAK,EACT;EAEJ,EACF,eAEF,oBAAC,SAAS,OAAG,CACR,CACM,CACT;AAEZ,CAAC;AAED,eAAerB,sBAAsB"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
var _ProfileUpdatePasswordModalMutation;
|
|
2
|
-
|
|
3
|
-
import { message, Modal } from '@os-design/core';
|
|
4
|
-
import {
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
import { Form, FormItem, InputPassword, message, Modal } from '@os-design/core';
|
|
4
|
+
import { FormProvider, useForm } from '@os-design/form';
|
|
5
|
+
import React, { useCallback, useEffect } from 'react';
|
|
5
6
|
import { useTranslation } from 'react-i18next';
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
7
|
+
import { useMutation } from 'react-relay/hooks';
|
|
8
|
+
import handleFormErrors from '../../utils/handleFormErrors';
|
|
9
|
+
import FormError from '../shared/FormError';
|
|
8
10
|
const ProfileUpdatePasswordModal = ({
|
|
9
11
|
visibility,
|
|
10
12
|
onClose
|
|
@@ -12,9 +14,10 @@ const ProfileUpdatePasswordModal = ({
|
|
|
12
14
|
const {
|
|
13
15
|
t
|
|
14
16
|
} = useTranslation(['profile']);
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const {
|
|
18
|
+
form,
|
|
19
|
+
Field
|
|
20
|
+
} = useForm({
|
|
18
21
|
currentPassword: '',
|
|
19
22
|
password: ''
|
|
20
23
|
});
|
|
@@ -22,40 +25,20 @@ const ProfileUpdatePasswordModal = ({
|
|
|
22
25
|
|
|
23
26
|
// Reset the data if the modal is visible
|
|
24
27
|
useEffect(() => {
|
|
25
|
-
if (visibility)
|
|
26
|
-
|
|
27
|
-
currentPassword: '',
|
|
28
|
-
password: ''
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}, [visibility]);
|
|
28
|
+
if (visibility) form.reset();
|
|
29
|
+
}, [form, visibility]);
|
|
32
30
|
const onSubmit = useCallback(() => {
|
|
33
31
|
commit({
|
|
34
32
|
variables: {
|
|
35
|
-
input:
|
|
36
|
-
},
|
|
37
|
-
onError: error => {
|
|
38
|
-
handleFormErrors(error, {
|
|
39
|
-
setFieldErrors,
|
|
40
|
-
setFormError
|
|
41
|
-
});
|
|
33
|
+
input: form.values.getAll()
|
|
42
34
|
},
|
|
35
|
+
onError: error => handleFormErrors(form, error),
|
|
43
36
|
onCompleted: () => {
|
|
44
|
-
setFieldErrors({});
|
|
45
|
-
setFormError(undefined);
|
|
46
37
|
message.success(t('profile:updatePasswordModal.success'));
|
|
47
38
|
onClose();
|
|
48
39
|
}
|
|
49
40
|
});
|
|
50
|
-
}, [commit,
|
|
51
|
-
const formContext = useMemo(() => ({
|
|
52
|
-
data,
|
|
53
|
-
setData,
|
|
54
|
-
fieldErrors,
|
|
55
|
-
setFieldErrors,
|
|
56
|
-
formError,
|
|
57
|
-
setFormError
|
|
58
|
-
}), [data, fieldErrors, formError]);
|
|
41
|
+
}, [commit, form, onClose, t]);
|
|
59
42
|
return /*#__PURE__*/React.createElement(Modal, {
|
|
60
43
|
title: t('profile:updatePasswordModal.title'),
|
|
61
44
|
visible: visibility,
|
|
@@ -63,9 +46,33 @@ const ProfileUpdatePasswordModal = ({
|
|
|
63
46
|
okLoading: loading,
|
|
64
47
|
onOk: onSubmit,
|
|
65
48
|
onClose: onClose
|
|
66
|
-
}, /*#__PURE__*/React.createElement(
|
|
67
|
-
|
|
68
|
-
}, /*#__PURE__*/React.createElement(
|
|
49
|
+
}, /*#__PURE__*/React.createElement(FormProvider, {
|
|
50
|
+
form: form
|
|
51
|
+
}, /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Field, {
|
|
52
|
+
name: "currentPassword",
|
|
53
|
+
render: (props, {
|
|
54
|
+
error
|
|
55
|
+
}) => /*#__PURE__*/React.createElement(FormItem, {
|
|
56
|
+
label: t('profile:updatePasswordModal.currentPassword.label'),
|
|
57
|
+
error: error
|
|
58
|
+
}, /*#__PURE__*/React.createElement(InputPassword, _extends({
|
|
59
|
+
placeholder: t('profile:updatePasswordModal.currentPassword.placeholder')
|
|
60
|
+
}, props)))
|
|
61
|
+
}), /*#__PURE__*/React.createElement(Field, {
|
|
62
|
+
name: "password",
|
|
63
|
+
render: (props, {
|
|
64
|
+
error
|
|
65
|
+
}) => /*#__PURE__*/React.createElement(FormItem, {
|
|
66
|
+
label: t('profile:updatePasswordModal.newPassword.label'),
|
|
67
|
+
error: error
|
|
68
|
+
}, /*#__PURE__*/React.createElement(InputPassword, _extends({
|
|
69
|
+
placeholder: t('profile:updatePasswordModal.newPassword.placeholder'),
|
|
70
|
+
showStrengthMeter: true,
|
|
71
|
+
strengthNames: t('profile:updatePasswordModal.passwordStrengthNames', {
|
|
72
|
+
returnObjects: true
|
|
73
|
+
})
|
|
74
|
+
}, props)))
|
|
75
|
+
}), /*#__PURE__*/React.createElement(FormError, null))));
|
|
69
76
|
};
|
|
70
77
|
export default ProfileUpdatePasswordModal;
|
|
71
78
|
//# sourceMappingURL=ProfileUpdatePasswordModal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileUpdatePasswordModal.js","names":["
|
|
1
|
+
{"version":3,"file":"ProfileUpdatePasswordModal.js","names":["Form","FormItem","InputPassword","message","Modal","FormProvider","useForm","React","useCallback","useEffect","useTranslation","useMutation","handleFormErrors","FormError","ProfileUpdatePasswordModal","visibility","onClose","t","form","Field","currentPassword","password","commit","loading","reset","onSubmit","variables","input","values","getAll","onError","error","onCompleted","success","props","returnObjects"],"sources":["../../../../src/lib/components/profile/ProfileUpdatePasswordModal.tsx"],"sourcesContent":["import { Form, FormItem, InputPassword, message, Modal } from '@os-design/core';\nimport { FormProvider, useForm } from '@os-design/form';\nimport { graphql } from 'babel-plugin-relay/macro';\nimport React, { useCallback, useEffect } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { useMutation } from 'react-relay/hooks';\nimport handleFormErrors from '../../utils/handleFormErrors';\nimport FormError from '../shared/FormError';\nimport { ProfileUpdatePasswordModalMutation } from './__generated__/ProfileUpdatePasswordModalMutation.graphql';\n\ninterface ProfileUpdatePasswordFormData {\n currentPassword: string;\n password: string;\n}\n\ninterface ProfileUpdatePasswordModalProps {\n visibility: boolean;\n onClose: () => void;\n}\n\nconst ProfileUpdatePasswordModal: React.FC<ProfileUpdatePasswordModalProps> = ({\n visibility,\n onClose,\n}) => {\n const { t } = useTranslation(['profile']);\n\n const { form, Field } = useForm<ProfileUpdatePasswordFormData>({\n currentPassword: '',\n password: '',\n });\n\n const [commit, loading] =\n useMutation<ProfileUpdatePasswordModalMutation>(graphql`\n mutation ProfileUpdatePasswordModalMutation(\n $input: UpdatePasswordInput!\n ) {\n updatePassword(input: $input) {\n id\n }\n }\n `);\n\n // Reset the data if the modal is visible\n useEffect(() => {\n if (visibility) form.reset();\n }, [form, visibility]);\n\n const onSubmit = useCallback(() => {\n commit({\n variables: {\n input: form.values.getAll(),\n },\n onError: (error) => handleFormErrors(form, error),\n onCompleted: () => {\n message.success(t('profile:updatePasswordModal.success'));\n onClose();\n },\n });\n }, [commit, form, onClose, t]);\n\n return (\n <Modal\n title={t('profile:updatePasswordModal.title')}\n visible={visibility}\n okText={t('profile:updatePasswordModal.button')}\n okLoading={loading}\n onOk={onSubmit}\n onClose={onClose}\n >\n <FormProvider form={form}>\n <Form>\n <Field\n name='currentPassword'\n render={(props, { error }) => (\n <FormItem\n label={t('profile:updatePasswordModal.currentPassword.label')}\n error={error}\n >\n <InputPassword\n placeholder={t(\n 'profile:updatePasswordModal.currentPassword.placeholder'\n )}\n {...props}\n />\n </FormItem>\n )}\n />\n\n <Field\n name='password'\n render={(props, { error }) => (\n <FormItem\n label={t('profile:updatePasswordModal.newPassword.label')}\n error={error}\n >\n <InputPassword\n placeholder={t(\n 'profile:updatePasswordModal.newPassword.placeholder'\n )}\n showStrengthMeter\n strengthNames={t(\n 'profile:updatePasswordModal.passwordStrengthNames',\n { returnObjects: true }\n )}\n {...props}\n />\n </FormItem>\n )}\n />\n\n <FormError />\n </Form>\n </FormProvider>\n </Modal>\n );\n};\n\nexport default ProfileUpdatePasswordModal;\n"],"mappings":";;AAAA,SAASA,IAAI,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,OAAO,EAAEC,KAAK,QAAQ,iBAAiB;AAC/E,SAASC,YAAY,EAAEC,OAAO,QAAQ,iBAAiB;AAEvD,OAAOC,KAAK,IAAIC,WAAW,EAAEC,SAAS,QAAQ,OAAO;AACrD,SAASC,cAAc,QAAQ,eAAe;AAC9C,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,gBAAgB,MAAM,8BAA8B;AAC3D,OAAOC,SAAS,MAAM,qBAAqB;AAa3C,MAAMC,0BAAqE,GAAG,CAAC;EAC7EC,UAAU;EACVC;AACF,CAAC,KAAK;EACJ,MAAM;IAAEC;EAAE,CAAC,GAAGP,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC;EAEzC,MAAM;IAAEQ,IAAI;IAAEC;EAAM,CAAC,GAAGb,OAAO,CAAgC;IAC7Dc,eAAe,EAAE,EAAE;IACnBC,QAAQ,EAAE;EACZ,CAAC,CAAC;EAEF,MAAM,CAACC,MAAM,EAAEC,OAAO,CAAC,GACrBZ,WAAW,6hBAQT;;EAEJ;EACAF,SAAS,CAAC,MAAM;IACd,IAAIM,UAAU,EAAEG,IAAI,CAACM,KAAK,EAAE;EAC9B,CAAC,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AAK,EAAEc;IAAM,gBAEb,oBAAC,aAAa;MACZ,WAAW,EAAEd,CAAC,CACZ,qDAAqD,CACrD;MACF,iBAAiB;MACjB,aAAa,EAAEA,CAAC,CACd,mDAAmD,EACnD;QAAEkB,aAAa,EAAE;MAAK,CAAC;IACvB,GACED,KAAK,EACT;EAEJ,EACF,eAEF,oBAAC,SAAS,OAAG,CACR,CACM,CACT;AAEZ,CAAC;AAED,eAAepB,0BAA0B"}
|
|
@@ -6,7 +6,7 @@ import styled from '@emotion/styled';
|
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
7
|
import { clr } from '@os-design/theming';
|
|
8
8
|
import SessionListItem from './SessionListItem';
|
|
9
|
-
const
|
|
9
|
+
const sessionsFragment = _SessionList_sessions !== void 0 ? _SessionList_sessions : (_SessionList_sessions = require("./__generated__/SessionList_sessions.graphql"), _SessionList_sessions.hash && _SessionList_sessions.hash !== "1b21c937c7ba795f09bfcb5ada7d2510" && console.error("The definition of 'SessionList_sessions' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _SessionList_sessions);
|
|
10
10
|
export const Title = styled.div`
|
|
11
11
|
font-weight: 500;
|
|
12
12
|
margin: 1em 1em 0.5em;
|
|
@@ -30,7 +30,7 @@ const SessionList = ({
|
|
|
30
30
|
}) => {
|
|
31
31
|
const {
|
|
32
32
|
sessions
|
|
33
|
-
} = useFragment(
|
|
33
|
+
} = useFragment(sessionsFragment, sessionsKey);
|
|
34
34
|
const {
|
|
35
35
|
t
|
|
36
36
|
} = useTranslation(['profile']);
|