| 1 | "use client"; |
| 2 | |
| 3 | import { useEffect } from |
| 4 | import { use } |
| 5 | import { useRouter } |
| 6 | import { useQuery } |
| 7 | import { Activity, Power |
| 8 | import type { LucideIcon |
| 9 | import { useTranslations } |
| 10 | import { orpc } |
| 11 | import { authClient } |
| 12 | import Loader from "@/components/loader |
| 13 | import { DitherAvatar } |
| 14 | |
| 15 | function StatRow({ |
| 16 | icon: Icon, |
| 17 | label, |
| 18 | children, |
| 19 | }: { |
| 20 | icon: LucideIcon |
| 21 | label: string |
| 22 | children: React |
| 23 | }) { |
| 24 | return ( |
| 25 | <div className="flex flex-col border-b border-border last:border-b-0 |
| 26 | <div className="flex flex-col gap-1.5 px-4 pt-3 pb-2.5 |
| 27 | <div className="flex items-center gap-1.5 text-[10px] font-medium uppercase tracking-widest text-muted-foreground |
| 28 | <Icon className=" |
| 29 | {label} |
| 30 | </div> |
| 31 | {children} |
| 32 | </div> |
| 33 | </div> |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | const EVENT_STYLES: Record |
| 38 | "server:power.start": { color: |
| 39 | "server:power.restart": { color: |
| 40 | "server:power.stop": { color: |
| 41 | backup: { color: " |
| 42 | files: { color: " |
| 43 | console: { color: " |
| 44 | user: { color: " |
| 45 | }; |
| 46 | |
| 47 | function getEventStyle(event: |
| 48 | if (event.startsWith |
| 49 | if (event.startsWith |
| 50 | if (event.startsWith |
| 51 | if (event.startsWith |
| 52 | if (event.startsWith |
| 53 | if (event === |
| 54 | if (event.startsWith |
| 55 | if (event.startsWith |
| 56 | return { color: |
| 57 | } |
| 58 | |
| 59 | const EVENT_LABEL_KEYS: Record |
| 60 | "server:power.start": "eventPowerStart", |
| 61 | "server:power.stop": "eventPowerStop", |
| 62 | "server:power.restart": "eventPowerRestart", |
| 63 | "server:power.kill": "eventPowerKill", |
| 64 | "server:backup.start": "eventBackupCreate", |
| 65 | "server:backup.delete": "eventBackupDelete", |
| 66 | "server:backup.restore": "eventBackupRestore", |
| 67 | "server:files.read": "eventFilesRead", |
| 68 | "server:files.write": "eventFilesWrite", |
| 69 | "server:files.rename": "eventFilesRename", |
| 70 | "server:files.delete": "eventFilesDelete", |
| 71 | "server:settings": "eventSettingsUpdate", |
| 72 | "server:reinstall": "eventServerReinstall", |
| 73 | "server:database.create": "eventDatabaseCreate", |
| 74 | "server:database.delete": "eventDatabaseDelete", |
| 75 | "server:database.rotate-password": "eventDatabaseRotatePassword", |
| 76 | "server:schedule.create": "eventScheduleCreate", |
| 77 | "server:schedule.update": "eventScheduleUpdate", |
| 78 | "server:schedule.delete": "eventScheduleDelete", |
| 79 | "user:subuser-create": "eventUsersAdd", |
| 80 | "user:subuser-update": "eventUsersUpdate", |
| 81 | "user:subuser-delete": "eventUsersRemove", |
| 82 | }; |
| 83 | |
| 84 | function ActorCell({ user |
| 85 | if (!user) |
| 86 | const displayName = |
| 87 | return ( |
| 88 | <div className="flex items-center gap-2 min-w-0 |
| 89 | <div className="flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-muted text-xs font-semibold text-foreground overflow-hidden |
| 90 | {user.image ? |
| 91 | // eslint-disable-next-line @next/next/no-img-element |
| 92 | <img src={user |
| 93 | ) : ( |
| 94 | <DitherAvatar name={ |
| 95 | )} |
| 96 | </div> |
| 97 | <span className="truncate text-sm text-foreground |
| 98 | </div> |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | function getEventDetails(eventType: |
| 103 | if (!propertiesJson) |
| 104 | let props: |
| 105 | try { props = |
| 106 | |
| 107 | if (eventType.startsWith |
| 108 | if (eventType.startsWith |
| 109 | if (eventType.startsWith |
| 110 | if (eventType.startsWith |
| 111 | if (eventType === |
| 112 | if (typeof props. |
| 113 | if (typeof props. |
| 114 | if (typeof props. |
| 115 | } |
| 116 | if (eventType === |
| 117 | return null; |
| 118 | } |
| 119 | |
| 120 | function fmtDate(d: |
| 121 | if (!d) |
| 122 | return new Date |
| 123 | } |
| 124 | |
| 125 | export default function ActivityPage |
| 126 | const t = |
| 127 | const router = |
| 128 | const { data: |
| 129 | const { id |
| 130 | |
| 131 | useEffect(() => |
| 132 | if (!isPending && |
| 133 | }, [isPending, |
| 134 | |
| 135 | const { data: |
| 136 | const serverId = |
| 137 | |
| 138 | const { data: |
| 139 | ...orpc.activity. |
| 140 | enabled: !!serverId, |
| 141 | }); |
| 142 | |
| 143 | if (isPending || |
| 144 | |
| 145 | const entries = |
| 146 | const powerCount = |
| 147 | const fileCount = |
| 148 | const backupCount = |
| 149 | |
| 150 | return ( |
| 151 | <> |
| 152 | <div className="flex flex-1 flex-col gap-3 overflow-auto px-4 py-4 md:flex-row md:overflow-hidden |
| 153 | <div className="flex flex-1 flex-col overflow-hidden rounded-xl border border-border bg-card |
| 154 | {/* Table header */} |
| 155 | <div className="grid grid-cols-[160px_180px_200px_1fr_130px] border-b border-border bg-muted/40 px-4 py-2.5 |
| 156 | <span className="text-xs font-medium text-muted-foreground |
| 157 | <span className="text-xs font-medium text-muted-foreground |
| 158 | <span className="text-xs font-medium text-muted-foreground |
| 159 | <span className="text-xs font-medium text-muted-foreground |
| 160 | <span className="text-xs font-medium text-muted-foreground |
| 161 | </div> |
| 162 | |
| 163 | <div className="flex-1 overflow-y-auto |
| 164 | {activityPending ? ( |
| 165 | <div className="flex items-center justify-center py-12 text-sm text-muted-foreground |
| 166 | ) : entries.length |
| 167 | <div className="flex flex-col items-center justify-center py-12 gap-2 |
| 168 | <Activity className=" |
| 169 | <p className="text-sm text-muted-foreground |
| 170 | </div> |
| 171 | ) : ( |
| 172 | entries.map((entry |
| 173 | const style = |
| 174 | const isLast = |
| 175 | return ( |
| 176 | <div |
| 177 | key={entry.id |
| 178 | className={`grid grid-cols-[160px_180px_200px_1fr_130px] items-center px-4 py-3 transition-colors hover:bg-muted/40 ${! |
| 179 | > |
| 180 | <span className="font-mono text-xs text-muted-foreground |
| 181 | <span> |
| 182 | <span |
| 183 | className="rounded-full px-2 py-0.5 font-mono text-xs font-medium" |
| 184 | style={{ color: |
| 185 | > |
| 186 | {EVENT_LABEL_KEYS[entry.eventType |
| 187 | </span> |
| 188 | </span> |
| 189 | <div className="min-w-0 pr-4 |
| 190 | <ActorCell user={ |
| 191 | </div> |
| 192 | <span className="truncate pr-4 font-mono text-xs text-muted-foreground |
| 193 | {getEventDetails(entry.eventType |
| 194 | </span> |
| 195 | <span className="font-mono text-xs text-muted-foreground |
| 196 | </div> |
| 197 | ); |
| 198 | }) |
| 199 | )} |
| 200 | </div> |
| 201 | </div> |
| 202 | |
| 203 | <aside className="flex w-full shrink-0 flex-col overflow-hidden rounded-xl border border-border bg-card md:w-[220px] |
| 204 | <StatRow icon={ |
| 205 | <span className="text-xl font-bold text-foreground |
| 206 | </StatRow> |
| 207 | <StatRow icon={ |
| 208 | <span className="text-xl font-bold text-foreground |
| 209 | </StatRow> |
| 210 | <StatRow icon={ |
| 211 | <span className="text-xl font-bold |
| 212 | </StatRow> |
| 213 | <StatRow icon={ |
| 214 | <span className="text-xl font-bold |
| 215 | </StatRow> |
| 216 | </aside> |
| 217 | </div> |
| 218 | </> |
| 219 | ); |
| 220 | } |