From c14e32522a21dac36126eae204d0be10c5751bf5 Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Tue, 10 Mar 2026 13:05:33 +0530 Subject: [PATCH] enh --- .../(tabs)/flash-delivery/_layout.tsx | 2 +- .../app/(drawer)/(tabs)/home/index.tsx | 2 +- .../(drawer)/(tabs)/me/complaints/index.tsx | 2 +- apps/user-ui/components/HealthTestWrapper.tsx | 2 +- apps/user-ui/components/NextOrderGlimpse.tsx | 2 +- apps/user-ui/components/WebViewWrapper.tsx | 2 +- apps/user-ui/components/cart-page.tsx | 2 +- apps/user-ui/components/checkout-page.tsx | 2 +- .../src/api-hooks/essential-consts.api.ts | 8 ---- .../src/components/AddToCartDialog.tsx | 2 +- apps/user-ui/src/hooks/prominent-api-hooks.ts | 40 +++++++++++++++---- 11 files changed, 42 insertions(+), 24 deletions(-) delete mode 100644 apps/user-ui/src/api-hooks/essential-consts.api.ts diff --git a/apps/user-ui/app/(drawer)/(tabs)/flash-delivery/_layout.tsx b/apps/user-ui/app/(drawer)/(tabs)/flash-delivery/_layout.tsx index 5a1c8bc..a9e39dc 100644 --- a/apps/user-ui/app/(drawer)/(tabs)/flash-delivery/_layout.tsx +++ b/apps/user-ui/app/(drawer)/(tabs)/flash-delivery/_layout.tsx @@ -5,7 +5,7 @@ import { trpc } from '@/src/trpc-client'; import { MyText, MyTouchableOpacity, tw, AppContainer } from 'common-ui'; import { useRouter } from 'expo-router'; import MaterialIcons from '@expo/vector-icons/MaterialIcons'; -import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'; +import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; export default function FlashDeliveryBaseLayout() { const router = useRouter(); diff --git a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx index fd6bb7e..74ecb8d 100755 --- a/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx +++ b/apps/user-ui/app/(drawer)/(tabs)/home/index.tsx @@ -28,7 +28,7 @@ import BannerCarousel from "@/components/BannerCarousel"; import { useUserDetails } from "@/src/contexts/AuthContext"; import TabLayoutWrapper from "@/components/TabLayoutWrapper"; import { useNavigationStore } from "@/src/store/navigationStore"; -import { useGetEssentialConsts } from "@/src/api-hooks/essential-consts.api"; +import { useGetEssentialConsts } from "@/src/hooks/prominent-api-hooks"; import NextOrderGlimpse from "@/components/NextOrderGlimpse"; dayjs.extend(relativeTime); diff --git a/apps/user-ui/app/(drawer)/(tabs)/me/complaints/index.tsx b/apps/user-ui/app/(drawer)/(tabs)/me/complaints/index.tsx index 948182d..67240ff 100644 --- a/apps/user-ui/app/(drawer)/(tabs)/me/complaints/index.tsx +++ b/apps/user-ui/app/(drawer)/(tabs)/me/complaints/index.tsx @@ -4,7 +4,7 @@ import { Image } from 'expo-image'; import { MyText, tw, useManualRefresh, MyFlatList, useMarkDataFetchers, theme, MyTouchableOpacity } from 'common-ui'; import { MaterialIcons, Ionicons } from '@expo/vector-icons'; import { trpc } from '@/src/trpc-client'; -import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'; +import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import dayjs from 'dayjs'; import { useRouter } from 'expo-router'; diff --git a/apps/user-ui/components/HealthTestWrapper.tsx b/apps/user-ui/components/HealthTestWrapper.tsx index 227bdc5..bc8387f 100644 --- a/apps/user-ui/components/HealthTestWrapper.tsx +++ b/apps/user-ui/components/HealthTestWrapper.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import { View, ActivityIndicator, Platform } from 'react-native'; import { tw, theme, MyText, MyTouchableOpacity , BottomDialog } from 'common-ui'; import { trpc, trpcClient } from '@/src/trpc-client'; -import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'; +import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import Constants from 'expo-constants'; import * as Linking from 'expo-linking'; diff --git a/apps/user-ui/components/NextOrderGlimpse.tsx b/apps/user-ui/components/NextOrderGlimpse.tsx index f3d154b..933ddfb 100644 --- a/apps/user-ui/components/NextOrderGlimpse.tsx +++ b/apps/user-ui/components/NextOrderGlimpse.tsx @@ -8,7 +8,7 @@ import dayjs from 'dayjs'; import { trpc } from '@/src/trpc-client'; import { Image } from 'expo-image'; import { orderStatusManipulator } from '@/src/lib/string-manipulators'; -import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'; +import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; interface OrderItem { productName: string; diff --git a/apps/user-ui/components/WebViewWrapper.tsx b/apps/user-ui/components/WebViewWrapper.tsx index 2f64735..c0ea863 100644 --- a/apps/user-ui/components/WebViewWrapper.tsx +++ b/apps/user-ui/components/WebViewWrapper.tsx @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import { View, ActivityIndicator } from 'react-native'; import { WebView } from 'react-native-webview'; import { trpc } from '@/src/trpc-client'; -import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'; +import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import { theme, MyText, MyTouchableOpacity } from 'common-ui'; import MaterialIcons from '@expo/vector-icons/MaterialIcons'; diff --git a/apps/user-ui/components/cart-page.tsx b/apps/user-ui/components/cart-page.tsx index e8a58d4..8f0077f 100644 --- a/apps/user-ui/components/cart-page.tsx +++ b/apps/user-ui/components/cart-page.tsx @@ -26,7 +26,7 @@ import dayjs from "dayjs"; import { trpc } from "@/src/trpc-client"; import { useAllProducts } from "@/src/hooks/prominent-api-hooks"; import { useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks'; -import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'; +import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; interface CartPageProps { isFlashDelivery?: boolean; diff --git a/apps/user-ui/components/checkout-page.tsx b/apps/user-ui/components/checkout-page.tsx index d7934f2..60a33f1 100644 --- a/apps/user-ui/components/checkout-page.tsx +++ b/apps/user-ui/components/checkout-page.tsx @@ -10,7 +10,7 @@ import { useAuthenticatedRoute } from '@/hooks/useAuthenticatedRoute'; import { trpc } from '@/src/trpc-client'; import { useAllProducts } from '@/src/hooks/prominent-api-hooks'; import { useGetCart } from '@/hooks/cart-query-hooks'; -import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'; +import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import PaymentAndOrderComponent from '@/components/PaymentAndOrderComponent'; import CheckoutAddressSelector from '@/components/CheckoutAddressSelector'; import { useAddressStore } from '@/src/store/addressStore'; diff --git a/apps/user-ui/src/api-hooks/essential-consts.api.ts b/apps/user-ui/src/api-hooks/essential-consts.api.ts deleted file mode 100644 index 7791682..0000000 --- a/apps/user-ui/src/api-hooks/essential-consts.api.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { trpc } from '@/src/trpc-client'; - -export const useGetEssentialConsts = () => { - const query = trpc.common.essentialConsts.useQuery(undefined, { - refetchInterval: 60000, - }); - return { ...query, refetch: query.refetch }; -}; diff --git a/apps/user-ui/src/components/AddToCartDialog.tsx b/apps/user-ui/src/components/AddToCartDialog.tsx index 66a9ff4..d005993 100644 --- a/apps/user-ui/src/components/AddToCartDialog.tsx +++ b/apps/user-ui/src/components/AddToCartDialog.tsx @@ -7,7 +7,7 @@ import { useCartStore } from '@/src/store/cartStore'; import { useFlashCartStore } from '@/src/store/flashCartStore'; import { trpc } from '@/src/trpc-client'; import { useAddToCart, useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks'; -import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api'; +import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import dayjs from 'dayjs'; import { SafeAreaView } from 'react-native-safe-area-context'; diff --git a/apps/user-ui/src/hooks/prominent-api-hooks.ts b/apps/user-ui/src/hooks/prominent-api-hooks.ts index d7d4bce..1c412af 100644 --- a/apps/user-ui/src/hooks/prominent-api-hooks.ts +++ b/apps/user-ui/src/hooks/prominent-api-hooks.ts @@ -1,11 +1,39 @@ import { useQuery } from '@tanstack/react-query' import axios from 'axios' -import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api' -// import { AllProductsApiType } from '@backend/trpc/router' +import { trpc } from '@/src/trpc-client' import { AllProductsApiType } from "@backend/trpc/router"; +// Local useGetEssentialConsts hook +export const useGetEssentialConsts = () => { + const query = trpc.common.essentialConsts.useQuery(undefined, { + refetchInterval: 60000, + }) + return { ...query, refetch: query.refetch } +} - -type ProductsResponse = AllProductsApiType; +// // Type definitions matching the backend response +// interface ProductSummary { +// id: number +// name: string +// shortDescription: string | null +// price: number +// marketPrice: number | null +// unit: string +// unitNotation: string +// incrementStep: number +// productQuantity: number +// storeId: number | null +// isOutOfStock: boolean +// isFlashAvailable: boolean +// nextDeliveryDate: string | null +// images: string[] +// } +// +// interface ProductsResponse { +// products: ProductSummary[] +// count: number +// } +// +type ProductsResponse = AllProductsApiType; export function useAllProducts() { const { data: essentialConsts } = useGetEssentialConsts() @@ -16,15 +44,13 @@ export function useAllProducts() { const cacheUrl = assetsDomain && apiCacheKey ? `${assetsDomain}${apiCacheKey}/products.json` : null - + return useQuery({ queryKey: ['all-products', cacheUrl], queryFn: async () => { if (!cacheUrl) { throw new Error('Cache URL not available') } - console.log(cacheUrl) - const response = await axios.get(cacheUrl) return response.data },