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
+10 -4
View File
@@ -124,8 +124,7 @@ function emptyPlanFeatureForm(plan = PLANS[0]): PlanFeatureForm {
}
function authHeaders(): Record<string, string> {
const token = typeof window !== 'undefined' ? localStorage.getItem('admin_token') : null
return token ? { Authorization: `Bearer ${token}` } : {}
return {}
}
function sortFeatures(list: PlanFeature[]) {
@@ -315,7 +314,7 @@ function PlanFeaturesSection() {
const [deleteConfirm, setDeleteConfirm] = useState<string | null>(null)
useEffect(() => {
fetch(`${ADMIN_API_BASE}/admin/pricing/features`, { headers: authHeaders() })
fetch(`${ADMIN_API_BASE}/admin/pricing/features`, { headers: authHeaders(), credentials: 'include' })
.then(async (r) => {
const json = await r.json()
if (!r.ok) throw new Error(json?.message ?? 'Failed to load plan features')
@@ -377,6 +376,7 @@ function PlanFeaturesSection() {
const res = await fetch(url, {
method: isEdit ? 'PATCH' : 'POST',
headers: { 'Content-Type': 'application/json', ...authHeaders() },
credentials: 'include',
body: JSON.stringify(result.payload),
})
const json = await res.json()
@@ -398,6 +398,7 @@ function PlanFeaturesSection() {
const res = await fetch(`${ADMIN_API_BASE}/admin/pricing/features/${id}`, {
method: 'DELETE',
headers: authHeaders(),
credentials: 'include',
})
if (!res.ok) throw new Error('Delete failed')
setFeatures((prev) => prev.filter((feature) => feature.id !== id))
@@ -712,7 +713,7 @@ function PromotionsSection() {
const [deleteConfirm, setDeleteConfirm] = useState<string | null>(null)
useEffect(() => {
fetch(`${ADMIN_API_BASE}/admin/pricing/promotions`, { headers: authHeaders() })
fetch(`${ADMIN_API_BASE}/admin/pricing/promotions`, { headers: authHeaders(), credentials: 'include' })
.then(async (r) => {
const json = await r.json()
if (!r.ok) throw new Error(json?.message ?? 'Failed to load promotions')
@@ -795,6 +796,7 @@ function PromotionsSection() {
const res = await fetch(url, {
method: isEdit ? 'PATCH' : 'POST',
headers: { 'Content-Type': 'application/json', ...authHeaders() },
credentials: 'include',
body: JSON.stringify(result.payload),
})
const json = await res.json()
@@ -816,6 +818,7 @@ function PromotionsSection() {
const res = await fetch(`${ADMIN_API_BASE}/admin/pricing/promotions/${promo.id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...authHeaders() },
credentials: 'include',
body: JSON.stringify({ isActive: !promo.isActive }),
})
const json = await res.json()
@@ -829,6 +832,7 @@ function PromotionsSection() {
const res = await fetch(`${ADMIN_API_BASE}/admin/pricing/promotions/${id}`, {
method: 'DELETE',
headers: authHeaders(),
credentials: 'include',
})
if (!res.ok) throw new Error('Delete failed')
setPromotions((prev) => prev.filter((p) => p.id !== id))
@@ -1005,6 +1009,7 @@ export default function PricingPage() {
useEffect(() => {
fetch(`${ADMIN_API_BASE}/admin/pricing`, {
headers: authHeaders(),
credentials: 'include',
cache: 'no-store',
})
.then((r) => r.json())
@@ -1037,6 +1042,7 @@ export default function PricingPage() {
const res = await fetch(`${ADMIN_API_BASE}/admin/pricing`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...authHeaders() },
credentials: 'include',
body: JSON.stringify({ entries }),
})
const json = await res.json()