test #2
7 changed files with 35 additions and 56 deletions
|
|
@ -5,7 +5,7 @@ import { productInfo, units, productSlots, deliverySlotInfo, specialDeals, store
|
||||||
import { claimUploadUrl, extractKeyFromPresignedUrl, scaffoldAssetUrl } from '@/src/lib/s3-client';
|
import { claimUploadUrl, extractKeyFromPresignedUrl, scaffoldAssetUrl } from '@/src/lib/s3-client';
|
||||||
import { ApiError } from '@/src/lib/api-error';
|
import { ApiError } from '@/src/lib/api-error';
|
||||||
import { eq, and, gt, sql, inArray, desc } from 'drizzle-orm';
|
import { eq, and, gt, sql, inArray, desc } from 'drizzle-orm';
|
||||||
import { getProductById as getProductByIdFromCache, getAllProducts as getAllProductsFromCache } from '@/src/stores/product-store';
|
import { getProductById as getProductByIdFromCache } from '@/src/stores/product-store';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
// Uniform Product Type
|
// Uniform Product Type
|
||||||
|
|
@ -246,20 +246,4 @@ export const productRouter = router({
|
||||||
return { success: true, review: newReview };
|
return { success: true, review: newReview };
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getAllProductsSummary: publicProcedure
|
|
||||||
.query(async (): Promise<Product[]> => {
|
|
||||||
// Get all products from cache
|
|
||||||
const allCachedProducts = await getAllProductsFromCache();
|
|
||||||
|
|
||||||
// Transform the cached products to match the expected summary format
|
|
||||||
// (with empty deliverySlots and specialDeals arrays for summary view)
|
|
||||||
const transformedProducts = allCachedProducts.map(product => ({
|
|
||||||
...product,
|
|
||||||
deliverySlots: [], // Empty for summary view
|
|
||||||
specialDeals: [], // Empty for summary view
|
|
||||||
}));
|
|
||||||
|
|
||||||
return transformedProducts;
|
|
||||||
}),
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -54,13 +54,13 @@ const PaymentAndOrderComponent: React.FC<PaymentAndOrderProps> = ({
|
||||||
queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] });
|
queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] });
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data: productsData } = trpc.user.product.getAllProductsSummary.useQuery();
|
const { data: productsData } = trpc.common.product.getAllProductsSummary.useQuery({});
|
||||||
|
|
||||||
// Memoized flash-eligible product IDs
|
// Memoized flash-eligible product IDs
|
||||||
const flashEligibleProductIds = useMemo(() => {
|
const flashEligibleProductIds = useMemo(() => {
|
||||||
if (!productsData) return new Set<number>();
|
if (!productsData?.products) return new Set<number>();
|
||||||
return new Set(
|
return new Set(
|
||||||
productsData
|
productsData.products
|
||||||
.filter((product: any) => product.isFlashAvailable)
|
.filter((product: any) => product.isFlashAvailable)
|
||||||
.map((product: any) => product.id)
|
.map((product: any) => product.id)
|
||||||
);
|
);
|
||||||
|
|
@ -397,4 +397,4 @@ const PaymentAndOrderComponent: React.FC<PaymentAndOrderProps> = ({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PaymentAndOrderComponent;
|
export default PaymentAndOrderComponent;
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,7 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU
|
||||||
|
|
||||||
const slotQuery = trpc.user.slots.getSlotById.useQuery({ slotId: slotId! }, { enabled: !!slotId });
|
const slotQuery = trpc.user.slots.getSlotById.useQuery({ slotId: slotId! }, { enabled: !!slotId });
|
||||||
|
|
||||||
const productsQuery = trpc.user.product.getAllProductsSummary.useQuery();
|
const productsQuery = trpc.common.product.getAllProductsSummary.useQuery({});
|
||||||
|
|
||||||
const { addToCart = () => { } } = useAddToCart({ showSuccessAlert: false, showErrorAlert: false, refetchCart: true }, "regular") || {};
|
const { addToCart = () => { } } = useAddToCart({ showSuccessAlert: false, showErrorAlert: false, refetchCart: true }, "regular") || {};
|
||||||
|
|
||||||
|
|
@ -401,8 +401,8 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU
|
||||||
const slotProductIds = new Set(slotQuery.data.products?.map((p: any) => p.id) || []);
|
const slotProductIds = new Set(slotQuery.data.products?.map((p: any) => p.id) || []);
|
||||||
|
|
||||||
const filteredProducts: any[] = storeIdNum
|
const filteredProducts: any[] = storeIdNum
|
||||||
? productsQuery?.data?.filter(p =>
|
? productsQuery?.data?.products?.filter(p =>
|
||||||
p.store?.id === storeIdNum && slotProductIds.has(p.id)
|
p.storeId === storeIdNum && slotProductIds.has(p.id)
|
||||||
) || []
|
) || []
|
||||||
: slotQuery.data.products;
|
: slotQuery.data.products;
|
||||||
|
|
||||||
|
|
@ -448,7 +448,7 @@ export function FlashDeliveryProducts({ storeId:storeIdParent, baseUrl, onProduc
|
||||||
const storeId = storeIdParent;
|
const storeId = storeIdParent;
|
||||||
const storeIdNum = storeId;
|
const storeIdNum = storeId;
|
||||||
|
|
||||||
const productsQuery = trpc.user.product.getAllProductsSummary.useQuery();
|
const productsQuery = trpc.common.product.getAllProductsSummary.useQuery({});
|
||||||
|
|
||||||
const { addToCart = () => { } } = useAddToCart({ showSuccessAlert: false, showErrorAlert: false, refetchCart: true }, "flash") || {};
|
const { addToCart = () => { } } = useAddToCart({ showSuccessAlert: false, showErrorAlert: false, refetchCart: true }, "flash") || {};
|
||||||
|
|
||||||
|
|
@ -489,14 +489,14 @@ export function FlashDeliveryProducts({ storeId:storeIdParent, baseUrl, onProduc
|
||||||
let flashProducts: any[] = [];
|
let flashProducts: any[] = [];
|
||||||
if (storeIdNum) {
|
if (storeIdNum) {
|
||||||
// Filter by store, flash availability, and stock status
|
// Filter by store, flash availability, and stock status
|
||||||
flashProducts = productsQuery?.data?.filter(p =>
|
flashProducts = productsQuery?.data?.products?.filter(p =>
|
||||||
p.store?.id === storeIdNum &&
|
p.storeId === storeIdNum &&
|
||||||
p.isFlashAvailable &&
|
p.isFlashAvailable &&
|
||||||
!p.isOutOfStock
|
!p.isOutOfStock
|
||||||
) || [];
|
) || [];
|
||||||
} else {
|
} else {
|
||||||
// Show all flash-available products that are in stock
|
// Show all flash-available products that are in stock
|
||||||
flashProducts = productsQuery?.data?.filter(p =>
|
flashProducts = productsQuery?.data?.products?.filter(p =>
|
||||||
p.isFlashAvailable &&
|
p.isFlashAvailable &&
|
||||||
!p.isOutOfStock
|
!p.isOutOfStock
|
||||||
) || [];
|
) || [];
|
||||||
|
|
@ -533,4 +533,4 @@ export function FlashDeliveryProducts({ storeId:storeIdParent, baseUrl, onProduc
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,16 +80,16 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
|
||||||
|
|
||||||
const { data: couponsRaw, error: couponsError } = trpc.user.coupon.getEligible.useQuery();
|
const { data: couponsRaw, error: couponsError } = trpc.user.coupon.getEligible.useQuery();
|
||||||
const { data: constsData } = useGetEssentialConsts();
|
const { data: constsData } = useGetEssentialConsts();
|
||||||
const { data: productsData } = trpc.user.product.getAllProductsSummary.useQuery();
|
const { data: productsData } = trpc.common.product.getAllProductsSummary.useQuery({});
|
||||||
|
|
||||||
const cartItems = cartData?.items || [];
|
const cartItems = cartData?.items || [];
|
||||||
|
|
||||||
|
|
||||||
// Memoized flash-eligible product IDs
|
// Memoized flash-eligible product IDs
|
||||||
const flashEligibleProductIds = useMemo(() => {
|
const flashEligibleProductIds = useMemo(() => {
|
||||||
if (!productsData) return new Set<number>();
|
if (!productsData?.products) return new Set<number>();
|
||||||
return new Set(
|
return new Set(
|
||||||
productsData
|
productsData.products
|
||||||
.filter((product: any) => product.isFlashAvailable)
|
.filter((product: any) => product.isFlashAvailable)
|
||||||
.map((product: any) => product.id)
|
.map((product: any) => product.id)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ const CheckoutPage: React.FC<CheckoutPageProps> = ({ isFlashDelivery = false })
|
||||||
const { data: addresses, refetch: refetchAddresses } = trpc.user.address.getUserAddresses.useQuery();
|
const { data: addresses, refetch: refetchAddresses } = trpc.user.address.getUserAddresses.useQuery();
|
||||||
const { data: slotsData, refetch: refetchSlots } = trpc.user.slots.getSlots.useQuery();
|
const { data: slotsData, refetch: refetchSlots } = trpc.user.slots.getSlots.useQuery();
|
||||||
const { data: constsData } = useGetEssentialConsts();
|
const { data: constsData } = useGetEssentialConsts();
|
||||||
const { data: productsData } = trpc.user.product.getAllProductsSummary.useQuery();
|
const { data: productsData } = trpc.common.product.getAllProductsSummary.useQuery({});
|
||||||
|
|
||||||
useMarkDataFetchers(() => {
|
useMarkDataFetchers(() => {
|
||||||
refetchCart();
|
refetchCart();
|
||||||
|
|
@ -53,9 +53,9 @@ const CheckoutPage: React.FC<CheckoutPageProps> = ({ isFlashDelivery = false })
|
||||||
|
|
||||||
// Memoized flash-eligible product IDs
|
// Memoized flash-eligible product IDs
|
||||||
const flashEligibleProductIds = useMemo(() => {
|
const flashEligibleProductIds = useMemo(() => {
|
||||||
if (!productsData) return new Set<number>();
|
if (!productsData?.products) return new Set<number>();
|
||||||
return new Set(
|
return new Set(
|
||||||
productsData
|
productsData.products
|
||||||
.filter((product: any) => product.isFlashAvailable)
|
.filter((product: any) => product.isFlashAvailable)
|
||||||
.map((product: any) => product.id)
|
.map((product: any) => product.id)
|
||||||
);
|
);
|
||||||
|
|
@ -273,4 +273,4 @@ const CheckoutPage: React.FC<CheckoutPageProps> = ({ isFlashDelivery = false })
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CheckoutPage;
|
export default CheckoutPage;
|
||||||
|
|
|
||||||
|
|
@ -24,21 +24,8 @@ interface LocalCartItem {
|
||||||
|
|
||||||
interface ProductSummary {
|
interface ProductSummary {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
|
||||||
shortDescription?: string | null;
|
|
||||||
longDescription?: string | null;
|
|
||||||
price: string;
|
price: string;
|
||||||
marketPrice?: string | null;
|
|
||||||
unitNotation: string;
|
|
||||||
images: string[];
|
|
||||||
isOutOfStock: boolean;
|
|
||||||
store?: { id: number; name: string; description?: string | null } | null;
|
|
||||||
incrementStep: number;
|
incrementStep: number;
|
||||||
productQuantity: number;
|
|
||||||
isFlashAvailable: boolean;
|
|
||||||
flashPrice?: string | null;
|
|
||||||
deliverySlots: Array<{ id: number; deliveryTime: Date; freezeTime: Date }>;
|
|
||||||
specialDeals: Array<{ quantity: string; price: string; validTill: Date }>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CartItem {
|
interface CartItem {
|
||||||
|
|
@ -146,15 +133,23 @@ export function useGetCart(options?: {
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const { data: products } = trpc.user.product.getAllProductsSummary.useQuery();
|
const { data: products } = trpc.common.product.getAllProductsSummary.useQuery({});
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: [`local-cart-${cartType}`],
|
queryKey: [`local-cart-${cartType}`],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
|
||||||
const cartItems = await getLocalCart(cartType);
|
const cartItems = await getLocalCart(cartType);
|
||||||
|
|
||||||
// const productMap = Object.fromEntries(products?.map((p: ProductSummary) => [p.id, p]) || []);
|
const productMap = Object.fromEntries(
|
||||||
const productMap = Object.fromEntries(products?.map((p) => [p.id, p]) || []);
|
products?.products?.map((p) => [
|
||||||
|
p.id,
|
||||||
|
{
|
||||||
|
...p,
|
||||||
|
price: String(p.price),
|
||||||
|
marketPrice: p.marketPrice === null || p.marketPrice === undefined ? null : String(p.marketPrice),
|
||||||
|
} as ProductSummary,
|
||||||
|
]) || []
|
||||||
|
);
|
||||||
|
|
||||||
const items: CartItem[] = cartItems.map(cartItem => {
|
const items: CartItem[] = cartItems.map(cartItem => {
|
||||||
const product = productMap[cartItem.productId];
|
const product = productMap[cartItem.productId];
|
||||||
|
|
@ -507,4 +502,4 @@ export function useRemoveFromCart(options?: {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export clear cart function for direct use
|
// Export clear cart function for direct use
|
||||||
export { clearLocalCart };
|
export { clearLocalCart };
|
||||||
|
|
|
||||||
|
|
@ -64,9 +64,9 @@ const isDevMode = Constants.executionEnvironment !== "standalone";
|
||||||
// const BASE_API_URL = 'http://10.0.2.2:4000';
|
// const BASE_API_URL = 'http://10.0.2.2:4000';
|
||||||
// const BASE_API_URL = 'http://192.168.100.101:4000';
|
// const BASE_API_URL = 'http://192.168.100.101:4000';
|
||||||
// const BASE_API_URL = 'http://192.168.1.5:4000';
|
// const BASE_API_URL = 'http://192.168.1.5:4000';
|
||||||
// let BASE_API_URL = "https://mf.freshyo.in";
|
let BASE_API_URL = "https://mf.freshyo.in";
|
||||||
let BASE_API_URL = "https://freshyo.technocracy.ovh";
|
// let BASE_API_URL = "https://freshyo.technocracy.ovh";
|
||||||
// let BASE_API_URL = 'http://192.168.100.104:4000';
|
// let BASE_API_URL = 'http://192.168.100.107:4000';
|
||||||
// let BASE_API_URL = 'http://192.168.29.176:4000';
|
// let BASE_API_URL = 'http://192.168.29.176:4000';
|
||||||
|
|
||||||
// if(isDevMode) {
|
// if(isDevMode) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue