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.
@@ -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
- if (!profile.dateOfBirth || !profile.countryCode) {
33
- openOverlay({ kind: 'prompt', title: 'Complete profile · date of birth (YYYY-MM-DD)', initial: profile.dateOfBirth ?? '', onSubmit: (dateOfBirth) => {
34
- if (!/^\d{4}-\d{2}-\d{2}$/.test(dateOfBirth))
35
- return false;
36
- return run(async () => {
37
- await client.request('PUT', '/v1/profile', { displayName: profile.displayName, dateOfBirth, countryCode: profile.countryCode ?? '' });
38
- invalidateQueries([topic]);
39
- }, 'Profile updated');
40
- } });
41
- return false;
42
- }
43
- return run(async () => {
44
- await client.request('PUT', '/v1/profile', { displayName: changes.displayName ?? profile.displayName, dateOfBirth: changes.dateOfBirth ?? profile.dateOfBirth, countryCode: changes.countryCode ?? profile.countryCode });
45
- invalidateQueries([topic]);
46
- }, 'Profile updated');
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soja-cli",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Software Operations & Job Assistant",
5
5
  "author": "Enmauel.biz",
6
6
  "license": "SEE LICENSE IN LICENSE",