@os-team/profile 1.1.15 → 1.1.16
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 +4 -4
- package/dist/cjs/components/profile/ProfileDrawerContent.js.map +1 -1
- package/dist/cjs/components/session/formatDate.js.map +1 -1
- package/dist/cjs/components/shared/ErrorResult.js +2 -2
- package/dist/cjs/components/shared/ErrorResult.js.map +1 -1
- package/dist/cjs/utils/getError.js +59 -0
- package/dist/cjs/utils/getError.js.map +1 -0
- package/dist/cjs/utils/handleFormErrors.js +13 -28
- package/dist/cjs/utils/handleFormErrors.js.map +1 -1
- package/dist/esm/components/profile/ProfileDrawerContent.js +4 -4
- package/dist/esm/components/profile/ProfileDrawerContent.js.map +1 -1
- package/dist/esm/components/session/formatDate.js.map +1 -1
- package/dist/esm/components/shared/ErrorResult.js +2 -2
- package/dist/esm/components/shared/ErrorResult.js.map +1 -1
- package/dist/esm/utils/getError.js +53 -0
- package/dist/esm/utils/getError.js.map +1 -0
- package/dist/esm/utils/handleFormErrors.js +10 -24
- package/dist/esm/utils/handleFormErrors.js.map +1 -1
- package/dist/types/components/session/formatDate.d.ts +2 -2
- package/dist/types/components/session/formatDate.d.ts.map +1 -1
- package/dist/types/utils/getError.d.ts +12 -0
- package/dist/types/utils/getError.d.ts.map +1 -0
- package/dist/types/utils/handleFormErrors.d.ts +1 -6
- package/dist/types/utils/handleFormErrors.d.ts.map +1 -1
- package/package.json +32 -32
- package/dist/cjs/utils/getErrorMessage.js +0 -42
- package/dist/cjs/utils/getErrorMessage.js.map +0 -1
- package/dist/esm/utils/getErrorMessage.js +0 -36
- package/dist/esm/utils/getErrorMessage.js.map +0 -1
- package/dist/types/utils/getErrorMessage.d.ts +0 -3
- package/dist/types/utils/getErrorMessage.d.ts.map +0 -1
|
@@ -10,7 +10,7 @@ var _theming = require("@os-design/theming");
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _reactI18next = require("react-i18next");
|
|
12
12
|
var _hooks = require("react-relay/hooks");
|
|
13
|
-
var
|
|
13
|
+
var _getError = _interopRequireDefault(require("../../utils/getError"));
|
|
14
14
|
var _ProfileButton = _interopRequireDefault(require("./ProfileButton"));
|
|
15
15
|
var _ProfileContext = require("./ProfileContext");
|
|
16
16
|
var _ProfileUpdateNameModal = _interopRequireDefault(require("./ProfileUpdateNameModal"));
|
|
@@ -41,7 +41,7 @@ const DeleteAvatarButton = () => {
|
|
|
41
41
|
avatar: null
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
-
onError:
|
|
44
|
+
onError: e => _core.message.error((0, _getError.default)(e).message),
|
|
45
45
|
onCompleted: () => {
|
|
46
46
|
_core.message.success(t('profile:updated'));
|
|
47
47
|
}
|
|
@@ -76,7 +76,7 @@ const UpdateAvatarButton = _ref => {
|
|
|
76
76
|
uploadables: {
|
|
77
77
|
avatar: file
|
|
78
78
|
},
|
|
79
|
-
onError: error => _core.message.error((0,
|
|
79
|
+
onError: error => _core.message.error((0, _getError.default)(error).message),
|
|
80
80
|
onCompleted: () => {
|
|
81
81
|
_core.message.success(t('profile:updated'));
|
|
82
82
|
}
|
|
@@ -131,7 +131,7 @@ const SignOutButton = () => {
|
|
|
131
131
|
const handler = (0, _react.useCallback)(() => {
|
|
132
132
|
commit({
|
|
133
133
|
variables: {},
|
|
134
|
-
onError:
|
|
134
|
+
onError: e => _core.message.error((0, _getError.default)(e).message),
|
|
135
135
|
onCompleted: () => {
|
|
136
136
|
window.location.href = '/auth/';
|
|
137
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileDrawerContent.js","names":["_styled","_interopRequireDefault","require","_core","_theming","_react","_interopRequireWildcard","_reactI18next","_hooks","_getErrorMessage","_ProfileButton","_ProfileContext","_ProfileUpdateNameModal","_ProfileUpdatePasswordModal","_UserAvatar","_ProfileDrawerContentUpdateAvatarMutation","_ProfileDrawerContentSignOutMutation","_templateObject","_templateObject2","_templateObject3","_templateObject4","_templateObject5","_templateObject6","_templateObject7","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","_taggedTemplateLiteral","strings","raw","slice","freeze","defineProperties","value","AvatarContainer","styled","div","UserContent","FullName","p","theme","sizes","large","Email","clr","inputColorPlaceholder","ActionsContainer","Footer","HiddenInput","input","query","hash","console","error","DeleteAvatarButton","useTranslation","commit","loading","useMutation","handler","useCallback","variables","avatar","onError","message","getErrorMessage","onCompleted","success","createElement","onClick","UpdateAvatarButton","_ref","hasAvatar","fileInputRef","useRef","target","files","file","uploadables","Fragment","current","click","concat","type","accept","onChange","ref","UpdateNameButton","_ref2","hasName","modalVisible","setModalVisible","useState","visible","onClose","ChangePasswordButton","SignOutButton","window","location","href","danger","ProfileDrawerContent","_ref3","actions","children","email","firstName","lastName","useProfile","fullName","useMemo","filter","join","size","ThemeSwitcher","_default","exports"],"sources":["../../../../src/lib/components/profile/ProfileDrawerContent.tsx"],"sourcesContent":["import styled from '@emotion/styled';\nimport { ThemeSwitcher, message } from '@os-design/core';\nimport { clr } from '@os-design/theming';\nimport { graphql } from 'babel-plugin-relay/macro';\nimport React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { useMutation } from 'react-relay/hooks';\nimport getErrorMessage from '../../utils/getErrorMessage';\nimport ProfileButton from './ProfileButton';\nimport { useProfile } from './ProfileContext';\nimport ProfileUpdateNameModal from './ProfileUpdateNameModal';\nimport ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';\nimport UserAvatar from './UserAvatar';\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 query = 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>(query);\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>(query);\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 [modalVisible, setModalVisible] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisible(true)}>\n {t(`profile:${hasName ? 'changeName' : 'setName'}`)}\n </ProfileButton>\n\n <ProfileUpdateNameModal\n visible={modalVisible}\n onClose={() => setModalVisible(false)}\n />\n </>\n );\n};\n\nconst ChangePasswordButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n const [modalVisible, setModalVisible] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisible(true)}>\n {t('profile:changePassword')}\n </ProfileButton>\n\n <ProfileUpdatePasswordModal\n visible={modalVisible}\n onClose={() => setModalVisible(false)}\n />\n </>\n );\n};\n\nconst SignOutButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n\n const [commit, loading] = useMutation<ProfileDrawerContentSignOutMutation>(\n graphql`\n mutation ProfileDrawerContentSignOutMutation {\n signOut {\n ok\n }\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,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,cAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,eAAA,GAAAT,OAAA;AACA,IAAAU,uBAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,2BAAA,GAAAZ,sBAAA,CAAAC,OAAA;AACA,IAAAY,WAAA,GAAAb,sBAAA,CAAAC,OAAA;AAAsC,IAAAa,yCAAA,EAAAC,oCAAA,EAAAC,eAAA,EAAAC,gBAAA,EAAAC,gBAAA,EAAAC,gBAAA,EAAAC,gBAAA,EAAAC,gBAAA,EAAAC,gBAAA;AAAA,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAA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C,EAEhBQ,QACe,CAAC,eAEnBtH,MAAA,CAAAyB,OAAA,CAAAyD,aAAA,CAACrB,MAAM,qBACL7D,MAAA,CAAAyB,OAAA,CAAAyD,aAAA,CAACpF,KAAA,CAAAkI,aAAa,MAAE,CACV,CACR,CAAC;AAEP,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAzG,OAAA,GAEa0F,oBAAoB"}
|
|
1
|
+
{"version":3,"file":"ProfileDrawerContent.js","names":["_styled","_interopRequireDefault","require","_core","_theming","_react","_interopRequireWildcard","_reactI18next","_hooks","_getError","_ProfileButton","_ProfileContext","_ProfileUpdateNameModal","_ProfileUpdatePasswordModal","_UserAvatar","_ProfileDrawerContentUpdateAvatarMutation","_ProfileDrawerContentSignOutMutation","_templateObject","_templateObject2","_templateObject3","_templateObject4","_templateObject5","_templateObject6","_templateObject7","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","_taggedTemplateLiteral","strings","raw","slice","freeze","defineProperties","value","AvatarContainer","styled","div","UserContent","FullName","p","theme","sizes","large","Email","clr","inputColorPlaceholder","ActionsContainer","Footer","HiddenInput","input","query","hash","console","error","DeleteAvatarButton","useTranslation","commit","loading","useMutation","handler","useCallback","variables","avatar","onError","message","getError","onCompleted","success","createElement","onClick","UpdateAvatarButton","_ref","hasAvatar","fileInputRef","useRef","target","files","file","uploadables","Fragment","current","click","concat","type","accept","onChange","ref","UpdateNameButton","_ref2","hasName","modalVisible","setModalVisible","useState","visible","onClose","ChangePasswordButton","SignOutButton","window","location","href","danger","ProfileDrawerContent","_ref3","actions","children","email","firstName","lastName","useProfile","fullName","useMemo","filter","join","size","ThemeSwitcher","_default","exports"],"sources":["../../../../src/lib/components/profile/ProfileDrawerContent.tsx"],"sourcesContent":["import styled from '@emotion/styled';\nimport { ThemeSwitcher, message } from '@os-design/core';\nimport { clr } from '@os-design/theming';\nimport { graphql } from 'babel-plugin-relay/macro';\nimport React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { useMutation } from 'react-relay/hooks';\nimport getError from '../../utils/getError';\nimport ProfileButton from './ProfileButton';\nimport { useProfile } from './ProfileContext';\nimport ProfileUpdateNameModal from './ProfileUpdateNameModal';\nimport ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';\nimport UserAvatar from './UserAvatar';\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 query = 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>(query);\n\n const handler = useCallback(() => {\n commit({\n variables: {\n input: { avatar: null },\n },\n onError: (e) => message.error(getError(e).message),\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>(query);\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(getError(error).message),\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 [modalVisible, setModalVisible] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisible(true)}>\n {t(`profile:${hasName ? 'changeName' : 'setName'}`)}\n </ProfileButton>\n\n <ProfileUpdateNameModal\n visible={modalVisible}\n onClose={() => setModalVisible(false)}\n />\n </>\n );\n};\n\nconst ChangePasswordButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n const [modalVisible, setModalVisible] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisible(true)}>\n {t('profile:changePassword')}\n </ProfileButton>\n\n <ProfileUpdatePasswordModal\n visible={modalVisible}\n onClose={() => setModalVisible(false)}\n />\n </>\n );\n};\n\nconst SignOutButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n\n const [commit, loading] = useMutation<ProfileDrawerContentSignOutMutation>(\n graphql`\n mutation ProfileDrawerContentSignOutMutation {\n signOut {\n ok\n }\n }\n `\n );\n\n const handler = useCallback(() => {\n commit({\n variables: {},\n onError: (e) => message.error(getError(e).message),\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,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAR,sBAAA,CAAAC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AA,CAAAyD,aAAA,CAACtB,gBAAgB,QACdgB,MAAM,iBAAI5E,MAAA,CAAAyB,OAAA,CAAAyD,aAAA,CAACd,kBAAkB,MAAE,CAAC,eAEjCpE,MAAA,CAAAyB,OAAA,CAAAyD,aAAA,CAACE,kBAAkB;IAACE,SAAS,EAAE,CAAC,CAACV;EAAO,CAAE,CAAC,eAC3C5E,MAAA,CAAAyB,OAAA,CAAAyD,aAAA,CAACmB,gBAAgB;IAACE,OAAO,EAAE,CAAC,CAACoB;EAAS,CAAE,CAAC,eACzC3H,MAAA,CAAAyB,OAAA,CAAAyD,aAAA,CAAC2B,oBAAoB,MAAE,CAAC,EAEvBQ,OAAO,eAERrH,MAAA,CAAAyB,OAAA,CAAAyD,aAAA,CAAC4B,aAAa,MAAE,CAAC,EAEhBQ,QACe,CAAC,eAEnBtH,MAAA,CAAAyB,OAAA,CAAAyD,aAAA,CAACrB,MAAM,qBACL7D,MAAA,CAAAyB,OAAA,CAAAyD,aAAA,CAACpF,KAAA,CAAAkI,aAAa,MAAE,CACV,CACR,CAAC;AAEP,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAzG,OAAA,GAEa0F,oBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatDate.js","names":["formatDate","timestamp","t","lng","date","Date","day","getDate","month","returnObjects","getMonth","year","getFullYear","isPrevYear","concat","_default","exports","default"],"sources":["../../../../src/lib/components/session/formatDate.ts"],"sourcesContent":["import { TFunction } from 'i18next';\n\nconst formatDate = (\n timestamp: number,\n t: TFunction<
|
|
1
|
+
{"version":3,"file":"formatDate.js","names":["formatDate","timestamp","t","lng","date","Date","day","getDate","month","returnObjects","getMonth","year","getFullYear","isPrevYear","concat","_default","exports","default"],"sources":["../../../../src/lib/components/session/formatDate.ts"],"sourcesContent":["import { Namespace, TFunction } from 'i18next';\n\nconst formatDate = (\n timestamp: number,\n t: TFunction<Namespace, undefined>,\n lng: string\n): string => {\n const date = new Date(timestamp);\n\n const day = date.getDate();\n const month = t('profile:sessions.monthAbbreviations', {\n returnObjects: true,\n })[date.getMonth()];\n const year = date.getFullYear();\n const isPrevYear = year < new Date().getFullYear();\n\n if (lng === 'ru') return `${day} ${month}${isPrevYear ? ` ${year}` : ''}`;\n return `${month} ${day}${isPrevYear ? `, ${year}` : ''}`;\n};\n\nexport default formatDate;\n"],"mappings":";;;;;;AAEA,MAAMA,UAAU,GAAGA,CACjBC,SAAiB,EACjBC,CAAkC,EAClCC,GAAW,KACA;EACX,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAACJ,SAAS,CAAC;EAEhC,MAAMK,GAAG,GAAGF,IAAI,CAACG,OAAO,CAAC,CAAC;EAC1B,MAAMC,KAAK,GAAGN,CAAC,CAAC,qCAAqC,EAAE;IACrDO,aAAa,EAAE;EACjB,CAAC,CAAC,CAACL,IAAI,CAACM,QAAQ,CAAC,CAAC,CAAC;EACnB,MAAMC,IAAI,GAAGP,IAAI,CAACQ,WAAW,CAAC,CAAC;EAC/B,MAAMC,UAAU,GAAGF,IAAI,GAAG,IAAIN,IAAI,CAAC,CAAC,CAACO,WAAW,CAAC,CAAC;EAElD,IAAIT,GAAG,KAAK,IAAI,EAAE,UAAAW,MAAA,CAAUR,GAAG,OAAAQ,MAAA,CAAIN,KAAK,EAAAM,MAAA,CAAGD,UAAU,OAAAC,MAAA,CAAOH,IAAI,IAAK,EAAE;EACvE,UAAAG,MAAA,CAAUN,KAAK,OAAAM,MAAA,CAAIR,GAAG,EAAAQ,MAAA,CAAGD,UAAU,QAAAC,MAAA,CAAQH,IAAI,IAAK,EAAE;AACxD,CAAC;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEajB,UAAU"}
|
|
@@ -9,7 +9,7 @@ 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
|
|
12
|
+
var _getError = _interopRequireDefault(require("../../utils/getError"));
|
|
13
13
|
var _templateObject;
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
@@ -23,7 +23,7 @@ const ErrorResult = _ref => {
|
|
|
23
23
|
} = (0, _reactI18next.useTranslation)(['common']);
|
|
24
24
|
return /*#__PURE__*/_react.default.createElement(StyledResult, {
|
|
25
25
|
title: t('common:errorTitle'),
|
|
26
|
-
description: (0,
|
|
26
|
+
description: (0, _getError.default)(error).message,
|
|
27
27
|
icon: /*#__PURE__*/_react.default.createElement(_icons.CloseCircle, null)
|
|
28
28
|
});
|
|
29
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorResult.js","names":["_react","_interopRequireDefault","require","_icons","_core","_reactI18next","_styled","
|
|
1
|
+
{"version":3,"file":"ErrorResult.js","names":["_react","_interopRequireDefault","require","_icons","_core","_reactI18next","_styled","_getError","_templateObject","obj","__esModule","default","_taggedTemplateLiteral","strings","raw","slice","Object","freeze","defineProperties","value","StyledResult","styled","Result","ErrorResult","_ref","error","t","useTranslation","createElement","title","description","getError","message","icon","CloseCircle","_default","exports"],"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 getError from '../../utils/getError';\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={getError(error).message}\n icon={<CloseCircle />}\n />\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B,OAAA,GAEaY,WAAW"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const DEFAULT_CODE = 'no_code';
|
|
8
|
+
const DEFAULT_MESSAGE = 'Error';
|
|
9
|
+
const isObject = value => typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
10
|
+
const isData = value => isObject(value) && Object.values(value).every(constraint => isObject(constraint) && 'code' in constraint && typeof constraint.code === 'string' && 'message' in constraint && typeof constraint.message === 'string');
|
|
11
|
+
const getError = error => {
|
|
12
|
+
// Trying to find the message of an error
|
|
13
|
+
if (!isObject(error) || !('message' in error) || typeof error.message !== 'string') {
|
|
14
|
+
return {
|
|
15
|
+
code: DEFAULT_CODE,
|
|
16
|
+
message: DEFAULT_MESSAGE
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Trying to find the first GraphQL error
|
|
21
|
+
if (!('source' in error) || !isObject(error.source) || !('errors' in error.source) || !Array.isArray(error.source.errors) || error.source.errors.length === 0) {
|
|
22
|
+
return {
|
|
23
|
+
code: DEFAULT_CODE,
|
|
24
|
+
message: error.message
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const firstError = error.source.errors[0];
|
|
28
|
+
|
|
29
|
+
// Trying to find the message of the GraphQL error
|
|
30
|
+
if (!isObject(firstError) || !('message' in firstError) || typeof firstError.message !== 'string') {
|
|
31
|
+
return {
|
|
32
|
+
code: DEFAULT_CODE,
|
|
33
|
+
message: error.message
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Trying to find the code of the GraphQL message
|
|
38
|
+
if (!('extensions' in firstError) || !isObject(firstError.extensions) || !('code' in firstError.extensions) || typeof firstError.extensions.code !== 'string') {
|
|
39
|
+
return {
|
|
40
|
+
code: DEFAULT_CODE,
|
|
41
|
+
message: firstError.message
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Trying to find the data in the GraphQL message
|
|
46
|
+
if (!('data' in firstError.extensions) || !isData(firstError.extensions.data)) {
|
|
47
|
+
return {
|
|
48
|
+
code: firstError.extensions.code,
|
|
49
|
+
message: firstError.message
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
code: firstError.extensions.code,
|
|
54
|
+
message: firstError.message,
|
|
55
|
+
data: firstError.extensions.data
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
var _default = exports.default = getError;
|
|
59
|
+
//# sourceMappingURL=getError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getError.js","names":["DEFAULT_CODE","DEFAULT_MESSAGE","isObject","value","Array","isArray","isData","Object","values","every","constraint","code","message","getError","error","source","errors","length","firstError","extensions","data","_default","exports","default"],"sources":["../../../src/lib/utils/getError.ts"],"sourcesContent":["interface Constraint {\n code: string;\n message: string;\n}\n\ninterface ErrorObject {\n code: string;\n message: string;\n data?: Record<string, Constraint>;\n}\n\nconst DEFAULT_CODE = 'no_code';\nconst DEFAULT_MESSAGE = 'Error';\n\nconst isObject = (value: unknown): value is object =>\n typeof value === 'object' && !Array.isArray(value) && value !== null;\n\nconst isData = (value: unknown): value is Record<string, Constraint> =>\n isObject(value) &&\n Object.values(value).every(\n (constraint: unknown) =>\n isObject(constraint) &&\n 'code' in constraint &&\n typeof constraint.code === 'string' &&\n 'message' in constraint &&\n typeof constraint.message === 'string'\n );\n\nconst getError = (error: unknown): ErrorObject => {\n // Trying to find the message of an error\n if (\n !isObject(error) ||\n !('message' in error) ||\n typeof error.message !== 'string'\n ) {\n return {\n code: DEFAULT_CODE,\n message: DEFAULT_MESSAGE,\n };\n }\n\n // Trying to find the first GraphQL error\n if (\n !('source' in error) ||\n !isObject(error.source) ||\n !('errors' in error.source) ||\n !Array.isArray(error.source.errors) ||\n error.source.errors.length === 0\n ) {\n return {\n code: DEFAULT_CODE,\n message: error.message,\n };\n }\n\n const firstError = error.source.errors[0] as unknown;\n\n // Trying to find the message of the GraphQL error\n if (\n !isObject(firstError) ||\n !('message' in firstError) ||\n typeof firstError.message !== 'string'\n ) {\n return {\n code: DEFAULT_CODE,\n message: error.message,\n };\n }\n\n // Trying to find the code of the GraphQL message\n if (\n !('extensions' in firstError) ||\n !isObject(firstError.extensions) ||\n !('code' in firstError.extensions) ||\n typeof firstError.extensions.code !== 'string'\n ) {\n return {\n code: DEFAULT_CODE,\n message: firstError.message,\n };\n }\n\n // Trying to find the data in the GraphQL message\n if (\n !('data' in firstError.extensions) ||\n !isData(firstError.extensions.data)\n ) {\n return {\n code: firstError.extensions.code,\n message: firstError.message,\n };\n }\n\n return {\n code: firstError.extensions.code,\n message: firstError.message,\n data: firstError.extensions.data,\n };\n};\n\nexport default getError;\n"],"mappings":";;;;;;AAWA,MAAMA,YAAY,GAAG,SAAS;AAC9B,MAAMC,eAAe,GAAG,OAAO;AAE/B,MAAMC,QAAQ,GAAIC,KAAc,IAC9B,OAAOA,KAAK,KAAK,QAAQ,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,IAAIA,KAAK,KAAK,IAAI;AAEtE,MAAMG,MAAM,GAAIH,KAAc,IAC5BD,QAAQ,CAACC,KAAK,CAAC,IACfI,MAAM,CAACC,MAAM,CAACL,KAAK,CAAC,CAACM,KAAK,CACvBC,UAAmB,IAClBR,QAAQ,CAACQ,UAAU,CAAC,IACpB,MAAM,IAAIA,UAAU,IACpB,OAAOA,UAAU,CAACC,IAAI,KAAK,QAAQ,IACnC,SAAS,IAAID,UAAU,IACvB,OAAOA,UAAU,CAACE,OAAO,KAAK,QAClC,CAAC;AAEH,MAAMC,QAAQ,GAAIC,KAAc,IAAkB;EAChD;EACA,IACE,CAACZ,QAAQ,CAACY,KAAK,CAAC,IAChB,EAAE,SAAS,IAAIA,KAAK,CAAC,IACrB,OAAO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AI,EAAEO,UAAU,CAACC,UAAU,CAACR,IAAI;MAChCC,OAAO,EAAEM,UAAU,CAACN;IACtB,CAAC;EACH;EAEA,OAAO;IACLD,IAAI,EAAEO,UAAU,CAACC,UAAU,CAACR,IAAI;IAChCC,OAAO,EAAEM,UAAU,CAACN,OAAO;IAC3BQ,IAAI,EAAEF,UAAU,CAACC,UAAU,CAACC;EAC9B,CAAC;AACH,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaV,QAAQ"}
|
|
@@ -3,37 +3,22 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const getErrorConstraints = error => {
|
|
11
|
-
const e = error;
|
|
12
|
-
if (!e.source || !Array.isArray(e.source.errors) || e.source.errors.length === 0 || !e.source.errors[0].extensions || !e.source.errors[0].extensions.code) {
|
|
13
|
-
return NO_CONSTRAINTS;
|
|
14
|
-
}
|
|
15
|
-
if (e.source.errors[0].extensions.code !== 'BAD_ARGUMENTS') {
|
|
16
|
-
return NO_CONSTRAINTS;
|
|
17
|
-
}
|
|
18
|
-
return e.source.errors[0].extensions.constraints;
|
|
19
|
-
};
|
|
20
|
-
exports.getErrorConstraints = getErrorConstraints;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _getError = _interopRequireDefault(require("./getError"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
10
|
const handleFormErrors = (form, error) => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let [fieldName, {
|
|
31
|
-
message
|
|
32
|
-
}] = _ref;
|
|
33
|
-
form.errors.set(fieldName, message);
|
|
11
|
+
const {
|
|
12
|
+
message,
|
|
13
|
+
data
|
|
14
|
+
} = (0, _getError.default)(error);
|
|
15
|
+
if (data) {
|
|
16
|
+
Object.entries(data).forEach(_ref => {
|
|
17
|
+
let [key, constraint] = _ref;
|
|
18
|
+
form.errors.set(key, constraint.message);
|
|
34
19
|
});
|
|
35
20
|
} else {
|
|
36
|
-
form.errors.set('_error',
|
|
21
|
+
form.errors.set('_error', message);
|
|
37
22
|
}
|
|
38
23
|
};
|
|
39
24
|
var _default = exports.default = handleFormErrors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleFormErrors.js","names":["
|
|
1
|
+
{"version":3,"file":"handleFormErrors.js","names":["_getError","_interopRequireDefault","require","obj","__esModule","default","handleFormErrors","form","error","message","data","getError","Object","entries","forEach","_ref","key","constraint","errors","set","_default","exports"],"sources":["../../../src/lib/utils/handleFormErrors.ts"],"sourcesContent":["import { Form } from '@os-design/form';\nimport getError from './getError';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst handleFormErrors = (form: Form<any>, error: unknown): void => {\n const { message, data } = getError(error);\n if (data) {\n Object.entries(data).forEach(([key, constraint]) => {\n form.errors.set(key, constraint.message);\n });\n } else {\n form.errors.set('_error', message);\n }\n};\n\nexport default handleFormErrors;\n"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAkC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAElC;AACA,MAAMG,gBAAgB,GAAGA,CAACC,IAAe,EAAEC,KAAc,KAAW;EAClE,MAAM;IAAEC,OAAO;IAAEC;EAAK,CAAC,GAAG,IAAAC,iBAAQ,EAACH,KAAK,CAAC;EACzC,IAAIE,IAAI,EAAE;IACRE,MAAM,CAACC,OAAO,CAACH,IAAI,CAAC,CAACI,OAAO,CAACC,IAAA,IAAuB;MAAA,IAAtB,CAACC,GAAG,EAAEC,UAAU,CAAC,GAAAF,IAAA;MAC7CR,IAAI,CAACW,MAAM,CAACC,GAAG,CAACH,GAAG,EAAEC,UAAU,CAACR,OAAO,CAAC;IAC1C,CAAC,CAAC;EACJ,CAAC,MAAM;IACLF,IAAI,CAACW,MAAM,CAACC,GAAG,CAAC,QAAQ,EAAEV,OAAO,CAAC;EACpC;AACF,CAAC;AAAC,IAAAW,QAAA,GAAAC,OAAA,CAAAhB,OAAA,GAEaC,gBAAgB"}
|
|
@@ -5,7 +5,7 @@ import { clr } from '@os-design/theming';
|
|
|
5
5
|
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
7
|
import { useMutation } from 'react-relay/hooks';
|
|
8
|
-
import
|
|
8
|
+
import getError from '../../utils/getError';
|
|
9
9
|
import ProfileButton from './ProfileButton';
|
|
10
10
|
import { useProfile } from './ProfileContext';
|
|
11
11
|
import ProfileUpdateNameModal from './ProfileUpdateNameModal';
|
|
@@ -56,7 +56,7 @@ const DeleteAvatarButton = () => {
|
|
|
56
56
|
avatar: null
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
-
onError:
|
|
59
|
+
onError: e => message.error(getError(e).message),
|
|
60
60
|
onCompleted: () => {
|
|
61
61
|
message.success(t('profile:updated'));
|
|
62
62
|
}
|
|
@@ -90,7 +90,7 @@ const UpdateAvatarButton = ({
|
|
|
90
90
|
uploadables: {
|
|
91
91
|
avatar: file
|
|
92
92
|
},
|
|
93
|
-
onError: error => message.error(
|
|
93
|
+
onError: error => message.error(getError(error).message),
|
|
94
94
|
onCompleted: () => {
|
|
95
95
|
message.success(t('profile:updated'));
|
|
96
96
|
}
|
|
@@ -144,7 +144,7 @@ const SignOutButton = () => {
|
|
|
144
144
|
const handler = useCallback(() => {
|
|
145
145
|
commit({
|
|
146
146
|
variables: {},
|
|
147
|
-
onError:
|
|
147
|
+
onError: e => message.error(getError(e).message),
|
|
148
148
|
onCompleted: () => {
|
|
149
149
|
window.location.href = '/auth/';
|
|
150
150
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileDrawerContent.js","names":["styled","ThemeSwitcher","message","clr","React","useCallback","useMemo","useRef","useState","useTranslation","useMutation","getErrorMessage","ProfileButton","useProfile","ProfileUpdateNameModal","ProfileUpdatePasswordModal","UserAvatar","AvatarContainer","div","UserContent","FullName","p","theme","sizes","large","Email","inputColorPlaceholder","ActionsContainer","Footer","HiddenInput","input","query","_ProfileDrawerContentUpdateAvatarMutation","require","hash","console","error","DeleteAvatarButton","t","commit","loading","handler","variables","avatar","onError","onCompleted","success","createElement","onClick","UpdateAvatarButton","hasAvatar","fileInputRef","e","target","files","file","uploadables","Fragment","current","value","click","type","accept","onChange","ref","UpdateNameButton","hasName","modalVisible","setModalVisible","visible","onClose","ChangePasswordButton","SignOutButton","_ProfileDrawerContentSignOutMutation","window","location","href","danger","ProfileDrawerContent","actions","children","email","firstName","lastName","fullName","filter","i","join","size"],"sources":["../../../../src/lib/components/profile/ProfileDrawerContent.tsx"],"sourcesContent":["import styled from '@emotion/styled';\nimport { ThemeSwitcher, message } from '@os-design/core';\nimport { clr } from '@os-design/theming';\nimport { graphql } from 'babel-plugin-relay/macro';\nimport React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { useMutation } from 'react-relay/hooks';\nimport getErrorMessage from '../../utils/getErrorMessage';\nimport ProfileButton from './ProfileButton';\nimport { useProfile } from './ProfileContext';\nimport ProfileUpdateNameModal from './ProfileUpdateNameModal';\nimport ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';\nimport UserAvatar from './UserAvatar';\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 query = 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>(query);\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>(query);\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 [modalVisible, setModalVisible] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisible(true)}>\n {t(`profile:${hasName ? 'changeName' : 'setName'}`)}\n </ProfileButton>\n\n <ProfileUpdateNameModal\n visible={modalVisible}\n onClose={() => setModalVisible(false)}\n />\n </>\n );\n};\n\nconst ChangePasswordButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n const [modalVisible, setModalVisible] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisible(true)}>\n {t('profile:changePassword')}\n </ProfileButton>\n\n <ProfileUpdatePasswordModal\n visible={modalVisible}\n onClose={() => setModalVisible(false)}\n />\n </>\n );\n};\n\nconst SignOutButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n\n const [commit, loading] = useMutation<ProfileDrawerContentSignOutMutation>(\n graphql`\n mutation ProfileDrawerContentSignOutMutation {\n signOut {\n ok\n }\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,MAAM,MAAM,iBAAiB;AACpC,SAASC,aAAa,EAAEC,OAAO,QAAQ,iBAAiB;AACxD,SAASC,GAAG,QAAQ,oBAAoB;AAExC,OAAOC,KAAK,IAAIC,WAAW,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACrE,SAASC,cAAc,QAAQ,eAAe;AAC9C,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,eAAe,MAAM,6BAA6B;AACzD,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,OAAOC,sBAAsB,MAAM,0BAA0B;AAC7D,OAAOC,0BAA0B,MAAM,8BAA8B;AACrE,OAAOC,UAAU,MAAM,cAAc;AAgBrC,MAAMC,eAAe,GAAGjB,MAAM,CAACkB,GAAI;AACnC;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAGnB,MAAM,CAACkB,GAAI;AAC/B;AACA,CAAC;AAED,MAAME,QAAQ,GAAGpB,MAAM,CAACkB,GAAI;AAC5B,eAAgBG,CAAC,IAAKA,CAAC,CA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xB,KAAA,CAAA2C,aAAA,CAAC9C,aAAa,MAAE,CACV,CACR,CAAC;AAEP,CAAC;AAED,eAAe6E,oBAAoB"}
|
|
1
|
+
{"version":3,"file":"ProfileDrawerContent.js","names":["styled","ThemeSwitcher","message","clr","React","useCallback","useMemo","useRef","useState","useTranslation","useMutation","getError","ProfileButton","useProfile","ProfileUpdateNameModal","ProfileUpdatePasswordModal","UserAvatar","AvatarContainer","div","UserContent","FullName","p","theme","sizes","large","Email","inputColorPlaceholder","ActionsContainer","Footer","HiddenInput","input","query","_ProfileDrawerContentUpdateAvatarMutation","require","hash","console","error","DeleteAvatarButton","t","commit","loading","handler","variables","avatar","onError","e","onCompleted","success","createElement","onClick","UpdateAvatarButton","hasAvatar","fileInputRef","target","files","file","uploadables","Fragment","current","value","click","type","accept","onChange","ref","UpdateNameButton","hasName","modalVisible","setModalVisible","visible","onClose","ChangePasswordButton","SignOutButton","_ProfileDrawerContentSignOutMutation","window","location","href","danger","ProfileDrawerContent","actions","children","email","firstName","lastName","fullName","filter","i","join","size"],"sources":["../../../../src/lib/components/profile/ProfileDrawerContent.tsx"],"sourcesContent":["import styled from '@emotion/styled';\nimport { ThemeSwitcher, message } from '@os-design/core';\nimport { clr } from '@os-design/theming';\nimport { graphql } from 'babel-plugin-relay/macro';\nimport React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { useMutation } from 'react-relay/hooks';\nimport getError from '../../utils/getError';\nimport ProfileButton from './ProfileButton';\nimport { useProfile } from './ProfileContext';\nimport ProfileUpdateNameModal from './ProfileUpdateNameModal';\nimport ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';\nimport UserAvatar from './UserAvatar';\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 query = 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>(query);\n\n const handler = useCallback(() => {\n commit({\n variables: {\n input: { avatar: null },\n },\n onError: (e) => message.error(getError(e).message),\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>(query);\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(getError(error).message),\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 [modalVisible, setModalVisible] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisible(true)}>\n {t(`profile:${hasName ? 'changeName' : 'setName'}`)}\n </ProfileButton>\n\n <ProfileUpdateNameModal\n visible={modalVisible}\n onClose={() => setModalVisible(false)}\n />\n </>\n );\n};\n\nconst ChangePasswordButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n const [modalVisible, setModalVisible] = useState(false);\n\n return (\n <>\n <ProfileButton onClick={() => setModalVisible(true)}>\n {t('profile:changePassword')}\n </ProfileButton>\n\n <ProfileUpdatePasswordModal\n visible={modalVisible}\n onClose={() => setModalVisible(false)}\n />\n </>\n );\n};\n\nconst SignOutButton: React.FC = () => {\n const { t } = useTranslation(['profile']);\n\n const [commit, loading] = useMutation<ProfileDrawerContentSignOutMutation>(\n graphql`\n mutation ProfileDrawerContentSignOutMutation {\n signOut {\n ok\n }\n }\n `\n );\n\n const handler = useCallback(() => {\n commit({\n variables: {},\n onError: (e) => message.error(getError(e).message),\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,MAAM,MAAM,iBAAiB;AACpC,SAASC,aAAa,EAAEC,OAAO,QAAQ,iBAAiB;AACxD,SAASC,GAAG,QAAQ,oBAAoB;AAExC,OAAOC,KAAK,IAAIC,WAAW,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACrE,SAASC,cAAc,QAAQ,eAAe;AAC9C,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,OAAOC,QAAQ,MAAM,sBAAsB;AAC3C,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,OAAOC,sBAAsB,MAAM,0BAA0B;AAC7D,OAAOC,0BAA0B,MAAM,8BAA8B;AACrE,OAAOC,UAAU,MAAM,cAAc;AAgBrC,MAAMC,eAAe,GAAGjB,MAAM,CAACkB,GAAI;AACnC;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,WAAW,GAAGnB,MAAM,CAACkB,GAAI;AAC/B;AACA,CAAC;AAED,MAAME,QAAQ,GAAGpB,MAAM,CAACkB,GAAI;AAC5B,eAAgBG,CAAC,IAAKA,CAAC,CAACC,KAAK,CAAC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CAAA4C,aAAA,CAACpB,MAAM,qBACLxB,KAAA,CAAA4C,aAAA,CAAC/C,aAAa,MAAE,CACV,CACR,CAAC;AAEP,CAAC;AAED,eAAe6E,oBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatDate.js","names":["formatDate","timestamp","t","lng","date","Date","day","getDate","month","returnObjects","getMonth","year","getFullYear","isPrevYear"],"sources":["../../../../src/lib/components/session/formatDate.ts"],"sourcesContent":["import { TFunction } from 'i18next';\n\nconst formatDate = (\n timestamp: number,\n t: TFunction<
|
|
1
|
+
{"version":3,"file":"formatDate.js","names":["formatDate","timestamp","t","lng","date","Date","day","getDate","month","returnObjects","getMonth","year","getFullYear","isPrevYear"],"sources":["../../../../src/lib/components/session/formatDate.ts"],"sourcesContent":["import { Namespace, TFunction } from 'i18next';\n\nconst formatDate = (\n timestamp: number,\n t: TFunction<Namespace, undefined>,\n lng: string\n): string => {\n const date = new Date(timestamp);\n\n const day = date.getDate();\n const month = t('profile:sessions.monthAbbreviations', {\n returnObjects: true,\n })[date.getMonth()];\n const year = date.getFullYear();\n const isPrevYear = year < new Date().getFullYear();\n\n if (lng === 'ru') return `${day} ${month}${isPrevYear ? ` ${year}` : ''}`;\n return `${month} ${day}${isPrevYear ? `, ${year}` : ''}`;\n};\n\nexport default formatDate;\n"],"mappings":"AAEA,MAAMA,UAAU,GAAGA,CACjBC,SAAiB,EACjBC,CAAkC,EAClCC,GAAW,KACA;EACX,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAACJ,SAAS,CAAC;EAEhC,MAAMK,GAAG,GAAGF,IAAI,CAACG,OAAO,CAAC,CAAC;EAC1B,MAAMC,KAAK,GAAGN,CAAC,CAAC,qCAAqC,EAAE;IACrDO,aAAa,EAAE;EACjB,CAAC,CAAC,CAACL,IAAI,CAACM,QAAQ,CAAC,CAAC,CAAC;EACnB,MAAMC,IAAI,GAAGP,IAAI,CAACQ,WAAW,CAAC,CAAC;EAC/B,MAAMC,UAAU,GAAGF,IAAI,GAAG,IAAIN,IAAI,CAAC,CAAC,CAACO,WAAW,CAAC,CAAC;EAElD,IAAIT,GAAG,KAAK,IAAI,EAAE,OAAQ,GAAEG,GAAI,IAAGE,KAAM,GAAEK,UAAU,GAAI,IAAGF,IAAK,EAAC,GAAG,EAAG,EAAC;EACzE,OAAQ,GAAEH,KAAM,IAAGF,GAAI,GAAEO,UAAU,GAAI,KAAIF,IAAK,EAAC,GAAG,EAAG,EAAC;AAC1D,CAAC;AAED,eAAeX,UAAU"}
|
|
@@ -3,7 +3,7 @@ import { CloseCircle } from '@os-design/icons';
|
|
|
3
3
|
import { Result } from '@os-design/core';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import styled from '@emotion/styled';
|
|
6
|
-
import
|
|
6
|
+
import getError from '../../utils/getError';
|
|
7
7
|
const StyledResult = styled(Result)`
|
|
8
8
|
margin: 0 1em;
|
|
9
9
|
`;
|
|
@@ -15,7 +15,7 @@ const ErrorResult = ({
|
|
|
15
15
|
} = useTranslation(['common']);
|
|
16
16
|
return /*#__PURE__*/React.createElement(StyledResult, {
|
|
17
17
|
title: t('common:errorTitle'),
|
|
18
|
-
description:
|
|
18
|
+
description: getError(error).message,
|
|
19
19
|
icon: /*#__PURE__*/React.createElement(CloseCircle, null)
|
|
20
20
|
});
|
|
21
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorResult.js","names":["React","CloseCircle","Result","useTranslation","styled","
|
|
1
|
+
{"version":3,"file":"ErrorResult.js","names":["React","CloseCircle","Result","useTranslation","styled","getError","StyledResult","ErrorResult","error","t","createElement","title","description","message","icon"],"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 getError from '../../utils/getError';\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={getError(error).message}\n icon={<CloseCircle />}\n />\n );\n};\n\nexport default ErrorResult;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,MAAM,QAAQ,iBAAiB;AACxC,SAASC,cAAc,QAAQ,eAAe;AAC9C,OAAOC,MAAM,MAAM,iBAAiB;AACpC,OAAOC,QAAQ,MAAM,sBAAsB;AAM3C,MAAMC,YAAY,GAAGF,MAAM,CAACF,MAAM,CAAE;AACpC;AACA,CAAC;AAED,MAAMK,WAAuC,GAAGA,CAAC;EAAEC;AAAM,CAAC,KAAK;EAC7D,MAAM;IAAEC;EAAE,CAAC,GAAGN,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC;EAExC,oBACEH,KAAA,CAAAU,aAAA,CAACJ,YAAY;IACXK,KAAK,EAAEF,CAAC,CAAC,mBAAmB,CAAE;IAC9BG,WAAW,EAAEP,QAAQ,CAACG,KAAK,CAAC,CAACK,OAAQ;IACrCC,IAAI,eAAEd,KAAA,CAAAU,aAAA,CAACT,WAAW,MAAE;EAAE,CACvB,CAAC;AAEN,CAAC;AAED,eAAeM,WAAW"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const DEFAULT_CODE = 'no_code';
|
|
2
|
+
const DEFAULT_MESSAGE = 'Error';
|
|
3
|
+
const isObject = value => typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
4
|
+
const isData = value => isObject(value) && Object.values(value).every(constraint => isObject(constraint) && 'code' in constraint && typeof constraint.code === 'string' && 'message' in constraint && typeof constraint.message === 'string');
|
|
5
|
+
const getError = error => {
|
|
6
|
+
// Trying to find the message of an error
|
|
7
|
+
if (!isObject(error) || !('message' in error) || typeof error.message !== 'string') {
|
|
8
|
+
return {
|
|
9
|
+
code: DEFAULT_CODE,
|
|
10
|
+
message: DEFAULT_MESSAGE
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Trying to find the first GraphQL error
|
|
15
|
+
if (!('source' in error) || !isObject(error.source) || !('errors' in error.source) || !Array.isArray(error.source.errors) || error.source.errors.length === 0) {
|
|
16
|
+
return {
|
|
17
|
+
code: DEFAULT_CODE,
|
|
18
|
+
message: error.message
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const firstError = error.source.errors[0];
|
|
22
|
+
|
|
23
|
+
// Trying to find the message of the GraphQL error
|
|
24
|
+
if (!isObject(firstError) || !('message' in firstError) || typeof firstError.message !== 'string') {
|
|
25
|
+
return {
|
|
26
|
+
code: DEFAULT_CODE,
|
|
27
|
+
message: error.message
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Trying to find the code of the GraphQL message
|
|
32
|
+
if (!('extensions' in firstError) || !isObject(firstError.extensions) || !('code' in firstError.extensions) || typeof firstError.extensions.code !== 'string') {
|
|
33
|
+
return {
|
|
34
|
+
code: DEFAULT_CODE,
|
|
35
|
+
message: firstError.message
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Trying to find the data in the GraphQL message
|
|
40
|
+
if (!('data' in firstError.extensions) || !isData(firstError.extensions.data)) {
|
|
41
|
+
return {
|
|
42
|
+
code: firstError.extensions.code,
|
|
43
|
+
message: firstError.message
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
code: firstError.extensions.code,
|
|
48
|
+
message: firstError.message,
|
|
49
|
+
data: firstError.extensions.data
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export default getError;
|
|
53
|
+
//# sourceMappingURL=getError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getError.js","names":["DEFAULT_CODE","DEFAULT_MESSAGE","isObject","value","Array","isArray","isData","Object","values","every","constraint","code","message","getError","error","source","errors","length","firstError","extensions","data"],"sources":["../../../src/lib/utils/getError.ts"],"sourcesContent":["interface Constraint {\n code: string;\n message: string;\n}\n\ninterface ErrorObject {\n code: string;\n message: string;\n data?: Record<string, Constraint>;\n}\n\nconst DEFAULT_CODE = 'no_code';\nconst DEFAULT_MESSAGE = 'Error';\n\nconst isObject = (value: unknown): value is object =>\n typeof value === 'object' && !Array.isArray(value) && value !== null;\n\nconst isData = (value: unknown): value is Record<string, Constraint> =>\n isObject(value) &&\n Object.values(value).every(\n (constraint: unknown) =>\n isObject(constraint) &&\n 'code' in constraint &&\n typeof constraint.code === 'string' &&\n 'message' in constraint &&\n typeof constraint.message === 'string'\n );\n\nconst getError = (error: unknown): ErrorObject => {\n // Trying to find the message of an error\n if (\n !isObject(error) ||\n !('message' in error) ||\n typeof error.message !== 'string'\n ) {\n return {\n code: DEFAULT_CODE,\n message: DEFAULT_MESSAGE,\n };\n }\n\n // Trying to find the first GraphQL error\n if (\n !('source' in error) ||\n !isObject(error.source) ||\n !('errors' in error.source) ||\n !Array.isArray(error.source.errors) ||\n error.source.errors.length === 0\n ) {\n return {\n code: DEFAULT_CODE,\n message: error.message,\n };\n }\n\n const firstError = error.source.errors[0] as unknown;\n\n // Trying to find the message of the GraphQL error\n if (\n !isObject(firstError) ||\n !('message' in firstError) ||\n typeof firstError.message !== 'string'\n ) {\n return {\n code: DEFAULT_CODE,\n message: error.message,\n };\n }\n\n // Trying to find the code of the GraphQL message\n if (\n !('extensions' in firstError) ||\n !isObject(firstError.extensions) ||\n !('code' in firstError.extensions) ||\n typeof firstError.extensions.code !== 'string'\n ) {\n return {\n code: DEFAULT_CODE,\n message: firstError.message,\n };\n }\n\n // Trying to find the data in the GraphQL message\n if (\n !('data' in firstError.extensions) ||\n !isData(firstError.extensions.data)\n ) {\n return {\n code: firstError.extensions.code,\n message: firstError.message,\n };\n }\n\n return {\n code: firstError.extensions.code,\n message: firstError.message,\n data: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CAACC,MAAM,CAAC,CAAC,CAAY;;EAEpD;EACA,IACE,CAACd,QAAQ,CAACgB,UAAU,CAAC,IACrB,EAAE,SAAS,IAAIA,UAAU,CAAC,IAC1B,OAAOA,UAAU,CAACN,OAAO,KAAK,QAAQ,EACtC;IACA,OAAO;MACLD,IAAI,EAAEX,YAAY;MAClBY,OAAO,EAAEE,KAAK,CAACF;IACjB,CAAC;EACH;;EAEA;EACA,IACE,EAAE,YAAY,IAAIM,UAAU,CAAC,IAC7B,CAAChB,QAAQ,CAACgB,UAAU,CAACC,UAAU,CAAC,IAChC,EAAE,MAAM,IAAID,UAAU,CAACC,UAAU,CAAC,IAClC,OAAOD,UAAU,CAACC,UAAU,CAACR,IAAI,KAAK,QAAQ,EAC9C;IACA,OAAO;MACLA,IAAI,EAAEX,YAAY;MAClBY,OAAO,EAAEM,UAAU,CAACN;IACtB,CAAC;EACH;;EAEA;EACA,IACE,EAAE,MAAM,IAAIM,UAAU,CAACC,UAAU,CAAC,IAClC,CAACb,MAAM,CAACY,UAAU,CAACC,UAAU,CAACC,IAAI,CAAC,EACnC;IACA,OAAO;MACLT,IAAI,EAAEO,UAAU,CAACC,UAAU,CAACR,IAAI;MAChCC,OAAO,EAAEM,UAAU,CAACN;IACtB,CAAC;EACH;EAEA,OAAO;IACLD,IAAI,EAAEO,UAAU,CAACC,UAAU,CAACR,IAAI;IAChCC,OAAO,EAAEM,UAAU,CAACN,OAAO;IAC3BQ,IAAI,EAAEF,UAAU,CAACC,UAAU,CAACC;EAC9B,CAAC;AACH,CAAC;AAED,eAAeP,QAAQ"}
|
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import getError from './getError';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export const getErrorConstraints = error => {
|
|
5
|
-
const e = error;
|
|
6
|
-
if (!e.source || !Array.isArray(e.source.errors) || e.source.errors.length === 0 || !e.source.errors[0].extensions || !e.source.errors[0].extensions.code) {
|
|
7
|
-
return NO_CONSTRAINTS;
|
|
8
|
-
}
|
|
9
|
-
if (e.source.errors[0].extensions.code !== 'BAD_ARGUMENTS') {
|
|
10
|
-
return NO_CONSTRAINTS;
|
|
11
|
-
}
|
|
12
|
-
return e.source.errors[0].extensions.constraints;
|
|
13
|
-
};
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
4
|
const handleFormErrors = (form, error) => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Object.entries(constraints).forEach(([fieldName, {
|
|
23
|
-
message
|
|
24
|
-
}]) => {
|
|
25
|
-
form.errors.set(fieldName, message);
|
|
5
|
+
const {
|
|
6
|
+
message,
|
|
7
|
+
data
|
|
8
|
+
} = getError(error);
|
|
9
|
+
if (data) {
|
|
10
|
+
Object.entries(data).forEach(([key, constraint]) => {
|
|
11
|
+
form.errors.set(key, constraint.message);
|
|
26
12
|
});
|
|
27
13
|
} else {
|
|
28
|
-
form.errors.set('_error',
|
|
14
|
+
form.errors.set('_error', message);
|
|
29
15
|
}
|
|
30
16
|
};
|
|
31
17
|
export default handleFormErrors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleFormErrors.js","names":["
|
|
1
|
+
{"version":3,"file":"handleFormErrors.js","names":["getError","handleFormErrors","form","error","message","data","Object","entries","forEach","key","constraint","errors","set"],"sources":["../../../src/lib/utils/handleFormErrors.ts"],"sourcesContent":["import { Form } from '@os-design/form';\nimport getError from './getError';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst handleFormErrors = (form: Form<any>, error: unknown): void => {\n const { message, data } = getError(error);\n if (data) {\n Object.entries(data).forEach(([key, constraint]) => {\n form.errors.set(key, constraint.message);\n });\n } else {\n form.errors.set('_error', message);\n }\n};\n\nexport default handleFormErrors;\n"],"mappings":"AACA,OAAOA,QAAQ,MAAM,YAAY;;AAEjC;AACA,MAAMC,gBAAgB,GAAGA,CAACC,IAAe,EAAEC,KAAc,KAAW;EAClE,MAAM;IAAEC,OAAO;IAAEC;EAAK,CAAC,GAAGL,QAAQ,CAACG,KAAK,CAAC;EACzC,IAAIE,IAAI,EAAE;IACRC,MAAM,CAACC,OAAO,CAACF,IAAI,CAAC,CAACG,OAAO,CAAC,CAAC,CAACC,GAAG,EAAEC,UAAU,CAAC,KAAK;MAClDR,IAAI,CAACS,MAAM,CAACC,GAAG,CAACH,GAAG,EAAEC,UAAU,CAACN,OAAO,CAAC;IAC1C,CAAC,CAAC;EACJ,CAAC,MAAM;IACLF,IAAI,CAACS,MAAM,CAACC,GAAG,CAAC,QAAQ,EAAER,OAAO,CAAC;EACpC;AACF,CAAC;AAED,eAAeH,gBAAgB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TFunction } from 'i18next';
|
|
2
|
-
declare const formatDate: (timestamp: number, t: TFunction<
|
|
1
|
+
import { Namespace, TFunction } from 'i18next';
|
|
2
|
+
declare const formatDate: (timestamp: number, t: TFunction<Namespace, undefined>, lng: string) => string;
|
|
3
3
|
export default formatDate;
|
|
4
4
|
//# sourceMappingURL=formatDate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatDate.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/session/formatDate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"formatDate.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/session/formatDate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE/C,QAAA,MAAM,UAAU,cACH,MAAM,KACd,UAAU,SAAS,EAAE,SAAS,CAAC,OAC7B,MAAM,KACV,MAYF,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface Constraint {
|
|
2
|
+
code: string;
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
interface ErrorObject {
|
|
6
|
+
code: string;
|
|
7
|
+
message: string;
|
|
8
|
+
data?: Record<string, Constraint>;
|
|
9
|
+
}
|
|
10
|
+
declare const getError: (error: unknown) => ErrorObject;
|
|
11
|
+
export default getError;
|
|
12
|
+
//# sourceMappingURL=getError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getError.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/getError.ts"],"names":[],"mappings":"AAAA,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACnC;AAmBD,QAAA,MAAM,QAAQ,UAAW,OAAO,KAAG,WAsElC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { Form } from '@os-design/form';
|
|
2
|
-
|
|
3
|
-
name: string;
|
|
4
|
-
message: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const getErrorConstraints: (error: Error) => Record<string, Constraint>;
|
|
7
|
-
declare const handleFormErrors: (form: Form<any>, error: Error) => void;
|
|
2
|
+
declare const handleFormErrors: (form: Form<any>, error: unknown) => void;
|
|
8
3
|
export default handleFormErrors;
|
|
9
4
|
//# sourceMappingURL=handleFormErrors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleFormErrors.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/handleFormErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAIvC,
|
|
1
|
+
{"version":3,"file":"handleFormErrors.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/handleFormErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAIvC,QAAA,MAAM,gBAAgB,SAAU,KAAK,GAAG,CAAC,SAAS,OAAO,KAAG,IAS3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@os-team/profile",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.16",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": "git@gitlab.com:os-team/libs/profile.git",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"lint-check": "eslint .",
|
|
29
29
|
"pretty": "prettier --write --ignore-unknown .",
|
|
30
30
|
"pretty-check": "prettier --check .",
|
|
31
|
-
"prepare": "husky
|
|
31
|
+
"prepare": "husky"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public",
|
|
35
35
|
"registry": "https://registry.npmjs.org"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@os-design/core": "^1.0.
|
|
39
|
-
"@os-design/form": "^1.0.
|
|
38
|
+
"@os-design/core": "^1.0.239",
|
|
39
|
+
"@os-design/form": "^1.0.72",
|
|
40
40
|
"@os-design/icons": "^1.0.56",
|
|
41
41
|
"@os-design/media": "^1.0.24",
|
|
42
42
|
"@os-design/styles": "^1.0.53",
|
|
@@ -45,58 +45,58 @@
|
|
|
45
45
|
"@os-team/plural-forms": "^1.0.12"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@babel/cli": "^7.23.
|
|
49
|
-
"@babel/core": "^7.
|
|
48
|
+
"@babel/cli": "^7.23.9",
|
|
49
|
+
"@babel/core": "^7.24.0",
|
|
50
50
|
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
|
|
51
|
-
"@babel/preset-env": "^7.
|
|
51
|
+
"@babel/preset-env": "^7.24.0",
|
|
52
52
|
"@babel/preset-react": "^7.23.3",
|
|
53
53
|
"@babel/preset-typescript": "^7.23.3",
|
|
54
|
-
"@emotion/react": "^11.11.
|
|
54
|
+
"@emotion/react": "^11.11.4",
|
|
55
55
|
"@emotion/serialize": "^1.1.3",
|
|
56
56
|
"@emotion/styled": "^11.11.0",
|
|
57
57
|
"@os-team/prettier-config": "1.1.11",
|
|
58
|
-
"@os-team/relay-network-creator": "^1.2.
|
|
59
|
-
"@os-team/relay-network-mw-upload": "^1.2.
|
|
60
|
-
"@types/jest": "^29.5.
|
|
61
|
-
"@types/node": "^20.
|
|
62
|
-
"@types/react": "^18.2.
|
|
63
|
-
"@types/react-dom": "^18.2.
|
|
64
|
-
"@types/react-relay": "^16.0.
|
|
58
|
+
"@os-team/relay-network-creator": "^1.2.19",
|
|
59
|
+
"@os-team/relay-network-mw-upload": "^1.2.18",
|
|
60
|
+
"@types/jest": "^29.5.12",
|
|
61
|
+
"@types/node": "^20.11.22",
|
|
62
|
+
"@types/react": "^18.2.60",
|
|
63
|
+
"@types/react-dom": "^18.2.19",
|
|
64
|
+
"@types/react-relay": "^16.0.6",
|
|
65
65
|
"@types/react-router-dom": "^5.3.3",
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
67
|
-
"@typescript-eslint/parser": "^
|
|
68
|
-
"babel-plugin-relay": "^16.
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
67
|
+
"@typescript-eslint/parser": "^7.1.0",
|
|
68
|
+
"babel-plugin-relay": "^16.2.0",
|
|
69
69
|
"cross-env": "^7.0.3",
|
|
70
|
-
"eslint": "^8.
|
|
71
|
-
"eslint-config-os-team-react": "1.1.
|
|
70
|
+
"eslint": "^8.57.0",
|
|
71
|
+
"eslint-config-os-team-react": "1.1.48",
|
|
72
72
|
"eslint-plugin-import": "^2.29.1",
|
|
73
|
-
"eslint-plugin-jest": "^27.
|
|
73
|
+
"eslint-plugin-jest": "^27.9.0",
|
|
74
74
|
"eslint-plugin-jsx-a11y": "^6.8.0",
|
|
75
75
|
"eslint-plugin-promise": "^6.1.1",
|
|
76
76
|
"eslint-plugin-react": "^7.33.2",
|
|
77
77
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
78
78
|
"get-graphql-schema": "^2.1.2",
|
|
79
79
|
"graphql": "^16.8.1",
|
|
80
|
-
"husky": "^
|
|
81
|
-
"i18next": "^23.
|
|
80
|
+
"husky": "^9.0.11",
|
|
81
|
+
"i18next": "^23.10.0",
|
|
82
82
|
"i18next-browser-languagedetector": "^7.2.0",
|
|
83
|
-
"i18next-http-backend": "^2.
|
|
83
|
+
"i18next-http-backend": "^2.5.0",
|
|
84
84
|
"lazysizes": "^5.3.2",
|
|
85
|
-
"lint-staged": "^15.2.
|
|
85
|
+
"lint-staged": "^15.2.2",
|
|
86
86
|
"npm-run-all": "^4.1.5",
|
|
87
|
-
"prettier": "3.
|
|
87
|
+
"prettier": "3.2.5",
|
|
88
88
|
"progress-bar-webpack-plugin": "^2.1.0",
|
|
89
89
|
"react": "^18.2.0",
|
|
90
90
|
"react-app-rewired": "^2.2.1",
|
|
91
91
|
"react-dom": "^18.2.0",
|
|
92
|
-
"react-i18next": "^14.0.
|
|
93
|
-
"react-relay": "^16.
|
|
94
|
-
"react-router-dom": "^6.
|
|
92
|
+
"react-i18next": "^14.0.5",
|
|
93
|
+
"react-relay": "^16.2.0",
|
|
94
|
+
"react-router-dom": "^6.22.2",
|
|
95
95
|
"react-scripts": "^5.0.1",
|
|
96
96
|
"react-test-renderer": "^18.2.0",
|
|
97
|
-
"relay-compiler": "^16.
|
|
98
|
-
"relay-runtime": "^16.
|
|
99
|
-
"release-it": "^17.
|
|
97
|
+
"relay-compiler": "^16.2.0",
|
|
98
|
+
"relay-runtime": "^16.2.0",
|
|
99
|
+
"release-it": "^17.1.1",
|
|
100
100
|
"rimraf": "^5.0.5",
|
|
101
101
|
"typescript": "^5.3.3",
|
|
102
102
|
"webpack-bundle-analyzer": "^4.10.1"
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
-
|
|
9
|
-
const isObject = value => typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
10
|
-
const DEFAULT_MESSAGE = 'Error';
|
|
11
|
-
const getErrorMessage = error => {
|
|
12
|
-
if (!isObject(error)) return DEFAULT_MESSAGE;
|
|
13
|
-
const {
|
|
14
|
-
source
|
|
15
|
-
} = error;
|
|
16
|
-
let {
|
|
17
|
-
message = DEFAULT_MESSAGE
|
|
18
|
-
} = error;
|
|
19
|
-
if (!isObject(source) || !Array.isArray(source.errors) || source.errors.length === 0) {
|
|
20
|
-
return message;
|
|
21
|
-
}
|
|
22
|
-
const 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
|
-
const constraintKeys = Object.keys(firstError.extensions.constraints);
|
|
31
|
-
if (constraintKeys.length === 0) {
|
|
32
|
-
return message;
|
|
33
|
-
}
|
|
34
|
-
const firstKey = constraintKeys[0];
|
|
35
|
-
const 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 = exports.default = getErrorMessage;
|
|
42
|
-
//# sourceMappingURL=getErrorMessage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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","_default","exports","default"],"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,MAAMA,QAAQ,GAAIC,KAAU,IAC1B,OAAOA,KAAK,KAAK,QAAQ,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,IAAIA,KAAK,KAAK,IAAI;AAEtE,MAAMG,eAAe,GAAG,OAAO;AAE/B,MAAMC,eAAe,GAAIC,KAAU,IAAK;EACtC,IAAI,CAACN,QAAQ,CAACM,KAAK,CAAC,EAAE,OAAOF,eAAe;EAE5C,MAAM;IAAEG;EAAO,CAAC,GAAGD,KAAK;EACxB,IAAI;IAAEE,OAAO,GAAGJ;EAAgB,CAAC,GAAGE,KAAK;EACzC,IACE,CAACN,QAAQ,CAACO,MAAM,CAAC,IACjB,CAACL,KAAK,CAACC,OAAO,CAACI,MAAM,CAACE,MAAM,CAAC,IAC7BF,MAAM,CAACE,MAAM,CAACC,MAAM,KAAK,CAAC,EAC1B;IACA,OAAOF,OAAO;EAChB;EAEA,MAAMG,UAAU,GAAGJ,MAAM,CAACE,MAAM,CAAC,CAAC,CAAC;EACnC,IAAI,CAACT,QAAQ,CAACW,UAAU,CAAC,EAAE;IACzB,OAAOH,OAAO;EAChB;EAEAA,OAAO,GAAGG,UAAU,CAACH,OAAO,IAAIA,OAAO;EACvC,IACE,CAACR,QAAQ,CAACW,UAAU,CAACC,UAAU,CAAC,IAChC,CAACZ,QAAQ,CAACW,UAAU,CAACC,UAAU,CAACC,WAAW,CAAC,EAC5C;IACA,OAAOL,OAAO;EAChB;EAEA,MAAMM,cAAc,GAAGC,MAAM,CAACC,IAAI,CAACL,UAAU,CAACC,UAAU,CAACC,WAAW,CAAC;EACrE,IAAIC,cAAc,CAACJ,MAAM,KAAK,CAAC,EAAE;IAC/B,OAAOF,OAAO;EAChB;EAEA,MAAMS,QAAQ,GAAGH,cAAc,CAAC,CAAC,CAAC;EAClC,MAAMI,eAAe,GAAGP,UAAU,CAACC,UAAU,CAACC,WAAW,CAACI,QAAQ,CAAC;EACnE,IACE,CAACjB,QAAQ,CAACkB,eAAe,CAAC,IAC1B,OAAOA,eAAe,CAACV,OAAO,KAAK,QAAQ,EAC3C;IACA,OAAOA,OAAO;EAChB;EAEA,OAAOU,eAAe,CAACV,OAAO;AAChC,CAAC;AAAC,IAAAW,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEahB,eAAe"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
const isObject = value => typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
4
|
-
const DEFAULT_MESSAGE = 'Error';
|
|
5
|
-
const getErrorMessage = error => {
|
|
6
|
-
if (!isObject(error)) return DEFAULT_MESSAGE;
|
|
7
|
-
const {
|
|
8
|
-
source
|
|
9
|
-
} = error;
|
|
10
|
-
let {
|
|
11
|
-
message = DEFAULT_MESSAGE
|
|
12
|
-
} = error;
|
|
13
|
-
if (!isObject(source) || !Array.isArray(source.errors) || source.errors.length === 0) {
|
|
14
|
-
return message;
|
|
15
|
-
}
|
|
16
|
-
const firstError = source.errors[0];
|
|
17
|
-
if (!isObject(firstError)) {
|
|
18
|
-
return message;
|
|
19
|
-
}
|
|
20
|
-
message = firstError.message || message;
|
|
21
|
-
if (!isObject(firstError.extensions) || !isObject(firstError.extensions.constraints)) {
|
|
22
|
-
return message;
|
|
23
|
-
}
|
|
24
|
-
const constraintKeys = Object.keys(firstError.extensions.constraints);
|
|
25
|
-
if (constraintKeys.length === 0) {
|
|
26
|
-
return message;
|
|
27
|
-
}
|
|
28
|
-
const firstKey = constraintKeys[0];
|
|
29
|
-
const firstConstraint = firstError.extensions.constraints[firstKey];
|
|
30
|
-
if (!isObject(firstConstraint) || typeof firstConstraint.message !== 'string') {
|
|
31
|
-
return message;
|
|
32
|
-
}
|
|
33
|
-
return firstConstraint.message;
|
|
34
|
-
};
|
|
35
|
-
export default getErrorMessage;
|
|
36
|
-
//# sourceMappingURL=getErrorMessage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,MAAMA,QAAQ,GAAIC,KAAU,IAC1B,OAAOA,KAAK,KAAK,QAAQ,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,IAAIA,KAAK,KAAK,IAAI;AAEtE,MAAMG,eAAe,GAAG,OAAO;AAE/B,MAAMC,eAAe,GAAIC,KAAU,IAAK;EACtC,IAAI,CAACN,QAAQ,CAACM,KAAK,CAAC,EAAE,OAAOF,eAAe;EAE5C,MAAM;IAAEG;EAAO,CAAC,GAAGD,KAAK;EACxB,IAAI;IAAEE,OAAO,GAAGJ;EAAgB,CAAC,GAAGE,KAAK;EACzC,IACE,CAACN,QAAQ,CAACO,MAAM,CAAC,IACjB,CAACL,KAAK,CAACC,OAAO,CAACI,MAAM,CAACE,MAAM,CAAC,IAC7BF,MAAM,CAACE,MAAM,CAACC,MAAM,KAAK,CAAC,EAC1B;IACA,OAAOF,OAAO;EAChB;EAEA,MAAMG,UAAU,GAAGJ,MAAM,CAACE,MAAM,CAAC,CAAC,CAAC;EACnC,IAAI,CAACT,QAAQ,CAACW,UAAU,CAAC,EAAE;IACzB,OAAOH,OAAO;EAChB;EAEAA,OAAO,GAAGG,UAAU,CAACH,OAAO,IAAIA,OAAO;EACvC,IACE,CAACR,QAAQ,CAACW,UAAU,CAACC,UAAU,CAAC,IAChC,CAACZ,QAAQ,CAACW,UAAU,CAACC,UAAU,CAACC,WAAW,CAAC,EAC5C;IACA,OAAOL,OAAO;EAChB;EAEA,MAAMM,cAAc,GAAGC,MAAM,CAACC,IAAI,CAACL,UAAU,CAACC,UAAU,CAACC,WAAW,CAAC;EACrE,IAAIC,cAAc,CAACJ,MAAM,KAAK,CAAC,EAAE;IAC/B,OAAOF,OAAO;EAChB;EAEA,MAAMS,QAAQ,GAAGH,cAAc,CAAC,CAAC,CAAC;EAClC,MAAMI,eAAe,GAAGP,UAAU,CAACC,UAAU,CAACC,WAAW,CAACI,QAAQ,CAAC;EACnE,IACE,CAACjB,QAAQ,CAACkB,eAAe,CAAC,IAC1B,OAAOA,eAAe,CAACV,OAAO,KAAK,QAAQ,EAC3C;IACA,OAAOA,OAAO;EAChB;EAEA,OAAOU,eAAe,CAACV,OAAO;AAChC,CAAC;AAED,eAAeH,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getErrorMessage.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/getErrorMessage.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,eAAe,UAAW,GAAG,QAyClC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|