Open History to see the last commit
1import type { RelayClientDeviceRecord } from "@t3tools/contracts/relay";
2import { msg } from "gt-react";
3
4import { m, type MessageResolver } from "~/i18n/messages";
5
6const mobileClientUpdatedAtFormatter = new Intl.DateTimeFormat(undefined, {
7 dateStyle: "medium",
8 timeStyle: "short",
9});
10
11const NOTIFICATION_PREFERENCES = [
12 ["notifyOnApproval", msg("approvals")],
13 ["notifyOnInput", msg("input requests")],
14 ["notifyOnCompletion", msg("completions")],
15 ["notifyOnFailure", msg("failures")],
16] as const satisfies ReadonlyArray<
17 readonly [keyof RelayClientDeviceRecord["notifications"], string]
18>;
19
20export function mobileClientPlatformLabel(device: RelayClientDeviceRecord): string {
21 const platform =
22 device.platform === "android"
23 ? "Android"
24 : device.iosMajorVersion === null
25 ? "iOS"
26 : `iOS ${device.iosMajorVersion}`;
27 return `${platform}${device.appVersion ? ` · T3 Code ${device.appVersion}` : ""}`;
28}
29
30/** Components pass `useMessages()` so the detail follows a language switch. */
31export function mobileClientNotificationDetail(
32 device: RelayClientDeviceRecord,
33 resolve: MessageResolver = m,
34): string {
35 if (!device.notifications.enabled) {
36 return resolve(msg("Push notifications are disabled on this device."));
37 }
38
39 const enabledPreferences = NOTIFICATION_PREFERENCES.flatMap(([preference, label]) =>
40 device.notifications[preference] ? [resolve(label)] : [],
41 );
42 return enabledPreferences.length > 0
43 ? resolve(msg("Alerts enabled for {alerts}.", { alerts: enabledPreferences.join(", ") }))
44 : resolve(msg("Push notifications are enabled, but no alert types are selected."));
45}
46
47export function mobileClientUpdatedAtLabel(
48 updatedAt: string,
49 resolve: MessageResolver = m,
50): string {
51 const date = new Date(updatedAt);
52 return Number.isNaN(date.getTime())
53 ? resolve(msg("Update time unavailable"))
54 : resolve(msg("Updated {date}", { date: mobileClientUpdatedAtFormatter.format(date) }));
55}