@memori.ai/memori-react 8.7.4 → 8.7.5
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/CHANGELOG.md +22 -0
- package/dist/components/Chat/Chat.js +1 -1
- package/dist/components/Chat/Chat.js.map +1 -1
- package/dist/components/LoginDrawer/LoginDrawer.d.ts +2 -2
- package/dist/components/LoginDrawer/LoginDrawer.js +181 -139
- package/dist/components/LoginDrawer/LoginDrawer.js.map +1 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.d.ts +2 -2
- package/dist/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js +61 -32
- package/dist/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js.map +1 -1
- package/dist/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +1 -1
- package/dist/components/MemoriWidget/MemoriWidget.js +2 -3
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/components/layouts/HiddenChat.js +3 -9
- package/dist/components/layouts/HiddenChat.js.map +1 -1
- package/dist/components/layouts/hidden-chat.css +14 -3
- package/dist/helpers/utils.js +1 -1
- package/dist/helpers/utils.js.map +1 -1
- package/esm/components/Chat/Chat.js +1 -1
- package/esm/components/Chat/Chat.js.map +1 -1
- package/esm/components/LoginDrawer/LoginDrawer.d.ts +2 -2
- package/esm/components/LoginDrawer/LoginDrawer.js +183 -141
- package/esm/components/LoginDrawer/LoginDrawer.js.map +1 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.d.ts +2 -2
- package/esm/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js +62 -33
- package/esm/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.js.map +1 -1
- package/esm/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +1 -1
- package/esm/components/MemoriWidget/MemoriWidget.js +2 -3
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/components/layouts/HiddenChat.js +3 -9
- package/esm/components/layouts/HiddenChat.js.map +1 -1
- package/esm/components/layouts/hidden-chat.css +14 -3
- package/esm/helpers/utils.js +1 -1
- package/esm/helpers/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Chat/Chat.tsx +1 -1
- package/src/components/LoginDrawer/LoginDrawer.test.tsx +12 -12
- package/src/components/LoginDrawer/LoginDrawer.tsx +391 -321
- package/src/components/MemoriArtifactSystem/ArtifactDrawer.stories.tsx +96 -179
- package/src/components/MemoriArtifactSystem/components/ArtifactHandler/ArtifactHandler.tsx +88 -39
- package/src/components/MemoriArtifactSystem/components/ArtifactPreview/ArtifactPreview.css +1 -1
- package/src/components/MemoriWidget/MemoriWidget.tsx +3 -4
- package/src/components/layouts/HiddenChat.tsx +4 -9
- package/src/components/layouts/hidden-chat.css +14 -3
- package/src/helpers/utils.ts +1 -1
- package/src/components/AccountForm/AccountForm.tsx +0 -325
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import { User, Tenant } from '@memori.ai/memori-api-client/dist/types';
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
import Button from '../ui/Button';
|
|
4
|
-
import { useTranslation } from 'react-i18next';
|
|
5
|
-
import memoriApiClient from '@memori.ai/memori-api-client';
|
|
6
|
-
import toast from 'react-hot-toast';
|
|
7
|
-
import { mailRegEx, pwdRegEx, usernameRegEx } from '../../helpers/utils';
|
|
8
|
-
import { getErrori18nKey } from '../../helpers/error';
|
|
9
|
-
import Tooltip from '../ui/Tooltip';
|
|
10
|
-
|
|
11
|
-
export interface Props {
|
|
12
|
-
user: User;
|
|
13
|
-
loginToken: string;
|
|
14
|
-
apiClient: ReturnType<typeof memoriApiClient>;
|
|
15
|
-
onUserUpdate: (user: User) => void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const imgMimeTypes = ['image/jpeg', 'image/png', 'image/jpg', 'image/gif'];
|
|
19
|
-
|
|
20
|
-
const AccountForm = ({ user, loginToken, apiClient, onUserUpdate }: Props) => {
|
|
21
|
-
const { t, i18n } = useTranslation();
|
|
22
|
-
const lang = i18n.language === 'it' ? 'it' : 'en';
|
|
23
|
-
|
|
24
|
-
const { updateUser, uploadAsset } = apiClient.backend;
|
|
25
|
-
|
|
26
|
-
const [email, setEmail] = useState<string>();
|
|
27
|
-
const [password, setPassword] = useState<string>();
|
|
28
|
-
const [confirmPassword, setConfirmPassword] = useState<string>();
|
|
29
|
-
|
|
30
|
-
const pwdAcceptable = !password || (password && pwdRegEx.test(password));
|
|
31
|
-
const pwdGreen = pwdAcceptable && password && password.length >= 24;
|
|
32
|
-
const pwdEmpty = !password || password.length === 0;
|
|
33
|
-
const pwdMeterValue =
|
|
34
|
-
!pwdAcceptable || pwdEmpty
|
|
35
|
-
? 0
|
|
36
|
-
: password.length < 8
|
|
37
|
-
? 15
|
|
38
|
-
: password.length >= 32
|
|
39
|
-
? 100
|
|
40
|
-
: (password.length - 8) * (50 / 24) + 50;
|
|
41
|
-
|
|
42
|
-
const [loading, setLoading] = useState(false);
|
|
43
|
-
const [error, setError] = useState<string | null>(null);
|
|
44
|
-
|
|
45
|
-
const sendUserUpdate = async (userID: string, user: Partial<User>) => {
|
|
46
|
-
try {
|
|
47
|
-
const { user: updatedUser, ...resp } = await updateUser(
|
|
48
|
-
loginToken,
|
|
49
|
-
userID,
|
|
50
|
-
user
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
if (resp.resultCode !== 0) {
|
|
54
|
-
console.error(resp);
|
|
55
|
-
toast.error(t(getErrori18nKey(resp.resultCode)));
|
|
56
|
-
} else if (updatedUser) {
|
|
57
|
-
toast.success(t('success'));
|
|
58
|
-
onUserUpdate(updatedUser);
|
|
59
|
-
}
|
|
60
|
-
} catch (e) {
|
|
61
|
-
let err = e as Error;
|
|
62
|
-
console.error('[signup]', err);
|
|
63
|
-
if (err?.message) toast.error(err.message);
|
|
64
|
-
} finally {
|
|
65
|
-
setLoading(false);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const submitUserUpdate = async (e: React.FormEvent<HTMLFormElement>) => {
|
|
70
|
-
e.preventDefault();
|
|
71
|
-
if (!user.userID) return;
|
|
72
|
-
const userID = user.userID;
|
|
73
|
-
|
|
74
|
-
const form = e.currentTarget as HTMLFormElement;
|
|
75
|
-
|
|
76
|
-
const eMail = form.eMail.value ?? email;
|
|
77
|
-
const newPassword = form.newPassword.value ?? password;
|
|
78
|
-
const currentPassword = form.password.value;
|
|
79
|
-
const confirmPassword = form.confirmPassword.value;
|
|
80
|
-
const pAndCUAccepted = (form.pAndCUAccepted as HTMLInputElement | null)
|
|
81
|
-
?.checked;
|
|
82
|
-
const avatar = (form.avatar as HTMLInputElement | null)?.files?.[0];
|
|
83
|
-
|
|
84
|
-
setLoading(true);
|
|
85
|
-
setError(null);
|
|
86
|
-
|
|
87
|
-
if (newPassword?.length && newPassword !== confirmPassword) {
|
|
88
|
-
setError(t('login.passwordMatchingError'));
|
|
89
|
-
setLoading(false);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let patchedUser: User = {
|
|
94
|
-
...(eMail?.length && eMail !== user.eMail ? { eMail } : {}),
|
|
95
|
-
...(newPassword ? { password: currentPassword, newPassword } : {}),
|
|
96
|
-
...(pAndCUAccepted !== undefined && pAndCUAccepted !== user.pAndCUAccepted
|
|
97
|
-
? { pAndCUAccepted, pAndCUAcceptanceDate: new Date().toISOString() }
|
|
98
|
-
: {}),
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
if (Object.values(patchedUser).length === 0 && !avatar) {
|
|
102
|
-
console.debug('No changes to submit');
|
|
103
|
-
setLoading(false);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (avatar) {
|
|
108
|
-
const reader = new FileReader();
|
|
109
|
-
reader.onload = async e => {
|
|
110
|
-
try {
|
|
111
|
-
const { asset: avatarAsset, ...resp } = await uploadAsset(
|
|
112
|
-
avatar.name ?? 'avatar',
|
|
113
|
-
e.target?.result as string,
|
|
114
|
-
loginToken
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
if (resp.resultCode !== 0) {
|
|
118
|
-
console.error(resp);
|
|
119
|
-
toast.error(t(getErrori18nKey(resp.resultCode)));
|
|
120
|
-
} else if (avatarAsset) {
|
|
121
|
-
patchedUser.avatarURL = avatarAsset.assetURL;
|
|
122
|
-
|
|
123
|
-
await sendUserUpdate(userID, patchedUser);
|
|
124
|
-
}
|
|
125
|
-
} catch (e) {
|
|
126
|
-
let err = e as Error;
|
|
127
|
-
console.error('[avatar upload]', err);
|
|
128
|
-
|
|
129
|
-
if (err?.message) toast.error(err.message);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
reader.readAsDataURL(avatar);
|
|
133
|
-
} else {
|
|
134
|
-
await sendUserUpdate(userID, patchedUser);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
<>
|
|
140
|
-
<h3 className="memori--login-drawer--edit-account-title">
|
|
141
|
-
{t('login.editAccount')}
|
|
142
|
-
</h3>
|
|
143
|
-
|
|
144
|
-
<form
|
|
145
|
-
className="memori--login-drawer--form memori--login-drawer--account-form"
|
|
146
|
-
onSubmit={submitUserUpdate}
|
|
147
|
-
>
|
|
148
|
-
<details className="memori--details">
|
|
149
|
-
<summary>{t('login.emailChange')}</summary>
|
|
150
|
-
|
|
151
|
-
<label htmlFor="#eMail">
|
|
152
|
-
{t('login.email')}
|
|
153
|
-
<input
|
|
154
|
-
type="email"
|
|
155
|
-
name="eMail"
|
|
156
|
-
id="eMail"
|
|
157
|
-
autoComplete="email"
|
|
158
|
-
placeholder={user.eMail}
|
|
159
|
-
onChange={e => setEmail(e.target.value)}
|
|
160
|
-
aria-invalid={!!email?.length && !mailRegEx.test(email)}
|
|
161
|
-
/>
|
|
162
|
-
</label>
|
|
163
|
-
{!!email?.length && !mailRegEx.test(email) && (
|
|
164
|
-
<p className="memori--login-drawer--inline-error">
|
|
165
|
-
{t('login.emailFormatError')}
|
|
166
|
-
</p>
|
|
167
|
-
)}
|
|
168
|
-
</details>
|
|
169
|
-
|
|
170
|
-
<details className="memori--details">
|
|
171
|
-
<summary>{t('login.passwordChange')}</summary>
|
|
172
|
-
|
|
173
|
-
<label htmlFor="#password">
|
|
174
|
-
{t('login.currentPassword')}
|
|
175
|
-
<input
|
|
176
|
-
id="password"
|
|
177
|
-
name="password"
|
|
178
|
-
type="password"
|
|
179
|
-
autoComplete="password"
|
|
180
|
-
placeholder={t('login.currentPassword') || 'Password'}
|
|
181
|
-
/>
|
|
182
|
-
</label>
|
|
183
|
-
|
|
184
|
-
<label htmlFor="#newPassword">
|
|
185
|
-
{t('login.newPassword')}
|
|
186
|
-
<input
|
|
187
|
-
id="newPassword"
|
|
188
|
-
name="newPassword"
|
|
189
|
-
type="password"
|
|
190
|
-
autoComplete="new-password"
|
|
191
|
-
placeholder={t('login.password') || 'Password'}
|
|
192
|
-
onChange={e => setPassword(e.target.value)}
|
|
193
|
-
aria-invalid={!pwdAcceptable}
|
|
194
|
-
/>
|
|
195
|
-
</label>
|
|
196
|
-
{!pwdAcceptable && (
|
|
197
|
-
<p className="memori--login-drawer--inline-error">
|
|
198
|
-
{t('login.passwordFormatError')}
|
|
199
|
-
</p>
|
|
200
|
-
)}
|
|
201
|
-
|
|
202
|
-
<label htmlFor="#confirm-password">
|
|
203
|
-
{t('login.confirmPassword')}
|
|
204
|
-
<input
|
|
205
|
-
id="confirm-password"
|
|
206
|
-
name="confirmPassword"
|
|
207
|
-
type="password"
|
|
208
|
-
autoComplete="new-password"
|
|
209
|
-
placeholder={t('login.confirmPassword') || 'Password'}
|
|
210
|
-
onChange={e => setConfirmPassword(e.target.value)}
|
|
211
|
-
aria-invalid={
|
|
212
|
-
!!password?.length &&
|
|
213
|
-
!!confirmPassword?.length &&
|
|
214
|
-
password !== confirmPassword
|
|
215
|
-
}
|
|
216
|
-
/>
|
|
217
|
-
</label>
|
|
218
|
-
{!!password?.length &&
|
|
219
|
-
!!confirmPassword?.length &&
|
|
220
|
-
password !== confirmPassword && (
|
|
221
|
-
<p className="memori--login-drawer--inline-error">
|
|
222
|
-
{t('login.passwordMatchingError')}
|
|
223
|
-
</p>
|
|
224
|
-
)}
|
|
225
|
-
|
|
226
|
-
<meter
|
|
227
|
-
className="memori--login-drawer--password-meter"
|
|
228
|
-
min={0}
|
|
229
|
-
low={33}
|
|
230
|
-
high={66}
|
|
231
|
-
optimum={80}
|
|
232
|
-
max={100}
|
|
233
|
-
value={pwdMeterValue}
|
|
234
|
-
id="password-strength-meter"
|
|
235
|
-
/>
|
|
236
|
-
<small>
|
|
237
|
-
{t(
|
|
238
|
-
`login.pwd${
|
|
239
|
-
pwdGreen ? 'Strong' : pwdAcceptable ? 'Acceptable' : 'Weak'
|
|
240
|
-
}`
|
|
241
|
-
)}
|
|
242
|
-
</small>
|
|
243
|
-
</details>
|
|
244
|
-
|
|
245
|
-
<details className="memori--details">
|
|
246
|
-
<summary>{t('login.avatarChange')}</summary>
|
|
247
|
-
|
|
248
|
-
<label htmlFor="#avatar">
|
|
249
|
-
Avatar
|
|
250
|
-
<input
|
|
251
|
-
type="file"
|
|
252
|
-
name="avatar"
|
|
253
|
-
id="avatar"
|
|
254
|
-
accept={imgMimeTypes.join(', ')}
|
|
255
|
-
placeholder={user.avatarURL}
|
|
256
|
-
/>
|
|
257
|
-
</label>
|
|
258
|
-
</details>
|
|
259
|
-
|
|
260
|
-
<label className="memori-checkbox memori-checkbox--disabled">
|
|
261
|
-
<span className="memori-checkbox--input-wrapper">
|
|
262
|
-
<input
|
|
263
|
-
type="checkbox"
|
|
264
|
-
name="tnCAndPPAccepted"
|
|
265
|
-
disabled
|
|
266
|
-
defaultChecked={user.tnCAndPPAccepted}
|
|
267
|
-
checked={user.tnCAndPPAccepted}
|
|
268
|
-
className="memori-checkbox--input"
|
|
269
|
-
/>
|
|
270
|
-
<span className="memori-checkbox--inner" />
|
|
271
|
-
</span>
|
|
272
|
-
<span className="memori-checkbox--text">
|
|
273
|
-
{t('login.privacyLabel')}{' '}
|
|
274
|
-
<a
|
|
275
|
-
href={`https://memori.ai/${lang}/privacy_and_cookie`}
|
|
276
|
-
target="_blank"
|
|
277
|
-
rel="noopener noreferrer"
|
|
278
|
-
>
|
|
279
|
-
{t('login.privacyAndCookiePolicy')}
|
|
280
|
-
</a>{' '}
|
|
281
|
-
{t('login.and')}{' '}
|
|
282
|
-
<a
|
|
283
|
-
href={`https://memori.ai/${lang}/tos`}
|
|
284
|
-
target="_blank"
|
|
285
|
-
rel="noopener noreferrer"
|
|
286
|
-
>
|
|
287
|
-
{t('login.termsOfService')}
|
|
288
|
-
</a>
|
|
289
|
-
</span>
|
|
290
|
-
</label>
|
|
291
|
-
|
|
292
|
-
<label className="memori-checkbox">
|
|
293
|
-
<span className="memori-checkbox--input-wrapper">
|
|
294
|
-
<input
|
|
295
|
-
type="checkbox"
|
|
296
|
-
name="pAndCUAccepted"
|
|
297
|
-
className="memori-checkbox--input"
|
|
298
|
-
defaultChecked={user.pAndCUAccepted}
|
|
299
|
-
/>
|
|
300
|
-
<span className="memori-checkbox--inner" />
|
|
301
|
-
</span>
|
|
302
|
-
<Tooltip align="left" content={t('login.deepThoughtExplaination')}>
|
|
303
|
-
<span className="memori-checkbox--text">
|
|
304
|
-
{t('login.pAndCUAccepted')}{' '}
|
|
305
|
-
<small>
|
|
306
|
-
<em>({t('login.optional')})</em>
|
|
307
|
-
</small>
|
|
308
|
-
</span>
|
|
309
|
-
</Tooltip>
|
|
310
|
-
</label>
|
|
311
|
-
|
|
312
|
-
<Button htmlType="submit" primary loading={loading}>
|
|
313
|
-
{t('login.save')}
|
|
314
|
-
</Button>
|
|
315
|
-
</form>
|
|
316
|
-
{error && (
|
|
317
|
-
<p role="alert" className="memori--login-drawer--error">
|
|
318
|
-
{error}
|
|
319
|
-
</p>
|
|
320
|
-
)}
|
|
321
|
-
</>
|
|
322
|
-
);
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
export default AccountForm;
|