@os-team/profile 1.0.34 → 1.0.37
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/ProfileConfigContext.js +1 -1
- package/dist/cjs/components/profile/ProfileContext.js +1 -1
- package/dist/cjs/components/profile/ProfileDrawer.js +19 -232
- package/dist/cjs/components/profile/ProfileDrawer.js.map +1 -1
- package/dist/cjs/components/profile/ProfileDrawerContent.js +259 -0
- package/dist/cjs/components/profile/ProfileDrawerContent.js.map +1 -0
- package/dist/cjs/components/profile/ProfileUpdateNameModal.js +1 -1
- package/dist/cjs/components/profile/ProfileUpdatePasswordModal.js +1 -1
- package/dist/cjs/components/profile/ProtectedWrapper.js +1 -1
- package/dist/cjs/components/profile/UserAvatar.js +1 -1
- package/dist/cjs/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.js +70 -0
- package/dist/cjs/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.js.map +1 -0
- package/dist/cjs/components/profile/__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql.js +89 -0
- package/dist/cjs/components/profile/__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql.js.map +1 -0
- package/dist/cjs/components/profile/__generated__/ProfileDrawerSignOutMutation.graphql.js +7 -9
- package/dist/cjs/components/profile/__generated__/ProfileDrawerSignOutMutation.graphql.js.map +1 -1
- package/dist/cjs/components/profile/__generated__/ProfileDrawerUpdateAvatarMutation.graphql.js +7 -12
- package/dist/cjs/components/profile/__generated__/ProfileDrawerUpdateAvatarMutation.graphql.js.map +1 -1
- package/dist/cjs/components/profile/__generated__/ProfileUpdateNameModalMutation.graphql.js +7 -13
- package/dist/cjs/components/profile/__generated__/ProfileUpdateNameModalMutation.graphql.js.map +1 -1
- package/dist/cjs/components/profile/__generated__/ProfileUpdatePasswordModalMutation.graphql.js +7 -11
- package/dist/cjs/components/profile/__generated__/ProfileUpdatePasswordModalMutation.graphql.js.map +1 -1
- package/dist/cjs/components/profile/__generated__/ProtectedWrapperQuery.graphql.js +7 -13
- package/dist/cjs/components/profile/__generated__/ProtectedWrapperQuery.graphql.js.map +1 -1
- package/dist/cjs/components/session/SessionDrawer.js +17 -10
- package/dist/cjs/components/session/SessionDrawer.js.map +1 -1
- package/dist/cjs/components/session/SessionDrawerContent.js +2 -5
- package/dist/cjs/components/session/SessionDrawerContent.js.map +1 -1
- package/dist/cjs/components/session/SessionList.js +1 -1
- package/dist/cjs/components/session/SessionListItem.js +1 -1
- package/dist/cjs/components/session/__generated__/SessionDrawerContentQuery.graphql.js +7 -34
- package/dist/cjs/components/session/__generated__/SessionDrawerContentQuery.graphql.js.map +1 -1
- package/dist/cjs/components/session/__generated__/SessionListDestroyAllOtherSessionsMutation.graphql.js +7 -9
- package/dist/cjs/components/session/__generated__/SessionListDestroyAllOtherSessionsMutation.graphql.js.map +1 -1
- package/dist/cjs/components/session/__generated__/SessionListItemDestroySessionMutation.graphql.js +7 -11
- package/dist/cjs/components/session/__generated__/SessionListItemDestroySessionMutation.graphql.js.map +1 -1
- package/dist/cjs/components/session/__generated__/SessionListItem_session.graphql.js +7 -1
- package/dist/cjs/components/session/__generated__/SessionListItem_session.graphql.js.map +1 -1
- package/dist/cjs/components/session/__generated__/SessionListRefetchQuery.graphql.js +7 -34
- package/dist/cjs/components/session/__generated__/SessionListRefetchQuery.graphql.js.map +1 -1
- package/dist/cjs/components/session/__generated__/SessionList_sessions.graphql.js +7 -5
- package/dist/cjs/components/session/__generated__/SessionList_sessions.graphql.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/components/profile/ProfileDrawer.js +12 -196
- package/dist/esm/components/profile/ProfileDrawer.js.map +1 -1
- package/dist/esm/components/profile/ProfileDrawerContent.js +201 -0
- package/dist/esm/components/profile/ProfileDrawerContent.js.map +1 -0
- package/dist/esm/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.js +62 -0
- package/dist/esm/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.js.map +1 -0
- package/dist/esm/components/profile/__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql.js +81 -0
- package/dist/esm/components/profile/__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql.js.map +1 -0
- package/dist/esm/components/profile/__generated__/ProfileDrawerSignOutMutation.graphql.js +7 -9
- package/dist/esm/components/profile/__generated__/ProfileDrawerSignOutMutation.graphql.js.map +1 -1
- package/dist/esm/components/profile/__generated__/ProfileDrawerUpdateAvatarMutation.graphql.js +7 -12
- package/dist/esm/components/profile/__generated__/ProfileDrawerUpdateAvatarMutation.graphql.js.map +1 -1
- package/dist/esm/components/profile/__generated__/ProfileUpdateNameModalMutation.graphql.js +7 -13
- package/dist/esm/components/profile/__generated__/ProfileUpdateNameModalMutation.graphql.js.map +1 -1
- package/dist/esm/components/profile/__generated__/ProfileUpdatePasswordModalMutation.graphql.js +7 -11
- package/dist/esm/components/profile/__generated__/ProfileUpdatePasswordModalMutation.graphql.js.map +1 -1
- package/dist/esm/components/profile/__generated__/ProtectedWrapperQuery.graphql.js +7 -13
- package/dist/esm/components/profile/__generated__/ProtectedWrapperQuery.graphql.js.map +1 -1
- package/dist/esm/components/session/SessionDrawer.js +7 -4
- package/dist/esm/components/session/SessionDrawer.js.map +1 -1
- package/dist/esm/components/session/SessionDrawerContent.js +0 -1
- package/dist/esm/components/session/SessionDrawerContent.js.map +1 -1
- package/dist/esm/components/session/__generated__/SessionDrawerContentQuery.graphql.js +7 -34
- package/dist/esm/components/session/__generated__/SessionDrawerContentQuery.graphql.js.map +1 -1
- package/dist/esm/components/session/__generated__/SessionListDestroyAllOtherSessionsMutation.graphql.js +7 -9
- package/dist/esm/components/session/__generated__/SessionListDestroyAllOtherSessionsMutation.graphql.js.map +1 -1
- package/dist/esm/components/session/__generated__/SessionListItemDestroySessionMutation.graphql.js +7 -11
- package/dist/esm/components/session/__generated__/SessionListItemDestroySessionMutation.graphql.js.map +1 -1
- package/dist/esm/components/session/__generated__/SessionListItem_session.graphql.js +7 -1
- package/dist/esm/components/session/__generated__/SessionListItem_session.graphql.js.map +1 -1
- package/dist/esm/components/session/__generated__/SessionListRefetchQuery.graphql.js +7 -34
- package/dist/esm/components/session/__generated__/SessionListRefetchQuery.graphql.js.map +1 -1
- package/dist/esm/components/session/__generated__/SessionList_sessions.graphql.js +8 -3
- package/dist/esm/components/session/__generated__/SessionList_sessions.graphql.js.map +1 -1
- package/dist/types/components/profile/ProfileDrawer.d.ts +2 -3
- package/dist/types/components/profile/ProfileDrawer.d.ts.map +1 -1
- package/dist/types/components/profile/ProfileDrawerContent.d.ts +7 -0
- package/dist/types/components/profile/ProfileDrawerContent.d.ts.map +1 -0
- package/dist/types/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.d.ts +14 -0
- package/dist/types/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.d.ts.map +1 -0
- package/dist/types/components/profile/__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql.d.ts +20 -0
- package/dist/types/components/profile/__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql.d.ts.map +1 -0
- package/dist/types/components/profile/__generated__/ProfileDrawerSignOutMutation.graphql.d.ts +5 -5
- package/dist/types/components/profile/__generated__/ProfileDrawerSignOutMutation.graphql.d.ts.map +1 -1
- package/dist/types/components/profile/__generated__/ProfileDrawerUpdateAvatarMutation.graphql.d.ts +6 -6
- package/dist/types/components/profile/__generated__/ProfileDrawerUpdateAvatarMutation.graphql.d.ts.map +1 -1
- package/dist/types/components/profile/__generated__/ProfileUpdateNameModalMutation.graphql.d.ts +7 -7
- package/dist/types/components/profile/__generated__/ProfileUpdateNameModalMutation.graphql.d.ts.map +1 -1
- package/dist/types/components/profile/__generated__/ProfileUpdatePasswordModalMutation.graphql.d.ts +5 -5
- package/dist/types/components/profile/__generated__/ProfileUpdatePasswordModalMutation.graphql.d.ts.map +1 -1
- package/dist/types/components/profile/__generated__/ProtectedWrapperQuery.graphql.d.ts +5 -5
- package/dist/types/components/profile/__generated__/ProtectedWrapperQuery.graphql.d.ts.map +1 -1
- package/dist/types/components/session/SessionDrawer.d.ts.map +1 -1
- package/dist/types/components/session/SessionDrawerContent.d.ts +0 -1
- package/dist/types/components/session/SessionDrawerContent.d.ts.map +1 -1
- package/dist/types/components/session/__generated__/SessionDrawerContentQuery.graphql.d.ts +6 -6
- package/dist/types/components/session/__generated__/SessionDrawerContentQuery.graphql.d.ts.map +1 -1
- package/dist/types/components/session/__generated__/SessionListDestroyAllOtherSessionsMutation.graphql.d.ts +5 -5
- package/dist/types/components/session/__generated__/SessionListDestroyAllOtherSessionsMutation.graphql.d.ts.map +1 -1
- package/dist/types/components/session/__generated__/SessionListItemDestroySessionMutation.graphql.d.ts +5 -5
- package/dist/types/components/session/__generated__/SessionListItemDestroySessionMutation.graphql.d.ts.map +1 -1
- package/dist/types/components/session/__generated__/SessionListItem_session.graphql.d.ts +5 -6
- package/dist/types/components/session/__generated__/SessionListItem_session.graphql.d.ts.map +1 -1
- package/dist/types/components/session/__generated__/SessionListRefetchQuery.graphql.d.ts +6 -6
- package/dist/types/components/session/__generated__/SessionListRefetchQuery.graphql.d.ts.map +1 -1
- package/dist/types/components/session/__generated__/SessionList_sessions.graphql.d.ts +6 -7
- package/dist/types/components/session/__generated__/SessionList_sessions.graphql.d.ts.map +1 -1
- package/package.json +45 -47
|
@@ -1,212 +1,28 @@
|
|
|
1
|
-
var _ProfileDrawerUpdateAvatarMutation, _ProfileDrawerSignOutMutation;
|
|
2
|
-
|
|
3
1
|
function _extends() { _extends = Object.assign || 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); }
|
|
4
2
|
|
|
5
|
-
import React, {
|
|
6
|
-
import { Drawer
|
|
3
|
+
import React, { lazy, Suspense } from 'react';
|
|
4
|
+
import { Drawer } from '@os-design/core';
|
|
7
5
|
import styled from '@emotion/styled';
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import { useMutation } from 'react-relay/hooks';
|
|
11
|
-
import { useProfile } from './ProfileContext';
|
|
12
|
-
import UserAvatar from './UserAvatar';
|
|
13
|
-
import ProfileButton from './ProfileButton';
|
|
14
|
-
import ProfileUpdateNameModal from './ProfileUpdateNameModal';
|
|
15
|
-
import ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';
|
|
6
|
+
import MainLoader from '../shared/MainLoader';
|
|
7
|
+
const LazyProfileDrawerContent = /*#__PURE__*/lazy(() => import('./ProfileDrawerContent'));
|
|
16
8
|
const StyledDrawer = styled(Drawer)`
|
|
17
9
|
display: flex;
|
|
18
10
|
flex-direction: column;
|
|
19
11
|
padding: 2em 1em;
|
|
20
12
|
`;
|
|
21
|
-
const AvatarContainer = styled.div`
|
|
22
|
-
display: flex;
|
|
23
|
-
flex-direction: column;
|
|
24
|
-
justify-content: center;
|
|
25
|
-
align-items: center;
|
|
26
|
-
`;
|
|
27
|
-
const UserContent = styled.div`
|
|
28
|
-
margin-top: 1em;
|
|
29
|
-
`;
|
|
30
|
-
const FullName = styled.div`
|
|
31
|
-
font-size: ${p => p.theme.sizes.large}em;
|
|
32
|
-
font-weight: 500;
|
|
33
|
-
text-align: center;
|
|
34
|
-
line-height: 1.2;
|
|
35
|
-
`;
|
|
36
|
-
const Email = styled.div`
|
|
37
|
-
color: ${p => clr(p.theme.inputColorPlaceholder)};
|
|
38
|
-
margin-top: 0.2em;
|
|
39
|
-
text-align: center;
|
|
40
|
-
`;
|
|
41
|
-
const ActionsContainer = styled.div`
|
|
42
|
-
margin-top: 1.5em;
|
|
43
|
-
`;
|
|
44
|
-
const Footer = styled.div`
|
|
45
|
-
display: flex;
|
|
46
|
-
justify-content: center;
|
|
47
|
-
margin-top: auto;
|
|
48
|
-
padding-top: 1.5em;
|
|
49
|
-
`;
|
|
50
|
-
const HiddenInput = styled.input`
|
|
51
|
-
display: none;
|
|
52
|
-
`;
|
|
53
|
-
const profileDrawerUpdateAvatarMutation = _ProfileDrawerUpdateAvatarMutation !== void 0 ? _ProfileDrawerUpdateAvatarMutation : (_ProfileDrawerUpdateAvatarMutation = require("./__generated__/ProfileDrawerUpdateAvatarMutation.graphql"), _ProfileDrawerUpdateAvatarMutation.hash && _ProfileDrawerUpdateAvatarMutation.hash !== "c129cb1974b7cb9090d6c5df4e0f790d" && console.error("The definition of 'ProfileDrawerUpdateAvatarMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _ProfileDrawerUpdateAvatarMutation);
|
|
54
|
-
|
|
55
|
-
const DeleteAvatarButton = () => {
|
|
56
|
-
const {
|
|
57
|
-
t
|
|
58
|
-
} = useTranslation('profile');
|
|
59
|
-
const [commit, loading] = useMutation(profileDrawerUpdateAvatarMutation);
|
|
60
|
-
const handler = useCallback(() => {
|
|
61
|
-
commit({
|
|
62
|
-
variables: {
|
|
63
|
-
input: {
|
|
64
|
-
avatar: null
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
onError: error => {
|
|
68
|
-
var _source, _source$errors, _source$errors$;
|
|
69
|
-
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
-
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);
|
|
72
|
-
},
|
|
73
|
-
onCompleted: () => {
|
|
74
|
-
message.success(t('profile:updated'));
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}, [commit, t]);
|
|
78
|
-
return /*#__PURE__*/React.createElement(ProfileButton, {
|
|
79
|
-
loading: loading,
|
|
80
|
-
onClick: handler
|
|
81
|
-
}, t('profile:deleteAvatar'));
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const UpdateAvatarButton = ({
|
|
85
|
-
hasAvatar
|
|
86
|
-
}) => {
|
|
87
|
-
const {
|
|
88
|
-
t
|
|
89
|
-
} = useTranslation('profile');
|
|
90
|
-
const fileInputRef = useRef(null);
|
|
91
|
-
const [commit, loading] = useMutation(profileDrawerUpdateAvatarMutation);
|
|
92
|
-
const handler = useCallback(e => {
|
|
93
|
-
const target = e.target;
|
|
94
|
-
if (!target) return;
|
|
95
|
-
const {
|
|
96
|
-
files
|
|
97
|
-
} = target;
|
|
98
|
-
if (!files) return;
|
|
99
|
-
const file = files[0];
|
|
100
|
-
commit({
|
|
101
|
-
variables: {
|
|
102
|
-
input: {}
|
|
103
|
-
},
|
|
104
|
-
uploadables: {
|
|
105
|
-
avatar: file
|
|
106
|
-
},
|
|
107
|
-
onError: error => {
|
|
108
|
-
var _source2, _source2$errors, _source2$errors$;
|
|
109
|
-
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
-
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);
|
|
112
|
-
},
|
|
113
|
-
onCompleted: () => {
|
|
114
|
-
message.success(t('profile:updated'));
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}, [commit, t]);
|
|
118
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProfileButton, {
|
|
119
|
-
loading: loading,
|
|
120
|
-
onClick: () => {
|
|
121
|
-
if (!fileInputRef.current) return;
|
|
122
|
-
fileInputRef.current.value = '';
|
|
123
|
-
fileInputRef.current.click();
|
|
124
|
-
}
|
|
125
|
-
}, t(`profile:${hasAvatar ? 'changeAvatar' : 'setAvatar'}`)), /*#__PURE__*/React.createElement(HiddenInput, {
|
|
126
|
-
type: "file",
|
|
127
|
-
accept: "image/jpeg,image/png,image/webp",
|
|
128
|
-
onChange: handler,
|
|
129
|
-
ref: fileInputRef
|
|
130
|
-
}));
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const UpdateNameButton = ({
|
|
134
|
-
hasName
|
|
135
|
-
}) => {
|
|
136
|
-
const {
|
|
137
|
-
t
|
|
138
|
-
} = useTranslation('profile');
|
|
139
|
-
const [modalVisibility, setModalVisibility] = useState(false);
|
|
140
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProfileButton, {
|
|
141
|
-
onClick: () => setModalVisibility(true)
|
|
142
|
-
}, t(`profile:${hasName ? 'changeName' : 'setName'}`)), /*#__PURE__*/React.createElement(ProfileUpdateNameModal, {
|
|
143
|
-
visibility: modalVisibility,
|
|
144
|
-
onClose: () => setModalVisibility(false)
|
|
145
|
-
}));
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const ChangePasswordButton = () => {
|
|
149
|
-
const {
|
|
150
|
-
t
|
|
151
|
-
} = useTranslation('profile');
|
|
152
|
-
const [modalVisibility, setModalVisibility] = useState(false);
|
|
153
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProfileButton, {
|
|
154
|
-
onClick: () => setModalVisibility(true)
|
|
155
|
-
}, t('profile:changePassword')), /*#__PURE__*/React.createElement(ProfileUpdatePasswordModal, {
|
|
156
|
-
visibility: modalVisibility,
|
|
157
|
-
onClose: () => setModalVisibility(false)
|
|
158
|
-
}));
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const SignOutButton = () => {
|
|
162
|
-
const {
|
|
163
|
-
t
|
|
164
|
-
} = useTranslation('profile');
|
|
165
|
-
const [commit, loading] = useMutation(_ProfileDrawerSignOutMutation !== void 0 ? _ProfileDrawerSignOutMutation : (_ProfileDrawerSignOutMutation = require("./__generated__/ProfileDrawerSignOutMutation.graphql"), _ProfileDrawerSignOutMutation.hash && _ProfileDrawerSignOutMutation.hash !== "8510e6462e8f7839ce100254080ba293" && console.error("The definition of 'ProfileDrawerSignOutMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _ProfileDrawerSignOutMutation));
|
|
166
|
-
const handler = useCallback(() => {
|
|
167
|
-
commit({
|
|
168
|
-
variables: {},
|
|
169
|
-
onError: error => {
|
|
170
|
-
var _source3, _source3$errors, _source3$errors$;
|
|
171
|
-
|
|
172
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
173
|
-
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);
|
|
174
|
-
},
|
|
175
|
-
onCompleted: () => {
|
|
176
|
-
window.location.href = '/auth/';
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}, [commit]);
|
|
180
|
-
return /*#__PURE__*/React.createElement(ProfileButton, {
|
|
181
|
-
danger: true,
|
|
182
|
-
loading: loading,
|
|
183
|
-
onClick: handler
|
|
184
|
-
}, t('profile:signOut'));
|
|
185
|
-
};
|
|
186
13
|
|
|
187
14
|
const ProfileDrawer = ({
|
|
188
15
|
actions,
|
|
189
16
|
children,
|
|
190
17
|
...rest
|
|
191
|
-
}) => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return /*#__PURE__*/React.createElement(StyledDrawer, _extends({
|
|
200
|
-
placement: "right",
|
|
201
|
-
width: "15em"
|
|
202
|
-
}, rest), /*#__PURE__*/React.createElement(AvatarContainer, null, /*#__PURE__*/React.createElement(UserAvatar, {
|
|
203
|
-
size: "10em"
|
|
204
|
-
}), /*#__PURE__*/React.createElement(UserContent, null, fullName && /*#__PURE__*/React.createElement(FullName, null, fullName), /*#__PURE__*/React.createElement(Email, null, email))), /*#__PURE__*/React.createElement(ActionsContainer, null, avatar && /*#__PURE__*/React.createElement(DeleteAvatarButton, null), /*#__PURE__*/React.createElement(UpdateAvatarButton, {
|
|
205
|
-
hasAvatar: !!avatar
|
|
206
|
-
}), /*#__PURE__*/React.createElement(UpdateNameButton, {
|
|
207
|
-
hasName: !!fullName
|
|
208
|
-
}), /*#__PURE__*/React.createElement(ChangePasswordButton, null), actions, /*#__PURE__*/React.createElement(SignOutButton, null), children), /*#__PURE__*/React.createElement(Footer, null, /*#__PURE__*/React.createElement(ThemeSwitcher, null)));
|
|
209
|
-
};
|
|
18
|
+
}) => /*#__PURE__*/React.createElement(StyledDrawer, _extends({
|
|
19
|
+
placement: "right",
|
|
20
|
+
width: "15em"
|
|
21
|
+
}, rest), /*#__PURE__*/React.createElement(Suspense, {
|
|
22
|
+
fallback: /*#__PURE__*/React.createElement(MainLoader, null)
|
|
23
|
+
}, /*#__PURE__*/React.createElement(LazyProfileDrawerContent, {
|
|
24
|
+
actions: actions
|
|
25
|
+
}, children)));
|
|
210
26
|
|
|
211
27
|
export default ProfileDrawer;
|
|
212
28
|
//# sourceMappingURL=ProfileDrawer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/components/profile/ProfileDrawer.tsx"],"names":["React","useCallback","useMemo","useRef","useState","Drawer","message","ThemeSwitcher","styled","clr","useTranslation","useMutation","useProfile","UserAvatar","ProfileButton","ProfileUpdateNameModal","ProfileUpdatePasswordModal","StyledDrawer","AvatarContainer","div","UserContent","FullName","p","theme","sizes","large","Email","inputColorPlaceholder","ActionsContainer","Footer","HiddenInput","input","profileDrawerUpdateAvatarMutation","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","ProfileDrawer","actions","children","rest","email","firstName","lastName","fullName","filter","i","join"],"mappings":";;;;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,OAA7B,EAAsCC,MAAtC,EAA8CC,QAA9C,QAA8D,OAA9D;AACA,S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gBAAD;AAAkB,IAAA,OAAO,EAAE,CAAC,CAACkC;AAA7B,IAJF,eAKE,oBAAC,oBAAD,OALF,EAOGN,OAPH,eASE,oBAAC,aAAD,OATF,EAWGC,QAXH,CATF,eAuBE,oBAAC,MAAD,qBACE,oBAAC,aAAD,OADF,CAvBF,CADF;AA6BD,CAzCD;;AA2CA,eAAeF,aAAf","sourcesContent":["import React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { Drawer, DrawerProps, message, ThemeSwitcher } from '@os-design/core';\nimport styled from '@emotion/styled';\nimport { clr } from '@os-design/theming';\nimport { useTranslation } from 'react-i18next';\nimport { graphql } from 'babel-plugin-relay/macro';\nimport { useMutation } from 'react-relay/hooks';\nimport { useProfile } from './ProfileContext';\nimport UserAvatar from './UserAvatar';\nimport ProfileButton from './ProfileButton';\nimport ProfileUpdateNameModal from './ProfileUpdateNameModal';\nimport ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';\nimport { ProfileDrawerSignOutMutation } from './__generated__/ProfileDrawerSignOutMutation.graphql';\nimport { ProfileDrawerUpdateAvatarMutation } from './__generated__/ProfileDrawerUpdateAvatarMutation.graphql';\n\nexport interface ProfileDrawerProps extends DrawerProps {\n /**\n * Additional actions placed under the avatar.\n * @default undefined\n */\n actions?: React.ReactNode;\n}\n\nconst StyledDrawer = styled(Drawer)`\n display: flex;\n flex-direction: column;\n padding: 2em 1em;\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 profileDrawerUpdateAvatarMutation = graphql`\n mutation ProfileDrawerUpdateAvatarMutation($input: UpdateAvatarInput!) {\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] = useMutation<ProfileDrawerUpdateAvatarMutation>(\n profileDrawerUpdateAvatarMutation\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] = useMutation<ProfileDrawerUpdateAvatarMutation>(\n profileDrawerUpdateAvatarMutation\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] = useMutation<ProfileDrawerSignOutMutation>(graphql`\n mutation ProfileDrawerSignOutMutation {\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 ProfileDrawer: React.FC<ProfileDrawerProps> = ({\n actions,\n children,\n ...rest\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 <StyledDrawer placement='right' width='15em' {...rest}>\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 </StyledDrawer>\n );\n};\n\nexport default ProfileDrawer;\n"],"file":"ProfileDrawer.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/components/profile/ProfileDrawer.tsx"],"names":["React","lazy","Suspense","Drawer","styled","MainLoader","LazyProfileDrawerContent","StyledDrawer","ProfileDrawer","actions","children","rest"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,IAAhB,EAAsBC,QAAtB,QAAsC,OAAtC;AACA,SAASC,MAAT,QAAoC,iBAApC;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AAEA,OAAOC,UAAP,MAAuB,sBAAvB;AAEA,MAAMC,wBAAwB,gBAAGL,IAAI,CAAC,MAAM,OAAO,wBAAP,CAAP,CAArC;AAIA,MAAMM,YAAY,GAAGH,MAAM,CAACD,MAAD,CAAS;AACpC;AACA;AACA;AACA,CAJA;;AAMA,MAAMK,aAA2C,GAAG,CAAC;AACnDC,EAAAA,OADmD;AAEnDC,EAAAA,QAFmD;AAGnD,KAAGC;AAHgD,CAAD,kBAKlD,oBAAC,YAAD;AAAc,EAAA,SAAS,EAAC,OAAxB;AAAgC,EAAA,KAAK,EAAC;AAAtC,GAAiDA,IAAjD,gBACE,oBAAC,QAAD;AAAU,EAAA,QAAQ,eAAE,oBAAC,UAAD;AAApB,gBACE,oBAAC,wBAAD;AAA0B,EAAA,OAAO,EAAEF;AAAnC,GACGC,QADH,CADF,CADF,CALF;;AAcA,eAAeF,aAAf","sourcesContent":["import React, { lazy, Suspense } from 'react';\nimport { Drawer, DrawerProps } from '@os-design/core';\nimport styled from '@emotion/styled';\nimport { ProfileDrawerContentProps } from './ProfileDrawerContent';\nimport MainLoader from '../shared/MainLoader';\n\nconst LazyProfileDrawerContent = lazy(() => import('./ProfileDrawerContent'));\n\nexport type ProfileDrawerProps = ProfileDrawerContentProps & DrawerProps;\n\nconst StyledDrawer = styled(Drawer)`\n display: flex;\n flex-direction: column;\n padding: 2em 1em;\n`;\n\nconst ProfileDrawer: React.FC<ProfileDrawerProps> = ({\n actions,\n children,\n ...rest\n}) => (\n <StyledDrawer placement='right' width='15em' {...rest}>\n <Suspense fallback={<MainLoader />}>\n <LazyProfileDrawerContent actions={actions}>\n {children}\n </LazyProfileDrawerContent>\n </Suspense>\n </StyledDrawer>\n);\n\nexport default ProfileDrawer;\n"],"file":"ProfileDrawer.js"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
var _ProfileDrawerContentUpdateAvatarMutation, _ProfileDrawerContentSignOutMutation;
|
|
2
|
+
|
|
3
|
+
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { message, ThemeSwitcher } from '@os-design/core';
|
|
5
|
+
import styled from '@emotion/styled';
|
|
6
|
+
import { clr } from '@os-design/theming';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { useMutation } from 'react-relay/hooks';
|
|
9
|
+
import UserAvatar from './UserAvatar';
|
|
10
|
+
import { useProfile } from './ProfileContext';
|
|
11
|
+
import ProfileButton from './ProfileButton';
|
|
12
|
+
import ProfileUpdateNameModal from './ProfileUpdateNameModal';
|
|
13
|
+
import ProfileUpdatePasswordModal from './ProfileUpdatePasswordModal';
|
|
14
|
+
const AvatarContainer = styled.div`
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
align-items: center;
|
|
19
|
+
`;
|
|
20
|
+
const UserContent = styled.div`
|
|
21
|
+
margin-top: 1em;
|
|
22
|
+
`;
|
|
23
|
+
const FullName = styled.div`
|
|
24
|
+
font-size: ${p => p.theme.sizes.large}em;
|
|
25
|
+
font-weight: 500;
|
|
26
|
+
text-align: center;
|
|
27
|
+
line-height: 1.2;
|
|
28
|
+
`;
|
|
29
|
+
const Email = styled.div`
|
|
30
|
+
color: ${p => clr(p.theme.inputColorPlaceholder)};
|
|
31
|
+
margin-top: 0.2em;
|
|
32
|
+
text-align: center;
|
|
33
|
+
`;
|
|
34
|
+
const ActionsContainer = styled.div`
|
|
35
|
+
margin-top: 1.5em;
|
|
36
|
+
`;
|
|
37
|
+
const Footer = styled.div`
|
|
38
|
+
display: flex;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
margin-top: auto;
|
|
41
|
+
padding-top: 1.5em;
|
|
42
|
+
`;
|
|
43
|
+
const HiddenInput = styled.input`
|
|
44
|
+
display: none;
|
|
45
|
+
`;
|
|
46
|
+
const profileDrawerContentUpdateAvatarMutation = _ProfileDrawerContentUpdateAvatarMutation !== void 0 ? _ProfileDrawerContentUpdateAvatarMutation : (_ProfileDrawerContentUpdateAvatarMutation = require("./__generated__/ProfileDrawerContentUpdateAvatarMutation.graphql"), _ProfileDrawerContentUpdateAvatarMutation.hash && _ProfileDrawerContentUpdateAvatarMutation.hash !== "cf72a6314772ed0d1f182b197c858505" && console.error("The definition of 'ProfileDrawerContentUpdateAvatarMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _ProfileDrawerContentUpdateAvatarMutation);
|
|
47
|
+
|
|
48
|
+
const DeleteAvatarButton = () => {
|
|
49
|
+
const {
|
|
50
|
+
t
|
|
51
|
+
} = useTranslation('profile');
|
|
52
|
+
const [commit, loading] = useMutation(profileDrawerContentUpdateAvatarMutation);
|
|
53
|
+
const handler = useCallback(() => {
|
|
54
|
+
commit({
|
|
55
|
+
variables: {
|
|
56
|
+
input: {
|
|
57
|
+
avatar: null
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
onError: error => {
|
|
61
|
+
var _source, _source$errors, _source$errors$;
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
+
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);
|
|
65
|
+
},
|
|
66
|
+
onCompleted: () => {
|
|
67
|
+
message.success(t('profile:updated'));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}, [commit, t]);
|
|
71
|
+
return /*#__PURE__*/React.createElement(ProfileButton, {
|
|
72
|
+
loading: loading,
|
|
73
|
+
onClick: handler
|
|
74
|
+
}, t('profile:deleteAvatar'));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const UpdateAvatarButton = ({
|
|
78
|
+
hasAvatar
|
|
79
|
+
}) => {
|
|
80
|
+
const {
|
|
81
|
+
t
|
|
82
|
+
} = useTranslation('profile');
|
|
83
|
+
const fileInputRef = useRef(null);
|
|
84
|
+
const [commit, loading] = useMutation(profileDrawerContentUpdateAvatarMutation);
|
|
85
|
+
const handler = useCallback(e => {
|
|
86
|
+
const target = e.target;
|
|
87
|
+
if (!target) return;
|
|
88
|
+
const {
|
|
89
|
+
files
|
|
90
|
+
} = target;
|
|
91
|
+
if (!files) return;
|
|
92
|
+
const file = files[0];
|
|
93
|
+
commit({
|
|
94
|
+
variables: {
|
|
95
|
+
input: {}
|
|
96
|
+
},
|
|
97
|
+
uploadables: {
|
|
98
|
+
avatar: file
|
|
99
|
+
},
|
|
100
|
+
onError: error => {
|
|
101
|
+
var _source2, _source2$errors, _source2$errors$;
|
|
102
|
+
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
+
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);
|
|
105
|
+
},
|
|
106
|
+
onCompleted: () => {
|
|
107
|
+
message.success(t('profile:updated'));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}, [commit, t]);
|
|
111
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProfileButton, {
|
|
112
|
+
loading: loading,
|
|
113
|
+
onClick: () => {
|
|
114
|
+
if (!fileInputRef.current) return;
|
|
115
|
+
fileInputRef.current.value = '';
|
|
116
|
+
fileInputRef.current.click();
|
|
117
|
+
}
|
|
118
|
+
}, t(`profile:${hasAvatar ? 'changeAvatar' : 'setAvatar'}`)), /*#__PURE__*/React.createElement(HiddenInput, {
|
|
119
|
+
type: "file",
|
|
120
|
+
accept: "image/jpeg,image/png,image/webp",
|
|
121
|
+
onChange: handler,
|
|
122
|
+
ref: fileInputRef
|
|
123
|
+
}));
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const UpdateNameButton = ({
|
|
127
|
+
hasName
|
|
128
|
+
}) => {
|
|
129
|
+
const {
|
|
130
|
+
t
|
|
131
|
+
} = useTranslation('profile');
|
|
132
|
+
const [modalVisibility, setModalVisibility] = useState(false);
|
|
133
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProfileButton, {
|
|
134
|
+
onClick: () => setModalVisibility(true)
|
|
135
|
+
}, t(`profile:${hasName ? 'changeName' : 'setName'}`)), /*#__PURE__*/React.createElement(ProfileUpdateNameModal, {
|
|
136
|
+
visibility: modalVisibility,
|
|
137
|
+
onClose: () => setModalVisibility(false)
|
|
138
|
+
}));
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const ChangePasswordButton = () => {
|
|
142
|
+
const {
|
|
143
|
+
t
|
|
144
|
+
} = useTranslation('profile');
|
|
145
|
+
const [modalVisibility, setModalVisibility] = useState(false);
|
|
146
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProfileButton, {
|
|
147
|
+
onClick: () => setModalVisibility(true)
|
|
148
|
+
}, t('profile:changePassword')), /*#__PURE__*/React.createElement(ProfileUpdatePasswordModal, {
|
|
149
|
+
visibility: modalVisibility,
|
|
150
|
+
onClose: () => setModalVisibility(false)
|
|
151
|
+
}));
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const SignOutButton = () => {
|
|
155
|
+
const {
|
|
156
|
+
t
|
|
157
|
+
} = useTranslation('profile');
|
|
158
|
+
const [commit, loading] = useMutation(_ProfileDrawerContentSignOutMutation !== void 0 ? _ProfileDrawerContentSignOutMutation : (_ProfileDrawerContentSignOutMutation = require("./__generated__/ProfileDrawerContentSignOutMutation.graphql"), _ProfileDrawerContentSignOutMutation.hash && _ProfileDrawerContentSignOutMutation.hash !== "c7ca96e9e713315606b0c22d196b6f7b" && console.error("The definition of 'ProfileDrawerContentSignOutMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _ProfileDrawerContentSignOutMutation));
|
|
159
|
+
const handler = useCallback(() => {
|
|
160
|
+
commit({
|
|
161
|
+
variables: {},
|
|
162
|
+
onError: error => {
|
|
163
|
+
var _source3, _source3$errors, _source3$errors$;
|
|
164
|
+
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
166
|
+
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);
|
|
167
|
+
},
|
|
168
|
+
onCompleted: () => {
|
|
169
|
+
window.location.href = '/auth/';
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}, [commit]);
|
|
173
|
+
return /*#__PURE__*/React.createElement(ProfileButton, {
|
|
174
|
+
danger: true,
|
|
175
|
+
loading: loading,
|
|
176
|
+
onClick: handler
|
|
177
|
+
}, t('profile:signOut'));
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const ProfileDrawerContent = ({
|
|
181
|
+
actions,
|
|
182
|
+
children
|
|
183
|
+
}) => {
|
|
184
|
+
const {
|
|
185
|
+
email,
|
|
186
|
+
firstName,
|
|
187
|
+
lastName,
|
|
188
|
+
avatar
|
|
189
|
+
} = useProfile();
|
|
190
|
+
const fullName = useMemo(() => [firstName, lastName].filter(i => i).join(' '), [firstName, lastName]);
|
|
191
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AvatarContainer, null, /*#__PURE__*/React.createElement(UserAvatar, {
|
|
192
|
+
size: "10em"
|
|
193
|
+
}), /*#__PURE__*/React.createElement(UserContent, null, fullName && /*#__PURE__*/React.createElement(FullName, null, fullName), /*#__PURE__*/React.createElement(Email, null, email))), /*#__PURE__*/React.createElement(ActionsContainer, null, avatar && /*#__PURE__*/React.createElement(DeleteAvatarButton, null), /*#__PURE__*/React.createElement(UpdateAvatarButton, {
|
|
194
|
+
hasAvatar: !!avatar
|
|
195
|
+
}), /*#__PURE__*/React.createElement(UpdateNameButton, {
|
|
196
|
+
hasName: !!fullName
|
|
197
|
+
}), /*#__PURE__*/React.createElement(ChangePasswordButton, null), actions, /*#__PURE__*/React.createElement(SignOutButton, null), children), /*#__PURE__*/React.createElement(Footer, null, /*#__PURE__*/React.createElement(ThemeSwitcher, null)));
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export default ProfileDrawerContent;
|
|
201
|
+
//# sourceMappingURL=ProfileDrawerContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/components/profile/ProfileDrawerContent.tsx"],"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"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,OAA7B,EAAsCC,MAAtC,EAA8CC,QAA9C,QAA8D,OAA9D;AACA,SAASC,OAAT,EAAkBC,aAAlB,QAAuC,iBAAvC;AACA,OAAOC,MAAP,MAAmB,iBAAnB;AACA,SAASC,GAAT,QAAoB,oBAApB;AACA,SAASC,cAAT,QAA+B,eAA/B;AACA,SAASC,WAAT,QAA4B,mBAA5B;AAEA,OAAOC,UAAP,MAAuB,cAAvB;AACA,SAASC,UAAT,QAA2B,kBAA3B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,sBAAP,MAAmC,0BAAnC;AACA,OAAOC,0BAAP,MAAuC,8BAAvC;AAYA,MAAMC,eAAe,GAAGT,MAAM,CAACU,GAAI;AACnC;AACA;AACA;AACA;AACA,CALA;AAOA,MAAMC,WAAW,GAAGX,MAAM,CAACU,GAAI;AAC/B;AACA,CAFA;AAIA,MAAME,QAAQ,GAAGZ,MAAM,CAACU,GAAI;AAC5B,eAAgBG,CAAD,IAAOA,CAAC,CAACC,KAAF,CAAQC,KAAR,CAAcC,KAAM;AAC1C;AACA;AACA;AACA,CALA;AAOA,MAAMC,KAAK,GAAGjB,MAAM,CAACU,GAAI;AACzB,WAAYG,CAAD,IAAOZ,GAAG,CAACY,CAAC,CAACC,KAAF,CAAQI,qBAAT,CAAgC;AACrD;AACA;AACA,CAJA;AAMA,MAAMC,gBAAgB,GAAGnB,MAAM,CAACU,GAAI;AACpC;AACA,CAFA;AAIA,MAAMU,MAAM,GAAGpB,MAAM,CAACU,GAAI;AAC1B;AACA;AACA;AACA;AACA,CALA;AAOA,MAAMW,WAAW,GAA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oBAAC,kBAAD;AAAoB,IAAA,SAAS,EAAE,CAAC,CAACA;AAAjC,IAHF,eAIE,oBAAC,gBAAD;AAAkB,IAAA,OAAO,EAAE,CAAC,CAACiC;AAA7B,IAJF,eAKE,oBAAC,oBAAD,OALF,EAOGL,OAPH,eASE,oBAAC,aAAD,OATF,EAWGC,QAXH,CATF,eAuBE,oBAAC,MAAD,qBACE,oBAAC,aAAD,OADF,CAvBF,CADF;AA6BD,CAxCD;;AA0CA,eAAeF,oBAAf","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\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"],"file":"ProfileDrawerContent.js"}
|
package/dist/esm/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<832737ac96fa474b0ed0902ff8d86b14>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
* @nogrep
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* tslint:disable */
|
|
8
|
+
|
|
9
|
+
/* eslint-disable */
|
|
10
|
+
// @ts-nocheck
|
|
11
|
+
const node = function () {
|
|
12
|
+
var v0 = [{
|
|
13
|
+
"alias": null,
|
|
14
|
+
"args": null,
|
|
15
|
+
"concreteType": "StatusPayload",
|
|
16
|
+
"kind": "LinkedField",
|
|
17
|
+
"name": "signOut",
|
|
18
|
+
"plural": false,
|
|
19
|
+
"selections": [{
|
|
20
|
+
"alias": null,
|
|
21
|
+
"args": null,
|
|
22
|
+
"kind": "ScalarField",
|
|
23
|
+
"name": "ok",
|
|
24
|
+
"storageKey": null
|
|
25
|
+
}],
|
|
26
|
+
"storageKey": null
|
|
27
|
+
}];
|
|
28
|
+
return {
|
|
29
|
+
"fragment": {
|
|
30
|
+
"argumentDefinitions": [],
|
|
31
|
+
"kind": "Fragment",
|
|
32
|
+
"metadata": null,
|
|
33
|
+
"name": "ProfileDrawerContentSignOutMutation",
|
|
34
|
+
"selections": v0
|
|
35
|
+
/*: any*/
|
|
36
|
+
,
|
|
37
|
+
"type": "Mutation",
|
|
38
|
+
"abstractKey": null
|
|
39
|
+
},
|
|
40
|
+
"kind": "Request",
|
|
41
|
+
"operation": {
|
|
42
|
+
"argumentDefinitions": [],
|
|
43
|
+
"kind": "Operation",
|
|
44
|
+
"name": "ProfileDrawerContentSignOutMutation",
|
|
45
|
+
"selections": v0
|
|
46
|
+
/*: any*/
|
|
47
|
+
|
|
48
|
+
},
|
|
49
|
+
"params": {
|
|
50
|
+
"cacheID": "f5241cc562af19628cf38a9731067807",
|
|
51
|
+
"id": null,
|
|
52
|
+
"metadata": {},
|
|
53
|
+
"name": "ProfileDrawerContentSignOutMutation",
|
|
54
|
+
"operationKind": "mutation",
|
|
55
|
+
"text": "mutation ProfileDrawerContentSignOutMutation {\n signOut {\n ok\n }\n}\n"
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}();
|
|
59
|
+
|
|
60
|
+
node.hash = "c7ca96e9e713315606b0c22d196b6f7b";
|
|
61
|
+
export default node;
|
|
62
|
+
//# sourceMappingURL=ProfileDrawerContentSignOutMutation.graphql.js.map
|
package/dist/esm/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/components/profile/__generated__/ProfileDrawerContentSignOutMutation.graphql.ts"],"names":["node","v0","hash"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;;AACA;AACA;AAcA,MAAMA,IAAqB,GAAI,YAAU;AACzC,MAAIC,EAAE,GAAG,CACP;AACE,aAAS,IADX;AAEE,YAAQ,IAFV;AAGE,oBAAgB,eAHlB;AAIE,YAAQ,aAJV;AAKE,YAAQ,SALV;AAME,cAAU,KANZ;AAOE,kBAAc,CACZ;AACE,eAAS,IADX;AAEE,cAAQ,IAFV;AAGE,cAAQ,aAHV;AAIE,cAAQ,IAJV;AAKE,oBAAc;AALhB,KADY,CAPhB;AAgBE,kBAAc;AAhBhB,GADO,CAAT;AAoBA,SAAO;AACL,gBAAY;AACV,6BAAuB,EADb;AAEV,cAAQ,UAFE;AAGV,kBAAY,IAHF;AAIV,cAAQ,qCAJE;AAKV,oBAAeA;AAAE;AALP;AAMV,cAAQ,UANE;AAOV,qBAAe;AAPL,KADP;AAUL,YAAQ,SAVH;AAWL,iBAAa;AACX,6BAAuB,EADZ;AAEX,cAAQ,WAFG;AAGX,cAAQ,qCAHG;AAIX,oBAAeA;AAAE;;AAJN,KAXR;AAiBL,cAAU;AACR,iBAAW,kCADH;AAER,YAAM,IAFE;AAGR,kBAAY,EAHJ;AAIR,cAAQ,qCAJA;AAKR,uBAAiB,UALT;AAMR,cAAQ;AANA;AAjBL,GAAP;AA0BC,CA/C6B,EAA9B;;AAiDCD,IAAD,CAAcE,IAAd,GAAqB,kCAArB;AAEA,eAAeF,IAAf","sourcesContent":["/**\n * @generated SignedSource<<832737ac96fa474b0ed0902ff8d86b14>>\n * @lightSyntaxTransform\n * @nogrep\n */\n\n/* tslint:disable */\n/* eslint-disable */\n// @ts-nocheck\n\nimport { ConcreteRequest, Mutation } from 'relay-runtime';\nexport type ProfileDrawerContentSignOutMutation$variables = {};\nexport type ProfileDrawerContentSignOutMutation$data = {\n readonly signOut: {\n readonly ok: boolean;\n };\n};\nexport type ProfileDrawerContentSignOutMutation = {\n variables: ProfileDrawerContentSignOutMutation$variables;\n response: ProfileDrawerContentSignOutMutation$data;\n};\n\nconst node: ConcreteRequest = (function(){\nvar v0 = [\n {\n \"alias\": null,\n \"args\": null,\n \"concreteType\": \"StatusPayload\",\n \"kind\": \"LinkedField\",\n \"name\": \"signOut\",\n \"plural\": false,\n \"selections\": [\n {\n \"alias\": null,\n \"args\": null,\n \"kind\": \"ScalarField\",\n \"name\": \"ok\",\n \"storageKey\": null\n }\n ],\n \"storageKey\": null\n }\n];\nreturn {\n \"fragment\": {\n \"argumentDefinitions\": [],\n \"kind\": \"Fragment\",\n \"metadata\": null,\n \"name\": \"ProfileDrawerContentSignOutMutation\",\n \"selections\": (v0/*: any*/),\n \"type\": \"Mutation\",\n \"abstractKey\": null\n },\n \"kind\": \"Request\",\n \"operation\": {\n \"argumentDefinitions\": [],\n \"kind\": \"Operation\",\n \"name\": \"ProfileDrawerContentSignOutMutation\",\n \"selections\": (v0/*: any*/)\n },\n \"params\": {\n \"cacheID\": \"f5241cc562af19628cf38a9731067807\",\n \"id\": null,\n \"metadata\": {},\n \"name\": \"ProfileDrawerContentSignOutMutation\",\n \"operationKind\": \"mutation\",\n \"text\": \"mutation ProfileDrawerContentSignOutMutation {\\n signOut {\\n ok\\n }\\n}\\n\"\n }\n};\n})();\n\n(node as any).hash = \"c7ca96e9e713315606b0c22d196b6f7b\";\n\nexport default node;\n"],"file":"ProfileDrawerContentSignOutMutation.graphql.js"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<dfa244a4ba1902852ff99f94a3333fa7>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
* @nogrep
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* tslint:disable */
|
|
8
|
+
|
|
9
|
+
/* eslint-disable */
|
|
10
|
+
// @ts-nocheck
|
|
11
|
+
const node = function () {
|
|
12
|
+
var v0 = [{
|
|
13
|
+
"defaultValue": null,
|
|
14
|
+
"kind": "LocalArgument",
|
|
15
|
+
"name": "input"
|
|
16
|
+
}],
|
|
17
|
+
v1 = [{
|
|
18
|
+
"alias": null,
|
|
19
|
+
"args": [{
|
|
20
|
+
"kind": "Variable",
|
|
21
|
+
"name": "input",
|
|
22
|
+
"variableName": "input"
|
|
23
|
+
}],
|
|
24
|
+
"concreteType": "User",
|
|
25
|
+
"kind": "LinkedField",
|
|
26
|
+
"name": "updateAvatar",
|
|
27
|
+
"plural": false,
|
|
28
|
+
"selections": [{
|
|
29
|
+
"alias": null,
|
|
30
|
+
"args": null,
|
|
31
|
+
"kind": "ScalarField",
|
|
32
|
+
"name": "id",
|
|
33
|
+
"storageKey": null
|
|
34
|
+
}, {
|
|
35
|
+
"alias": null,
|
|
36
|
+
"args": null,
|
|
37
|
+
"kind": "ScalarField",
|
|
38
|
+
"name": "avatar",
|
|
39
|
+
"storageKey": null
|
|
40
|
+
}],
|
|
41
|
+
"storageKey": null
|
|
42
|
+
}];
|
|
43
|
+
return {
|
|
44
|
+
"fragment": {
|
|
45
|
+
"argumentDefinitions": v0
|
|
46
|
+
/*: any*/
|
|
47
|
+
,
|
|
48
|
+
"kind": "Fragment",
|
|
49
|
+
"metadata": null,
|
|
50
|
+
"name": "ProfileDrawerContentUpdateAvatarMutation",
|
|
51
|
+
"selections": v1
|
|
52
|
+
/*: any*/
|
|
53
|
+
,
|
|
54
|
+
"type": "Mutation",
|
|
55
|
+
"abstractKey": null
|
|
56
|
+
},
|
|
57
|
+
"kind": "Request",
|
|
58
|
+
"operation": {
|
|
59
|
+
"argumentDefinitions": v0
|
|
60
|
+
/*: any*/
|
|
61
|
+
,
|
|
62
|
+
"kind": "Operation",
|
|
63
|
+
"name": "ProfileDrawerContentUpdateAvatarMutation",
|
|
64
|
+
"selections": v1
|
|
65
|
+
/*: any*/
|
|
66
|
+
|
|
67
|
+
},
|
|
68
|
+
"params": {
|
|
69
|
+
"cacheID": "b749732615af9f8027386d69ffb57b63",
|
|
70
|
+
"id": null,
|
|
71
|
+
"metadata": {},
|
|
72
|
+
"name": "ProfileDrawerContentUpdateAvatarMutation",
|
|
73
|
+
"operationKind": "mutation",
|
|
74
|
+
"text": "mutation ProfileDrawerContentUpdateAvatarMutation(\n $input: UpdateAvatarInput!\n) {\n updateAvatar(input: $input) {\n id\n avatar\n }\n}\n"
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}();
|
|
78
|
+
|
|
79
|
+
node.hash = "cf72a6314772ed0d1f182b197c858505";
|
|
80
|
+
export default node;
|
|
81
|
+
//# sourceMappingURL=ProfileDrawerContentUpdateAvatarMutation.graphql.js.map
|