5.2 KiB
5.2 KiB
Phase 3 — Admin UI (React-Native admin-ui + web admin-web)
Status: not started. Depends on: Phase 2 backend.
1. Goal
Let a regional admin:
- see global + regional products on the Products page;
- edit a global product's market data only (price / stock / offer / region suspension) — everything else read-only — via a separate component;
- see global stores read-only (no edit/delete).
2. Shared types (packages/shared/types/*)
Store: addisGlobal: boolean; changeownertonumber | null.AdminProduct(andAdminProductWithRelations): addisGlobal: boolean(derived from the store) so lists/edits can branch without a second call.- No change to
AdminSkushape (it already carries all market flags).
Confirm exact files:
packages/shared/types/admin.ts(Store,AdminProduct).
3. Server contract (from Phase 2 — restate so the UI is built to match)
admin.product.getProducts/getProductByIdreturn global + regional; each product hasisGlobal.admin.store.getStores/getStoreByIdreturn global stores withisGlobal: true,owner: null.admin.product.updateProductfor a global product accepts only market fields:price,marketPrice,flashPrice,isFlashAvailable,isOutOfStock,isSuspendedInRegion,isOffer. Structural fields are rejected/ignored.admin.product.updateProductPrices/toggleOutOfStockremain region-scoped and work on global SKUs.- Admins get 403/error for global store create/update/delete and global product create/delete.
4. admin-ui (Expo / React Native)
Products list — app/(drawer)/dashboard/products/index.tsx
- Show global + regional products.
- Add a Global badge on global rows/cards.
- Optionally a filter chip
All / Regional / Globalalongside the existingall / in-stock / out-of-stockchips (FilterType). onEdit(id)→ navigates toproducts/edit?id=…as today; the edit screen branches.
Products edit — app/(drawer)/dashboard/products/edit.tsx
- After
trpc.admin.product.getProductById, branch onproduct.isGlobal:- regional → existing
ProductForm(+ add/update flows unchanged). - global → render the new
GlobalProductForm.
- regional → existing
- Keep the existing image-upload / mutation plumbing for the regional path.
New component — src/components/GlobalProductForm.tsx
- Read-only (rendered as text/locked): name, short/long description, store, increment step, product type, per-SKU name + images + features, combo items.
- Editable: a per-SKU market block —
price,marketPrice,flashPrice,isFlashAvailable,isOutOfStock,isOffer,isSuspendedInRegion. - Submit →
admin.product.updateProductwith only the market fields (never structural). - Show a hint banner: "Global product — shared across regions. You can edit price & stock for your region only."
Products add — app/(drawer)/dashboard/products/add.tsx
- Unchanged (admins cannot create global products). Optionally hide/note global store choices in the store picker (a regional product can't be assigned to a global store).
Stores list — app/(drawer)/dashboard/stores/index.tsx
- Show global stores with a Global badge.
- Disable edit/delete for global stores (read-only). Keep them visible.
Stores edit — app/(drawer)/dashboard/stores/edit.tsx
- If the store
isGlobal: render read-only (no submit) with a "Global store — managed by a superadmin" banner.
Store picker (in ProductForm / ProductsSelector)
- Ensure global stores don't appear as selectable owners/stores for regional product creation (or are clearly marked and rejected by the backend).
5. admin-web (TanStack Router)
Mirror §4:
src/routes/dashboard.products.tsx— global badge + optional filter.src/routes/dashboard.products.edit.tsx— branch to a newsrc/components/GlobalProductForm.tsxwhenproduct.isGlobal.src/routes/dashboard.products.new.tsx— unchanged.src/routes/dashboard.stores.tsx— global badge, edit/delete disabled.src/routes/dashboard.stores.edit.tsx— read-only for global.- Reuse the same field rules; share the market-fields type from
@packages/sharedif helpful.
6. Verification
bunx tsc --noEmiton both apps (compare any pre-existing web-ui/admin-web error counts).- Manual/RTL smoke (only if asked — not the full suite):
- Products page lists a seeded global product with a badge.
- Editing it shows read-only structure + editable market fields; saving changes only
the caller region's price/stock (verify via
availability.json). - Global store rows show a badge and have no edit/delete action.
- No migrations, no test-suite run (unless the user asks).
7. Risks / notes
admin-uiandadmin-webboth have aProductForm; keep them behaviourally consistent but don't force a shared component across the RN/web boundary.- The global edit must never send structural fields — the backend rejects them, but avoid surfacing false "saved" states.
owner: number | nullchange ripples to store display components (StoreItem, store detail) — handle null ("Global" / "—").
8. Out of scope
Superadmin creation/editing of global entities (Phase 4).