From d9a61818de61addbcb534894d2d6ea113e5d941d Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Thu, 13 Aug 2026 00:39:23 +0530 Subject: [PATCH] enh --- .../delivery-sequences/index.tsx | 6 ++-- .../dashboard/manage-orders/orders/index.tsx | 4 +-- .../dashboard/prices-overview/index.tsx | 2 +- .../(drawer)/dashboard/product-tags/index.tsx | 4 +-- .../app/(drawer)/dashboard/slots/index.tsx | 6 ++-- .../(drawer)/dashboard/slots/slot-details.tsx | 2 +- apps/admin-ui/src/components/TagMenu.tsx | 2 +- .../src/trpc/apis/admin-apis/apis/const.ts | 14 ++++++++ .../app/(drawer)/(tabs)/home/index.tsx | 33 ++++--------------- 9 files changed, 33 insertions(+), 40 deletions(-) diff --git a/apps/admin-ui/app/(drawer)/dashboard/manage-orders/delivery-sequences/index.tsx b/apps/admin-ui/app/(drawer)/dashboard/manage-orders/delivery-sequences/index.tsx index e7a076c..0519753 100644 --- a/apps/admin-ui/app/(drawer)/dashboard/manage-orders/delivery-sequences/index.tsx +++ b/apps/admin-ui/app/(drawer)/dashboard/manage-orders/delivery-sequences/index.tsx @@ -302,7 +302,7 @@ export default function DeliverySequences() { // Auto-select first slot if no slotId provided useEffect(() => { if (!slotId && slotsData?.slots && slotsData.slots.length > 0) { - router.replace(`/manage-orders/delivery-sequences?slotId=${slotsData.slots[0].id}`); + router.replace(`/(drawer)/dashboard/manage-orders/delivery-sequences?slotId=${slotsData.slots[0].id}`); } }, [slotId, slotsData, router]); @@ -505,7 +505,7 @@ export default function DeliverySequences() { value={selectedSlotId || ""} onValueChange={(val) => { if (val) { - router.replace(`/manage-orders/delivery-sequences?slotId=${val}`); + router.replace(`/(drawer)/dashboard/manage-orders/delivery-sequences?slotId=${val}`); } }} placeholder="Select slot" @@ -726,7 +726,7 @@ export default function DeliverySequences() { }} onViewDetails={() => { if (selectedOrder) { - router.push(`/manage-orders/order-details/${selectedOrder.id}`); + router.push(`/(drawer)/dashboard/manage-orders/order-details/${selectedOrder.id}`); } setShowOrderMenu(false); }} diff --git a/apps/admin-ui/app/(drawer)/dashboard/manage-orders/orders/index.tsx b/apps/admin-ui/app/(drawer)/dashboard/manage-orders/orders/index.tsx index 024db6f..263f1e8 100644 --- a/apps/admin-ui/app/(drawer)/dashboard/manage-orders/orders/index.tsx +++ b/apps/admin-ui/app/(drawer)/dashboard/manage-orders/orders/index.tsx @@ -105,12 +105,12 @@ const OrderItem = ({ order, refetch }: { order: OrderType; refetch: () => void } const updateItemPackagingMutation = trpc.admin.order.updateOrderItemPackaging.useMutation(); const handleOrderPress = () => { - router.push(`/manage-orders/order-details/${order.orderId}` as any); + router.push(`/(drawer)/dashboard/manage-orders/order-details/${order.orderId}` as any); }; const handleMenuOption = () => { setMenuOpen(false); - router.push(`/manage-orders/order-details/${order.orderId}` as any); + router.push(`/(drawer)/dashboard/manage-orders/order-details/${order.orderId}` as any); }; const handleMarkPackaged = (isPackaged: boolean) => { diff --git a/apps/admin-ui/app/(drawer)/dashboard/prices-overview/index.tsx b/apps/admin-ui/app/(drawer)/dashboard/prices-overview/index.tsx index eb39369..8bcdb03 100644 --- a/apps/admin-ui/app/(drawer)/dashboard/prices-overview/index.tsx +++ b/apps/admin-ui/app/(drawer)/dashboard/prices-overview/index.tsx @@ -419,7 +419,7 @@ export default function PricesOverview() { { - router.push('/rebalance-orders' as any); + router.push('/(drawer)/dashboard/rebalance-orders' as any); setShowMenu(false); }} > diff --git a/apps/admin-ui/app/(drawer)/dashboard/product-tags/index.tsx b/apps/admin-ui/app/(drawer)/dashboard/product-tags/index.tsx index d520c2b..a1eae54 100644 --- a/apps/admin-ui/app/(drawer)/dashboard/product-tags/index.tsx +++ b/apps/admin-ui/app/(drawer)/dashboard/product-tags/index.tsx @@ -95,11 +95,11 @@ export default function ProductTags() { }; const handleAddNewTag = () => { - router.push('/product-tags/add'); + router.push('/(drawer)/dashboard/product-tags/add'); }; const handleOrderTags = () => { - router.push('/product-tags/order'); + router.push('/(drawer)/dashboard/product-tags/order'); }; diff --git a/apps/admin-ui/app/(drawer)/dashboard/slots/index.tsx b/apps/admin-ui/app/(drawer)/dashboard/slots/index.tsx index ed6b6a0..9ac862b 100644 --- a/apps/admin-ui/app/(drawer)/dashboard/slots/index.tsx +++ b/apps/admin-ui/app/(drawer)/dashboard/slots/index.tsx @@ -72,7 +72,7 @@ const SlotItemComponent: React.FC = ({ router.push(`/slots/edit/${slot.id}` as any)} + onPress={() => router.push(`/(drawer)/dashboard/slots/edit/${slot.id}` as any)} style={tw`px-3 py-1 rounded-full bg-pink2 mr-2`} > @@ -147,7 +147,7 @@ const SlotItemComponent: React.FC = ({ { setMenuOpen(false); - router.push(`/slots/add?baseslot=${slot.id}` as any); + router.push(`/(drawer)/dashboard/slots/add?baseslot=${slot.id}` as any); }} style={tw`py-4 border-b border-gray-200`} > @@ -277,7 +277,7 @@ export default function Slots() { router.push('/slots/add' as any)} + onPress={() => router.push('/(drawer)/dashboard/slots/add' as any)} activeOpacity={0.95} style={{ position: 'absolute', bottom: 32, right: 24, zIndex: 100 }} > diff --git a/apps/admin-ui/app/(drawer)/dashboard/slots/slot-details.tsx b/apps/admin-ui/app/(drawer)/dashboard/slots/slot-details.tsx index 08a6287..153f10f 100644 --- a/apps/admin-ui/app/(drawer)/dashboard/slots/slot-details.tsx +++ b/apps/admin-ui/app/(drawer)/dashboard/slots/slot-details.tsx @@ -198,7 +198,7 @@ export default function SlotDetails() { {/* FAB for Edit Slot */} router.push(`/slots/edit/${slot.id}` as any)} + onPress={() => router.push(`/(drawer)/dashboard/slots/edit/${slot.id}` as any)} activeOpacity={0.95} style={{ position: 'absolute', bottom: 32, right: 24, zIndex: 100 }} > diff --git a/apps/admin-ui/src/components/TagMenu.tsx b/apps/admin-ui/src/components/TagMenu.tsx index 5961d5d..4e203be 100644 --- a/apps/admin-ui/src/components/TagMenu.tsx +++ b/apps/admin-ui/src/components/TagMenu.tsx @@ -34,7 +34,7 @@ export const TagMenu: React.FC = ({ const handleEditTag = () => { setIsOpen(false); - router.push(`/product-tags/edit?tagId=${tagId}`); + router.push(`/(drawer)/dashboard/product-tags/edit?tagId=${tagId}`); }; const handleDeleteTag = () => { diff --git a/apps/backend/src/trpc/apis/admin-apis/apis/const.ts b/apps/backend/src/trpc/apis/admin-apis/apis/const.ts index e99961e..3c86119 100644 --- a/apps/backend/src/trpc/apis/admin-apis/apis/const.ts +++ b/apps/backend/src/trpc/apis/admin-apis/apis/const.ts @@ -2,9 +2,16 @@ import { router, protectedProcedure } from '@/src/trpc/trpc-index' import { z } from 'zod'; import { computeConstants } from '@/src/lib/const-store' import { CONST_KEYS } from '@/src/lib/const-keys' +import { scheduleStoreInitialization } from '@/src/stores/store-initializer' import { getAllConstants as getAllConstantsFromDb, upsertConstants as upsertConstantsInDb } from '@/src/dbService' import type { Constant, ConstantUpdateResult } from '@packages/shared' +// Constants that are baked into the versioned cache files (products.json etc.) +// — changing them requires regenerating the cache so the user app picks it up. +const CACHE_AFFECTING_KEYS: string[] = [ + CONST_KEYS.tagsOrder, +] + export const constRouter = router({ getConstants: protectedProcedure .query(async (): Promise => { @@ -64,6 +71,13 @@ export const constRouter = router({ // Refresh all constants in Redis after database update await computeConstants(); + // Constants like tagsOrder are baked into the versioned cache files. + // Regenerate the cache (bumps cacheVersion) so the user app fetches the + // new data (e.g., the new tab order on the home page). + if (constants.some((c) => CACHE_AFFECTING_KEYS.includes(c.key))) { + await scheduleStoreInitialization() + } + return { success: true, updatedCount: constants.length, diff --git a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx index 3930108..d44b53c 100755 --- a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx +++ b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx @@ -593,35 +593,14 @@ export default function Dashboard() { productById.set(product.id, product); } - // tag.productIds is already in the admin-curated order (backend sorts by sortOrder). - const orderedIds = (tag.productIds || []).filter((id: number) => productById.has(id)); - const ordered: any[] = []; - const rest: any[] = []; - for (const id of orderedIds) { - const product = productById.get(id); - const isOutOfStock = Boolean(productSlotsMap[id]?.isOutOfStock) || !getQuickestSlot(id); - if (isOutOfStock) rest.push(product); - else ordered.push(product); - } - - // Products in the tag's productIds but not in the curated order (added later) — availability sort. - const seen = new Set(orderedIds); - const extra = products - .filter((product: any) => (tag.productIds?.includes(product.id) ?? false) && !seen.has(product.id)) - .sort((a: any, b: any) => { - const slotA = getQuickestSlot(a.id) - const slotB = getQuickestSlot(b.id) - const aOutOfStock = Boolean(productSlotsMap[a.id]?.isOutOfStock) || !slotA - const bOutOfStock = Boolean(productSlotsMap[b.id]?.isOutOfStock) || !slotB - if (aOutOfStock && !bOutOfStock) return 1 - if (!aOutOfStock && bOutOfStock) return -1 - return 0 - }); - - map[tag.id] = [...ordered, ...rest, ...extra]; + // Respect the admin-curated order — tag.productIds is already ordered by + // the tag's sortOrder (backend reorders it when building the cache). + map[tag.id] = (tag.productIds || []) + .map((id: number) => productById.get(id)) + .filter(Boolean) as any[]; } return map; - }, [dashboardTags, products, getQuickestSlot, productSlotsMap]); + }, [dashboardTags, products]); const handleRefresh = useCallback(async () => { setIsRefreshing(true);