soja-cli 1.7.0 → 1.7.1
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/ui/screens/ProfileScreen.js +38 -15
- package/package.json +1 -1
|
@@ -13,6 +13,12 @@ import { Panel } from '../kit/Panel.js';
|
|
|
13
13
|
import { ScreenFrame } from './ScreenFrame.js';
|
|
14
14
|
import { palette, symbols } from '../theme/theme.js';
|
|
15
15
|
import { toDisplayError } from '../../utils/errors.js';
|
|
16
|
+
function validBirthDate(value) {
|
|
17
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
18
|
+
return false;
|
|
19
|
+
const parsed = new Date(`${value}T00:00:00.000Z`);
|
|
20
|
+
return !Number.isNaN(parsed.valueOf()) && parsed.toISOString().slice(0, 10) === value && parsed <= new Date();
|
|
21
|
+
}
|
|
16
22
|
export function ProfileScreen({ active }) {
|
|
17
23
|
const { services, session, openOverlay, run, invalidateQueries, notify } = useAppState();
|
|
18
24
|
const client = useMemo(() => {
|
|
@@ -29,21 +35,38 @@ export function ProfileScreen({ active }) {
|
|
|
29
35
|
const save = (changes) => {
|
|
30
36
|
if (!client || !profile)
|
|
31
37
|
return false;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
const draft = {
|
|
39
|
+
displayName: changes.displayName ?? profile.displayName,
|
|
40
|
+
dateOfBirth: changes.dateOfBirth ?? profile.dateOfBirth ?? '',
|
|
41
|
+
countryCode: changes.countryCode ?? profile.countryCode ?? '',
|
|
42
|
+
};
|
|
43
|
+
const saveCompleteProfile = (value) => {
|
|
44
|
+
const displayName = value.displayName.trim();
|
|
45
|
+
if (!displayName || displayName.length > 80) {
|
|
46
|
+
openOverlay({ kind: 'prompt', title: 'Display name', initial: displayName, placeholder: 'Your name', onSubmit: (nextName) => {
|
|
47
|
+
const cleaned = nextName.trim();
|
|
48
|
+
return cleaned && cleaned.length <= 80 ? saveCompleteProfile({ ...value, displayName: cleaned }) : false;
|
|
49
|
+
} });
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (!validBirthDate(value.dateOfBirth)) {
|
|
53
|
+
openOverlay({ kind: 'prompt', title: 'Date of birth (YYYY-MM-DD)', initial: value.dateOfBirth, placeholder: '1990-01-31', onSubmit: (dateOfBirth) => validBirthDate(dateOfBirth) ? saveCompleteProfile({ ...value, dateOfBirth }) : false });
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (!/^[A-Z]{2}$/.test(value.countryCode)) {
|
|
57
|
+
void client.get('/v1/auth/countries').then(({ countries }) => {
|
|
58
|
+
openOverlay({ kind: 'picker', title: 'Country', initial: null, filterable: true,
|
|
59
|
+
options: countries.map((country) => ({ value: country.code, label: `${country.flag} ${country.name} · ${country.code}` })),
|
|
60
|
+
onSelect: (countryCode) => saveCompleteProfile({ ...value, countryCode }) });
|
|
61
|
+
}).catch((error) => notify(toDisplayError(error).message, 'error'));
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return run(async () => {
|
|
65
|
+
await client.request('PUT', '/v1/profile', { displayName, dateOfBirth: value.dateOfBirth, countryCode: value.countryCode });
|
|
66
|
+
invalidateQueries([topic]);
|
|
67
|
+
}, 'Profile updated');
|
|
68
|
+
};
|
|
69
|
+
return saveCompleteProfile(draft);
|
|
47
70
|
};
|
|
48
71
|
useKeys(Layer.screen, (input) => {
|
|
49
72
|
if (!profile || !client)
|