@gemies/sdk 3.3.1 → 4.1.0
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 +31 -0
- package/package.json +2 -2
- package/src/accounts.ts +18 -14
- package/src/components/GemieGroupWelcome.tsx +1 -1
- package/src/components/accounts/GemieAccountGrants.tsx +117 -0
- package/src/components/{GemieAccounts.tsx → accounts/GemieConnectedAccounts.tsx} +210 -174
- package/src/components/accounts/account-parts.tsx +53 -0
- package/src/components/connectors/GrantSwitchRow.tsx +57 -0
- package/src/connectors.ts +4 -1
- package/src/lib/copy-en.ts +26 -12
- package/src/lib/copy-es.ts +27 -13
- package/src/runtime/api.ts +4 -2
- package/src/runtime/connected-accounts.ts +218 -0
- package/src/runtime/query-keys.ts +6 -7
- package/src/runtime/routes.ts +14 -4
- package/src/runtime/gemie-accounts.ts +0 -189
|
@@ -16,29 +16,24 @@ import { Text } from '@oxy.so/bloom/typography';
|
|
|
16
16
|
import { useCallback, useEffect, useState } from 'react';
|
|
17
17
|
import { Linking, View } from 'react-native';
|
|
18
18
|
import QRCode from 'react-native-qrcode-svg';
|
|
19
|
-
import { englishCopy, type Translate } from '
|
|
20
|
-
import { errorMessage } from '
|
|
19
|
+
import { englishCopy, type Translate } from '../../lib/copy';
|
|
20
|
+
import { errorMessage } from '../../runtime/error-utils';
|
|
21
21
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
type
|
|
28
|
-
type GemieAccountGroupReplies,
|
|
22
|
+
useConnectedAccountChats,
|
|
23
|
+
useConnectedAccountMutations,
|
|
24
|
+
useConnectedAccountQr,
|
|
25
|
+
useConnectedAccounts,
|
|
26
|
+
type ConnectedAccount,
|
|
27
|
+
type ConnectedAccountPatch,
|
|
29
28
|
type GemieAccountLink,
|
|
30
29
|
type GemieAccountPlatform,
|
|
31
|
-
type
|
|
32
|
-
} from '
|
|
30
|
+
type GrantableGemie,
|
|
31
|
+
} from '../../runtime/connected-accounts';
|
|
32
|
+
import { GrantSwitchRow } from '../connectors/GrantSwitchRow';
|
|
33
|
+
import { K, PLATFORM_LABELS, PlatformMark, accountName, statusText } from './account-parts';
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
/** Product names, the same in every language. */
|
|
38
|
-
const PLATFORM_LABELS: Record<GemieAccountPlatform, string> = {
|
|
39
|
-
whatsapp: 'WhatsApp',
|
|
40
|
-
telegram: 'Telegram',
|
|
41
|
-
};
|
|
35
|
+
/** The value the answering select gives "nobody answers on its own". */
|
|
36
|
+
const NOBODY = '';
|
|
42
37
|
|
|
43
38
|
/** One row of the list: the same rhythm as a settings row, a divider above all but the first. */
|
|
44
39
|
function Row({ children, first }: { children: React.ReactNode; first?: boolean }) {
|
|
@@ -136,38 +131,34 @@ function TelegramSteps({ link, t }: { link: string | null; t: Translate }) {
|
|
|
136
131
|
}
|
|
137
132
|
|
|
138
133
|
/**
|
|
139
|
-
* The account being
|
|
140
|
-
* Telegram's steps.
|
|
134
|
+
* The account being connected, until the person finishes on their phone: WhatsApp's code to scan,
|
|
135
|
+
* or Telegram's steps.
|
|
141
136
|
*/
|
|
142
|
-
function
|
|
143
|
-
gemieId,
|
|
144
|
-
name,
|
|
137
|
+
function ConnectingAccount({
|
|
145
138
|
platform,
|
|
146
139
|
link,
|
|
147
140
|
t,
|
|
148
141
|
onDone,
|
|
149
142
|
onCancel,
|
|
150
143
|
}: {
|
|
151
|
-
gemieId: string;
|
|
152
|
-
name: string;
|
|
153
144
|
platform: GemieAccountPlatform;
|
|
154
145
|
link: GemieAccountLink;
|
|
155
146
|
t: Translate;
|
|
156
147
|
onDone: () => void;
|
|
157
148
|
onCancel: () => void;
|
|
158
149
|
}) {
|
|
159
|
-
const { data } =
|
|
150
|
+
const { data } = useConnectedAccountQr(link);
|
|
160
151
|
const status = data?.status ?? 'qr-pending';
|
|
161
152
|
const label = PLATFORM_LABELS[platform];
|
|
162
153
|
|
|
163
154
|
useEffect(() => {
|
|
164
155
|
if (status === 'qr-pending') return;
|
|
165
|
-
// Telegram reports a connection its person turned off as paused:
|
|
156
|
+
// Telegram reports a connection its person turned off as paused: connected all the same.
|
|
166
157
|
if (status === 'connected' || status === 'paused') {
|
|
167
|
-
toast.success(t(`${K}.
|
|
158
|
+
toast.success(t(`${K}.connected`, { platform: label }));
|
|
168
159
|
} else toast.error(t(`${K}.linkExpired`, { platform: label }));
|
|
169
160
|
onDone();
|
|
170
|
-
}, [label,
|
|
161
|
+
}, [label, onDone, status, t]);
|
|
171
162
|
|
|
172
163
|
return (
|
|
173
164
|
<Row>
|
|
@@ -194,43 +185,25 @@ function LinkingAccount({
|
|
|
194
185
|
);
|
|
195
186
|
}
|
|
196
187
|
|
|
197
|
-
/** A Telegram account the person left before finishing: its steps, kept until it is
|
|
198
|
-
function PendingTelegram({
|
|
199
|
-
|
|
200
|
-
account,
|
|
201
|
-
t,
|
|
202
|
-
}: {
|
|
203
|
-
gemieId: string;
|
|
204
|
-
account: GemieAccount;
|
|
205
|
-
t: Translate;
|
|
206
|
-
}) {
|
|
207
|
-
const { data } = useGemieAccountQr(gemieId, { accountId: account._id, qr: null });
|
|
188
|
+
/** A Telegram account the person left before finishing: its steps, kept until it is connected. */
|
|
189
|
+
function PendingTelegram({ account, t }: { account: ConnectedAccount; t: Translate }) {
|
|
190
|
+
const { data } = useConnectedAccountQr({ accountId: account._id, qr: null });
|
|
208
191
|
return <TelegramSteps link={data?.qr ?? null} t={t} />;
|
|
209
192
|
}
|
|
210
193
|
|
|
211
194
|
/** The chats a `chosen` account answers, picked from its recent ones. */
|
|
212
195
|
function ChosenChats({
|
|
213
|
-
gemieId,
|
|
214
196
|
account,
|
|
197
|
+
save,
|
|
198
|
+
saving,
|
|
215
199
|
t,
|
|
216
200
|
}: {
|
|
217
|
-
|
|
218
|
-
|
|
201
|
+
account: ConnectedAccount;
|
|
202
|
+
save: (patch: ConnectedAccountPatch) => Promise<void>;
|
|
203
|
+
saving: boolean;
|
|
219
204
|
t: Translate;
|
|
220
205
|
}) {
|
|
221
|
-
const { data: chats, isPending } =
|
|
222
|
-
const { setReplies } = useGemieAccountMutations(gemieId);
|
|
223
|
-
|
|
224
|
-
const toggle = async (chatId: string, on: boolean) => {
|
|
225
|
-
const replyChatIds = on
|
|
226
|
-
? [...account.replyChatIds, chatId]
|
|
227
|
-
: account.replyChatIds.filter((id) => id !== chatId);
|
|
228
|
-
try {
|
|
229
|
-
await setReplies.mutateAsync({ accountId: account._id, replyChatIds });
|
|
230
|
-
} catch {
|
|
231
|
-
toast.error(t(`${K}.saveFailed`));
|
|
232
|
-
}
|
|
233
|
-
};
|
|
206
|
+
const { data: chats, isPending } = useConnectedAccountChats(account._id);
|
|
234
207
|
|
|
235
208
|
if (isPending) {
|
|
236
209
|
return (
|
|
@@ -260,8 +233,14 @@ function ChosenChats({
|
|
|
260
233
|
<Switch
|
|
261
234
|
accessibilityLabel={t(`${K}.answerChat`, { name: chat.name })}
|
|
262
235
|
checked={account.replyChatIds.includes(chat.chatId)}
|
|
263
|
-
disabled={
|
|
264
|
-
onCheckedChange={(on) =>
|
|
236
|
+
disabled={saving}
|
|
237
|
+
onCheckedChange={(on) =>
|
|
238
|
+
save({
|
|
239
|
+
replyChatIds: on
|
|
240
|
+
? [...account.replyChatIds, chat.chatId]
|
|
241
|
+
: account.replyChatIds.filter((id) => id !== chat.chatId),
|
|
242
|
+
})
|
|
243
|
+
}
|
|
265
244
|
/>
|
|
266
245
|
</View>
|
|
267
246
|
))}
|
|
@@ -269,42 +248,114 @@ function ChosenChats({
|
|
|
269
248
|
);
|
|
270
249
|
}
|
|
271
250
|
|
|
272
|
-
/**
|
|
251
|
+
/**
|
|
252
|
+
* Who answers the account on its own — one of the person's gemies, or nobody — and, when one
|
|
253
|
+
* does, whom it answers. Choosing a gemie grants it the account too.
|
|
254
|
+
*/
|
|
255
|
+
function Answering({
|
|
256
|
+
account,
|
|
257
|
+
gemies,
|
|
258
|
+
save,
|
|
259
|
+
saving,
|
|
260
|
+
t,
|
|
261
|
+
}: {
|
|
262
|
+
account: ConnectedAccount;
|
|
263
|
+
gemies: readonly GrantableGemie[];
|
|
264
|
+
save: (patch: ConnectedAccountPatch) => Promise<void>;
|
|
265
|
+
saving: boolean;
|
|
266
|
+
t: Translate;
|
|
267
|
+
}) {
|
|
268
|
+
const answering = gemies.find((gemie) => gemie.id === account.answeringGemieId) ?? null;
|
|
269
|
+
const telegram = account.platform === 'telegram';
|
|
270
|
+
return (
|
|
271
|
+
<View className="gap-3">
|
|
272
|
+
<Choice
|
|
273
|
+
label={t(`${K}.answeringLabel`)}
|
|
274
|
+
value={answering?.id ?? NOBODY}
|
|
275
|
+
disabled={saving}
|
|
276
|
+
items={[
|
|
277
|
+
{ value: NOBODY, label: t(`${K}.answeringNobody`) },
|
|
278
|
+
...gemies.map((gemie) => ({ value: gemie.id, label: gemie.name })),
|
|
279
|
+
]}
|
|
280
|
+
onChange={(id) => save({ answeringGemieId: id === NOBODY ? null : id })}
|
|
281
|
+
/>
|
|
282
|
+
{answering === null ? (
|
|
283
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
284
|
+
{t(`${K}.answeringNone`)}
|
|
285
|
+
</Text>
|
|
286
|
+
) : (
|
|
287
|
+
<>
|
|
288
|
+
{telegram && account.status === 'connected' && account.canReply === false ? (
|
|
289
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
290
|
+
{t(`${K}.telegram.cannotReply`, { name: answering.name })}
|
|
291
|
+
</Text>
|
|
292
|
+
) : null}
|
|
293
|
+
<Choice
|
|
294
|
+
label={t(`${K}.repliesLabel`, { name: answering.name })}
|
|
295
|
+
value={account.replies}
|
|
296
|
+
disabled={saving}
|
|
297
|
+
items={[
|
|
298
|
+
{ value: 'everyone', label: t(`${K}.replies.everyone`) },
|
|
299
|
+
{ value: 'chosen', label: t(`${K}.replies.chosen`) },
|
|
300
|
+
{ value: 'nobody', label: t(`${K}.replies.nobody`, { name: answering.name }) },
|
|
301
|
+
]}
|
|
302
|
+
onChange={(replies) => save({ replies })}
|
|
303
|
+
/>
|
|
304
|
+
{account.replies === 'chosen' ? (
|
|
305
|
+
<ChosenChats account={account} save={save} saving={saving} t={t} />
|
|
306
|
+
) : null}
|
|
307
|
+
{/* Telegram Business covers private chats only: it has no groups to choose for. */}
|
|
308
|
+
{account.replies !== 'nobody' && !telegram ? (
|
|
309
|
+
<Choice
|
|
310
|
+
label={t(`${K}.groupRepliesLabel`)}
|
|
311
|
+
value={account.groupReplies}
|
|
312
|
+
disabled={saving}
|
|
313
|
+
items={[
|
|
314
|
+
{ value: 'mentions', label: t(`${K}.groupReplies.mentions`) },
|
|
315
|
+
{ value: 'never', label: t(`${K}.groupReplies.never`) },
|
|
316
|
+
]}
|
|
317
|
+
onChange={(groupReplies) => save({ groupReplies })}
|
|
318
|
+
/>
|
|
319
|
+
) : null}
|
|
320
|
+
</>
|
|
321
|
+
)}
|
|
322
|
+
</View>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** One connected account: its live status, the gemies that may use it, who answers it, removing it. */
|
|
273
327
|
function AccountRow({
|
|
274
|
-
gemieId,
|
|
275
|
-
name,
|
|
276
328
|
account,
|
|
277
|
-
|
|
329
|
+
gemies,
|
|
278
330
|
t,
|
|
279
331
|
}: {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
account: GemieAccount;
|
|
283
|
-
first: boolean;
|
|
332
|
+
account: ConnectedAccount;
|
|
333
|
+
gemies: readonly GrantableGemie[];
|
|
284
334
|
t: Translate;
|
|
285
335
|
}) {
|
|
286
|
-
const {
|
|
336
|
+
const { update, grant, remove } = useConnectedAccountMutations();
|
|
287
337
|
const platform = PLATFORM_LABELS[account.platform] ?? account.platform;
|
|
338
|
+
const name = accountName(account);
|
|
288
339
|
const telegram = account.platform === 'telegram';
|
|
289
|
-
// Telegram's statuses mean something of their own: a link waiting in Telegram, an account the
|
|
290
|
-
// person paused there, one that moved to another gemie. None asks them to sign in again.
|
|
291
|
-
const status = !GEMIE_ACCOUNT_STATUSES.includes(account.status)
|
|
292
|
-
? account.status
|
|
293
|
-
: telegram && account.status !== 'connected'
|
|
294
|
-
? t(`${K}.telegram.status.${account.status}`)
|
|
295
|
-
: t(`${K}.status.${account.status}`);
|
|
296
|
-
const identifier = account.phoneNumber || account.displayName;
|
|
297
340
|
const live =
|
|
298
341
|
account.status === 'connected' ||
|
|
299
342
|
account.status === 'disconnected' ||
|
|
300
343
|
account.status === 'paused';
|
|
301
344
|
|
|
302
|
-
const save =
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
345
|
+
const save = useCallback(
|
|
346
|
+
async (patch: ConnectedAccountPatch) => {
|
|
347
|
+
try {
|
|
348
|
+
await update.mutateAsync({ accountId: account._id, ...patch });
|
|
349
|
+
} catch {
|
|
350
|
+
toast.error(t(`${K}.saveFailed`));
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
[account._id, t, update],
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
const setGranted = async (gemieId: string, granted: boolean) => {
|
|
306
357
|
try {
|
|
307
|
-
await
|
|
358
|
+
await grant.mutateAsync({ accountId: account._id, gemieId, granted });
|
|
308
359
|
} catch {
|
|
309
360
|
toast.error(t(`${K}.saveFailed`));
|
|
310
361
|
}
|
|
@@ -314,8 +365,8 @@ function AccountRow({
|
|
|
314
365
|
const ok = await confirm({
|
|
315
366
|
title: t(`${K}.removeTitle`, { platform }),
|
|
316
367
|
description: telegram
|
|
317
|
-
? t(`${K}.telegram.removeDescription
|
|
318
|
-
: t(`${K}.removeDescription`, { platform
|
|
368
|
+
? t(`${K}.telegram.removeDescription`)
|
|
369
|
+
: t(`${K}.removeDescription`, { platform }),
|
|
319
370
|
confirmLabel: t(`${K}.remove`),
|
|
320
371
|
cancelLabel: t(`${K}.cancel`),
|
|
321
372
|
destructive: true,
|
|
@@ -330,11 +381,12 @@ function AccountRow({
|
|
|
330
381
|
};
|
|
331
382
|
|
|
332
383
|
return (
|
|
333
|
-
<Row
|
|
384
|
+
<Row>
|
|
334
385
|
<View className="flex-row flex-wrap items-center justify-between gap-3">
|
|
386
|
+
<PlatformMark platform={account.platform} size={28} />
|
|
335
387
|
<View className="flex-1 gap-0.5">
|
|
336
|
-
<Text variant="body-2-semibold">{
|
|
337
|
-
<Text variant="body-2-regular">{
|
|
388
|
+
<Text variant="body-2-semibold">{name}</Text>
|
|
389
|
+
<Text variant="body-2-regular">{statusText(account, t)}</Text>
|
|
338
390
|
<Text variant="body-2-regular" className="text-text-secondary">
|
|
339
391
|
{account.lastActiveAt
|
|
340
392
|
? t(`${K}.lastMessage`, { when: new Date(account.lastActiveAt).toLocaleString() })
|
|
@@ -353,77 +405,67 @@ function AccountRow({
|
|
|
353
405
|
</Button>
|
|
354
406
|
</View>
|
|
355
407
|
{telegram && account.status === 'qr-pending' ? (
|
|
356
|
-
<PendingTelegram
|
|
357
|
-
) : null}
|
|
358
|
-
{telegram && account.status === 'connected' && account.canReply === false ? (
|
|
359
|
-
<Text variant="body-2-regular" className="text-text-secondary">
|
|
360
|
-
{t(`${K}.telegram.cannotReply`, { name })}
|
|
361
|
-
</Text>
|
|
408
|
+
<PendingTelegram account={account} t={t} />
|
|
362
409
|
) : null}
|
|
363
410
|
{live ? (
|
|
364
411
|
<>
|
|
365
|
-
<
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
412
|
+
<View>
|
|
413
|
+
<Text variant="body-2-semibold">{t(`${K}.usedBy`)}</Text>
|
|
414
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
415
|
+
{t(`${K}.usedByHint`)}
|
|
416
|
+
</Text>
|
|
417
|
+
{gemies.map((gemie, index) => (
|
|
418
|
+
<GrantSwitchRow
|
|
419
|
+
key={gemie.id}
|
|
420
|
+
first={index === 0}
|
|
421
|
+
label={gemie.name}
|
|
422
|
+
detail={account.answeringGemieId === gemie.id ? t(`${K}.answersOnItsOwn`) : null}
|
|
423
|
+
checked={account.gemieIds.includes(gemie.id)}
|
|
424
|
+
disabled={grant.isPending || update.isPending}
|
|
425
|
+
accessibilityLabel={t(`${K}.grantLabel`, { gemie: gemie.name, account: name })}
|
|
426
|
+
onCheckedChange={(granted) => void setGranted(gemie.id, granted)}
|
|
427
|
+
/>
|
|
428
|
+
))}
|
|
429
|
+
</View>
|
|
430
|
+
<Answering
|
|
431
|
+
account={account}
|
|
432
|
+
gemies={gemies}
|
|
433
|
+
save={save}
|
|
434
|
+
saving={update.isPending || grant.isPending}
|
|
435
|
+
t={t}
|
|
375
436
|
/>
|
|
376
|
-
{account.replies === 'chosen' ? (
|
|
377
|
-
<ChosenChats gemieId={gemieId} account={account} t={t} />
|
|
378
|
-
) : null}
|
|
379
|
-
{/* Telegram Business covers private chats only: it has no groups to choose for. */}
|
|
380
|
-
{account.replies !== 'nobody' && !telegram ? (
|
|
381
|
-
<Choice
|
|
382
|
-
label={t(`${K}.groupRepliesLabel`)}
|
|
383
|
-
value={account.groupReplies}
|
|
384
|
-
disabled={setReplies.isPending}
|
|
385
|
-
items={[
|
|
386
|
-
{ value: 'mentions', label: t(`${K}.groupReplies.mentions`) },
|
|
387
|
-
{ value: 'never', label: t(`${K}.groupReplies.never`) },
|
|
388
|
-
]}
|
|
389
|
-
onChange={(groupReplies) => save({ groupReplies })}
|
|
390
|
-
/>
|
|
391
|
-
) : null}
|
|
392
437
|
</>
|
|
393
438
|
) : null}
|
|
394
439
|
</Row>
|
|
395
440
|
);
|
|
396
441
|
}
|
|
397
442
|
|
|
398
|
-
export interface
|
|
399
|
-
/** The gemie the accounts are linked to (Alia's id, in the Alia app). */
|
|
400
|
-
gemieId: string;
|
|
401
|
-
/** The gemie's name, as the copy says it. */
|
|
402
|
-
name: string;
|
|
443
|
+
export interface GemieConnectedAccountsProps {
|
|
403
444
|
/** The host's translator, keyed as `gemie.accounts.*`; English when absent. */
|
|
404
445
|
t?: Translate;
|
|
405
446
|
}
|
|
406
447
|
|
|
407
448
|
/**
|
|
408
|
-
*
|
|
409
|
-
* Telegram
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* its own
|
|
449
|
+
* Settings › Connected accounts (ADR 0035 as amended; Telegram through Telegram Business, ADR 0037):
|
|
450
|
+
* the person connects their WhatsApp and Telegram accounts ONCE, here, chooses which of their gemies
|
|
451
|
+
* may use each (Alia among them), and which one, if any, answers what arrives on it on its own. The
|
|
452
|
+
* other granted gemies read and send through it only when the person asks them or their tasks need
|
|
453
|
+
* it. Drawn without a frame of its own, so each app puts it in its own settings: the Gemies and the
|
|
454
|
+
* Alia apps draw this same panel. Only what this deployment can connect is offered.
|
|
413
455
|
*/
|
|
414
|
-
export function
|
|
415
|
-
const { data, isPending, isError, isFetching, refetch } =
|
|
416
|
-
const {
|
|
417
|
-
const [
|
|
456
|
+
export function GemieConnectedAccounts({ t = englishCopy }: GemieConnectedAccountsProps) {
|
|
457
|
+
const { data, isPending, isError, isFetching, refetch } = useConnectedAccounts();
|
|
458
|
+
const { connect, remove } = useConnectedAccountMutations();
|
|
459
|
+
const [connecting, setConnecting] = useState<{
|
|
418
460
|
platform: GemieAccountPlatform;
|
|
419
461
|
link: GemieAccountLink;
|
|
420
462
|
} | null>(null);
|
|
421
|
-
/** The last
|
|
422
|
-
const [
|
|
463
|
+
/** The last connection that failed, said in the panel with a way to try again. */
|
|
464
|
+
const [connectFailure, setConnectFailure] = useState<{
|
|
423
465
|
platform: GemieAccountPlatform;
|
|
424
466
|
reason: string;
|
|
425
467
|
} | null>(null);
|
|
426
|
-
const
|
|
468
|
+
const finished = useCallback(() => setConnecting(null), []);
|
|
427
469
|
|
|
428
470
|
if (isPending) {
|
|
429
471
|
return (
|
|
@@ -436,27 +478,21 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
436
478
|
);
|
|
437
479
|
}
|
|
438
480
|
|
|
439
|
-
const
|
|
440
|
-
|
|
481
|
+
const handleConnect = async (platform: GemieAccountPlatform) => {
|
|
482
|
+
setConnectFailure(null);
|
|
441
483
|
try {
|
|
442
|
-
|
|
484
|
+
setConnecting({ platform, link: await connect.mutateAsync(platform) });
|
|
443
485
|
} catch (error) {
|
|
444
|
-
|
|
486
|
+
setConnectFailure({ platform, reason: errorMessage(error, t(`${K}.tryAgain`)) });
|
|
445
487
|
}
|
|
446
488
|
};
|
|
447
489
|
|
|
448
490
|
const handleCancel = async () => {
|
|
449
|
-
const pending =
|
|
450
|
-
|
|
491
|
+
const pending = connecting;
|
|
492
|
+
setConnecting(null);
|
|
451
493
|
if (pending) await remove.mutateAsync(pending.link.accountId).catch(() => {});
|
|
452
494
|
};
|
|
453
495
|
|
|
454
|
-
// The account being linked shows as its QR code, not as a row beside it.
|
|
455
|
-
const accounts = (data?.accounts ?? []).filter(
|
|
456
|
-
(account) => account._id !== linking?.link.accountId,
|
|
457
|
-
);
|
|
458
|
-
const platforms = data?.platforms ?? [];
|
|
459
|
-
|
|
460
496
|
/**
|
|
461
497
|
* Nothing could be read: the API did not answer (offline, or mid-rollout before it serves these
|
|
462
498
|
* routes). Said so, with a retry, and nothing else is offered until it answers. A later refresh
|
|
@@ -485,36 +521,34 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
485
521
|
);
|
|
486
522
|
}
|
|
487
523
|
|
|
524
|
+
// The account being connected shows as its QR code, not as a row beside it.
|
|
525
|
+
const accounts = (data?.accounts ?? []).filter(
|
|
526
|
+
(account) => account._id !== connecting?.link.accountId,
|
|
527
|
+
);
|
|
528
|
+
const platforms = data?.platforms ?? [];
|
|
529
|
+
const gemies = data?.gemies ?? [];
|
|
530
|
+
|
|
488
531
|
return (
|
|
489
532
|
<View>
|
|
490
533
|
<Row first>
|
|
491
534
|
<Text variant="body-2-regular" className="text-text-secondary">
|
|
492
|
-
{t(`${K}.description
|
|
535
|
+
{t(`${K}.description`)}
|
|
493
536
|
</Text>
|
|
494
537
|
</Row>
|
|
495
538
|
{accounts.map((account) => (
|
|
496
|
-
<AccountRow
|
|
497
|
-
key={account._id}
|
|
498
|
-
gemieId={gemieId}
|
|
499
|
-
name={name}
|
|
500
|
-
account={account}
|
|
501
|
-
first={false}
|
|
502
|
-
t={t}
|
|
503
|
-
/>
|
|
539
|
+
<AccountRow key={account._id} account={account} gemies={gemies} t={t} />
|
|
504
540
|
))}
|
|
505
|
-
{
|
|
506
|
-
<
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
platform={linking.platform}
|
|
510
|
-
link={linking.link}
|
|
541
|
+
{connecting ? (
|
|
542
|
+
<ConnectingAccount
|
|
543
|
+
platform={connecting.platform}
|
|
544
|
+
link={connecting.link}
|
|
511
545
|
t={t}
|
|
512
|
-
onDone={
|
|
546
|
+
onDone={finished}
|
|
513
547
|
onCancel={handleCancel}
|
|
514
548
|
/>
|
|
515
549
|
) : (
|
|
516
550
|
<Row>
|
|
517
|
-
<Text variant="body-2-semibold">{t(`${K}.
|
|
551
|
+
<Text variant="body-2-semibold">{t(`${K}.connect`)}</Text>
|
|
518
552
|
{platforms.length === 0 ? (
|
|
519
553
|
<Text variant="body-2-regular" className="text-text-secondary">
|
|
520
554
|
{t(`${K}.unavailable`)}
|
|
@@ -533,26 +567,28 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
533
567
|
size="sm"
|
|
534
568
|
appearance="outline"
|
|
535
569
|
tone="neutral"
|
|
536
|
-
accessibilityLabel={t(`${K}.
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
570
|
+
accessibilityLabel={t(`${K}.connectNamed`, {
|
|
571
|
+
platform: PLATFORM_LABELS[platform],
|
|
572
|
+
})}
|
|
573
|
+
loading={connect.isPending && connect.variables === platform}
|
|
574
|
+
disabled={connect.isPending}
|
|
575
|
+
onPress={() => handleConnect(platform)}
|
|
540
576
|
>
|
|
541
577
|
{PLATFORM_LABELS[platform]}
|
|
542
578
|
</Button>
|
|
543
579
|
))}
|
|
544
580
|
</View>
|
|
545
581
|
)}
|
|
546
|
-
{
|
|
582
|
+
{connectFailure ? (
|
|
547
583
|
<View className="gap-2">
|
|
548
584
|
<Text
|
|
549
585
|
variant="body-2-regular"
|
|
550
586
|
className="text-error-primary"
|
|
551
587
|
accessibilityRole="alert"
|
|
552
588
|
>
|
|
553
|
-
{t(`${K}.
|
|
554
|
-
platform: PLATFORM_LABELS[
|
|
555
|
-
reason:
|
|
589
|
+
{t(`${K}.connectFailed`, {
|
|
590
|
+
platform: PLATFORM_LABELS[connectFailure.platform],
|
|
591
|
+
reason: connectFailure.reason,
|
|
556
592
|
})}
|
|
557
593
|
</Text>
|
|
558
594
|
<View className="flex-row">
|
|
@@ -560,8 +596,8 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
560
596
|
size="sm"
|
|
561
597
|
appearance="outline"
|
|
562
598
|
tone="neutral"
|
|
563
|
-
disabled={
|
|
564
|
-
onPress={() =>
|
|
599
|
+
disabled={connect.isPending}
|
|
600
|
+
onPress={() => handleConnect(connectFailure.platform)}
|
|
565
601
|
>
|
|
566
602
|
{t(`${K}.retry`)}
|
|
567
603
|
</Button>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { RiTelegramFill } from '@oxy.so/bloom/icons/RiTelegramFill';
|
|
2
|
+
import { RiWhatsappFill } from '@oxy.so/bloom/icons/RiWhatsappFill';
|
|
3
|
+
import type { Translate } from '../../lib/copy';
|
|
4
|
+
import {
|
|
5
|
+
GEMIE_ACCOUNT_STATUSES,
|
|
6
|
+
type ConnectedAccount,
|
|
7
|
+
type GemieAccountPlatform,
|
|
8
|
+
} from '../../runtime/connected-accounts';
|
|
9
|
+
|
|
10
|
+
/** The strings of the connected-accounts screens. */
|
|
11
|
+
export const K = 'gemie.accounts';
|
|
12
|
+
|
|
13
|
+
/** Product names, the same in every language. */
|
|
14
|
+
export const PLATFORM_LABELS: Record<GemieAccountPlatform, string> = {
|
|
15
|
+
whatsapp: 'WhatsApp',
|
|
16
|
+
telegram: 'Telegram',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Each platform's own mark, in its own colour: a logo, the same in either theme. */
|
|
20
|
+
const PLATFORM_MARKS = {
|
|
21
|
+
whatsapp: { Icon: RiWhatsappFill, color: '#25D366' },
|
|
22
|
+
telegram: { Icon: RiTelegramFill, color: '#26A5E4' },
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
export function PlatformMark({
|
|
26
|
+
platform,
|
|
27
|
+
size = 24,
|
|
28
|
+
}: {
|
|
29
|
+
platform: GemieAccountPlatform;
|
|
30
|
+
size?: number;
|
|
31
|
+
}) {
|
|
32
|
+
const { Icon, color } = PLATFORM_MARKS[platform];
|
|
33
|
+
return <Icon width={size} height={size} fill={color} />;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Which account it is, as a person reads it: `WhatsApp · +34 600…`. */
|
|
37
|
+
export function accountName(account: ConnectedAccount): string {
|
|
38
|
+
const who = account.phoneNumber || account.displayName;
|
|
39
|
+
const platform = PLATFORM_LABELS[account.platform] ?? account.platform;
|
|
40
|
+
return who ? `${platform} · ${who}` : platform;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The account's status in words. Telegram's mean something of their own: a link waiting in
|
|
45
|
+
* Telegram, an account the person paused there, one connected again elsewhere. None asks them to
|
|
46
|
+
* sign in again.
|
|
47
|
+
*/
|
|
48
|
+
export function statusText(account: ConnectedAccount, t: Translate): string {
|
|
49
|
+
if (!GEMIE_ACCOUNT_STATUSES.includes(account.status)) return account.status;
|
|
50
|
+
return account.platform === 'telegram' && account.status !== 'connected'
|
|
51
|
+
? t(`${K}.telegram.status.${account.status}`)
|
|
52
|
+
: t(`${K}.status.${account.status}`);
|
|
53
|
+
}
|