@oxy.so/services 14.23.0 → 14.24.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/lib/commonjs/ui/components/signIn/OxySignUpPanel.js +77 -9
- package/lib/commonjs/ui/components/signIn/OxySignUpPanel.js.map +1 -1
- package/lib/commonjs/ui/navigation/surfaceBackBridge.js +21 -9
- package/lib/commonjs/ui/navigation/surfaceBackBridge.js.map +1 -1
- package/lib/commonjs/ui/screens/EditProfileFieldScreen.js +4 -11
- package/lib/commonjs/ui/screens/EditProfileFieldScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SupervisionScreen.js +12 -0
- package/lib/commonjs/ui/screens/SupervisionScreen.js.map +1 -1
- package/lib/commonjs/ui/utils/apiErrorMessage.js +4 -0
- package/lib/commonjs/ui/utils/apiErrorMessage.js.map +1 -1
- package/lib/commonjs/ui/utils/calendarDate.js +30 -0
- package/lib/commonjs/ui/utils/calendarDate.js.map +1 -0
- package/lib/commonjs/ui/utils/persistedDataVersion.js +1 -1
- package/lib/module/ui/components/signIn/OxySignUpPanel.js +80 -12
- package/lib/module/ui/components/signIn/OxySignUpPanel.js.map +1 -1
- package/lib/module/ui/navigation/surfaceBackBridge.js +21 -9
- package/lib/module/ui/navigation/surfaceBackBridge.js.map +1 -1
- package/lib/module/ui/screens/EditProfileFieldScreen.js +4 -11
- package/lib/module/ui/screens/EditProfileFieldScreen.js.map +1 -1
- package/lib/module/ui/screens/SupervisionScreen.js +12 -0
- package/lib/module/ui/screens/SupervisionScreen.js.map +1 -1
- package/lib/module/ui/utils/apiErrorMessage.js +5 -1
- package/lib/module/ui/utils/apiErrorMessage.js.map +1 -1
- package/lib/module/ui/utils/calendarDate.js +25 -0
- package/lib/module/ui/utils/calendarDate.js.map +1 -0
- package/lib/module/ui/utils/persistedDataVersion.js +1 -1
- package/lib/typescript/commonjs/ui/components/signIn/OxySignUpPanel.d.ts +4 -1
- package/lib/typescript/commonjs/ui/components/signIn/OxySignUpPanel.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts +1 -0
- package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/navigation/surfaceBackBridge.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/SupervisionScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/apiErrorMessage.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/calendarDate.d.ts +13 -0
- package/lib/typescript/commonjs/ui/utils/calendarDate.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/utils/persistedDataVersion.d.ts +1 -1
- package/lib/typescript/module/ui/components/signIn/OxySignUpPanel.d.ts +4 -1
- package/lib/typescript/module/ui/components/signIn/OxySignUpPanel.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts +1 -0
- package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/module/ui/navigation/surfaceBackBridge.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/SupervisionScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/apiErrorMessage.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/calendarDate.d.ts +13 -0
- package/lib/typescript/module/ui/utils/calendarDate.d.ts.map +1 -0
- package/lib/typescript/module/ui/utils/persistedDataVersion.d.ts +1 -1
- package/package.json +3 -3
- package/src/ui/components/signIn/OxySignUpPanel.tsx +91 -10
- package/src/ui/navigation/__tests__/surfaceBackBridge.test.ts +44 -0
- package/src/ui/navigation/surfaceBackBridge.ts +20 -9
- package/src/ui/screens/EditProfileFieldScreen.tsx +4 -18
- package/src/ui/screens/SupervisionScreen.tsx +11 -0
- package/src/ui/utils/__tests__/calendarDate.test.ts +26 -0
- package/src/ui/utils/apiErrorMessage.ts +9 -1
- package/src/ui/utils/calendarDate.ts +22 -0
- package/src/ui/utils/persistedDataVersion.ts +1 -1
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Creating an Oxy account, in the account dialog of every app (web and native)
|
|
3
3
|
* and on auth.oxy.so's `/login`:
|
|
4
4
|
*
|
|
5
|
-
* username → email → the code sent to it → signed in
|
|
5
|
+
* username → date of birth → email → the code sent to it → signed in
|
|
6
|
+
*
|
|
7
|
+
* The date of birth sets the account's age band (ADR 0067); below the minimum
|
|
8
|
+
* unsupervised age the account is created under supervision, awaiting a guardian.
|
|
6
9
|
*
|
|
7
10
|
* The email is confirmed before the account exists, and it is how the account
|
|
8
11
|
* signs in (a code or a link each time). A password and an authenticator app
|
|
@@ -13,12 +16,16 @@
|
|
|
13
16
|
|
|
14
17
|
import type React from 'react';
|
|
15
18
|
import { useEffect, useState } from 'react';
|
|
16
|
-
import { Linking, Platform } from 'react-native';
|
|
19
|
+
import { Linking, Platform, View } from 'react-native';
|
|
20
|
+
import { DatePicker } from '@oxy.so/bloom/date-picker';
|
|
21
|
+
import { TextFieldLabel } from '@oxy.so/bloom/text-field';
|
|
17
22
|
import { toast } from '@oxy.so/bloom/toast';
|
|
18
23
|
import type { EmailVerificationConfirmResponse } from '@oxy.so/contracts';
|
|
19
24
|
import {
|
|
25
|
+
MIN_BIRTH_YEAR,
|
|
20
26
|
SIGN_IN_ERROR_CODES,
|
|
21
27
|
USERNAME_MAX_LENGTH,
|
|
28
|
+
ageBandOf,
|
|
22
29
|
checkContract,
|
|
23
30
|
emailAddressCheck,
|
|
24
31
|
stripDisallowedUsernameCharacters,
|
|
@@ -28,12 +35,14 @@ import { useAccountDialogSnapshot } from '../../hooks/accountDialogSnapshot';
|
|
|
28
35
|
import { useI18n } from '../../hooks/useI18n';
|
|
29
36
|
import { getCommonsAcquisitionUrl } from '../../utils/commonsStoreLinks';
|
|
30
37
|
import { isWebBrowser } from '../../utils/isWebBrowser';
|
|
38
|
+
import { fromCalendarDate, toCalendarDate } from '../../utils/calendarDate';
|
|
31
39
|
import { checkUsernameDraft, describeUsernameRefusal } from '../../utils/usernamePolicy';
|
|
32
40
|
import { SubtleLink } from '../authChooser/primitives';
|
|
33
41
|
import { OxyAuthScreen, OxyAuthScreenHeader, OxyAuthTerms } from './OxyAuthScreen';
|
|
34
42
|
import { readSignInFlow, writeSignInFlow } from './signInFlowStore';
|
|
35
43
|
import {
|
|
36
44
|
AccountFlowAction,
|
|
45
|
+
AccountFlowErrorLine,
|
|
37
46
|
AccountFlowField,
|
|
38
47
|
AccountFlowNote,
|
|
39
48
|
AccountFlowProgress,
|
|
@@ -45,7 +54,11 @@ import { withoutWhitespace } from '../../utils/withoutWhitespace';
|
|
|
45
54
|
/** Commons' own identity-creation deep link. */
|
|
46
55
|
const COMMONS_CREATE_IDENTITY_URL = 'oxycommons://create-identity';
|
|
47
56
|
|
|
48
|
-
type Step =
|
|
57
|
+
type Step =
|
|
58
|
+
| { name: 'username' }
|
|
59
|
+
| { name: 'birthdate' }
|
|
60
|
+
| { name: 'email' }
|
|
61
|
+
| { name: 'code'; verificationId: string };
|
|
49
62
|
|
|
50
63
|
export interface OxySignUpPanelProps {
|
|
51
64
|
/** The account exists and this origin is signed in as it. */
|
|
@@ -64,6 +77,8 @@ interface SavedSignUpFlow {
|
|
|
64
77
|
step: Step;
|
|
65
78
|
username: string;
|
|
66
79
|
email: string;
|
|
80
|
+
/** `YYYY-MM-DD`, or empty until the person has picked it. */
|
|
81
|
+
dateOfBirth?: string;
|
|
67
82
|
}
|
|
68
83
|
const SIGN_UP_FLOW_KEY = 'signup';
|
|
69
84
|
|
|
@@ -86,6 +101,7 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
|
|
|
86
101
|
const [step, setStep] = useState<Step>(saved?.step ?? { name: 'username' });
|
|
87
102
|
const [username, setUsername] = useState(saved?.username ?? '');
|
|
88
103
|
const [email, setEmail] = useState(saved?.email ?? '');
|
|
104
|
+
const [dateOfBirth, setDateOfBirth] = useState(saved?.dateOfBirth ?? '');
|
|
89
105
|
const [pending, setPending] = useState(false);
|
|
90
106
|
const [error, setError] = useState<string | null>(null);
|
|
91
107
|
|
|
@@ -94,8 +110,9 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
|
|
|
94
110
|
step,
|
|
95
111
|
username,
|
|
96
112
|
email,
|
|
113
|
+
dateOfBirth,
|
|
97
114
|
} satisfies SavedSignUpFlow);
|
|
98
|
-
}, [flowOwner, step, username, email]);
|
|
115
|
+
}, [flowOwner, step, username, email, dateOfBirth]);
|
|
99
116
|
|
|
100
117
|
const run = (work: () => Promise<void>) => {
|
|
101
118
|
if (pending) return;
|
|
@@ -127,10 +144,19 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
|
|
|
127
144
|
run(async () => {
|
|
128
145
|
const { available } = await oxyServices.auth.checkUsername(handle);
|
|
129
146
|
if (!available) throw new UsernameTakenError();
|
|
130
|
-
setStep({ name: '
|
|
147
|
+
setStep({ name: 'birthdate' });
|
|
131
148
|
});
|
|
132
149
|
};
|
|
133
150
|
|
|
151
|
+
const submitBirthdate = () => {
|
|
152
|
+
if (!dateOfBirth) {
|
|
153
|
+
setError(t('signup.birthdate.required'));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
setError(null);
|
|
157
|
+
setStep({ name: 'email' });
|
|
158
|
+
};
|
|
159
|
+
|
|
134
160
|
const sendCode = async (address: string) => {
|
|
135
161
|
const { verificationId } = await oxyServices.auth.email.startVerification({
|
|
136
162
|
purpose: 'signup',
|
|
@@ -158,11 +184,18 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
|
|
|
158
184
|
setError(draft.error);
|
|
159
185
|
return;
|
|
160
186
|
}
|
|
187
|
+
// A flow restored from before this step existed carries no date.
|
|
188
|
+
if (!dateOfBirth) {
|
|
189
|
+
setStep({ name: 'birthdate' });
|
|
190
|
+
setError(t('signup.birthdate.required'));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
161
193
|
try {
|
|
162
194
|
const session = await oxyServices.auth.signUp({
|
|
163
195
|
username: draft.username,
|
|
164
196
|
email,
|
|
165
197
|
emailTicket: ticket,
|
|
198
|
+
dateOfBirth,
|
|
166
199
|
languages: [currentLanguage],
|
|
167
200
|
...(campaignAttribution ? { campaignAttribution } : {}),
|
|
168
201
|
});
|
|
@@ -202,8 +235,13 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
|
|
|
202
235
|
.catch(() => toast.error(t('accountSwitcher.linkOpenFailed')));
|
|
203
236
|
};
|
|
204
237
|
|
|
205
|
-
// username → email → code, drawn as one segmented bar under each header.
|
|
206
|
-
const progressSteps = [
|
|
238
|
+
// username → date of birth → email → code, drawn as one segmented bar under each header.
|
|
239
|
+
const progressSteps = [
|
|
240
|
+
t('signup.username.label'),
|
|
241
|
+
t('signup.birthdate.label'),
|
|
242
|
+
t('signup.email.label'),
|
|
243
|
+
t('emailCode.title'),
|
|
244
|
+
];
|
|
207
245
|
const progress = (current: number) => (
|
|
208
246
|
<AccountFlowProgress steps={progressSteps} current={current} testID="signup-progress" />
|
|
209
247
|
);
|
|
@@ -217,7 +255,7 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
|
|
|
217
255
|
onConfirmed={createAccount}
|
|
218
256
|
onResend={() => sendCode(email)}
|
|
219
257
|
back={{ label: t('emailCode.changeEmail'), onPress: () => setStep({ name: 'email' }) }}
|
|
220
|
-
progress={progress(
|
|
258
|
+
progress={progress(3)}
|
|
221
259
|
/>
|
|
222
260
|
);
|
|
223
261
|
case 'email':
|
|
@@ -227,7 +265,7 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
|
|
|
227
265
|
title={t('signup.email.title')}
|
|
228
266
|
description={t('signup.email.subtitle')}
|
|
229
267
|
/>
|
|
230
|
-
{progress(
|
|
268
|
+
{progress(2)}
|
|
231
269
|
<AccountFlowField
|
|
232
270
|
label={t('signup.email.label')}
|
|
233
271
|
value={email}
|
|
@@ -252,12 +290,55 @@ export const OxySignUpPanel: React.FC<OxySignUpPanelProps> = ({
|
|
|
252
290
|
/>
|
|
253
291
|
<SubtleLink
|
|
254
292
|
label={t('signin.actions.back')}
|
|
255
|
-
onPress={() => setStep({ name: '
|
|
293
|
+
onPress={() => setStep({ name: 'birthdate' })}
|
|
256
294
|
testID="signup-back"
|
|
257
295
|
/>
|
|
258
296
|
<OxyAuthTerms />
|
|
259
297
|
</OxyAuthScreen>
|
|
260
298
|
);
|
|
299
|
+
case 'birthdate':
|
|
300
|
+
return (
|
|
301
|
+
<OxyAuthScreen>
|
|
302
|
+
<OxyAuthScreenHeader
|
|
303
|
+
title={t('signup.birthdate.title')}
|
|
304
|
+
description={t('signup.birthdate.subtitle')}
|
|
305
|
+
/>
|
|
306
|
+
{progress(1)}
|
|
307
|
+
<View style={{ gap: 8 }}>
|
|
308
|
+
<TextFieldLabel>{t('signup.birthdate.label')}</TextFieldLabel>
|
|
309
|
+
<DatePicker
|
|
310
|
+
value={fromCalendarDate(dateOfBirth)}
|
|
311
|
+
minDate={new Date(MIN_BIRTH_YEAR, 0, 1)}
|
|
312
|
+
maxDate={new Date()}
|
|
313
|
+
accessibilityLabel={t('signup.birthdate.label')}
|
|
314
|
+
placeholder={t('signup.birthdate.label')}
|
|
315
|
+
onChange={(date) => {
|
|
316
|
+
setDateOfBirth(date ? toCalendarDate(date) : '');
|
|
317
|
+
if (error) setError(null);
|
|
318
|
+
}}
|
|
319
|
+
testID="signup-birthdate"
|
|
320
|
+
/>
|
|
321
|
+
{error ? <AccountFlowErrorLine message={error} /> : null}
|
|
322
|
+
</View>
|
|
323
|
+
{dateOfBirth && ageBandOf(dateOfBirth) === 'under13' ? (
|
|
324
|
+
<AccountFlowNote testID="signup-birthdate-guardian-note">
|
|
325
|
+
{t('signup.birthdate.guardianNote')}
|
|
326
|
+
</AccountFlowNote>
|
|
327
|
+
) : null}
|
|
328
|
+
<AccountFlowAction
|
|
329
|
+
label={t('signin.actions.continue')}
|
|
330
|
+
onPress={submitBirthdate}
|
|
331
|
+
pending={pending}
|
|
332
|
+
testID="signup-birthdate-continue"
|
|
333
|
+
/>
|
|
334
|
+
<SubtleLink
|
|
335
|
+
label={t('signin.actions.back')}
|
|
336
|
+
onPress={() => setStep({ name: 'username' })}
|
|
337
|
+
testID="signup-birthdate-back"
|
|
338
|
+
/>
|
|
339
|
+
<OxyAuthTerms />
|
|
340
|
+
</OxyAuthScreen>
|
|
341
|
+
);
|
|
261
342
|
default:
|
|
262
343
|
return (
|
|
263
344
|
<OxyAuthScreen>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const listeners = new Set<() => boolean>();
|
|
2
|
+
|
|
3
|
+
jest.mock('react-native', () => ({
|
|
4
|
+
Platform: { OS: 'android' },
|
|
5
|
+
BackHandler: {
|
|
6
|
+
addEventListener: (_event: string, listener: () => boolean) => {
|
|
7
|
+
listeners.add(listener);
|
|
8
|
+
return { remove: () => listeners.delete(listener) };
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
import { __resetSurfaceBackBridgeForTests, pushSurfaceBackHandler } from '../surfaceBackBridge';
|
|
14
|
+
|
|
15
|
+
const press = () => [...listeners].some((listener) => listener());
|
|
16
|
+
|
|
17
|
+
afterEach(() => __resetSurfaceBackBridgeForTests());
|
|
18
|
+
|
|
19
|
+
it('holds Android Back only while a surface is open', () => {
|
|
20
|
+
expect(listeners.size).toBe(0);
|
|
21
|
+
const close = jest.fn(() => true);
|
|
22
|
+
const unregister = pushSurfaceBackHandler(close);
|
|
23
|
+
expect(listeners.size).toBe(1);
|
|
24
|
+
expect(press()).toBe(true);
|
|
25
|
+
expect(close).toHaveBeenCalledTimes(1);
|
|
26
|
+
unregister();
|
|
27
|
+
expect(listeners.size).toBe(0);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('routes Back to the topmost surface and keeps one listener for a stack', () => {
|
|
31
|
+
const lower = jest.fn(() => true);
|
|
32
|
+
const upper = jest.fn(() => true);
|
|
33
|
+
const releaseLower = pushSurfaceBackHandler(lower);
|
|
34
|
+
const releaseUpper = pushSurfaceBackHandler(upper);
|
|
35
|
+
expect(listeners.size).toBe(1);
|
|
36
|
+
press();
|
|
37
|
+
expect(upper).toHaveBeenCalledTimes(1);
|
|
38
|
+
expect(lower).not.toHaveBeenCalled();
|
|
39
|
+
releaseUpper();
|
|
40
|
+
press();
|
|
41
|
+
expect(lower).toHaveBeenCalledTimes(1);
|
|
42
|
+
releaseLower();
|
|
43
|
+
expect(listeners.size).toBe(0);
|
|
44
|
+
});
|
|
@@ -12,7 +12,7 @@ import { BackHandler, Platform } from 'react-native';
|
|
|
12
12
|
export type SurfaceBackHandler = () => boolean;
|
|
13
13
|
|
|
14
14
|
const handlerStack: SurfaceBackHandler[] = [];
|
|
15
|
-
let
|
|
15
|
+
let androidSubscription: { remove(): void } | null = null;
|
|
16
16
|
let escapeInstalled = false;
|
|
17
17
|
|
|
18
18
|
function invokeTopHandler(): boolean {
|
|
@@ -20,13 +20,22 @@ function invokeTopHandler(): boolean {
|
|
|
20
20
|
return handler ? handler() : false;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The Android listener is registered only while a surface is open. Any
|
|
25
|
+
* registered `hardwareBackPress` listener hands Back to JavaScript (React
|
|
26
|
+
* Native's native Back ownership counts listeners, not their answers), so a
|
|
27
|
+
* listener left behind after the first sheet closed routed every later Back
|
|
28
|
+
* through JavaScript: a pushed screen popped only after the JavaScript thread
|
|
29
|
+
* got to it (about 200 ms on a Pixel 8a) instead of natively at once.
|
|
30
|
+
*/
|
|
31
|
+
function syncAndroidHandler(): void {
|
|
32
|
+
if (Platform.OS !== 'android') return;
|
|
33
|
+
if (handlerStack.length > 0 && !androidSubscription) {
|
|
34
|
+
androidSubscription = BackHandler.addEventListener('hardwareBackPress', invokeTopHandler);
|
|
35
|
+
} else if (handlerStack.length === 0 && androidSubscription) {
|
|
36
|
+
androidSubscription.remove();
|
|
37
|
+
androidSubscription = null;
|
|
38
|
+
}
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
function installEscapeHandler(): void {
|
|
@@ -51,10 +60,11 @@ installEscapeHandler();
|
|
|
51
60
|
/** Push a handler for one live surface; returns unregister. */
|
|
52
61
|
export function pushSurfaceBackHandler(handler: SurfaceBackHandler): () => void {
|
|
53
62
|
handlerStack.push(handler);
|
|
54
|
-
|
|
63
|
+
syncAndroidHandler();
|
|
55
64
|
return () => {
|
|
56
65
|
const index = handlerStack.lastIndexOf(handler);
|
|
57
66
|
if (index >= 0) handlerStack.splice(index, 1);
|
|
67
|
+
syncAndroidHandler();
|
|
58
68
|
};
|
|
59
69
|
}
|
|
60
70
|
|
|
@@ -66,4 +76,5 @@ export function __invokeTopSurfaceBackForTests(): boolean {
|
|
|
66
76
|
/** Test-only reset. */
|
|
67
77
|
export function __resetSurfaceBackBridgeForTests(): void {
|
|
68
78
|
handlerStack.length = 0;
|
|
79
|
+
syncAndroidHandler();
|
|
69
80
|
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
SelectValue,
|
|
21
21
|
} from '@oxy.so/bloom/select';
|
|
22
22
|
import {
|
|
23
|
+
MIN_BIRTH_YEAR,
|
|
23
24
|
PRONOUNS,
|
|
24
25
|
USERNAME_MAX_LENGTH,
|
|
25
26
|
stripDisallowedUsernameCharacters,
|
|
@@ -28,6 +29,7 @@ import { useUsernameAvailability } from '../hooks/useUsernameAvailability';
|
|
|
28
29
|
import { GroupedSection, GroupedSectionItem } from '@oxy.so/bloom/grouped-section';
|
|
29
30
|
import type { User } from '@oxy.so/core';
|
|
30
31
|
import { useI18n } from '../hooks/useI18n';
|
|
32
|
+
import { fromCalendarDate, toCalendarDate } from '../utils/calendarDate';
|
|
31
33
|
import { useSurfaceHeader } from '../hooks/useSurfaceHeader';
|
|
32
34
|
import { useOxy } from '../context/oxyRuntimeContext';
|
|
33
35
|
import { useProfileEditing } from '../hooks/useProfileEditing';
|
|
@@ -71,13 +73,6 @@ interface FieldConfig {
|
|
|
71
73
|
isDatePicker?: boolean;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
/**
|
|
75
|
-
* The earliest calendar year the birthday picker offers — matches the
|
|
76
|
-
* platform's own lower bound (`dateOfBirthSchema`, `@oxy.so/contracts`) so a
|
|
77
|
-
* value this picker can produce is never one the API would reject.
|
|
78
|
-
*/
|
|
79
|
-
const MIN_BIRTH_YEAR = 1900;
|
|
80
|
-
|
|
81
76
|
interface EditProfileFieldScreenProps extends BaseScreenProps {
|
|
82
77
|
/** The field type to edit */
|
|
83
78
|
fieldType?: ProfileFieldType;
|
|
@@ -647,26 +642,17 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
|
|
|
647
642
|
|
|
648
643
|
// Keep birthdays date-only: local calendar components avoid UTC day shifts.
|
|
649
644
|
const renderBirthdayPicker = () => {
|
|
650
|
-
const value = fieldValues.dateOfBirth;
|
|
651
|
-
const parts = value ? value.split('-').map(Number) : null;
|
|
652
645
|
return (
|
|
653
646
|
<View className="gap-space-8">
|
|
654
647
|
<TextFieldLabel>{fieldConfig.title}</TextFieldLabel>
|
|
655
648
|
<DatePicker
|
|
656
|
-
value={
|
|
649
|
+
value={fromCalendarDate(fieldValues.dateOfBirth)}
|
|
657
650
|
minDate={new Date(MIN_BIRTH_YEAR, 0, 1)}
|
|
658
651
|
maxDate={new Date()}
|
|
659
652
|
accessibilityLabel={fieldConfig.title}
|
|
660
653
|
placeholder={fieldConfig.fields[0].placeholder}
|
|
661
654
|
disabled={isSaving}
|
|
662
|
-
onChange={(date) =>
|
|
663
|
-
handleFieldChange(
|
|
664
|
-
'dateOfBirth',
|
|
665
|
-
date
|
|
666
|
-
? `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
|
667
|
-
: '',
|
|
668
|
-
)
|
|
669
|
-
}
|
|
655
|
+
onChange={(date) => handleFieldChange('dateOfBirth', date ? toCalendarDate(date) : '')}
|
|
670
656
|
/>
|
|
671
657
|
</View>
|
|
672
658
|
);
|
|
@@ -271,6 +271,17 @@ function SupervisionBody({
|
|
|
271
271
|
)}
|
|
272
272
|
</Text>
|
|
273
273
|
<AccountFlowNote>{t('supervision.activeDescription')}</AccountFlowNote>
|
|
274
|
+
{own.guardianAccountId ? null : (
|
|
275
|
+
// No guardian holds this account: one created under supervision
|
|
276
|
+
// that awaits its first (ADR 0067), or one whose guardian is gone.
|
|
277
|
+
// The same invitation serves both; the server decides its effect.
|
|
278
|
+
<>
|
|
279
|
+
<AccountFlowNote>{t('supervision.guardianNeeded')}</AccountFlowNote>
|
|
280
|
+
<Button onPress={() => setAddingGuardian(!addingGuardian)}>
|
|
281
|
+
{t('supervision.invite')}
|
|
282
|
+
</Button>
|
|
283
|
+
</>
|
|
284
|
+
)}
|
|
274
285
|
<Button appearance="plain" onPress={() => navigate?.('HelpSupport')}>
|
|
275
286
|
{t('supervision.transitionHelp')}
|
|
276
287
|
</Button>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { fromCalendarDate, toCalendarDate } from '../calendarDate';
|
|
2
|
+
|
|
3
|
+
describe('calendarDate', () => {
|
|
4
|
+
it('writes the day the person picked, in the device zone', () => {
|
|
5
|
+
expect(toCalendarDate(new Date(2012, 0, 5))).toBe('2012-01-05');
|
|
6
|
+
expect(toCalendarDate(new Date(1999, 11, 31, 23, 59))).toBe('1999-12-31');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('reads an ISO calendar date back to the same local day', () => {
|
|
10
|
+
const date = fromCalendarDate('2012-01-05');
|
|
11
|
+
expect(date?.getFullYear()).toBe(2012);
|
|
12
|
+
expect(date?.getMonth()).toBe(0);
|
|
13
|
+
expect(date?.getDate()).toBe(5);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('round-trips', () => {
|
|
17
|
+
expect(toCalendarDate(fromCalendarDate('2008-02-29') as Date)).toBe('2008-02-29');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('reads nothing from an empty or malformed value', () => {
|
|
21
|
+
expect(fromCalendarDate('')).toBeNull();
|
|
22
|
+
expect(fromCalendarDate(null)).toBeNull();
|
|
23
|
+
expect(fromCalendarDate(undefined)).toBeNull();
|
|
24
|
+
expect(fromCalendarDate('5 January 2012')).toBeNull();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
* English, and for a validation failure it is "Validation failed".
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
DATE_OF_BIRTH_REFUSALS,
|
|
11
|
+
EMAIL_VERIFICATION_ERROR_CODES,
|
|
12
|
+
SIGN_IN_ERROR_CODES,
|
|
13
|
+
} from '@oxy.so/contracts/client';
|
|
10
14
|
import {
|
|
11
15
|
ErrorCodes,
|
|
12
16
|
getErrorStatus,
|
|
@@ -54,6 +58,10 @@ export function describeApiError(error: unknown, t: Translate, fallback?: string
|
|
|
54
58
|
const code = errorCode(error);
|
|
55
59
|
if (code !== undefined && OFFLINE_ERROR_CODES.has(code)) return t('signin.errors.network');
|
|
56
60
|
switch (code) {
|
|
61
|
+
case DATE_OF_BIRTH_REFUSALS.locked:
|
|
62
|
+
return t('editProfile.items.birthday.locked');
|
|
63
|
+
case DATE_OF_BIRTH_REFUSALS.supervisionRequired:
|
|
64
|
+
return t('editProfile.items.birthday.supervisionRequired');
|
|
57
65
|
case SIGN_IN_ERROR_CODES.invalidCredentials:
|
|
58
66
|
return t('signin.errors.invalidCredentials');
|
|
59
67
|
case SIGN_IN_ERROR_CODES.requestInvalid:
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A calendar date with no time of day (`YYYY-MM-DD`), to and from the local
|
|
3
|
+
* `Date` a picker works with.
|
|
4
|
+
*
|
|
5
|
+
* Local calendar components on purpose: `toISOString()` would shift the day for
|
|
6
|
+
* anyone east or west of UTC at the wrong hour, and the person picked a day on
|
|
7
|
+
* a calendar, not an instant.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** The ISO calendar date of a picker's `Date`, read in the device's own zone. */
|
|
11
|
+
export function toCalendarDate(date: Date): string {
|
|
12
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
13
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
14
|
+
return `${date.getFullYear()}-${month}-${day}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The local `Date` of an ISO calendar date, or `null` for anything else. */
|
|
18
|
+
export function fromCalendarDate(value: string | null | undefined): Date | null {
|
|
19
|
+
if (!value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
|
|
20
|
+
const [year, month, day] = value.split('-').map(Number);
|
|
21
|
+
return new Date(year, month - 1, day);
|
|
22
|
+
}
|