Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

MobileClientsUserProfilePage.logic.ts

39 lines1.4 KB

1import type { RelayClientDeviceRecord } from "@t3tools/contracts/relay";
2​
3const mobileClientUpdatedAtFormatter = new Intl.DateTimeFormat(undefined, {
4 dateStyle: "medium",
5 timeStyle: "short",
6});
7​
8const NOTIFICATION_PREFERENCES = [
9 ["notifyOnApproval", "approvals"],
10 ["notifyOnInput", "input requests"],
11 ["notifyOnCompletion", "completions"],
12 ["notifyOnFailure", "failures"],
13] as const satisfies ReadonlyArray<
14 readonly [keyof RelayClientDeviceRecord["notifications"], string]
15>;
16​
17export function mobileClientPlatformLabel(device: RelayClientDeviceRecord): string {
18 return `iOS ${device.iosMajorVersion}${device.appVersion ? ` · T3 Code ${device.appVersion}` : ""}`;
20​
21export function mobileClientNotificationDetail(device: RelayClientDeviceRecord): string {
22 if (!device.notifications.enabled) {
23 return "Push notifications are disabled on this device.";
24 }
25​
26 const enabledPreferences = NOTIFICATION_PREFERENCES.flatMap(([preference, label]) =>
27 device.notifications[preference] ? [label] : [],
28 );
29 return enabledPreferences.length > 0
30 ? `Alerts enabled for ${enabledPreferences.join(", ")}.`
31 : "Push notifications are enabled, but no alert types are selected.";
33​
34export function mobileClientUpdatedAtLabel(updatedAt: string): string {
35 const date = new Date(updatedAt);
36 return Number.isNaN(date.getTime())
37 ? "Update time unavailable"
38 : `Updated ${mobileClientUpdatedAtFormatter.format(date)}`;