@oxy.so/services 14.2.0 → 14.2.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/accountSettings/AccountSettings.js +8 -7
- package/lib/commonjs/ui/components/accountSettings/AccountSettings.js.map +1 -1
- package/lib/commonjs/ui/components/signIn/OxyPasswordPanel.js +0 -5
- package/lib/commonjs/ui/components/signIn/OxyPasswordPanel.js.map +1 -1
- package/lib/commonjs/ui/components/signIn/OxySignInPanel.js +2 -1
- package/lib/commonjs/ui/components/signIn/OxySignInPanel.js.map +1 -1
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +13 -24
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/commonjs/ui/hooks/mutations/useServicesMutations.js +11 -22
- package/lib/commonjs/ui/hooks/mutations/useServicesMutations.js.map +1 -1
- package/lib/commonjs/ui/hooks/useApiErrorToast.js +24 -0
- package/lib/commonjs/ui/hooks/useApiErrorToast.js.map +1 -0
- package/lib/commonjs/ui/hooks/useUsernameAvailability.js +2 -2
- package/lib/commonjs/ui/hooks/useUsernameAvailability.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountMembersScreen.js +14 -17
- package/lib/commonjs/ui/screens/AccountMembersScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/DomainsScreen.js +5 -4
- package/lib/commonjs/ui/screens/DomainsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/EditProfileFieldScreen.js +2 -5
- package/lib/commonjs/ui/screens/EditProfileFieldScreen.js.map +1 -1
- package/lib/commonjs/ui/utils/apiErrorMessage.js +18 -27
- package/lib/commonjs/ui/utils/apiErrorMessage.js.map +1 -1
- package/lib/commonjs/ui/utils/followErrors.js +2 -3
- package/lib/commonjs/ui/utils/followErrors.js.map +1 -1
- package/lib/commonjs/ui/utils/usernamePolicy.js +10 -6
- package/lib/commonjs/ui/utils/usernamePolicy.js.map +1 -1
- package/lib/module/ui/components/accountSettings/AccountSettings.js +8 -7
- package/lib/module/ui/components/accountSettings/AccountSettings.js.map +1 -1
- package/lib/module/ui/components/signIn/OxyPasswordPanel.js +0 -5
- package/lib/module/ui/components/signIn/OxyPasswordPanel.js.map +1 -1
- package/lib/module/ui/components/signIn/OxySignInPanel.js +3 -2
- package/lib/module/ui/components/signIn/OxySignInPanel.js.map +1 -1
- package/lib/module/ui/hooks/mutations/useAccountMutations.js +13 -24
- package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/module/ui/hooks/mutations/useServicesMutations.js +11 -22
- package/lib/module/ui/hooks/mutations/useServicesMutations.js.map +1 -1
- package/lib/module/ui/hooks/useApiErrorToast.js +21 -0
- package/lib/module/ui/hooks/useApiErrorToast.js.map +1 -0
- package/lib/module/ui/hooks/useUsernameAvailability.js +2 -2
- package/lib/module/ui/hooks/useUsernameAvailability.js.map +1 -1
- package/lib/module/ui/screens/AccountMembersScreen.js +14 -17
- package/lib/module/ui/screens/AccountMembersScreen.js.map +1 -1
- package/lib/module/ui/screens/DomainsScreen.js +5 -4
- package/lib/module/ui/screens/DomainsScreen.js.map +1 -1
- package/lib/module/ui/screens/EditProfileFieldScreen.js +2 -5
- package/lib/module/ui/screens/EditProfileFieldScreen.js.map +1 -1
- package/lib/module/ui/utils/apiErrorMessage.js +17 -24
- package/lib/module/ui/utils/apiErrorMessage.js.map +1 -1
- package/lib/module/ui/utils/followErrors.js +2 -3
- package/lib/module/ui/utils/followErrors.js.map +1 -1
- package/lib/module/ui/utils/usernamePolicy.js +11 -7
- package/lib/module/ui/utils/usernamePolicy.js.map +1 -1
- package/lib/typescript/commonjs/ui/components/accountSettings/AccountSettings.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/signIn/OxyPasswordPanel.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/mutations/useServicesMutations.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useApiErrorToast.d.ts +7 -0
- package/lib/typescript/commonjs/ui/hooks/useApiErrorToast.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/AccountMembersScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/DomainsScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/apiErrorMessage.d.ts +6 -4
- package/lib/typescript/commonjs/ui/utils/apiErrorMessage.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/followErrors.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/usernamePolicy.d.ts +2 -2
- package/lib/typescript/commonjs/ui/utils/usernamePolicy.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/accountSettings/AccountSettings.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/signIn/OxyPasswordPanel.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/mutations/useServicesMutations.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useApiErrorToast.d.ts +7 -0
- package/lib/typescript/module/ui/hooks/useApiErrorToast.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/AccountMembersScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/DomainsScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/apiErrorMessage.d.ts +6 -4
- package/lib/typescript/module/ui/utils/apiErrorMessage.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/followErrors.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/usernamePolicy.d.ts +2 -2
- package/lib/typescript/module/ui/utils/usernamePolicy.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/ui/components/accountSettings/AccountSettings.tsx +8 -7
- package/src/ui/components/signIn/OxyPasswordPanel.tsx +0 -3
- package/src/ui/components/signIn/OxySignInPanel.tsx +3 -7
- package/src/ui/hooks/mutations/useAccountMutations.ts +13 -12
- package/src/ui/hooks/mutations/useServicesMutations.ts +11 -12
- package/src/ui/hooks/useApiErrorToast.ts +19 -0
- package/src/ui/hooks/useUsernameAvailability.ts +2 -2
- package/src/ui/screens/AccountMembersScreen.tsx +14 -24
- package/src/ui/screens/DomainsScreen.tsx +5 -4
- package/src/ui/screens/EditProfileFieldScreen.tsx +2 -5
- package/src/ui/utils/apiErrorMessage.ts +19 -24
- package/src/ui/utils/followErrors.ts +2 -3
- package/src/ui/utils/usernamePolicy.ts +13 -11
|
@@ -4,14 +4,13 @@ import { queryKeys, invalidateSessionQueries } from '../queries/queryKeys';
|
|
|
4
4
|
import { mutationKeys } from './mutationKeys';
|
|
5
5
|
import { useOxy } from '../../context/oxyRuntimeContext';
|
|
6
6
|
import { toast } from '@oxy.so/bloom/toast';
|
|
7
|
-
import {
|
|
8
|
-
import { useI18n } from '../useI18n';
|
|
7
|
+
import { useApiErrorToast } from '../useApiErrorToast';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Switch active session
|
|
12
11
|
*/
|
|
13
12
|
export const useSwitchSession = () => {
|
|
14
|
-
const
|
|
13
|
+
const showApiError = useApiErrorToast();
|
|
15
14
|
const { switchSession } = useOxy();
|
|
16
15
|
const queryClient = useQueryClient();
|
|
17
16
|
|
|
@@ -31,7 +30,7 @@ export const useSwitchSession = () => {
|
|
|
31
30
|
queryClient.invalidateQueries({ queryKey: queryKeys.accounts.all });
|
|
32
31
|
},
|
|
33
32
|
onError: (error) => {
|
|
34
|
-
|
|
33
|
+
showApiError(error, 'actionErrors.switchSession');
|
|
35
34
|
},
|
|
36
35
|
});
|
|
37
36
|
};
|
|
@@ -40,7 +39,7 @@ export const useSwitchSession = () => {
|
|
|
40
39
|
* Logout from a session
|
|
41
40
|
*/
|
|
42
41
|
export const useLogoutSession = () => {
|
|
43
|
-
const
|
|
42
|
+
const showApiError = useApiErrorToast();
|
|
44
43
|
const { oxyServices, activeSessionId } = useOxy();
|
|
45
44
|
const queryClient = useQueryClient();
|
|
46
45
|
|
|
@@ -79,7 +78,7 @@ export const useLogoutSession = () => {
|
|
|
79
78
|
if (context?.previousSessions) {
|
|
80
79
|
queryClient.setQueryData(queryKeys.sessions.list(), context.previousSessions);
|
|
81
80
|
}
|
|
82
|
-
|
|
81
|
+
showApiError(error, 'actionErrors.logout');
|
|
83
82
|
},
|
|
84
83
|
onSuccess: () => {
|
|
85
84
|
// Invalidate all session queries
|
|
@@ -95,7 +94,7 @@ export const useLogoutSession = () => {
|
|
|
95
94
|
* Logout from all sessions
|
|
96
95
|
*/
|
|
97
96
|
export const useLogoutAll = () => {
|
|
98
|
-
const
|
|
97
|
+
const showApiError = useApiErrorToast();
|
|
99
98
|
const { oxyServices, activeSessionId, clearSessionState } = useOxy();
|
|
100
99
|
const queryClient = useQueryClient();
|
|
101
100
|
|
|
@@ -115,7 +114,7 @@ export const useLogoutAll = () => {
|
|
|
115
114
|
toast.success('Logged out from all sessions');
|
|
116
115
|
},
|
|
117
116
|
onError: (error) => {
|
|
118
|
-
|
|
117
|
+
showApiError(error, 'actionErrors.logoutAll');
|
|
119
118
|
},
|
|
120
119
|
});
|
|
121
120
|
};
|
|
@@ -124,7 +123,7 @@ export const useLogoutAll = () => {
|
|
|
124
123
|
* Update device name
|
|
125
124
|
*/
|
|
126
125
|
export const useUpdateDeviceName = () => {
|
|
127
|
-
const
|
|
126
|
+
const showApiError = useApiErrorToast();
|
|
128
127
|
const { oxyServices, activeSessionId } = useOxy();
|
|
129
128
|
const queryClient = useQueryClient();
|
|
130
129
|
|
|
@@ -144,7 +143,7 @@ export const useUpdateDeviceName = () => {
|
|
|
144
143
|
toast.success('Device name updated');
|
|
145
144
|
},
|
|
146
145
|
onError: (error) => {
|
|
147
|
-
|
|
146
|
+
showApiError(error, 'actionErrors.updateDeviceName');
|
|
148
147
|
},
|
|
149
148
|
});
|
|
150
149
|
};
|
|
@@ -153,7 +152,7 @@ export const useUpdateDeviceName = () => {
|
|
|
153
152
|
* Remove a device
|
|
154
153
|
*/
|
|
155
154
|
export const useRemoveDevice = () => {
|
|
156
|
-
const
|
|
155
|
+
const showApiError = useApiErrorToast();
|
|
157
156
|
const { oxyServices } = useOxy();
|
|
158
157
|
const queryClient = useQueryClient();
|
|
159
158
|
|
|
@@ -170,7 +169,7 @@ export const useRemoveDevice = () => {
|
|
|
170
169
|
toast.success('Device removed');
|
|
171
170
|
},
|
|
172
171
|
onError: (error) => {
|
|
173
|
-
|
|
172
|
+
showApiError(error, 'actionErrors.removeDevice');
|
|
174
173
|
},
|
|
175
174
|
});
|
|
176
175
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { toast } from '@oxy.so/bloom/toast';
|
|
3
|
+
import { describeApiError } from '../utils/apiErrorMessage';
|
|
4
|
+
import { useI18n } from './useI18n';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Toast a failed API call in the person's language: the reason when the error
|
|
8
|
+
* names one (offline, invalid input, rate limit, server fault), else the
|
|
9
|
+
* `fallbackKey` string saying what failed. Never the server's `message`.
|
|
10
|
+
*/
|
|
11
|
+
export function useApiErrorToast(): (error: unknown, fallbackKey: string) => void {
|
|
12
|
+
const { t } = useI18n();
|
|
13
|
+
return useCallback(
|
|
14
|
+
(error: unknown, fallbackKey: string) => {
|
|
15
|
+
toast.error(describeApiError(error, t, t(fallbackKey)));
|
|
16
|
+
},
|
|
17
|
+
[t],
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -11,8 +11,8 @@ export function useUsernameAvailability(value: string, enabled: boolean) {
|
|
|
11
11
|
const { t } = useI18n();
|
|
12
12
|
const candidate = value.trim();
|
|
13
13
|
// The policy of the signed-in account's kind: a bot's handle ends in `bot`.
|
|
14
|
-
const checked = checkUsernameDraft(candidate, t, user?.kind);
|
|
15
|
-
const invalid = checked.ok ?
|
|
14
|
+
const checked = enabled ? checkUsernameDraft(candidate, t, user?.kind) : null;
|
|
15
|
+
const invalid = checked && !checked.ok ? checked.error : undefined;
|
|
16
16
|
const unchanged = candidate.toLowerCase() === user?.username?.toLowerCase();
|
|
17
17
|
const [result, setResult] = useState<CheckResult>();
|
|
18
18
|
const [attempt, setAttempt] = useState(0);
|
|
@@ -22,7 +22,7 @@ import type { BaseScreenProps } from '../types/navigation';
|
|
|
22
22
|
import { useOxy } from '../context/oxyRuntimeContext';
|
|
23
23
|
import { useI18n } from '../hooks/useI18n';
|
|
24
24
|
import { useSurfaceHeader } from '../hooks/useSurfaceHeader';
|
|
25
|
-
import {
|
|
25
|
+
import { useApiErrorToast } from '../hooks/useApiErrorToast';
|
|
26
26
|
import { withoutWhitespace } from '../utils/withoutWhitespace';
|
|
27
27
|
|
|
28
28
|
/** Roles assignable via invite / role change — everything except `owner`. */
|
|
@@ -39,6 +39,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
39
39
|
const bloomTheme = useTheme();
|
|
40
40
|
const colors = bloomTheme.colors;
|
|
41
41
|
const { t, locale } = useI18n();
|
|
42
|
+
const showApiError = useApiErrorToast();
|
|
42
43
|
|
|
43
44
|
useSurfaceHeader({
|
|
44
45
|
title: t('accounts.members.title') || 'Members',
|
|
@@ -102,8 +103,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
102
103
|
onSuccess: () => {
|
|
103
104
|
void invitationsQuery.refetch();
|
|
104
105
|
},
|
|
105
|
-
onError: (error) =>
|
|
106
|
-
toast.error(describeApiError(error, t, t('accounts.members.toasts.invitationUpdateFailed'))),
|
|
106
|
+
onError: (error) => showApiError(error, 'accounts.members.toasts.invitationUpdateFailed'),
|
|
107
107
|
});
|
|
108
108
|
const members = useMemo<AccountMember[]>(() => membersQuery.data ?? [], [membersQuery.data]);
|
|
109
109
|
const memberUserIds = useMemo(
|
|
@@ -157,7 +157,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
157
157
|
}, [queryClient, id]);
|
|
158
158
|
|
|
159
159
|
// --- Invite form state ---
|
|
160
|
-
const [
|
|
160
|
+
const [inviteEmail, setInviteEmail] = useState('');
|
|
161
161
|
const [inviteRole, setInviteRole] = useState<AssignableRole>('editor');
|
|
162
162
|
const [inviteError, setInviteError] = useState<string | null>(null);
|
|
163
163
|
|
|
@@ -166,7 +166,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
166
166
|
mutationFn: (input: { email: string; role: AssignableRole }) =>
|
|
167
167
|
oxyServices.accounts.invitations.create(id, input),
|
|
168
168
|
onSuccess: () => {
|
|
169
|
-
|
|
169
|
+
setInviteEmail('');
|
|
170
170
|
setInviteRole('editor');
|
|
171
171
|
setInviteError(null);
|
|
172
172
|
invalidateMembers();
|
|
@@ -174,7 +174,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
174
174
|
},
|
|
175
175
|
onError: (error) => {
|
|
176
176
|
invalidateMembers();
|
|
177
|
-
|
|
177
|
+
showApiError(error, 'accounts.members.toasts.inviteFailed');
|
|
178
178
|
},
|
|
179
179
|
});
|
|
180
180
|
|
|
@@ -187,7 +187,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
187
187
|
toast.success(t('accounts.members.toasts.roleUpdated') || 'Role updated');
|
|
188
188
|
},
|
|
189
189
|
onError: (error) => {
|
|
190
|
-
|
|
190
|
+
showApiError(error, 'accounts.members.toasts.roleFailed');
|
|
191
191
|
},
|
|
192
192
|
});
|
|
193
193
|
|
|
@@ -199,7 +199,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
199
199
|
toast.success(t('accounts.members.toasts.removed') || 'Member removed');
|
|
200
200
|
},
|
|
201
201
|
onError: (error) => {
|
|
202
|
-
|
|
202
|
+
showApiError(error, 'accounts.members.toasts.removeFailed');
|
|
203
203
|
},
|
|
204
204
|
});
|
|
205
205
|
|
|
@@ -211,30 +211,20 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
211
211
|
toast.success(t('accounts.members.toasts.transferred') || 'Ownership transferred');
|
|
212
212
|
},
|
|
213
213
|
onError: (error) => {
|
|
214
|
-
|
|
215
|
-
describeApiError(
|
|
216
|
-
error,
|
|
217
|
-
t,
|
|
218
|
-
t('accounts.members.toasts.transferFailed') || 'Failed to transfer ownership',
|
|
219
|
-
),
|
|
220
|
-
);
|
|
214
|
+
showApiError(error, 'accounts.members.toasts.transferFailed');
|
|
221
215
|
},
|
|
222
216
|
});
|
|
223
217
|
|
|
224
218
|
const handleInvite = useCallback(() => {
|
|
225
|
-
if (!inviteIdentifier.trim()) {
|
|
226
|
-
setInviteError(t('accounts.members.errors.emailRequired'));
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
219
|
// The contract `POST /accounts/:id/invitations` holds the address to.
|
|
230
|
-
const email = checkContract(emailAddressCheck,
|
|
220
|
+
const email = checkContract(emailAddressCheck, inviteEmail);
|
|
231
221
|
if (email === null) {
|
|
232
222
|
setInviteError(t('accounts.members.errors.emailInvalid'));
|
|
233
223
|
return;
|
|
234
224
|
}
|
|
235
225
|
setInviteError(null);
|
|
236
226
|
inviteMutation.mutate({ email, role: inviteRole });
|
|
237
|
-
}, [
|
|
227
|
+
}, [inviteEmail, inviteRole, inviteMutation, t]);
|
|
238
228
|
|
|
239
229
|
const handleChangeRole = useCallback(
|
|
240
230
|
(member: AccountMember, role: AccountRole) => {
|
|
@@ -309,9 +299,9 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
309
299
|
<TextFieldInput
|
|
310
300
|
floatingLabel
|
|
311
301
|
label={t('accounts.members.invite.emailLabel')}
|
|
312
|
-
value={
|
|
302
|
+
value={inviteEmail}
|
|
313
303
|
onChangeText={(value) => {
|
|
314
|
-
|
|
304
|
+
setInviteEmail(withoutWhitespace(value));
|
|
315
305
|
if (inviteError) setInviteError(null);
|
|
316
306
|
}}
|
|
317
307
|
isInvalid={!!inviteError}
|
|
@@ -351,7 +341,7 @@ const AccountMembersScreen: React.FC<BaseScreenProps> = ({ onClose, goBack, acco
|
|
|
351
341
|
appearance="solid"
|
|
352
342
|
tone="accent"
|
|
353
343
|
onPress={handleInvite}
|
|
354
|
-
disabled={inviteMutation.isPending || !
|
|
344
|
+
disabled={inviteMutation.isPending || !inviteEmail}
|
|
355
345
|
loading={inviteMutation.isPending}
|
|
356
346
|
accessibilityLabel={t('accounts.members.invite.submit')}
|
|
357
347
|
className="w-full"
|
|
@@ -16,7 +16,7 @@ import { useOxy } from '../context/oxyRuntimeContext';
|
|
|
16
16
|
import { queryKeys } from '../hooks/queries/queryKeys';
|
|
17
17
|
import { useI18n } from '../hooks/useI18n';
|
|
18
18
|
import { useSurfaceHeader } from '../hooks/useSurfaceHeader';
|
|
19
|
-
import {
|
|
19
|
+
import { useApiErrorToast } from '../hooks/useApiErrorToast';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* DomainsScreen — prove that the signed-in identity controls a web domain.
|
|
@@ -28,6 +28,7 @@ import { describeApiError } from '../utils/apiErrorMessage';
|
|
|
28
28
|
*/
|
|
29
29
|
const DomainsScreen: React.FC<BaseScreenProps> = () => {
|
|
30
30
|
const { t } = useI18n();
|
|
31
|
+
const showApiError = useApiErrorToast();
|
|
31
32
|
useSurfaceHeader({ title: t('domains.title') });
|
|
32
33
|
const bloomTheme = useTheme();
|
|
33
34
|
const queryClient = useQueryClient();
|
|
@@ -50,7 +51,7 @@ const DomainsScreen: React.FC<BaseScreenProps> = () => {
|
|
|
50
51
|
setPending(instructions);
|
|
51
52
|
setDomain('');
|
|
52
53
|
},
|
|
53
|
-
onError: (error) =>
|
|
54
|
+
onError: (error) => showApiError(error, 'domains.errors.request'),
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
const verify = useMutation({
|
|
@@ -64,13 +65,13 @@ const DomainsScreen: React.FC<BaseScreenProps> = () => {
|
|
|
64
65
|
toast.success(t('domains.verified', { domain: result.domain.domain }));
|
|
65
66
|
void queryClient.invalidateQueries({ queryKey: listKey });
|
|
66
67
|
},
|
|
67
|
-
onError: (error) =>
|
|
68
|
+
onError: (error) => showApiError(error, 'domains.errors.notYet'),
|
|
68
69
|
});
|
|
69
70
|
|
|
70
71
|
const remove = useMutation({
|
|
71
72
|
mutationFn: (name: string) => oxyServices.identity.domains.remove(name),
|
|
72
73
|
onSuccess: () => void queryClient.invalidateQueries({ queryKey: listKey }),
|
|
73
|
-
onError: (error) =>
|
|
74
|
+
onError: (error) => showApiError(error, 'domains.errors.remove'),
|
|
74
75
|
});
|
|
75
76
|
|
|
76
77
|
const confirmRemove = useCallback(
|
|
@@ -12,7 +12,6 @@ import { DatePicker } from '@oxy.so/bloom/date-picker';
|
|
|
12
12
|
import { Field } from '@oxy.so/bloom/field';
|
|
13
13
|
import { USERNAME_MAX_LENGTH, stripDisallowedUsernameCharacters } from '@oxy.so/contracts/client';
|
|
14
14
|
import { useUsernameAvailability } from '../hooks/useUsernameAvailability';
|
|
15
|
-
import { checkUsernameDraft } from '../utils/usernamePolicy';
|
|
16
15
|
import { GroupedSection, GroupedSectionItem } from '@oxy.so/bloom/grouped-section';
|
|
17
16
|
import type { User } from '@oxy.so/core';
|
|
18
17
|
import { useI18n } from '../hooks/useI18n';
|
|
@@ -260,10 +259,8 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
|
|
|
260
259
|
key: 'username',
|
|
261
260
|
label: t('editProfile.items.username.label') || 'Username',
|
|
262
261
|
placeholder: t('editProfile.items.username.placeholder') || 'Choose a username',
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return checked.ok ? undefined : checked.error;
|
|
266
|
-
},
|
|
262
|
+
// `useUsernameAvailability` holds the draft to the policy and
|
|
263
|
+
// blocks saving; a second check here could only disagree.
|
|
267
264
|
inputProps: {
|
|
268
265
|
autoCapitalize: 'none',
|
|
269
266
|
autoCorrect: false,
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { EMAIL_VERIFICATION_ERROR_CODES, SIGN_IN_ERROR_CODES } from '@oxy.so/contracts/client';
|
|
10
|
+
import { ErrorCodes, getErrorStatus, isRateLimitError, isServerError } from '@oxy.so/core';
|
|
10
11
|
import type { Translate } from '../hooks/useI18n';
|
|
11
12
|
|
|
12
13
|
/** How long a screen waits after a 429 that names no wait of its own. */
|
|
@@ -18,18 +19,16 @@ export function errorCode(error: unknown): string | undefined {
|
|
|
18
19
|
return typeof code === 'string' ? code : undefined;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return errorStatus(error) === 429;
|
|
32
|
-
}
|
|
22
|
+
/**
|
|
23
|
+
* The transport codes (core's `ErrorCodes`) for a request that never got an
|
|
24
|
+
* answer: offline, or timed out. Literals, so a module-load read never depends
|
|
25
|
+
* on core's values being initialised first.
|
|
26
|
+
*/
|
|
27
|
+
export const OFFLINE_ERROR_CODES: ReadonlySet<string> = new Set([
|
|
28
|
+
'NETWORK_ERROR',
|
|
29
|
+
'CONNECTION_FAILED',
|
|
30
|
+
'TIMEOUT',
|
|
31
|
+
]);
|
|
33
32
|
|
|
34
33
|
/** How long to wait after a 429, from the API's `retryAfterSeconds` when it sent one. */
|
|
35
34
|
export function retryAfterSeconds(error: unknown): number {
|
|
@@ -47,7 +46,9 @@ export function retryAfterSeconds(error: unknown): number {
|
|
|
47
46
|
* for a failure with no more specific reason; it defaults to the generic line.
|
|
48
47
|
*/
|
|
49
48
|
export function describeApiError(error: unknown, t: Translate, fallback?: string): string {
|
|
50
|
-
|
|
49
|
+
const code = errorCode(error);
|
|
50
|
+
if (code !== undefined && OFFLINE_ERROR_CODES.has(code)) return t('signin.errors.network');
|
|
51
|
+
switch (code) {
|
|
51
52
|
case SIGN_IN_ERROR_CODES.invalidCredentials:
|
|
52
53
|
return t('signin.errors.invalidCredentials');
|
|
53
54
|
case SIGN_IN_ERROR_CODES.requestInvalid:
|
|
@@ -84,20 +85,14 @@ export function describeApiError(error: unknown, t: Translate, fallback?: string
|
|
|
84
85
|
return t('emailCode.errors.unavailable');
|
|
85
86
|
// A malformed request: every screen checks the contract before sending, so
|
|
86
87
|
// this is the backstop for a rule the client does not know yet.
|
|
87
|
-
case
|
|
88
|
+
case ErrorCodes.BAD_REQUEST:
|
|
88
89
|
return t('signin.errors.invalidInput');
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
case 'TIMEOUT':
|
|
92
|
-
return t('signin.errors.network');
|
|
93
|
-
default: {
|
|
94
|
-
if (isRateLimited(error))
|
|
90
|
+
default:
|
|
91
|
+
if (isRateLimitError(error))
|
|
95
92
|
return t('signin.errors.rateLimited', { seconds: retryAfterSeconds(error) });
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
if (status !== undefined && status >= 500) return t('signin.errors.server');
|
|
93
|
+
if (getErrorStatus(error) === 0) return t('signin.errors.network');
|
|
94
|
+
if (isServerError(error)) return t('signin.errors.server');
|
|
99
95
|
return fallback ?? t('signin.errors.generic');
|
|
100
|
-
}
|
|
101
96
|
}
|
|
102
97
|
}
|
|
103
98
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OFFLINE_ERROR_CODES } from './apiErrorMessage';
|
|
1
2
|
import { isSessionChangedError } from './sessionChangedError';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -34,8 +35,6 @@ export type FollowErrorCode =
|
|
|
34
35
|
/** The codes that name the caller's action rather than a cause. */
|
|
35
36
|
export type FollowActionErrorCode = 'read_failed' | 'update_failed' | 'mode_failed';
|
|
36
37
|
|
|
37
|
-
const OFFLINE_CODES = new Set(['NETWORK_ERROR', 'CONNECTION_FAILED', 'TIMEOUT']);
|
|
38
|
-
|
|
39
38
|
/**
|
|
40
39
|
* The code for whatever a follow request rejected with.
|
|
41
40
|
*
|
|
@@ -50,7 +49,7 @@ export function toFollowErrorCode(error: unknown, action: FollowActionErrorCode)
|
|
|
50
49
|
status?: unknown;
|
|
51
50
|
code?: unknown;
|
|
52
51
|
};
|
|
53
|
-
if (typeof code === 'string' &&
|
|
52
|
+
if (typeof code === 'string' && OFFLINE_ERROR_CODES.has(code)) return 'offline';
|
|
54
53
|
if (status === 401) return 'signed_out';
|
|
55
54
|
if (status === 403) return 'forbidden';
|
|
56
55
|
if (status === 404) return 'not_found';
|
|
@@ -10,15 +10,18 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type { AccountKind } from '@oxy.so/core';
|
|
13
|
+
import { ErrorCodes } from '@oxy.so/core';
|
|
13
14
|
import {
|
|
14
15
|
BOT_USERNAME_INVALID_MESSAGE,
|
|
15
16
|
NUMERIC_USERNAME_MESSAGE,
|
|
16
17
|
RESERVED_USERNAME_MESSAGE,
|
|
18
|
+
USERNAME_INVALID_MESSAGE,
|
|
17
19
|
USERNAME_MAX_LENGTH,
|
|
18
20
|
USERNAME_MIN_LENGTH,
|
|
19
21
|
usernameCheckForAccountKind,
|
|
20
22
|
} from '@oxy.so/contracts/client';
|
|
21
23
|
import type { Translate } from '../hooks/useI18n';
|
|
24
|
+
import { errorCode } from './apiErrorMessage';
|
|
22
25
|
|
|
23
26
|
export type UsernameDraftResult = { ok: true; username: string } | { ok: false; error: string };
|
|
24
27
|
|
|
@@ -42,20 +45,17 @@ export function checkUsernameDraft(
|
|
|
42
45
|
/**
|
|
43
46
|
* The server's refusal of `username` (a 400 naming the `username` field, whose
|
|
44
47
|
* message is the policy's), in the same words as {@link checkUsernameDraft};
|
|
45
|
-
* `null` when `reason` is something else.
|
|
46
|
-
*
|
|
48
|
+
* `null` when `reason` is something else. A message this client does not know
|
|
49
|
+
* reads as "something you entered isn't valid", never as a rule it did not break.
|
|
47
50
|
*/
|
|
48
51
|
export function describeUsernameRefusal(
|
|
49
52
|
reason: unknown,
|
|
50
53
|
username: string,
|
|
51
54
|
t: Translate,
|
|
52
55
|
): string | null {
|
|
53
|
-
const error = reason as {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
details?: { field?: unknown };
|
|
57
|
-
} | null;
|
|
58
|
-
if (error?.code !== 'BAD_REQUEST' || error.details?.field !== 'username') return null;
|
|
56
|
+
const error = reason as { message?: unknown; details?: { field?: unknown } } | null;
|
|
57
|
+
if (errorCode(reason) !== ErrorCodes.BAD_REQUEST || error?.details?.field !== 'username')
|
|
58
|
+
return null;
|
|
59
59
|
const message = typeof error.message === 'string' ? error.message : '';
|
|
60
60
|
return describeUsernameIssue(username.trim(), message, t);
|
|
61
61
|
}
|
|
@@ -68,14 +68,16 @@ function describeUsernameIssue(username: string, message: string, t: Translate):
|
|
|
68
68
|
return t('usernamePolicy.reserved');
|
|
69
69
|
case BOT_USERNAME_INVALID_MESSAGE:
|
|
70
70
|
return t('usernamePolicy.mustEndInBot');
|
|
71
|
-
|
|
72
|
-
//
|
|
73
|
-
//
|
|
71
|
+
case USERNAME_INVALID_MESSAGE:
|
|
72
|
+
// One message covers length and shape alike; the length is read here so
|
|
73
|
+
// the reason names the rule that actually failed.
|
|
74
74
|
if (username.length < USERNAME_MIN_LENGTH)
|
|
75
75
|
return t('usernamePolicy.tooShort', { min: USERNAME_MIN_LENGTH });
|
|
76
76
|
if (username.length > USERNAME_MAX_LENGTH)
|
|
77
77
|
return t('usernamePolicy.tooLong', { max: USERNAME_MAX_LENGTH });
|
|
78
78
|
if (/\s/.test(username)) return t('usernamePolicy.noSpaces');
|
|
79
79
|
return t('usernamePolicy.characters');
|
|
80
|
+
default:
|
|
81
|
+
return t('signin.errors.invalidInput');
|
|
80
82
|
}
|
|
81
83
|
}
|