Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | 1x 1x 50x 35x 50x 35x 35x 35x 35x 35x 35x 35x 35x 1x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 1x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 1x 15x 15x 1x 1x 1x 1x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 47x 1x 47x 20x 20x 47x 47x 8x 8x 19x 19x | import { useState, type ReactNode } from 'react';
export function formatAdminDate(value: string | null | undefined): string {
if (!value) return '-';
const date = new Date(value);
if (Number.isNaN(date.getTime())) return value;
return date.toLocaleString(undefined, {
year: 'numeric',
month: 'short',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
});
}
interface ShellProps {
title: string;
subtitle: string;
filters: ReactNode;
children: ReactNode;
}
export function BackofficePageShell({ title, subtitle, filters, children }: ShellProps) {
return (
<div className="bo-page">
<div className="bo-page-header">
<div>
<h1>{title}</h1>
<p>{subtitle}</p>
</div>
</div>
<div className="bo-filter-bar">{filters}</div>
{children}
</div>
);
}
export function BackofficeIdCell({ id }: { id: string }) {
const [copied, setCopied] = useState(false);
async function copyId() {
try {
await navigator.clipboard.writeText(id);
setCopied(true);
window.setTimeout(() => setCopied(false), 1200);
} catch {
setCopied(false);
}
}
return (
<div className="bo-id-cell">
<button type="button" onClick={copyId} aria-label={`Copy ID ${id}`} title={id}>
{copied ? (
<span className="bo-copy-check" aria-hidden="true">✓</span>
) : (
<svg viewBox="0 0 24 24" aria-hidden="true">
<rect x="9" y="9" width="10" height="10" rx="2" />
<path d="M5 15V7a2 2 0 0 1 2-2h8" />
</svg>
)}
</button>
</div>
);
}
export function BackofficeStatusPill({ status }: { status: string }) {
return <span className={`bo-status-pill bo-status-${status.toLowerCase().replace(/_/g, '-')}`}>{status}</span>;
}
export function BackofficeConfirmAction({
label,
confirmLabel = 'Confirm',
disabled,
busy,
onConfirm,
}: {
label: string;
confirmLabel?: string;
disabled?: boolean;
busy?: boolean;
onConfirm: () => void;
}) {
const [confirming, setConfirming] = useState(false);
if (confirming) {
return (
<span className="bo-row-actions">
<button type="button" className="bo-row-action" disabled={busy} onClick={onConfirm}>
{busy ? 'Working...' : confirmLabel}
</button>
<button type="button" className="bo-secondary-button" onClick={() => setConfirming(false)} disabled={busy}>
Cancel
</button>
</span>
);
}
return (
<button type="button" className="bo-row-action" disabled={disabled || busy} onClick={() => setConfirming(true)}>
{busy ? 'Working...' : label}
</button>
);
}
export function BackofficeImageModal({
imageUrl,
title,
message,
onClose,
}: {
imageUrl: string | null;
title: string;
message?: string;
onClose: () => void;
}) {
if (!imageUrl) return null;
return (
<div className="bo-modal-backdrop" role="presentation" onClick={onClose}>
<div className="bo-image-modal" role="dialog" aria-modal="true" aria-label={title} onClick={(event) => event.stopPropagation()}>
<div className="bo-modal-header">
<h2>{title}</h2>
<button type="button" className="bo-secondary-button" onClick={onClose}>Close</button>
</div>
<img src={imageUrl} alt={title} />
{message && <p>{message}</p>}
</div>
</div>
);
}
export function BackofficeRowActions({ children }: { children: ReactNode }) {
return <div className="bo-row-actions">{children}</div>;
}
interface PaginationProps {
offset: number;
limit: number;
totalCount: number;
hasNext: boolean;
isLoading: boolean;
onPrevious: () => void;
onNext: () => void;
onLimitChange: (limit: number) => void;
}
export function BackofficePagination({
offset,
limit,
totalCount,
hasNext,
isLoading,
onPrevious,
onNext,
onLimitChange,
}: PaginationProps) {
const first = totalCount === 0 ? 0 : offset + 1;
const last = Math.min(offset + limit, totalCount);
return (
<div className="bo-pagination">
<div className="bo-pagination-summary">
Showing {first}-{last} of {totalCount}
</div>
<div className="bo-pagination-controls">
<label>
Rows
<select
value={limit}
onChange={(event) => onLimitChange(Number(event.target.value))}
disabled={isLoading}
>
<option value={10}>10</option>
<option value={25}>25</option>
<option value={50}>50</option>
<option value={100}>100</option>
</select>
</label>
<button type="button" onClick={onPrevious} disabled={isLoading || offset === 0}>
Previous
</button>
<button type="button" onClick={onNext} disabled={isLoading || !hasNext}>
Next
</button>
</div>
</div>
);
}
interface StateProps {
isLoading: boolean;
error: string | null;
empty: boolean;
onRetry: () => void;
}
export function BackofficeTableState({ isLoading, error, empty, onRetry }: StateProps) {
if (isLoading) {
return <div className="bo-state">Loading...</div>;
}
if (error) {
return (
<div className="bo-state bo-state-error">
<span>{error}</span>
<button type="button" onClick={onRetry}>Retry</button>
</div>
);
}
if (empty) {
return <div className="bo-state">No rows match the current filters.</div>;
}
return null;
}
|