| 1 | "use client"; |
| 2 | |
| 3 | import Link from "next/link" |
| 4 | import { useState } |
| 5 | import { useQuery, useMutation |
| 6 | import { useTranslations } |
| 7 | import { toast } |
| 8 | import { Plus, ExternalLink |
| 9 | import { orpc, queryClient |
| 10 | import { ContextMenu, RowMenu |
| 11 | import { ConfirmDialog } |
| 12 | |
| 13 | function invalidate() { |
| 14 | void queryClient.invalidateQueries( |
| 15 | } |
| 16 | |
| 17 | export default function AdminServersPage |
| 18 | const t = |
| 19 | const tc = |
| 20 | |
| 21 | const STATUS_CONFIG: |
| 22 | "": { label: t |
| 23 | installing: { label: t |
| 24 | install_failed: { label: t |
| 25 | restoring_backup: { label: t |
| 26 | }; |
| 27 | |
| 28 | const { data: |
| 29 | const deleteMutation = |
| 30 | onSuccess: () => |
| 31 | })); |
| 32 | |
| 33 | const [search, |
| 34 | const [confirmDelete, |
| 35 | const [purge, |
| 36 | |
| 37 | const filtered = |
| 38 | const q = |
| 39 | return ( |
| 40 | s.name.toLowerCase |
| 41 | s.allocation.ip |
| 42 | ((s as { |
| 43 | ); |
| 44 | }); |
| 45 | |
| 46 | function serverActions(server |
| 47 | return [ |
| 48 | { |
| 49 | label: "View Panel", |
| 50 | icon: ExternalLink, |
| 51 | onClick: () => |
| 52 | }, |
| 53 | "separator", |
| 54 | { |
| 55 | label: tc("delete |
| 56 | icon: Trash2, |
| 57 | onClick: () => |
| 58 | destructive: true, |
| 59 | }, |
| 60 | ]; |
| 61 | } |
| 62 | |
| 63 | return ( |
| 64 | <> |
| 65 | <ConfirmDialog |
| 66 | open={confirmDelete !== |
| 67 | onOpenChange={(open) |
| 68 | title={t(" |
| 69 | description={t(" |
| 70 | confirmLabel={tc(" |
| 71 | destructive |
| 72 | loading={deleteMutation.isPending |
| 73 | onConfirm={async () |
| 74 | if (!confirmDelete) return |
| 75 | await deleteMutation.mutateAsync |
| 76 | setConfirmDelete(null); |
| 77 | setPurge(false); |
| 78 | }} |
| 79 | > |
| 80 | <label className="flex items-center gap-2 text-sm text-muted-foreground |
| 81 | <input |
| 82 | type="checkbox" |
| 83 | checked={purge} |
| 84 | onChange={(e) |
| 85 | className="h-3.5 w-3.5 rounded" |
| 86 | /> |
| 87 | {tc("purgeFromNode") |
| 88 | </label> |
| 89 | </ConfirmDialog> |
| 90 | |
| 91 | <div className="flex-1 overflow-auto px-6 py-5 |
| 92 | <div className="mx-auto max-w-5xl |
| 93 | <div className="mb-5 flex items-center justify-between |
| 94 | <div className="flex items-center gap-2.5 |
| 95 | <h1 className="text-sm font-semibold text-foreground |
| 96 | </div> |
| 97 | <div className="flex items-center gap-2 |
| 98 | <div className="relative flex items-center |
| 99 | <Search className=" |
| 100 | <input |
| 101 | className="rounded-lg border border-border bg-background py-1.5 pl-8 pr-3 text-sm text-foreground outline-none placeholder:text-muted-foreground/50 focus:border-ring transition-colors" |
| 102 | placeholder={t(" |
| 103 | value={search} |
| 104 | onChange={(e) |
| 105 | /> |
| 106 | </div> |
| 107 | <Link |
| 108 | href={"/admin/servers/new" |
| 109 | className="flex items-center gap-1.5 rounded-lg bg-foreground px-3 py-1.5 text-sm font-medium text-background transition-opacity hover:opacity-80" |
| 110 | > |
| 111 | <Plus className=" |
| 112 | {t("newServer") |
| 113 | </Link> |
| 114 | </div> |
| 115 | </div> |
| 116 | <div className="overflow-x-auto |
| 117 | <div className="min-w-[600px] rounded-xl border border-border bg-card overflow-hidden |
| 118 | <div className="grid grid-cols-[24px_1fr_180px_120px_120px_48px] border-b border-border bg-muted/40 px-4 py-2.5 |
| 119 | <span /> |
| 120 | <span className="text-xs font-medium text-muted-foreground |
| 121 | <span className="text-xs font-medium text-muted-foreground |
| 122 | <span className="text-xs font-medium text-muted-foreground |
| 123 | <span className="text-xs font-medium text-muted-foreground |
| 124 | <span /> |
| 125 | </div> |
| 126 | |
| 127 | {isLoading && ( |
| 128 | <div className="px-4 py-8 text-center text-sm text-muted-foreground |
| 129 | )} |
| 130 | {!isLoading && filtered |
| 131 | <div className="px-4 py-8 text-center text-sm text-muted-foreground |
| 132 | {search ? t |
| 133 | </div> |
| 134 | )} |
| 135 | {filtered.map(( |
| 136 | const isSuspended = ( |
| 137 | const cfg = |
| 138 | ? { label: t |
| 139 | : (STATUS_CONFIG[server. |
| 140 | const actions = |
| 141 | const isLast = |
| 142 | |
| 143 | return ( |
| 144 | <ContextMenu key={ |
| 145 | {({ onContextMenu } |
| 146 | <div |
| 147 | onContextMenu={onContextMenu} |
| 148 | className={`grid grid-cols-[24px_1fr_180px_120px_120px_48px] items-center px-4 py-3 hover:bg-muted/40 transition-colors ${! |
| 149 | > |
| 150 | <span className="h-2 w-2 rounded-full |
| 151 | <div className="flex items-center gap-2 |
| 152 | <Link |
| 153 | href={`/admin/servers/${server |
| 154 | className="text-sm font-medium text-foreground transition-colors hover:text-blue-500" |
| 155 | onClick={(e) |
| 156 | > |
| 157 | {server.name} |
| 158 | </Link> |
| 159 | </div> |
| 160 | <span className="text-xs text-muted-foreground |
| 161 | {server.allocation.ip |
| 162 | </span> |
| 163 | <span className="text-xs text-muted-foreground |
| 164 | {(server as { |
| 165 | </span> |
| 166 | <span> |
| 167 | <span |
| 168 | className="rounded-full px-2 py-0.5 text-[11px] font-medium" |
| 169 | style={{ color: |
| 170 | > |
| 171 | {cfg.label} |
| 172 | </span> |
| 173 | </span> |
| 174 | <div className="flex items-center justify-end gap-2 |
| 175 | <Link |
| 176 | href={`/servers/${server |
| 177 | className="rounded p-0.5 text-muted-foreground/50 hover:bg-muted hover:text-foreground transition-colors" |
| 178 | title="View panel" |
| 179 | onClick={(e) |
| 180 | > |
| 181 | <ExternalLink className=" |
| 182 | </Link> |
| 183 | <RowMenu items={ |
| 184 | </div> |
| 185 | </div> |
| 186 | )} |
| 187 | </ContextMenu> |
| 188 | ); |
| 189 | })} |
| 190 | </div> |
| 191 | </div> |
| 192 | </div> |
| 193 | </div> |
| 194 | </> |
| 195 | ); |
| 196 | } |