fix architecture and write new tests

This commit is contained in:
root
2026-06-10 00:40:19 -04:00
parent 560da1cadf
commit 80a597bc10
377 changed files with 84020 additions and 1337 deletions
@@ -207,10 +207,6 @@ const STATUS_COLORS: Record<string, string> = {
const INPUT_CLASS = 'mt-1 w-full rounded-xl border border-zinc-700 bg-zinc-900 px-3 py-2 text-sm text-zinc-100 outline-none focus:border-emerald-500'
const LABEL_CLASS = 'text-xs font-medium uppercase tracking-wide text-zinc-500'
function getToken() {
return localStorage.getItem('admin_token') ?? ''
}
function toDateInput(value: string | null | undefined) {
return value ? new Date(value).toISOString().slice(0, 10) : ''
}
@@ -324,11 +320,10 @@ export default function AdminCompanyDetailPage() {
const [deleteConfirm, setDeleteConfirm] = useState(false)
async function fetchData() {
const headers = { Authorization: `Bearer ${getToken()}` }
try {
const [cRes, aRes] = await Promise.all([
fetch(`${ADMIN_API_BASE}/admin/companies/${id}`, { headers, cache: 'no-store' }),
fetch(`${ADMIN_API_BASE}/admin/audit-logs?entityId=${id}&pageSize=10`, { headers, cache: 'no-store' }),
fetch(`${ADMIN_API_BASE}/admin/companies/${id}`, { cache: 'no-store', credentials: 'include' }),
fetch(`${ADMIN_API_BASE}/admin/audit-logs?entityId=${id}&pageSize=10`, { cache: 'no-store', credentials: 'include' }),
])
const cJson = await cRes.json()
const aJson = await aRes.json()
@@ -339,7 +334,7 @@ export default function AdminCompanyDetailPage() {
const subId = cJson.data?.subscription?.id
if (subId) {
const eRes = await fetch(`${ADMIN_API_BASE}/admin/subscriptions/${subId}/events`, { headers, cache: 'no-store' })
const eRes = await fetch(`${ADMIN_API_BASE}/admin/subscriptions/${subId}/events`, { cache: 'no-store', credentials: 'include' })
const eJson = await eRes.json()
setSubEvents(Array.isArray(eJson.data) ? eJson.data : [])
}
@@ -365,7 +360,8 @@ export default function AdminCompanyDetailPage() {
try {
const res = await fetch(`${ADMIN_API_BASE}/admin/companies/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` },
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({
company: {
name: form.company.name,
@@ -469,7 +465,8 @@ export default function AdminCompanyDetailPage() {
try {
const res = await fetch(`${ADMIN_API_BASE}/admin/subscriptions/${company.subscription.id}/${action}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` },
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ reason: subOverrideReason }),
})
const json = await res.json()
@@ -490,7 +487,8 @@ export default function AdminCompanyDetailPage() {
try {
const res = await fetch(`${ADMIN_API_BASE}/admin/companies/${id}/status`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` },
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ status }),
})
const json = await res.json()
@@ -508,7 +506,7 @@ export default function AdminCompanyDetailPage() {
try {
const res = await fetch(`${ADMIN_API_BASE}/admin/companies/${id}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${getToken()}` },
credentials: 'include',
})
const json = await res.json()
if (!res.ok) throw new Error(json?.message ?? 'Delete failed')