Compare commits

..

5 commits

Author SHA1 Message Date
shafi54
5ed889a34f Merge branch 'main' of https://git.technocracy.ovh/shafi/freshyo 2026-03-23 03:23:15 +05:30
shafi54
3ddc939a48 enh 2026-03-23 03:22:20 +05:30
shafi54
24252b717b enh 2026-03-22 21:43:44 +05:30
shafi54
78305e1670 enh 2026-03-22 21:28:32 +05:30
shafi54
1a3fe7826f enh 2026-03-15 22:38:17 +05:30
285 changed files with 33374 additions and 17273 deletions

View file

@ -1,9 +0,0 @@
**/node_modules
**/dist
apps/users-ui/app
apps/users-ui/src
apps/admin-ui/app
apps/users-ui/src
**/package-lock.json
test/

3
.gitignore vendored
View file

@ -7,13 +7,10 @@ yarn-debug.log*
yarn-error.log* yarn-error.log*
lerna-debug.log* lerna-debug.log*
.pnpm-debug.log* .pnpm-debug.log*
*.apk
# Diagnostic reports (https://nodejs.org/api/report.html) # Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
test/appBinaries
# Runtime data # Runtime data
pids pids
*.pid *.pid

View file

@ -1,4 +0,0 @@
- trpc.user.tags.getTagsByStore — apps/backend/src/trpc/apis/user-apis/apis/tags.ts
- trpc.common.product.getAllProductsSummary — apps/backend/src/trpc/apis/common-apis/common.ts
- remove slots from products cache
- remove redundant product details like name, description etc from the slots api

View file

@ -1,36 +1,32 @@
# Optimized Dockerfile for backend and fallback-ui services (project root) # Optimized Dockerfile for backend and fallback-ui services (project root)
# 1. ---- Base Bun image # 1. ---- Base Node image
FROM oven/bun:1.3.10 AS base FROM node:20-slim AS base
WORKDIR /app WORKDIR /app
# 2. ---- Pruner ---- # 2. ---- Pruner ----
FROM base AS pruner FROM base AS pruner
WORKDIR /app WORKDIR /app
# Copy config files first for better caching # Copy config files first for better caching
COPY package.json turbo.json ./ COPY package.json package-lock.json turbo.json ./
COPY apps/backend/package.json ./apps/backend/ COPY apps/backend/package.json ./apps/backend/
COPY apps/fallback-ui/package.json ./apps/fallback-ui/ COPY apps/fallback-ui/package.json ./apps/fallback-ui/
COPY packages/shared/ ./packages/shared
COPY packages/ui/package.json ./packages/ui/ COPY packages/ui/package.json ./packages/ui/
RUN bun install -g turbo RUN npm install -g turbo
COPY . . COPY . .
RUN turbo prune --scope=backend --scope=fallback-ui --scope=@packages/shared --docker RUN turbo prune --scope=backend --scope=fallback-ui --scope=common-ui --docker
# RUN find . -path "./node_modules" -prune -o -print
# 3. ---- Builder ---- # 3. ---- Builder ----
FROM base AS builder FROM base AS builder
WORKDIR /app WORKDIR /app
# Copy package files first to cache bun install # Copy package files first to cache npm install
COPY --from=pruner /app/out/json/ . COPY --from=pruner /app/out/json/ .
#COPY --from=pruner /app/out/bun.lock ./bun.lock COPY --from=pruner /app/out/package-lock.json ./package-lock.json
#RUN cat ./bun.lock
COPY --from=pruner /app/turbo.json . COPY --from=pruner /app/turbo.json .
RUN bun install RUN npm ci
# Copy source code after dependencies are installed # Copy source code after dependencies are installed
COPY --from=pruner /app/out/full/ . COPY --from=pruner /app/out/full/ .
RUN bunx turbo run build --filter=fallback-ui... --filter=backend... RUN npx turbo run build --filter=fallback-ui... --filter=backend...
RUN find . -path "./node_modules" -prune -o -print
# 4. ---- Runner ---- # 4. ---- Runner ----
FROM base AS runner FROM base AS runner
@ -38,15 +34,12 @@ WORKDIR /app
ENV NODE_ENV=production ENV NODE_ENV=production
# Copy package files and install production deps # Copy package files and install production deps
COPY --from=pruner /app/out/json/ . COPY --from=pruner /app/out/json/ .
#COPY --from=pruner /app/out/bun.lock ./bun.lock COPY --from=pruner /app/out/package-lock.json ./package-lock.json
RUN bun install --production RUN npm ci --production --omit=dev
# Copy built applications # Copy built applications
COPY --from=builder /app/apps/backend/dist ./apps/backend/dist COPY --from=builder /app/apps/backend/dist ./apps/backend/dist
COPY --from=builder /app/apps/fallback-ui/dist ./apps/fallback-ui/dist COPY --from=builder /app/apps/fallback-ui/dist ./apps/fallback-ui/dist
COPY --from=builder /app/packages/shared ./packages/shared
# RUN ls -R
RUN find . -path "./node_modules" -prune -o -print
EXPOSE 4000 EXPOSE 4000
CMD ["bun", "apps/backend/dist/apps/backend/index.js"] RUN npm i -g bun
CMD ["bun", "apps/backend/dist/index.js"]
# CMD ["node", "apps/backend/dist/index.js"]

File diff suppressed because one or more lines are too long

View file

@ -74,7 +74,7 @@ export default function Dashboard() {
const menuItems: MenuItem[] = [ const menuItems: MenuItem[] = [
{ {
title: 'Manage Orderss', title: 'Manage Orders',
icon: 'shopping-bag', icon: 'shopping-bag',
description: 'View and manage customer orders', description: 'View and manage customer orders',
route: '/(drawer)/manage-orders', route: '/(drawer)/manage-orders',
@ -158,15 +158,6 @@ export default function Dashboard() {
iconColor: '#8B5CF6', iconColor: '#8B5CF6',
iconBg: '#F3E8FF', iconBg: '#F3E8FF',
}, },
{
title: 'Stocking Schedules',
icon: 'schedule',
description: 'Manage product stocking schedules',
route: '/(drawer)/stocking-schedules',
category: 'products',
iconColor: '#0EA5E9',
iconBg: '#E0F2FE',
},
{ {
title: 'Stores', title: 'Stores',
icon: 'store', icon: 'store',
@ -303,4 +294,4 @@ export default function Dashboard() {
</ScrollView> </ScrollView>
</View> </View>
); );
} }

View file

@ -1,443 +0,0 @@
import React, { useState } from 'react';
import { View, ScrollView, Alert, FlatList, TouchableOpacity } from 'react-native';
import {
theme,
AppContainer,
MyText,
tw,
useManualRefresh,
useMarkDataFetchers,
MyTouchableOpacity,
RawBottomDialog,
BottomDialog,
} from 'common-ui';
import { trpc } from '../../../src/trpc-client';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import { Ionicons, Entypo } from '@expo/vector-icons';
import { LinearGradient } from 'expo-linear-gradient';
import AvailabilityScheduleForm from '../../../components/AvailabilityScheduleForm';
interface Schedule {
id: number;
scheduleName: string;
time: string;
action: 'in' | 'out';
createdAt: string;
lastUpdated: string;
productIds: number[];
groupIds: number[];
productCount: number;
groupCount: number;
}
const ScheduleItem = ({
schedule,
onDelete,
index,
onViewProducts,
onViewGroups,
onReplicate,
}: {
schedule: Schedule;
onDelete: (id: number) => void;
index: number;
onViewProducts: (productIds: number[]) => void;
onViewGroups: (groupIds: number[]) => void;
onReplicate: (schedule: Schedule) => void;
}) => {
const isIn = schedule.action === 'in';
const [menuOpen, setMenuOpen] = useState(false);
return (
<View style={tw``}>
<View style={tw`p-6`}>
{/* Top Header: Name & Action Badge */}
<View style={tw`flex-row justify-between items-start mb-4`}>
<View style={tw`flex-row items-center flex-1`}>
<View
style={tw`w-12 h-12 rounded-2xl bg-brand50 items-center justify-center mr-4`}
>
<MaterialIcons
name="schedule"
size={24}
color={theme.colors.brand600}
/>
</View>
<View style={tw`flex-1`}>
<MyText
style={tw`text-slate-400 text-[10px] font-black uppercase tracking-widest`}
>
Schedule Name
</MyText>
<MyText
style={tw`text-xl font-black text-slate-900`}
numberOfLines={1}
>
{schedule.scheduleName}
</MyText>
</View>
</View>
<View style={tw`flex-row items-center`}>
<View
style={[
tw`px-3 py-1.5 rounded-full flex-row items-center mr-2`,
{ backgroundColor: isIn ? '#F0FDF4' : '#FFF1F2' },
]}
>
<View
style={[
tw`w-1.5 h-1.5 rounded-full mr-2`,
{ backgroundColor: isIn ? '#10B981' : '#E11D48' },
]}
/>
<MyText
style={[
tw`text-[10px] font-black uppercase tracking-tighter`,
{ color: isIn ? '#10B981' : '#E11D48' },
]}
>
{isIn ? 'In Stock' : 'Out of Stock'}
</MyText>
</View>
<TouchableOpacity
onPress={() => setMenuOpen(true)}
style={tw`p-1`}
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
>
<Entypo name="dots-three-vertical" size={20} color="#9CA3AF" />
</TouchableOpacity>
</View>
</View>
{/* Menu Dialog */}
<BottomDialog open={menuOpen} onClose={() => setMenuOpen(false)}>
<View style={tw`p-4`}>
<MyText style={tw`text-lg font-bold mb-4`}>{schedule.scheduleName}</MyText>
<TouchableOpacity
onPress={() => {
setMenuOpen(false);
onReplicate(schedule);
}}
style={tw`py-4 border-b border-gray-200`}
>
<View style={tw`flex-row items-center`}>
<MaterialIcons name="content-copy" size={20} color="#4B5563" style={tw`mr-3`} />
<MyText style={tw`text-base text-gray-800`}>Replicate items</MyText>
</View>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
setMenuOpen(false);
Alert.alert('Coming Soon', 'Edit functionality will be available soon');
}}
style={tw`py-4 border-b border-gray-200`}
>
<View style={tw`flex-row items-center`}>
<MaterialIcons name="edit" size={20} color="#4B5563" style={tw`mr-3`} />
<MyText style={tw`text-base text-gray-800`}>Edit</MyText>
</View>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
setMenuOpen(false);
onDelete(schedule.id);
}}
style={tw`py-4 border-b border-gray-200`}
>
<View style={tw`flex-row items-center`}>
<MaterialIcons name="delete" size={20} color="#E11D48" style={tw`mr-3`} />
<MyText style={tw`text-base text-red-500`}>Delete</MyText>
</View>
</TouchableOpacity>
<TouchableOpacity
onPress={() => setMenuOpen(false)}
style={tw`py-4 mt-2`}
>
<View style={tw`flex-row items-center`}>
<MaterialIcons name="close" size={20} color="#6B7280" style={tw`mr-3`} />
<MyText style={tw`text-base text-gray-600`}>Cancel</MyText>
</View>
</TouchableOpacity>
</View>
</BottomDialog>
{/* Middle: Time Banner */}
<View
style={tw`bg-slate-50 rounded-3xl p-4 flex-row items-center mb-4 border border-slate-100`}
>
<View
style={tw`bg-white w-10 h-10 rounded-2xl items-center justify-center shadow-sm`}
>
<MaterialIcons name="access-time" size={20} color="#64748B" />
</View>
<View style={tw`ml-4 flex-1`}>
<MyText style={tw`text-slate-900 font-extrabold text-sm`}>
{schedule.time}
</MyText>
<MyText style={tw`text-slate-500 text-[10px] font-bold uppercase`}>
Daily at this time
</MyText>
</View>
</View>
{/* Stats & Actions */}
<View style={tw`flex-row items-center justify-between`}>
<View style={tw`flex-row items-center`}>
<MyTouchableOpacity
onPress={() => onViewProducts(schedule.productIds)}
style={tw`flex-row items-center mr-4`}
>
<MaterialIcons name="shopping-bag" size={14} color="#94A3B8" />
<MyText style={tw`text-xs font-bold text-brand600 ml-1.5`}>
{schedule.productCount} Products
</MyText>
</MyTouchableOpacity>
{schedule.groupCount > 0 && (
<MyTouchableOpacity
onPress={() => onViewGroups(schedule.groupIds)}
style={tw`flex-row items-center`}
>
<MaterialIcons name="category" size={14} color="#94A3B8" />
<MyText style={tw`text-xs font-bold text-brand600 ml-1.5`}>
{schedule.groupCount} Groups
</MyText>
</MyTouchableOpacity>
)}
</View>
</View>
</View>
</View>
);
};
export default function StockingSchedules() {
const {
data: schedules,
isLoading,
error,
refetch,
} = trpc.admin.productAvailabilitySchedules.getAll.useQuery();
const { data: productsData } = trpc.common.product.getAllProductsSummary.useQuery({});
const { data: groupsData } = trpc.admin.product.getGroups.useQuery();
const deleteSchedule = trpc.admin.productAvailabilitySchedules.delete.useMutation();
const [showCreateForm, setShowCreateForm] = useState(false);
// Dialog state
const [dialogOpen, setDialogOpen] = useState(false);
const [dialogType, setDialogType] = useState<'products' | 'groups'>('products');
const [selectedIds, setSelectedIds] = useState<number[]>([]);
// Replication state
const [replicatingSchedule, setReplicatingSchedule] = useState<Schedule | null>(null);
useManualRefresh(refetch);
useMarkDataFetchers(() => {
refetch();
});
const handleCreate = () => {
setShowCreateForm(true);
};
const handleDelete = (id: number) => {
Alert.alert(
'Delete Schedule',
'Are you sure you want to delete this schedule? This action cannot be undone.',
[
{ text: 'Cancel', style: 'cancel' },
{
text: 'Delete',
style: 'destructive',
onPress: () => {
deleteSchedule.mutate(
{ id },
{
onSuccess: () => {
refetch();
},
onError: (error: any) => {
Alert.alert('Error', error.message || 'Failed to delete schedule');
},
},
);
},
},
],
);
};
const handleViewProducts = (productIds: number[]) => {
setDialogType('products');
setSelectedIds(productIds);
setDialogOpen(true);
};
const handleViewGroups = (groupIds: number[]) => {
setDialogType('groups');
setSelectedIds(groupIds);
setDialogOpen(true);
};
const handleReplicate = (schedule: Schedule) => {
setReplicatingSchedule(schedule);
setShowCreateForm(true);
};
const handleCloseForm = () => {
setShowCreateForm(false);
setReplicatingSchedule(null);
};
// Get product/group names from IDs
const getProductNames = () => {
const allProducts = productsData?.products || [];
return selectedIds.map(id => {
const product = allProducts.find(p => p.id === id);
return product?.name || `Product #${id}`;
});
};
const getGroupNames = () => {
const allGroups = groupsData?.groups || [];
return selectedIds.map(id => {
const group = allGroups.find(g => g.id === id);
return group?.groupName || `Group #${id}`;
});
};
if (showCreateForm) {
return (
<AvailabilityScheduleForm
onClose={handleCloseForm}
onSuccess={() => {
refetch();
handleCloseForm();
}}
initialProductIds={replicatingSchedule?.productIds}
initialGroupIds={replicatingSchedule?.groupIds}
/>
);
}
if (isLoading) {
return (
<AppContainer>
<View style={tw`flex-1 justify-center items-center`}>
<MyText style={tw`text-gray-600`}>Loading schedules...</MyText>
</View>
</AppContainer>
);
}
if (error) {
return (
<AppContainer>
<View style={tw`flex-1 justify-center items-center`}>
<MyText style={tw`text-red-600`}>Error loading schedules</MyText>
</View>
</AppContainer>
);
}
return (
<>
<AppContainer>
<View style={tw`flex-1 bg-white h-full`}>
<ScrollView
style={tw`flex-1`}
contentContainerStyle={tw`pt-2 pb-32`}
showsVerticalScrollIndicator={false}
>
{schedules && schedules.length === 0 ? (
<View style={tw`flex-1 justify-center items-center py-20`}>
<View
style={tw`w-24 h-24 bg-slate-50 rounded-full items-center justify-center mb-6`}
>
<Ionicons name="time-outline" size={48} color="#94A3B8" />
</View>
<MyText
style={tw`text-slate-900 text-xl font-black tracking-tight`}
>
No Schedules Yet
</MyText>
<MyText
style={tw`text-slate-500 text-center mt-2 font-medium px-8`}
>
Start by creating your first availability schedule using the
button below.
</MyText>
</View>
) : (
schedules?.map((schedule, index) => (
<React.Fragment key={schedule.id}>
<ScheduleItem
schedule={schedule}
index={index}
onDelete={handleDelete}
onViewProducts={handleViewProducts}
onViewGroups={handleViewGroups}
onReplicate={handleReplicate}
/>
{index < schedules.length - 1 && (
<View style={tw`h-px bg-slate-200 w-full`} />
)}
</React.Fragment>
))
)}
</ScrollView>
</View>
</AppContainer>
<MyTouchableOpacity
onPress={handleCreate}
activeOpacity={0.95}
style={tw`absolute bottom-8 right-6 shadow-2xl z-50`}
>
<LinearGradient
colors={['#1570EF', '#194185']}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 1 }}
style={tw`w-16 h-16 rounded-[24px] items-center justify-center shadow-lg shadow-brand300`}
>
<MaterialIcons name="add" size={32} color="white" />
</LinearGradient>
</MyTouchableOpacity>
{/* Products/Groups Dialog */}
<RawBottomDialog open={dialogOpen} onClose={() => setDialogOpen(false)}>
<View style={tw`p-4`}>
<MyText style={tw`text-lg font-bold mb-4`}>
{dialogType === 'products' ? 'Products' : 'Groups'}
</MyText>
<FlatList
data={dialogType === 'products' ? getProductNames() : getGroupNames()}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => (
<View style={tw`py-3 border-b border-gray-100`}>
<MyText style={tw`text-base text-gray-800`}>{item}</MyText>
</View>
)}
showsVerticalScrollIndicator={false}
style={tw`max-h-80`}
ListEmptyComponent={
<View style={tw`py-8 items-center`}>
<MyText style={tw`text-gray-500`}>
No {dialogType} found
</MyText>
</View>
}
/>
</View>
</RawBottomDialog>
</>
);
}

View file

@ -1,237 +0,0 @@
import React, { useState } from 'react';
import { View, TouchableOpacity, Alert, ScrollView } from 'react-native';
import { useFormik } from 'formik';
import { MyText, tw, MyTextInput, MyTouchableOpacity, DateTimePickerMod } from 'common-ui';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import ProductsSelector from './ProductsSelector';
import { trpc } from '../src/trpc-client';
interface AvailabilityScheduleFormProps {
onClose: () => void;
onSuccess: () => void;
initialProductIds?: number[];
initialGroupIds?: number[];
}
const AvailabilityScheduleForm: React.FC<AvailabilityScheduleFormProps> = ({
onClose,
onSuccess,
initialProductIds,
initialGroupIds,
}) => {
const createSchedule = trpc.admin.productAvailabilitySchedules.create.useMutation();
const { data: groupsData } = trpc.admin.product.getGroups.useQuery();
// Map groups data to match ProductsSelector types (convert price from string to number)
const groups = (groupsData?.groups || []).map(group => ({
...group,
products: group.products.map(product => ({
...product,
price: parseFloat(product.price as unknown as string) || 0,
})),
}));
const formik = useFormik({
initialValues: {
scheduleName: '',
timeDate: null as Date | null,
action: 'in' as 'in' | 'out',
productIds: initialProductIds || ([] as number[]),
groupIds: initialGroupIds || ([] as number[]),
},
validate: (values) => {
const errors: {[key: string]: string} = {};
if (!values.scheduleName.trim()) {
errors.scheduleName = 'Schedule name is required';
}
if (!values.timeDate) {
errors.timeDate = 'Time is required';
}
if (!values.action) {
errors.action = 'Action is required';
}
if (values.productIds.length === 0) {
errors.productIds = 'At least one product must be selected';
}
return errors;
},
onSubmit: async (values) => {
try {
// Convert Date to HH:MM string
const hours = values.timeDate!.getHours().toString().padStart(2, '0');
const minutes = values.timeDate!.getMinutes().toString().padStart(2, '0');
const timeString = `${hours}:${minutes}`;
await createSchedule.mutateAsync({
scheduleName: values.scheduleName,
time: timeString,
action: values.action,
productIds: values.productIds,
groupIds: values.groupIds,
});
Alert.alert('Success', 'Schedule created successfully');
onSuccess();
onClose();
} catch (error: any) {
Alert.alert('Error', error.message || 'Failed to create schedule');
}
},
});
const actionOptions = [
{ label: 'In Stock', value: 'in' },
{ label: 'Out of Stock', value: 'out' },
];
return (
<View style={tw`flex-1 bg-white`}>
{/* Header */}
<View style={tw`flex-row items-center justify-between p-4 border-b border-gray-200 bg-white`}>
<MyText style={tw`text-xl font-bold text-gray-900`}>
Create Availability Schedule
</MyText>
<MyTouchableOpacity onPress={onClose}>
<MaterialIcons name="close" size={24} color="#6B7280" />
</MyTouchableOpacity>
</View>
<ScrollView style={tw`flex-1 p-4`} showsVerticalScrollIndicator={false}>
{/* Schedule Name */}
<View style={tw`mb-4`}>
<MyText style={tw`text-sm font-medium text-gray-700 mb-2`}>
Schedule Name
</MyText>
<MyTextInput
placeholder="Enter schedule name"
value={formik.values.scheduleName}
onChangeText={formik.handleChange('scheduleName')}
onBlur={formik.handleBlur('scheduleName')}
style={tw`border rounded-lg p-3 ${
formik.touched.scheduleName && formik.errors.scheduleName
? 'border-red-500'
: 'border-gray-300'
}`}
/>
{formik.touched.scheduleName && formik.errors.scheduleName && (
<MyText style={tw`text-red-500 text-xs mt-1`}>
{formik.errors.scheduleName}
</MyText>
)}
</View>
{/* Time */}
<View style={tw`mb-4`}>
<MyText style={tw`text-sm font-medium text-gray-700 mb-2`}>
Time
</MyText>
<DateTimePickerMod
value={formik.values.timeDate}
setValue={(date) => formik.setFieldValue('timeDate', date)}
timeOnly={true}
showLabels={false}
/>
{formik.touched.timeDate && formik.errors.timeDate && (
<MyText style={tw`text-red-500 text-xs mt-1`}>
{formik.errors.timeDate}
</MyText>
)}
</View>
{/* Action */}
<View style={tw`mb-4`}>
<MyText style={tw`text-sm font-medium text-gray-700 mb-2`}>
Action
</MyText>
<View style={tw`flex-row gap-3`}>
{actionOptions.map((option) => (
<TouchableOpacity
key={option.value}
onPress={() => formik.setFieldValue('action', option.value)}
style={tw`flex-1 flex-row items-center p-4 rounded-lg border ${
formik.values.action === option.value
? 'bg-blue-50 border-blue-500'
: 'bg-white border-gray-300'
}`}
>
<View
style={tw`w-5 h-5 rounded-full border-2 mr-3 items-center justify-center ${
formik.values.action === option.value
? 'border-blue-500'
: 'border-gray-300'
}`}
>
{formik.values.action === option.value && (
<View style={tw`w-3 h-3 rounded-full bg-blue-500`} />
)}
</View>
<MyText
style={tw`font-medium ${
formik.values.action === option.value
? 'text-blue-700'
: 'text-gray-700'
}`}
>
{option.label}
</MyText>
</TouchableOpacity>
))}
</View>
</View>
{/* Products and Groups */}
<View style={tw`mb-4`}>
<MyText style={tw`text-sm font-medium text-gray-700 mb-2`}>
Products & Groups
</MyText>
<ProductsSelector
value={formik.values.productIds}
onChange={(value) => formik.setFieldValue('productIds', value)}
groups={groups}
selectedGroupIds={formik.values.groupIds}
onGroupChange={(groupIds) => formik.setFieldValue('groupIds', groupIds)}
showGroups={true}
label="Select Products"
placeholder="Select products for this schedule"
/>
{formik.touched.productIds && formik.errors.productIds && (
<MyText style={tw`text-red-500 text-xs mt-1`}>
{formik.errors.productIds}
</MyText>
)}
</View>
{/* Spacer for bottom padding */}
<View style={tw`h-24`} />
</ScrollView>
{/* Footer Buttons */}
<View style={tw`p-4 border-t border-gray-200 bg-white flex-row gap-3`}>
<MyTouchableOpacity
onPress={onClose}
style={tw`flex-1 py-3 px-4 rounded-lg border border-gray-300 items-center`}
>
<MyText style={tw`font-medium text-gray-700`}>Cancel</MyText>
</MyTouchableOpacity>
<MyTouchableOpacity
onPress={() => formik.handleSubmit()}
disabled={formik.isSubmitting}
style={tw`flex-1 py-3 px-4 rounded-lg bg-blue-600 items-center ${
formik.isSubmitting ? 'opacity-50' : ''
}`}
>
<MyText style={tw`font-medium text-white`}>
{formik.isSubmitting ? 'Creating...' : 'Create Schedule'}
</MyText>
</MyTouchableOpacity>
</View>
</View>
);
};
export default AvailabilityScheduleForm;

View file

@ -5,8 +5,8 @@
}, },
"build": { "build": {
"development": { "development": {
"distribution": "internal", "developmentClient": true,
"autoIncrement": true "distribution": "internal"
}, },
"preview": { "preview": {
"distribution": "internal", "distribution": "internal",

View file

@ -1,6 +1,6 @@
ENV_MODE=PROD ENV_MODE=PROD
DATABASE_URL=postgresql://postgres:meatfarmer_master_password@57.128.212.174:7447/meatfarmer #technocracy # DATABASE_URL=postgresql://postgres:meatfarmer_master_password@57.128.212.174:7447/meatfarmer #technocracy
# DATABASE_URL=postgres://postgres:meatfarmer_master_password@5.223.55.14:7447/meatfarmer #hetzner DATABASE_URL=postgres://postgres:meatfarmer_master_password@5.223.55.14:7447/meatfarmer #hetzner
PHONE_PE_BASE_URL=https://api-preprod.phonepe.com/ PHONE_PE_BASE_URL=https://api-preprod.phonepe.com/
PHONE_PE_CLIENT_ID=TEST-M23F2IGP34ZAR_25090 PHONE_PE_CLIENT_ID=TEST-M23F2IGP34ZAR_25090
PHONE_PE_CLIENT_VERSION=1 PHONE_PE_CLIENT_VERSION=1
@ -21,10 +21,6 @@ S3_BUCKET_NAME=meatfarmer
EXPO_ACCESS_TOKEN=Asvpy8cByRh6T4ksnWScO6PLcio2n35-BwES5zK- EXPO_ACCESS_TOKEN=Asvpy8cByRh6T4ksnWScO6PLcio2n35-BwES5zK-
JWT_SECRET=my_meatfarmer_jwt_secret_key JWT_SECRET=my_meatfarmer_jwt_secret_key
ASSETS_DOMAIN=https://assets.freshyo.in/ ASSETS_DOMAIN=https://assets.freshyo.in/
API_CACHE_KEY=api-cache-dev
# CLOUDFLARE_API_TOKEN=I8Vp4E9TX58E8qEDeH0nTFDS2d2zXNYiXvbs4Ckj
CLOUDFLARE_API_TOKEN=N7jAg5X-RUj_fVfMW6zbfJ8qIYc81TSIKKlbZ6oh
CLOUDFLARE_ZONE_ID=edefbf750bfc3ff26ccd11e8e28dc8d7
# REDIS_URL=redis://default:redis_shafi_password@5.223.55.14:6379 # REDIS_URL=redis://default:redis_shafi_password@5.223.55.14:6379
REDIS_URL=redis://default:redis_shafi_password@57.128.212.174:6379 REDIS_URL=redis://default:redis_shafi_password@57.128.212.174:6379
APP_URL=http://localhost:4000 APP_URL=http://localhost:4000

File diff suppressed because one or more lines are too long

View file

@ -1,14 +0,0 @@
CREATE TYPE "public"."product_availability_action" AS ENUM('in', 'out');--> statement-breakpoint
CREATE TABLE "mf"."product_availability_schedules" (
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "mf"."product_availability_schedules_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"time" varchar(10) NOT NULL,
"schedule_name" varchar(255) NOT NULL,
"action" "product_availability_action" NOT NULL,
"product_ids" integer[] DEFAULT '{}' NOT NULL,
"group_ids" integer[] DEFAULT '{}' NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"last_updated" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "product_availability_schedules_schedule_name_unique" UNIQUE("schedule_name")
);
--> statement-breakpoint
ALTER TABLE "mf"."product_info" ADD COLUMN "scheduled_availability" boolean DEFAULT true NOT NULL;

File diff suppressed because it is too large Load diff

View file

@ -540,13 +540,6 @@
"when": 1772637259874, "when": 1772637259874,
"tag": "0076_sturdy_wolverine", "tag": "0076_sturdy_wolverine",
"breakpoints": true "breakpoints": true
},
{
"idx": 77,
"version": "7",
"when": 1773927855512,
"tag": "0077_wakeful_norrin_radd",
"breakpoints": true
} }
] ]
} }

View file

@ -180,6 +180,6 @@ app.use((err: any, req: express.Request, res: express.Response, next: express.Ne
res.status(status).json({ message }); res.status(status).json({ message });
}); });
app.listen(4000, () => { app.listen(4000, '::', () => {
console.log("Server is running on http://localhost:4000/api/mobile/"); console.log("Server is running on http://localhost:4000/api/mobile/");
}); });

View file

@ -5,8 +5,7 @@ import { eq } from "drizzle-orm";
import { ApiError } from "@/src/lib/api-error"; import { ApiError } from "@/src/lib/api-error";
import { imageUploadS3, generateSignedUrlFromS3Url } from "@/src/lib/s3-client"; import { imageUploadS3, generateSignedUrlFromS3Url } from "@/src/lib/s3-client";
import { deleteS3Image } from "@/src/lib/delete-image"; import { deleteS3Image } from "@/src/lib/delete-image";
import { scheduleStoreInitialization } from '@/src/stores/store-initializer'; import { initializeAllStores } from '@/src/stores/store-initializer';
/** /**
* Create a new product tag * Create a new product tag
@ -59,10 +58,9 @@ export const createTag = async (req: Request, res: Response) => {
.returning(); .returning();
// Reinitialize stores to reflect changes in cache // Reinitialize stores to reflect changes in cache
scheduleStoreInitialization() await initializeAllStores();
// Send response first return res.status(201).json({
res.status(201).json({
tag: newTag, tag: newTag,
message: "Tag created successfully", message: "Tag created successfully",
}); });
@ -95,7 +93,7 @@ export const getAllTags = async (req: Request, res: Response) => {
* Get a single product tag by ID * Get a single product tag by ID
*/ */
export const getTagById = async (req: Request, res: Response) => { export const getTagById = async (req: Request, res: Response) => {
const id = req.params.id as string const { id } = req.params;
const tag = await db.query.productTagInfo.findFirst({ const tag = await db.query.productTagInfo.findFirst({
where: eq(productTagInfo.id, parseInt(id)), where: eq(productTagInfo.id, parseInt(id)),
@ -121,7 +119,7 @@ export const getTagById = async (req: Request, res: Response) => {
* Update a product tag * Update a product tag
*/ */
export const updateTag = async (req: Request, res: Response) => { export const updateTag = async (req: Request, res: Response) => {
const id = req.params.id as string const { id } = req.params;
const { tagName, tagDescription, isDashboardTag, relatedStores } = req.body; const { tagName, tagDescription, isDashboardTag, relatedStores } = req.body;
// Get the current tag to check for existing image // Get the current tag to check for existing image
@ -179,10 +177,9 @@ export const updateTag = async (req: Request, res: Response) => {
.returning(); .returning();
// Reinitialize stores to reflect changes in cache // Reinitialize stores to reflect changes in cache
scheduleStoreInitialization() await initializeAllStores();
// Send response first return res.status(200).json({
res.status(200).json({
tag: updatedTag, tag: updatedTag,
message: "Tag updated successfully", message: "Tag updated successfully",
}); });
@ -192,7 +189,7 @@ export const updateTag = async (req: Request, res: Response) => {
* Delete a product tag * Delete a product tag
*/ */
export const deleteTag = async (req: Request, res: Response) => { export const deleteTag = async (req: Request, res: Response) => {
const id = req.params.id as string const { id } = req.params;
// Check if tag exists // Check if tag exists
const tag = await db.query.productTagInfo.findFirst({ const tag = await db.query.productTagInfo.findFirst({
@ -217,10 +214,9 @@ export const deleteTag = async (req: Request, res: Response) => {
await db.delete(productTagInfo).where(eq(productTagInfo.id, parseInt(id))); await db.delete(productTagInfo).where(eq(productTagInfo.id, parseInt(id)));
// Reinitialize stores to reflect changes in cache // Reinitialize stores to reflect changes in cache
scheduleStoreInitialization() await initializeAllStores();
// Send response first return res.status(200).json({
res.status(200).json({
message: "Tag deleted successfully", message: "Tag deleted successfully",
}); });
}; };

View file

@ -6,8 +6,7 @@ import { ApiError } from "@/src/lib/api-error";
import { imageUploadS3, getOriginalUrlFromSignedUrl } from "@/src/lib/s3-client"; import { imageUploadS3, getOriginalUrlFromSignedUrl } from "@/src/lib/s3-client";
import { deleteS3Image } from "@/src/lib/delete-image"; import { deleteS3Image } from "@/src/lib/delete-image";
import type { SpecialDeal } from "@/src/db/types"; import type { SpecialDeal } from "@/src/db/types";
import { scheduleStoreInitialization } from '@/src/stores/store-initializer'; import { initializeAllStores } from '@/src/stores/store-initializer';
type CreateDeal = { type CreateDeal = {
quantity: number; quantity: number;
@ -109,10 +108,9 @@ export const createProduct = async (req: Request, res: Response) => {
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
// Send response first return res.status(201).json({
res.status(201).json({
product: newProduct, product: newProduct,
deals: createdDeals, deals: createdDeals,
message: "Product created successfully", message: "Product created successfully",
@ -123,7 +121,7 @@ export const createProduct = async (req: Request, res: Response) => {
* Update a product * Update a product
*/ */
export const updateProduct = async (req: Request, res: Response) => { export const updateProduct = async (req: Request, res: Response) => {
const id = req.params.id as string const { id } = req.params;
const { name, shortDescription, longDescription, unitId, storeId, price, marketPrice, incrementStep, productQuantity, isSuspended, isFlashAvailable, flashPrice, deals:dealsRaw, imagesToDelete:imagesToDeleteRaw, tagIds } = req.body; const { name, shortDescription, longDescription, unitId, storeId, price, marketPrice, incrementStep, productQuantity, isSuspended, isFlashAvailable, flashPrice, deals:dealsRaw, imagesToDelete:imagesToDeleteRaw, tagIds } = req.body;
@ -296,11 +294,10 @@ export const updateProduct = async (req: Request, res: Response) => {
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
// Send response first return res.status(200).json({
res.status(200).json({
product: updatedProduct, product: updatedProduct,
message: "Product updated successfully", message: "Product updated successfully",
}); });
}; };

View file

@ -93,8 +93,6 @@ export const units = mf.table('units', {
unq_short_notation: unique('unique_short_notation').on(t.shortNotation), unq_short_notation: unique('unique_short_notation').on(t.shortNotation),
})); }));
export const productAvailabilityActionEnum = pgEnum('product_availability_action', ['in', 'out']);
export const productInfo = mf.table('product_info', { export const productInfo = mf.table('product_info', {
id: integer().primaryKey().generatedAlwaysAsIdentity(), id: integer().primaryKey().generatedAlwaysAsIdentity(),
name: varchar({ length: 255 }).notNull(), name: varchar({ length: 255 }).notNull(),
@ -108,22 +106,10 @@ export const productInfo = mf.table('product_info', {
isSuspended: boolean('is_suspended').notNull().default(false), isSuspended: boolean('is_suspended').notNull().default(false),
isFlashAvailable: boolean('is_flash_available').notNull().default(false), isFlashAvailable: boolean('is_flash_available').notNull().default(false),
flashPrice: numeric('flash_price', { precision: 10, scale: 2 }), flashPrice: numeric('flash_price', { precision: 10, scale: 2 }),
createdAt: timestamp('created_at').notNull().defaultNow(), createdAt: timestamp('created_at').notNull().defaultNow(),
incrementStep: real('increment_step').notNull().default(1), incrementStep: real('increment_step').notNull().default(1),
productQuantity: real('product_quantity').notNull().default(1), productQuantity: real('product_quantity').notNull().default(1),
storeId: integer('store_id').references(() => storeInfo.id), storeId: integer('store_id').references(() => storeInfo.id),
scheduledAvailability: boolean('scheduled_availability').notNull().default(true),
});
export const productAvailabilitySchedules = mf.table('product_availability_schedules', {
id: integer().primaryKey().generatedAlwaysAsIdentity(),
time: varchar('time', { length: 10 }).notNull(),
scheduleName: varchar('schedule_name', { length: 255 }).notNull().unique(),
action: productAvailabilityActionEnum('action').notNull(),
productIds: integer('product_ids').array().notNull().default([]),
groupIds: integer('group_ids').array().notNull().default([]),
createdAt: timestamp('created_at').notNull().defaultNow(),
lastUpdated: timestamp('last_updated').notNull().defaultNow(),
}); });
export const productGroupInfo = mf.table('product_group_info', { export const productGroupInfo = mf.table('product_group_info', {
@ -701,6 +687,3 @@ export const userIncidentsRelations = relations(userIncidents, ({ one }) => ({
order: one(orders, { fields: [userIncidents.orderId], references: [orders.id] }), order: one(orders, { fields: [userIncidents.orderId], references: [orders.id] }),
addedBy: one(staffUsers, { fields: [userIncidents.addedBy], references: [staffUsers.id] }), addedBy: one(staffUsers, { fields: [userIncidents.addedBy], references: [staffUsers.id] }),
})); }));
export const productAvailabilitySchedulesRelations = relations(productAvailabilitySchedules, ({}) => ({
}));

View file

@ -1,109 +1,85 @@
import * as cron from 'node-cron'; import * as cron from 'node-cron';
import { db } from '@/src/db/db_index' import { db } from '@/src/db/db_index'
import { productInfo, productAvailabilitySchedules } from '@/src/db/schema' import { productInfo, keyValStore } from '@/src/db/schema'
import { inArray } from 'drizzle-orm'; import { inArray, eq } from 'drizzle-orm';
import { initializeAllStores } from '../stores/store-initializer'; import { CONST_KEYS } from '@/src/lib/const-keys'
import { computeConstants } from '@/src/lib/const-store'
// Module-level storage for cron jobs
const scheduleJobs: Map<string, cron.ScheduledTask> = new Map();
// Stop all existing schedule-based jobs const MUTTON_ITEMS = [
const stopAllScheduleJobs = () => { 12, //Lamb mutton
for (const [time, job] of scheduleJobs) { 14, // Mutton Boti
job.stop(); 35, //Mutton Kheema
console.log(`Stopped cron job for ${time}`); 84, //Mutton Brain
} 4, //Mutton
scheduleJobs.clear(); 86, //Mutton Chops
}; 87, //Mutton Soup bones
85 //Mutton paya
];
// Main function to refresh jobs (called on init and after schedule changes)
export const refreshScheduleJobs = async (): Promise<void> => {
// Stop existing jobs
stopAllScheduleJobs();
// Fetch all schedules from DB
const schedules = await db.query.productAvailabilitySchedules.findMany();
if (schedules.length === 0) {
console.log('No schedules found, no jobs created');
return;
}
// Group schedules by time
const schedulesByTime = new Map<string, typeof schedules>();
for (const schedule of schedules) {
if (!schedulesByTime.has(schedule.time)) {
schedulesByTime.set(schedule.time, []);
}
schedulesByTime.get(schedule.time)!.push(schedule);
}
// For each time slot, resolve conflicts and create job
for (const [time, timeSchedules] of schedulesByTime) {
// Sort by ID descending (highest ID = latest = wins in conflicts)
const sortedSchedules = timeSchedules.sort((a, b) => b.id - a.id);
// Build final product states (later schedules override earlier ones)
const productStates = new Map<number, 'in' | 'out'>();
for (const schedule of sortedSchedules) {
for (const productId of schedule.productIds) {
if (!productStates.has(productId)) {
productStates.set(productId, schedule.action);
}
}
}
// Separate into in-stock and out-of-stock lists
const toTurnOn: number[] = [];
const toTurnOff: number[] = [];
for (const [productId, action] of productStates) {
if (action === 'in') {
toTurnOn.push(productId);
} else {
toTurnOff.push(productId);
}
}
// Create cron schedule from time (HH:mm to cron format)
const [hours, minutes] = time.split(':');
const cronExpression = `${minutes} ${hours} * * *`;
// Create and store the job
const job = cron.schedule(cronExpression, async () => {
console.log(`Running scheduled availability job for ${time}`);
// Batch update in single queries
if (toTurnOn.length > 0) {
await db.update(productInfo)
.set({ isOutOfStock: false })
.where(inArray(productInfo.id, toTurnOn));
console.log(`[${time}] Turned ON ${toTurnOn.length} products`);
}
if (toTurnOff.length > 0) {
await db.update(productInfo)
.set({ isOutOfStock: true })
.where(inArray(productInfo.id, toTurnOff));
console.log(`[${time}] Turned OFF ${toTurnOff.length} products`);
}
initializeAllStores();
});
scheduleJobs.set(time, job);
console.log(`Created cron job for ${time} (${toTurnOn.length} ON, ${toTurnOff.length} OFF)`);
}
};
// Initialize all automated jobs
export const startAutomatedJobs = () => { export const startAutomatedJobs = () => {
// Only schedule-based jobs (flash delivery jobs removed) // Job to disable flash delivery for mutton at 12 PM daily
refreshScheduleJobs().catch(err => { cron.schedule('0 12 * * *', async () => {
console.error('Failed to initialize schedule jobs:', err); try {
console.log('Disabling flash delivery for products at 12 PM');
await db
.update(productInfo)
.set({ isFlashAvailable: false })
.where(inArray(productInfo.id, MUTTON_ITEMS));
console.log('Flash delivery disabled successfully');
} catch (error) {
console.error('Error disabling flash delivery:', error);
}
}); });
// Job to enable flash delivery for mutton at 6 AM daily
cron.schedule('0 6 * * *', async () => {
try {
console.log('Enabling flash delivery for products at 5 AM');
await db
.update(productInfo)
.set({ isFlashAvailable: true })
.where(inArray(productInfo.id, MUTTON_ITEMS));
console.log('Flash delivery enabled successfully');
} catch (error) {
console.error('Error enabling flash delivery:', error);
}
});
// Job to disable flash delivery feature at 9 PM daily
cron.schedule('0 21 * * *', async () => {
try {
console.log('Disabling flash delivery feature at 9 PM');
await db
.update(keyValStore)
.set({ value: false })
.where(eq(keyValStore.key, CONST_KEYS.isFlashDeliveryEnabled));
await computeConstants(); // Refresh Redis cache
console.log('Flash delivery feature disabled successfully');
} catch (error) {
console.error('Error disabling flash delivery feature:', error);
}
});
// Job to enable flash delivery feature at 6 AM daily
cron.schedule('0 6 * * *', async () => {
try {
console.log('Enabling flash delivery feature at 6 AM');
await db
.update(keyValStore)
.set({ value: true })
.where(eq(keyValStore.key, CONST_KEYS.isFlashDeliveryEnabled));
await computeConstants(); // Refresh Redis cache
console.log('Flash delivery feature enabled successfully');
} catch (error) {
console.error('Error enabling flash delivery feature:', error);
}
});
console.log('Automated jobs scheduled'); console.log('Automated jobs scheduled');
}; };
// Optional: Call on import if desired, or export and call in main app
// startAutomatedJobs();

View file

@ -1,376 +0,0 @@
import axios from 'axios'
import { scaffoldProducts } from '@/src/trpc/apis/common-apis/common'
import { scaffoldEssentialConsts } from '@/src/trpc/apis/common-apis/common-trpc-index'
import { scaffoldStores } from '@/src/trpc/apis/user-apis/apis/stores'
import { scaffoldSlotsWithProducts } from '@/src/trpc/apis/user-apis/apis/slots'
import { scaffoldBanners } from '@/src/trpc/apis/user-apis/apis/banners'
import { scaffoldStoreWithProducts } from '@/src/trpc/apis/user-apis/apis/stores'
import { storeInfo } from '@/src/db/schema'
import { db } from '@/src/db/db_index'
import { imageUploadS3 } from '@/src/lib/s3-client'
import { apiCacheKey, cloudflareApiToken, cloudflareZoneId, assetsDomain } from '@/src/lib/env-exporter'
import { CACHE_FILENAMES } from '@packages/shared'
import { retryWithExponentialBackoff } from '@/src/lib/retry'
function constructCacheUrl(path: string): string {
return `${assetsDomain}${apiCacheKey}/${path}`
}
export async function createProductsFile(): Promise<string> {
// Get products data from the API method
const productsData = await scaffoldProducts()
// Convert to JSON string with pretty formatting
const jsonContent = JSON.stringify(productsData, null, 2)
// Convert to Buffer for S3 upload
const buffer = Buffer.from(jsonContent, 'utf-8')
// Upload to S3 at the specified path using apiCacheKey
const s3Key = await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.products}`)
// Purge cache with retry
const url = constructCacheUrl(CACHE_FILENAMES.products)
try {
await retryWithExponentialBackoff(() => clearUrlCache([url]))
console.log(`Cache purged for ${url}`)
} catch (error) {
console.error(`Failed to purge cache for ${url} after 3 retries:`, error)
}
return s3Key
}
export async function createEssentialConstsFile(): Promise<string> {
// Get essential consts data from the API method
const essentialConstsData = await scaffoldEssentialConsts()
// Convert to JSON string with pretty formatting
const jsonContent = JSON.stringify(essentialConstsData, null, 2)
// Convert to Buffer for S3 upload
const buffer = Buffer.from(jsonContent, 'utf-8')
// Upload to S3 at the specified path using apiCacheKey
const s3Key = await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.essentialConsts}`)
// Purge cache with retry
const url = constructCacheUrl(CACHE_FILENAMES.essentialConsts)
try {
await retryWithExponentialBackoff(() => clearUrlCache([url]))
console.log(`Cache purged for ${url}`)
} catch (error) {
console.error(`Failed to purge cache for ${url} after 3 retries:`, error)
}
return s3Key
}
export async function createStoresFile(): Promise<string> {
// Get stores data from the API method
const storesData = await scaffoldStores()
// Convert to JSON string with pretty formatting
const jsonContent = JSON.stringify(storesData, null, 2)
// Convert to Buffer for S3 upload
const buffer = Buffer.from(jsonContent, 'utf-8')
// Upload to S3 at the specified path using apiCacheKey
const s3Key = await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.stores}`)
// Purge cache with retry
const url = constructCacheUrl(CACHE_FILENAMES.stores)
try {
await retryWithExponentialBackoff(() => clearUrlCache([url]))
console.log(`Cache purged for ${url}`)
} catch (error) {
console.error(`Failed to purge cache for ${url} after 3 retries:`, error)
}
return s3Key
}
export async function createSlotsFile(): Promise<string> {
// Get slots data from the API method
const slotsData = await scaffoldSlotsWithProducts()
// Convert to JSON string with pretty formatting
const jsonContent = JSON.stringify(slotsData, null, 2)
// Convert to Buffer for S3 upload
const buffer = Buffer.from(jsonContent, 'utf-8')
// Upload to S3 at the specified path using apiCacheKey
const s3Key = await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.slots}`)
// Purge cache with retry
const url = constructCacheUrl(CACHE_FILENAMES.slots)
try {
await retryWithExponentialBackoff(() => clearUrlCache([url]))
console.log(`Cache purged for ${url}`)
} catch (error) {
console.error(`Failed to purge cache for ${url} after 3 retries:`, error)
}
return s3Key
}
export async function createBannersFile(): Promise<string> {
// Get banners data from the API method
const bannersData = await scaffoldBanners()
// Convert to JSON string with pretty formatting
const jsonContent = JSON.stringify(bannersData, null, 2)
// Convert to Buffer for S3 upload
const buffer = Buffer.from(jsonContent, 'utf-8')
// Upload to S3 at the specified path using apiCacheKey
const s3Key = await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.banners}`)
// Purge cache with retry
const url = constructCacheUrl(CACHE_FILENAMES.banners)
try {
await retryWithExponentialBackoff(() => clearUrlCache([url]))
console.log(`Cache purged for ${url}`)
} catch (error) {
console.error(`Failed to purge cache for ${url} after 3 retries:`, error)
}
return s3Key
}
export async function createStoreFile(storeId: number): Promise<string> {
// Get store data from the API method
const storeData = await scaffoldStoreWithProducts(storeId)
// Convert to JSON string with pretty formatting
const jsonContent = JSON.stringify(storeData, null, 2)
// Convert to Buffer for S3 upload
const buffer = Buffer.from(jsonContent, 'utf-8')
// Upload to S3 at the specified path using apiCacheKey
const s3Key = await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/stores/${storeId}.json`)
// Purge cache with retry
const url = constructCacheUrl(`stores/${storeId}.json`)
try {
await retryWithExponentialBackoff(() => clearUrlCache([url]))
console.log(`Cache purged for ${url}`)
} catch (error) {
console.error(`Failed to purge cache for ${url} after 3 retries:`, error)
}
return s3Key
}
export async function createAllStoresFiles(): Promise<string[]> {
// Fetch all store IDs from database
const stores = await db.select({ id: storeInfo.id }).from(storeInfo)
// Create cache files for all stores and collect URLs
const results: string[] = []
const urls: string[] = []
for (const store of stores) {
const s3Key = await createStoreFile(store.id)
results.push(s3Key)
urls.push(constructCacheUrl(`stores/${store.id}.json`))
}
console.log(`Created ${results.length} store cache files`)
// Purge all store caches in one batch with retry
try {
await retryWithExponentialBackoff(() => clearUrlCache(urls))
console.log(`Cache purged for ${urls.length} store files`)
} catch (error) {
console.error(`Failed to purge cache for store files after 3 retries. URLs: ${urls.join(', ')}`, error)
}
return results
}
export interface CreateAllCacheFilesResult {
products: string
essentialConsts: string
stores: string
slots: string
banners: string
individualStores: string[]
}
export async function createAllCacheFiles(): Promise<CreateAllCacheFilesResult> {
console.log('Starting creation of all cache files...')
// Create all global cache files in parallel
const [
productsKey,
essentialConstsKey,
storesKey,
slotsKey,
bannersKey,
individualStoreKeys,
] = await Promise.all([
createProductsFileInternal(),
createEssentialConstsFileInternal(),
createStoresFileInternal(),
createSlotsFileInternal(),
createBannersFileInternal(),
createAllStoresFilesInternal(),
])
// Collect all URLs for batch cache purge
const urls = [
constructCacheUrl(CACHE_FILENAMES.products),
constructCacheUrl(CACHE_FILENAMES.essentialConsts),
constructCacheUrl(CACHE_FILENAMES.stores),
constructCacheUrl(CACHE_FILENAMES.slots),
constructCacheUrl(CACHE_FILENAMES.banners),
...individualStoreKeys.map((_, index) => constructCacheUrl(`stores/${index + 1}.json`)),
]
// Purge all caches in one batch with retry
try {
await retryWithExponentialBackoff(() => clearUrlCache(urls))
console.log(`Cache purged for all ${urls.length} files`)
} catch (error) {
console.error(`Failed to purge cache for all files after 3 retries`, error)
}
console.log('All cache files created successfully')
return {
products: productsKey,
essentialConsts: essentialConstsKey,
stores: storesKey,
slots: slotsKey,
banners: bannersKey,
individualStores: individualStoreKeys,
}
}
// Internal versions that skip cache purging (for batch operations)
async function createProductsFileInternal(): Promise<string> {
const productsData = await scaffoldProducts()
const jsonContent = JSON.stringify(productsData, null, 2)
const buffer = Buffer.from(jsonContent, 'utf-8')
return await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.products}`)
}
async function createEssentialConstsFileInternal(): Promise<string> {
const essentialConstsData = await scaffoldEssentialConsts()
const jsonContent = JSON.stringify(essentialConstsData, null, 2)
const buffer = Buffer.from(jsonContent, 'utf-8')
return await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.essentialConsts}`)
}
async function createStoresFileInternal(): Promise<string> {
const storesData = await scaffoldStores()
const jsonContent = JSON.stringify(storesData, null, 2)
const buffer = Buffer.from(jsonContent, 'utf-8')
return await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.stores}`)
}
async function createSlotsFileInternal(): Promise<string> {
const slotsData = await scaffoldSlotsWithProducts()
const jsonContent = JSON.stringify(slotsData, null, 2)
const buffer = Buffer.from(jsonContent, 'utf-8')
return await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.slots}`)
}
async function createBannersFileInternal(): Promise<string> {
const bannersData = await scaffoldBanners()
const jsonContent = JSON.stringify(bannersData, null, 2)
const buffer = Buffer.from(jsonContent, 'utf-8')
return await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/${CACHE_FILENAMES.banners}`)
}
async function createAllStoresFilesInternal(): Promise<string[]> {
const stores = await db.select({ id: storeInfo.id }).from(storeInfo)
const results: string[] = []
for (const store of stores) {
const storeData = await scaffoldStoreWithProducts(store.id)
const jsonContent = JSON.stringify(storeData, null, 2)
const buffer = Buffer.from(jsonContent, 'utf-8')
const s3Key = await imageUploadS3(buffer, 'application/json', `${apiCacheKey}/stores/${store.id}.json`)
results.push(s3Key)
}
console.log(`Created ${results.length} store cache files`)
return results
}
export async function clearUrlCache(urls: string[]): Promise<{ success: boolean; errors?: string[] }> {
if (!cloudflareApiToken || !cloudflareZoneId) {
console.warn('Cloudflare credentials not configured, skipping cache clear')
return { success: false, errors: ['Cloudflare credentials not configured'] }
}
try {
const response = await axios.post(
`https://api.cloudflare.com/client/v4/zones/${cloudflareZoneId}/purge_cache`,
{ files: urls },
{
headers: {
'Authorization': `Bearer ${cloudflareApiToken}`,
'Content-Type': 'application/json',
},
}
)
const result = response.data as { success: boolean; errors?: { message: string }[] }
if (!result.success) {
const errorMessages = result.errors?.map(e => e.message) || ['Unknown error']
console.error(`Cloudflare cache purge failed for URLs: ${urls.join(', ')}`, errorMessages)
return { success: false, errors: errorMessages }
}
console.log(`Successfully purged ${urls.length} URLs from Cloudflare cache: ${urls.join(', ')}`)
return { success: true }
} catch (error) {
console.log(error)
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
console.error(`Error clearing Cloudflare cache for URLs: ${urls.join(', ')}`, errorMessage)
return { success: false, errors: [errorMessage] }
}
}
export async function clearAllCache(): Promise<{ success: boolean; errors?: string[] }> {
if (!cloudflareApiToken || !cloudflareZoneId) {
console.warn('Cloudflare credentials not configured, skipping cache clear')
return { success: false, errors: ['Cloudflare credentials not configured'] }
}
try {
const response = await axios.post(
`https://api.cloudflare.com/client/v4/zones/${cloudflareZoneId}/purge_cache`,
{ purge_everything: true },
{
headers: {
'Authorization': `Bearer ${cloudflareApiToken}`,
'Content-Type': 'application/json',
},
}
)
const result = response.data as { success: boolean; errors?: { message: string }[] }
if (!result.success) {
const errorMessages = result.errors?.map(e => e.message) || ['Unknown error']
console.error('Cloudflare cache purge failed:', errorMessages)
return { success: false, errors: errorMessages }
}
console.log('Successfully purged all cache from Cloudflare')
return { success: true }
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
console.error('Error clearing Cloudflare cache:', errorMessage)
return { success: false, errors: [errorMessage] }
}
}

View file

@ -17,12 +17,6 @@ export const s3Region = process.env.S3_REGION as string
export const assetsDomain = process.env.ASSETS_DOMAIN as string; export const assetsDomain = process.env.ASSETS_DOMAIN as string;
export const apiCacheKey = process.env.API_CACHE_KEY as string;
export const cloudflareApiToken = process.env.CLOUDFLARE_API_TOKEN as string;
export const cloudflareZoneId = process.env.CLOUDFLARE_ZONE_ID as string;
export const s3Url = process.env.S3_URL as string export const s3Url = process.env.S3_URL as string
export const redisUrl = process.env.REDIS_URL as string export const redisUrl = process.env.REDIS_URL as string

View file

@ -3,8 +3,6 @@ import { initializeAllStores } from '@/src/stores/store-initializer'
import { initializeUserNegativityStore } from '@/src/stores/user-negativity-store' import { initializeUserNegativityStore } from '@/src/stores/user-negativity-store'
import { startOrderHandler, startCancellationHandler, publishOrder } from '@/src/lib/post-order-handler' import { startOrderHandler, startCancellationHandler, publishOrder } from '@/src/lib/post-order-handler'
import { deleteOrders } from '@/src/lib/delete-orders' import { deleteOrders } from '@/src/lib/delete-orders'
import { createAllCacheFiles } from '@/src/lib/cloud_cache'
import { verifyProductsAvailabilityBySchedule } from './manage-scheduled-availability'
/** /**
* Initialize all application services * Initialize all application services
@ -19,8 +17,7 @@ import { verifyProductsAvailabilityBySchedule } from './manage-scheduled-availab
export const initFunc = async (): Promise<void> => { export const initFunc = async (): Promise<void> => {
try { try {
console.log('Starting application initialization...'); console.log('Starting application initialization...');
await verifyProductsAvailabilityBySchedule(false);
await Promise.all([ await Promise.all([
initializeAllStores(), initializeAllStores(),
initializeUserNegativityStore(), initializeUserNegativityStore(),
@ -28,10 +25,6 @@ export const initFunc = async (): Promise<void> => {
startCancellationHandler(), startCancellationHandler(),
]); ]);
// Create all cache files after stores are initialized
await createAllCacheFiles();
console.log('Cache files created successfully');
console.log('Application initialization completed successfully'); console.log('Application initialization completed successfully');
} catch (error) { } catch (error) {
console.error('Application initialization failed:', error); console.error('Application initialization failed:', error);

View file

@ -1,129 +0,0 @@
import { db } from '@/src/db/db_index'
import { productInfo, productAvailabilitySchedules } from '@/src/db/schema'
import { eq, inArray } from 'drizzle-orm';
import { initializeAllStores } from '@/src/stores/store-initializer';
import dayjs from 'dayjs';
/**
* Get all products that should be in stock or out of stock based on current schedules
* Only processes products that are actually involved in availability schedules
* Automatically updates products that need to change their availability status
* @returns Promise<{ inStock: number[], outOfStock: number[], changed: number[] }>
*/
export async function verifyProductsAvailabilityBySchedule(reInitialize:boolean = false): Promise<{
inStock: number[];
outOfStock: number[];
changed: number[];
}> {
// Get all schedules
const allSchedules = await db.query.productAvailabilitySchedules.findMany();
// Extract all unique product IDs from all schedules
const allScheduledProductIds = new Set<number>();
for (const schedule of allSchedules) {
for (const productId of schedule.productIds) {
allScheduledProductIds.add(productId);
}
}
// If no products are in any schedule, return empty arrays
if (allScheduledProductIds.size === 0) {
return { inStock: [], outOfStock: [], changed: [] };
}
// Get current time
const currentTime = dayjs().format('HH:mm');
const computedInStock: number[] = [];
const computedOutOfStock: number[] = [];
// Process each product that is involved in schedules
for (const productId of allScheduledProductIds) {
// Find applicable schedules for this product
const applicableSchedules = allSchedules.filter(schedule => {
return schedule.productIds.includes(productId);
});
// Filter active schedules (time <= current time)
const activeSchedules = applicableSchedules.filter(schedule =>
schedule.time <= currentTime
);
if (activeSchedules.length === 0) {
// No active schedule applies - skip this product
// (we only care about products with active schedule rules)
continue;
}
// Get most recent schedule
const mostRecentSchedule = activeSchedules.sort((a, b) => {
if (a.time !== b.time) {
return b.time.localeCompare(a.time);
}
return b.id - a.id;
})[0];
// Categorize based on schedule action
if (mostRecentSchedule.action === 'in') {
computedInStock.push(productId);
} else {
computedOutOfStock.push(productId);
}
}
// Query products to check current availability status
const allProductIds = [...computedInStock, ...computedOutOfStock];
if (allProductIds.length === 0) {
return { inStock: [], outOfStock: [], changed: [] };
}
const products = await db.query.productInfo.findMany({
where: inArray(productInfo.id, allProductIds),
});
// Find products that need to change
const toMarkInStock: number[] = [];
const toMarkOutOfStock: number[] = [];
const changed: number[] = [];
for (const product of products) {
const shouldBeInStock = computedInStock.includes(product.id);
const currentlyOutOfStock = product.isOutOfStock;
if (shouldBeInStock && currentlyOutOfStock) {
// Should be in stock but currently out of stock - needs change
toMarkInStock.push(product.id);
changed.push(product.id);
} else if (!shouldBeInStock && !currentlyOutOfStock) {
// Should be out of stock but currently in stock - needs change
toMarkOutOfStock.push(product.id);
changed.push(product.id);
}
}
// Batch update products in a single query
if (toMarkInStock.length > 0) {
await db.update(productInfo)
.set({ isOutOfStock: false })
.where(inArray(productInfo.id, toMarkInStock));
}
if (toMarkOutOfStock.length > 0) {
await db.update(productInfo)
.set({ isOutOfStock: true })
.where(inArray(productInfo.id, toMarkOutOfStock));
}
// Reinitialize stores if any products changed
if (changed.length > 0 && reInitialize) {
console.log(`Reinitializing stores after availability changes for ${changed.length} products`);
await initializeAllStores();
}
return {
inStock: computedInStock,
outOfStock: computedOutOfStock,
changed
};
}

View file

@ -35,7 +35,10 @@ const formatOrderMessageWithFullData = (ordersData: any[]): string => {
message += '📦 <b>Items:</b>\n'; message += '📦 <b>Items:</b>\n';
order.orderItems?.forEach((item: any) => { order.orderItems?.forEach((item: any) => {
message += `${item.product?.name || 'Unknown'} x${item.quantity}\n`; const productQuantity = item.product?.productQuantity ?? 1
const unitNotation = item.product?.unit?.shortNotation || ''
const quantityWithUnit = unitNotation ? `${productQuantity}${unitNotation}` : `${productQuantity}`
message += `${item.product?.name || 'Unknown'} ${quantityWithUnit} x${item.quantity}\n`;
}); });
message += `\n💰 <b>Total:</b> ₹${order.totalAmount}\n`; message += `\n💰 <b>Total:</b> ₹${order.totalAmount}\n`;
@ -72,7 +75,12 @@ const formatCancellationMessage = (orderData: any, cancellationData: Cancellatio
📞 <b>Phone:</b> ${orderData.address?.phone || 'N/A'} 📞 <b>Phone:</b> ${orderData.address?.phone || 'N/A'}
📦 <b>Items:</b> 📦 <b>Items:</b>
${orderData.orderItems?.map((item: any) => `${item.product?.name || 'Unknown'} x${item.quantity}`).join('\n') || ' N/A'} ${orderData.orderItems?.map((item: any) => {
const productQuantity = item.product?.productQuantity ?? 1
const unitNotation = item.product?.unit?.shortNotation || ''
const quantityWithUnit = unitNotation ? `${productQuantity}${unitNotation}` : `${productQuantity}`
return `${item.product?.name || 'Unknown'} ${quantityWithUnit} x${item.quantity}`
}).join('\n') || ' N/A'}
💰 <b>Total:</b> ${orderData.totalAmount} 💰 <b>Total:</b> ${orderData.totalAmount}
💳 <b>Refund:</b> ${orderData.refundStatus === 'na' ? 'N/A (COD)' : orderData.refundStatus || 'Pending'} 💳 <b>Refund:</b> ${orderData.refundStatus === 'na' ? 'N/A (COD)' : orderData.refundStatus || 'Pending'}
@ -102,7 +110,7 @@ export const startOrderHandler = async (): Promise<void> => {
where: inArray(orders.id, orderIds), where: inArray(orders.id, orderIds),
with: { with: {
address: true, address: true,
orderItems: { with: { product: true } }, orderItems: { with: { product: { with: { unit: true } } } },
slot: true, slot: true,
}, },
}); });
@ -147,7 +155,7 @@ export const startCancellationHandler = async (): Promise<void> => {
where: eq(orders.id, cancellationData.orderId), where: eq(orders.id, cancellationData.orderId),
with: { with: {
address: true, address: true,
orderItems: { with: { product: true } }, orderItems: { with: { product: { with: { unit: true } } } },
refunds: true, refunds: true,
}, },
}); });

View file

@ -1,23 +0,0 @@
export async function retryWithExponentialBackoff<T>(
fn: () => Promise<T>,
maxRetries: number = 3,
delayMs: number = 1000
): Promise<T> {
let lastError: Error | undefined
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await fn()
} catch (error) {
lastError = error instanceof Error ? error : new Error(String(error))
if (attempt < maxRetries) {
console.log(`Attempt ${attempt} failed, retrying in ${delayMs}ms...`)
await new Promise(resolve => setTimeout(resolve, delayMs))
delayMs *= 2
}
}
}
throw lastError
}

View file

@ -4,11 +4,6 @@ import { initializeProducts } from '@/src/stores/product-store'
import { initializeProductTagStore } from '@/src/stores/product-tag-store' import { initializeProductTagStore } from '@/src/stores/product-tag-store'
import { initializeSlotStore } from '@/src/stores/slot-store' import { initializeSlotStore } from '@/src/stores/slot-store'
import { initializeBannerStore } from '@/src/stores/banner-store' import { initializeBannerStore } from '@/src/stores/banner-store'
import { createAllCacheFiles } from '@/src/lib/cloud_cache'
// const STORE_INIT_DELAY_MS = 3 * 60 * 1000
const STORE_INIT_DELAY_MS = 0.5 * 60 * 1000
let storeInitializationTimeout: NodeJS.Timeout | null = null
/** /**
* Initialize all application stores * Initialize all application stores
@ -34,27 +29,8 @@ export const initializeAllStores = async (): Promise<void> => {
]); ]);
console.log('All application stores initialized successfully'); console.log('All application stores initialized successfully');
// Regenerate all cache files (fire-and-forget)
createAllCacheFiles().catch(error => {
console.error('Failed to regenerate cache files during store initialization:', error)
})
} catch (error) { } catch (error) {
console.error('Application stores initialization failed:', error); console.error('Application stores initialization failed:', error);
throw error; throw error;
} }
}; };
export const scheduleStoreInitialization = (): void => {
if (storeInitializationTimeout) {
clearTimeout(storeInitializationTimeout)
storeInitializationTimeout = null
}
storeInitializationTimeout = setTimeout(() => {
storeInitializationTimeout = null
initializeAllStores().catch(error => {
console.error('Scheduled store initialization failed:', error)
})
}, STORE_INIT_DELAY_MS)
}

View file

@ -14,7 +14,6 @@ import addressRouter from '@/src/trpc/apis/admin-apis/apis/address'
import { bannerRouter } from '@/src/trpc/apis/admin-apis/apis/banner' import { bannerRouter } from '@/src/trpc/apis/admin-apis/apis/banner'
import { userRouter } from '@/src/trpc/apis/admin-apis/apis/user' import { userRouter } from '@/src/trpc/apis/admin-apis/apis/user'
import { constRouter } from '@/src/trpc/apis/admin-apis/apis/const' import { constRouter } from '@/src/trpc/apis/admin-apis/apis/const'
import { productAvailabilitySchedulesRouter } from '@/src/trpc/apis/admin-apis/apis/product-availability-schedules'
export const adminRouter = router({ export const adminRouter = router({
complaint: complaintRouter, complaint: complaintRouter,
@ -31,7 +30,6 @@ export const adminRouter = router({
banner: bannerRouter, banner: bannerRouter,
user: userRouter, user: userRouter,
const: constRouter, const: constRouter,
productAvailabilitySchedules: productAvailabilitySchedulesRouter,
}); });
export type AdminRouter = typeof adminRouter; export type AdminRouter = typeof adminRouter;

View file

@ -5,8 +5,7 @@ import { eq, and, desc, sql } from 'drizzle-orm';
import { protectedProcedure, router } from '@/src/trpc/trpc-index' import { protectedProcedure, router } from '@/src/trpc/trpc-index'
import { extractKeyFromPresignedUrl, generateSignedUrlFromS3Url } from '@/src/lib/s3-client' import { extractKeyFromPresignedUrl, generateSignedUrlFromS3Url } from '@/src/lib/s3-client'
import { ApiError } from '@/src/lib/api-error'; import { ApiError } from '@/src/lib/api-error';
import { scheduleStoreInitialization } from '@/src/stores/store-initializer' import { initializeAllStores } from '@/src/stores/store-initializer'
export const bannerRouter = router({ export const bannerRouter = router({
// Get all banners // Get all banners
@ -105,7 +104,7 @@ export const bannerRouter = router({
}).returning(); }).returning();
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return banner; return banner;
} catch (error) { } catch (error) {
@ -152,7 +151,7 @@ export const bannerRouter = router({
.returning(); .returning();
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return banner; return banner;
} catch (error) { } catch (error) {
@ -168,7 +167,7 @@ export const bannerRouter = router({
await db.delete(homeBanners).where(eq(homeBanners.id, input.id)); await db.delete(homeBanners).where(eq(homeBanners.id, input.id));
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { success: true }; return { success: true };
}), }),

View file

@ -1,154 +0,0 @@
import { router, protectedProcedure } from '@/src/trpc/trpc-index'
import { z } from 'zod';
import { db } from '@/src/db/db_index'
import { productAvailabilitySchedules } from '@/src/db/schema'
import { eq } from 'drizzle-orm';
import { refreshScheduleJobs } from '@/src/lib/automatedJobs';
const createScheduleSchema = z.object({
scheduleName: z.string().min(1, "Schedule name is required"),
time: z.string().min(1, "Time is required").regex(/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/, "Invalid time format. Use HH:MM"),
action: z.enum(['in', 'out']),
productIds: z.array(z.number().int().positive()).min(1, "At least one product is required"),
groupIds: z.array(z.number().int().positive()).default([]),
});
const updateScheduleSchema = z.object({
id: z.number().int().positive(),
updates: createScheduleSchema.partial().extend({
scheduleName: z.string().min(1).optional(),
productIds: z.array(z.number().int().positive()).optional(),
groupIds: z.array(z.number().int().positive()).optional(),
}),
});
export const productAvailabilitySchedulesRouter = router({
create: protectedProcedure
.input(createScheduleSchema)
.mutation(async ({ input, ctx }) => {
const { scheduleName, time, action, productIds, groupIds } = input;
// Get staff user ID from auth middleware
const staffUserId = ctx.staffUser?.id;
if (!staffUserId) {
throw new Error("Unauthorized");
}
// Check if schedule name already exists
const existingSchedule = await db.query.productAvailabilitySchedules.findFirst({
where: eq(productAvailabilitySchedules.scheduleName, scheduleName),
});
if (existingSchedule) {
throw new Error("Schedule name already exists");
}
// Create schedule with arrays
const scheduleResult = await db.insert(productAvailabilitySchedules).values({
scheduleName,
time,
action,
productIds,
groupIds,
}).returning();
// Refresh cron jobs to include new schedule
await refreshScheduleJobs();
return scheduleResult[0];
}),
getAll: protectedProcedure
.query(async () => {
const schedules = await db.query.productAvailabilitySchedules.findMany({
orderBy: (productAvailabilitySchedules, { desc }) => [desc(productAvailabilitySchedules.createdAt)],
});
return schedules.map(schedule => ({
...schedule,
productCount: schedule.productIds.length,
groupCount: schedule.groupIds.length,
}));
}),
getById: protectedProcedure
.input(z.object({ id: z.number().int().positive() }))
.query(async ({ input }) => {
const { id } = input;
const schedule = await db.query.productAvailabilitySchedules.findFirst({
where: eq(productAvailabilitySchedules.id, id),
});
if (!schedule) {
throw new Error("Schedule not found");
}
return schedule;
}),
update: protectedProcedure
.input(updateScheduleSchema)
.mutation(async ({ input }) => {
const { id, updates } = input;
// Check if schedule exists
const existingSchedule = await db.query.productAvailabilitySchedules.findFirst({
where: eq(productAvailabilitySchedules.id, id),
});
if (!existingSchedule) {
throw new Error("Schedule not found");
}
// Check schedule name uniqueness if being updated
if (updates.scheduleName && updates.scheduleName !== existingSchedule.scheduleName) {
const duplicateSchedule = await db.query.productAvailabilitySchedules.findFirst({
where: eq(productAvailabilitySchedules.scheduleName, updates.scheduleName),
});
if (duplicateSchedule) {
throw new Error("Schedule name already exists");
}
}
// Update schedule
const updateData: any = {};
if (updates.scheduleName !== undefined) updateData.scheduleName = updates.scheduleName;
if (updates.time !== undefined) updateData.time = updates.time;
if (updates.action !== undefined) updateData.action = updates.action;
if (updates.productIds !== undefined) updateData.productIds = updates.productIds;
if (updates.groupIds !== undefined) updateData.groupIds = updates.groupIds;
updateData.lastUpdated = new Date();
const result = await db.update(productAvailabilitySchedules)
.set(updateData)
.where(eq(productAvailabilitySchedules.id, id))
.returning();
if (result.length === 0) {
throw new Error("Failed to update schedule");
}
// Refresh cron jobs to reflect changes
await refreshScheduleJobs();
return result[0];
}),
delete: protectedProcedure
.input(z.object({ id: z.number().int().positive() }))
.mutation(async ({ input }) => {
const { id } = input;
const result = await db.delete(productAvailabilitySchedules)
.where(eq(productAvailabilitySchedules.id, id))
.returning();
if (result.length === 0) {
throw new Error("Schedule not found");
}
// Refresh cron jobs to remove deleted schedule
await refreshScheduleJobs();
return { message: "Schedule deleted successfully" };
}),
});

View file

@ -7,8 +7,7 @@ import { ApiError } from '@/src/lib/api-error'
import { imageUploadS3, generateSignedUrlsFromS3Urls, getOriginalUrlFromSignedUrl, claimUploadUrl } from '@/src/lib/s3-client' import { imageUploadS3, generateSignedUrlsFromS3Urls, getOriginalUrlFromSignedUrl, claimUploadUrl } from '@/src/lib/s3-client'
import { deleteS3Image } from '@/src/lib/delete-image' import { deleteS3Image } from '@/src/lib/delete-image'
import type { SpecialDeal } from '@/src/db/types' import type { SpecialDeal } from '@/src/db/types'
import { scheduleStoreInitialization } from '@/src/stores/store-initializer' import { initializeAllStores } from '@/src/stores/store-initializer'
type CreateDeal = { type CreateDeal = {
quantity: number; quantity: number;
@ -103,7 +102,7 @@ export const productRouter = router({
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
message: "Product deleted successfully", message: "Product deleted successfully",
@ -134,7 +133,7 @@ export const productRouter = router({
.returning(); .returning();
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
product: updatedProduct, product: updatedProduct,
@ -190,7 +189,7 @@ export const productRouter = router({
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
message: "Slot products updated successfully", message: "Slot products updated successfully",
@ -392,7 +391,7 @@ export const productRouter = router({
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
group: newGroup, group: newGroup,
@ -440,7 +439,7 @@ export const productRouter = router({
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
group: updatedGroup, group: updatedGroup,
@ -468,15 +467,15 @@ export const productRouter = router({
throw new ApiError('Group not found', 404); throw new ApiError('Group not found', 404);
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
message: 'Group deleted successfully', message: 'Group deleted successfully',
}; };
}), }),
updateProductPrices: protectedProcedure updateProductPrices: protectedProcedure
.input(z.object({ .input(z.object({
updates: z.array(z.object({ updates: z.array(z.object({
productId: z.number(), productId: z.number(),
@ -524,12 +523,12 @@ export const productRouter = router({
await Promise.all(updatePromises); await Promise.all(updatePromises);
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
message: `Updated prices for ${updates.length} product(s)`, message: `Updated prices for ${updates.length} product(s)`,
updatedCount: updates.length, updatedCount: updates.length,
}; };
}), }),
}); });

View file

@ -8,8 +8,7 @@ import { ApiError } from "@/src/lib/api-error"
import { appUrl } from "@/src/lib/env-exporter" import { appUrl } from "@/src/lib/env-exporter"
import redisClient from "@/src/lib/redis-client" import redisClient from "@/src/lib/redis-client"
import { getSlotSequenceKey } from "@/src/lib/redisKeyGetters" import { getSlotSequenceKey } from "@/src/lib/redisKeyGetters"
import { scheduleStoreInitialization } from '@/src/stores/store-initializer' import { initializeAllStores } from '@/src/stores/store-initializer'
interface CachedDeliverySequence { interface CachedDeliverySequence {
[userId: string]: number[]; [userId: string]: number[];
@ -216,7 +215,7 @@ export const slotsRouter = router({
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
message: "Slot products updated successfully", message: "Slot products updated successfully",
@ -299,7 +298,7 @@ export const slotsRouter = router({
}); });
// Reinitialize stores to reflect changes (outside transaction) // Reinitialize stores to reflect changes (outside transaction)
scheduleStoreInitialization() await initializeAllStores();
return result; return result;
}), }),
@ -458,7 +457,7 @@ export const slotsRouter = router({
}); });
// Reinitialize stores to reflect changes (outside transaction) // Reinitialize stores to reflect changes (outside transaction)
scheduleStoreInitialization() await initializeAllStores();
return result; return result;
} }
@ -488,7 +487,7 @@ export const slotsRouter = router({
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
message: "Slot deleted successfully", message: "Slot deleted successfully",
@ -599,7 +598,7 @@ export const slotsRouter = router({
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
success: true, success: true,

View file

@ -6,8 +6,7 @@ import { eq, inArray } from 'drizzle-orm';
import { ApiError } from '@/src/lib/api-error' import { ApiError } from '@/src/lib/api-error'
import { extractKeyFromPresignedUrl, deleteImageUtil, generateSignedUrlFromS3Url } from '@/src/lib/s3-client' import { extractKeyFromPresignedUrl, deleteImageUtil, generateSignedUrlFromS3Url } from '@/src/lib/s3-client'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'; import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { scheduleStoreInitialization } from '@/src/stores/store-initializer' import { initializeAllStores } from '@/src/stores/store-initializer'
export const storeRouter = router({ export const storeRouter = router({
getStores: protectedProcedure getStores: protectedProcedure
@ -86,7 +85,7 @@ export const storeRouter = router({
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
store: newStore, store: newStore,
@ -164,16 +163,16 @@ export const storeRouter = router({
} }
} }
// Reinitialize stores to reflect changes // Reinitialize stores to reflect changes
scheduleStoreInitialization() await initializeAllStores();
return { return {
store: updatedStore, store: updatedStore,
message: "Store updated successfully", message: "Store updated successfully",
}; };
}), }),
deleteStore: protectedProcedure deleteStore: protectedProcedure
.input(z.object({ .input(z.object({
storeId: z.number(), storeId: z.number(),
})) }))
@ -202,9 +201,9 @@ export const storeRouter = router({
}; };
}); });
// Reinitialize stores to reflect changes (outside transaction) // Reinitialize stores to reflect changes (outside transaction)
scheduleStoreInitialization() await initializeAllStores();
return result; return result;
}), }),
}); });

View file

@ -9,32 +9,9 @@ import { generateUploadUrl } from '@/src/lib/s3-client'
import { ApiError } from '@/src/lib/api-error' import { ApiError } from '@/src/lib/api-error'
import { getAllConstValues } from '@/src/lib/const-store' import { getAllConstValues } from '@/src/lib/const-store'
import { CONST_KEYS } from '@/src/lib/const-keys' import { CONST_KEYS } from '@/src/lib/const-keys'
import { assetsDomain, apiCacheKey } from '@/src/lib/env-exporter'
const polygon = turf.polygon(mbnrGeoJson.features[0].geometry.coordinates); const polygon = turf.polygon(mbnrGeoJson.features[0].geometry.coordinates);
export async function scaffoldEssentialConsts() {
const consts = await getAllConstValues();
return {
freeDeliveryThreshold: consts[CONST_KEYS.freeDeliveryThreshold] ?? 200,
deliveryCharge: consts[CONST_KEYS.deliveryCharge] ?? 0,
flashFreeDeliveryThreshold: consts[CONST_KEYS.flashFreeDeliveryThreshold] ?? 500,
flashDeliveryCharge: consts[CONST_KEYS.flashDeliveryCharge] ?? 69,
popularItems: consts[CONST_KEYS.popularItems] ?? '5,3,2,4,1',
versionNum: consts[CONST_KEYS.versionNum] ?? '1.1.0',
playStoreUrl: consts[CONST_KEYS.playStoreUrl] ?? 'https://play.google.com/store/apps/details?id=in.freshyo.app',
appStoreUrl: consts[CONST_KEYS.appStoreUrl] ?? 'https://apps.apple.com/in/app/freshyo/id6756889077',
webViewHtml: null,
isWebviewClosable: true,
isFlashDeliveryEnabled: consts[CONST_KEYS.isFlashDeliveryEnabled] ?? true,
supportMobile: consts[CONST_KEYS.supportMobile] ?? '',
supportEmail: consts[CONST_KEYS.supportEmail] ?? '',
assetsDomain,
apiCacheKey,
};
}
export const commonApiRouter = router({ export const commonApiRouter = router({
product: commonRouter, product: commonRouter,
getStoresSummary: publicProcedure getStoresSummary: publicProcedure
@ -122,8 +99,23 @@ export const commonApiRouter = router({
}), }),
essentialConsts: publicProcedure essentialConsts: publicProcedure
.query(async () => { .query(async () => {
const response = await scaffoldEssentialConsts(); const consts = await getAllConstValues();
return response;
return {
freeDeliveryThreshold: consts[CONST_KEYS.freeDeliveryThreshold] ?? 200,
deliveryCharge: consts[CONST_KEYS.deliveryCharge] ?? 0,
flashFreeDeliveryThreshold: consts[CONST_KEYS.flashFreeDeliveryThreshold] ?? 500,
flashDeliveryCharge: consts[CONST_KEYS.flashDeliveryCharge] ?? 69,
popularItems: consts[CONST_KEYS.popularItems] ?? '5,3,2,4,1',
versionNum: consts[CONST_KEYS.versionNum] ?? '1.1.0',
playStoreUrl: consts[CONST_KEYS.playStoreUrl] ?? 'https://play.google.com/store/apps/details?id=in.freshyo.app',
appStoreUrl: consts[CONST_KEYS.appStoreUrl] ?? 'https://apps.apple.com/in/app/freshyo/id6756889077',
webViewHtml: null,
isWebviewClosable: true,
isFlashDeliveryEnabled: consts[CONST_KEYS.isFlashDeliveryEnabled] ?? true,
supportMobile: consts[CONST_KEYS.supportMobile] ?? '',
supportEmail: consts[CONST_KEYS.supportEmail] ?? '',
};
}), }),
}); });

View file

@ -1,10 +1,12 @@
import { router, publicProcedure } from '@/src/trpc/trpc-index' import { router, publicProcedure } from '@/src/trpc/trpc-index'
import { db } from '@/src/db/db_index' import { db } from '@/src/db/db_index'
import { productInfo, units, productSlots, deliverySlotInfo, storeInfo } from '@/src/db/schema' import { productInfo, units, productSlots, deliverySlotInfo, storeInfo, productTags, productTagInfo } from '@/src/db/schema'
import { eq, gt, and, sql, inArray } from 'drizzle-orm'; import { eq, gt, and, sql, inArray } from 'drizzle-orm';
import { generateSignedUrlsFromS3Urls, generateSignedUrlFromS3Url } from '@/src/lib/s3-client' import { generateSignedUrlsFromS3Urls, generateSignedUrlFromS3Url } from '@/src/lib/s3-client'
import { z } from 'zod';
import { getAllProducts as getAllProductsFromCache } from '@/src/stores/product-store' import { getAllProducts as getAllProductsFromCache } from '@/src/stores/product-store'
import { getDashboardTags as getDashboardTagsFromCache } from '@/src/stores/product-tag-store' import { getDashboardTags as getDashboardTagsFromCache } from '@/src/stores/product-tag-store'
import Fuse from 'fuse.js';
export const getNextDeliveryDate = async (productId: number): Promise<Date | null> => { export const getNextDeliveryDate = async (productId: number): Promise<Date | null> => {
const result = await db const result = await db
@ -26,51 +28,9 @@ export const getNextDeliveryDate = async (productId: number): Promise<Date | nul
return result[0]?.deliveryTime || null; return result[0]?.deliveryTime || null;
}; };
export async function scaffoldProducts() {
// Get all products from cache
let products = await getAllProductsFromCache();
products = products.filter(item => Boolean(item.id))
// Get suspended product IDs to filter them out
const suspendedProducts = await db
.select({ id: productInfo.id })
.from(productInfo)
.where(eq(productInfo.isSuspended, true));
const suspendedProductIds = new Set(suspendedProducts.map(sp => sp.id));
// Filter out suspended products
products = products.filter(product => !suspendedProductIds.has(product.id));
// Format products to match the expected response structure
const formattedProducts = await Promise.all(
products.map(async (product) => {
const nextDeliveryDate = await getNextDeliveryDate(product.id);
return {
id: product.id,
name: product.name,
shortDescription: product.shortDescription,
price: parseFloat(product.price),
marketPrice: product.marketPrice ? parseFloat(product.marketPrice) : null,
unit: product.unitNotation,
unitNotation: product.unitNotation,
incrementStep: product.incrementStep,
productQuantity: product.productQuantity,
storeId: product.store?.id || null,
isOutOfStock: product.isOutOfStock,
isFlashAvailable: product.isFlashAvailable,
nextDeliveryDate: nextDeliveryDate ? nextDeliveryDate.toISOString() : null,
images: product.images,
flashPrice: product.flashPrice
};
})
);
return {
products: formattedProducts,
count: formattedProducts.length,
};
}
export const commonRouter = router({ export const commonRouter = router({
getDashboardTags: publicProcedure getDashboardTags: publicProcedure
@ -84,9 +44,89 @@ export const commonRouter = router({
}), }),
getAllProductsSummary: publicProcedure getAllProductsSummary: publicProcedure
.query(async () => { .input(z.object({
const response = await scaffoldProducts(); searchQuery: z.string().optional(),
return response; tagId: z.number().optional()
}))
.query(async ({ input }) => {
const { searchQuery, tagId } = input;
// Get all products from cache
let products = await getAllProductsFromCache();
products = products.filter(item => Boolean(item.id))
// Apply tag filtering if tagId is provided
if (tagId) {
// Get products that have this tag from the database
const taggedProducts = await db
.select({ productId: productTags.productId })
.from(productTags)
.where(eq(productTags.tagId, tagId));
const taggedProductIds = new Set(taggedProducts.map(tp => tp.productId));
// Filter products based on tag
products = products.filter(product => taggedProductIds.has(product.id));
}
// Apply search filtering if searchQuery is provided using Fuse.js
if (searchQuery) {
const fuse = new Fuse(products, {
keys: [
'name',
'shortDescription',
'longDescription',
'store.name', // Search in store name too
'productTags', // Search in product tags too
],
threshold: 0.3, // Adjust fuzziness (0.0 = exact match, 1.0 = match anything)
includeScore: true,
shouldSort: true,
});
const fuseResults = fuse.search(searchQuery);
products = fuseResults.map(result => result.item);
}
// Get suspended product IDs to filter them out
const suspendedProducts = await db
.select({ id: productInfo.id })
.from(productInfo)
.where(eq(productInfo.isSuspended, true));
const suspendedProductIds = new Set(suspendedProducts.map(sp => sp.id));
// Filter out suspended products
products = products.filter(product => !suspendedProductIds.has(product.id));
// Format products to match the expected response structure
const formattedProducts = await Promise.all(
products.map(async (product) => {
const nextDeliveryDate = await getNextDeliveryDate(product.id);
return {
id: product.id,
name: product.name,
shortDescription: product.shortDescription,
price: parseFloat(product.price),
marketPrice: product.marketPrice ? parseFloat(product.marketPrice) : null,
unit: product.unitNotation,
unitNotation: product.unitNotation,
incrementStep: product.incrementStep,
productQuantity: product.productQuantity,
storeId: product.store?.id || null,
isOutOfStock: product.isOutOfStock,
isFlashAvailable: product.isFlashAvailable,
nextDeliveryDate: nextDeliveryDate ? nextDeliveryDate.toISOString() : null,
images: product.images, // Already signed URLs from cache
};
})
);
return {
products: formattedProducts,
count: formattedProducts.length,
};
}), }),
getStoresSummary: publicProcedure getStoresSummary: publicProcedure
@ -113,4 +153,4 @@ export const commonRouter = router({
status: "ok", status: "ok",
}; };
}), }),
}); });

View file

@ -1,30 +1,38 @@
import { db } from '@/src/db/db_index'; import { db } from '@/src/db/db_index';
import { homeBanners } from '@/src/db/schema'; import { homeBanners } from '@/src/db/schema';
import { publicProcedure, router } from '@/src/trpc/trpc-index'; import { publicProcedure, router } from '@/src/trpc/trpc-index';
import { scaffoldAssetUrl } from '@/src/lib/s3-client'; import { generateSignedUrlFromS3Url } from '@/src/lib/s3-client';
import { isNotNull, asc } from 'drizzle-orm'; import { isNotNull, asc } from 'drizzle-orm';
export async function scaffoldBanners() {
const banners = await db.query.homeBanners.findMany({
where: isNotNull(homeBanners.serialNum), // Only show assigned banners
orderBy: asc(homeBanners.serialNum), // Order by slot number 1-4
});
// Convert S3 keys to signed URLs for client
const bannersWithSignedUrls = banners.map((banner) => ({
...banner,
imageUrl: banner.imageUrl ? scaffoldAssetUrl(banner.imageUrl) : banner.imageUrl,
}));
return {
banners: bannersWithSignedUrls,
};
}
export const bannerRouter = router({ export const bannerRouter = router({
getBanners: publicProcedure getBanners: publicProcedure
.query(async () => { .query(async () => {
const response = await scaffoldBanners(); const banners = await db.query.homeBanners.findMany({
return response; where: isNotNull(homeBanners.serialNum), // Only show assigned banners
orderBy: asc(homeBanners.serialNum), // Order by slot number 1-4
});
// Convert S3 keys to signed URLs for client
const bannersWithSignedUrls = await Promise.all(
banners.map(async (banner) => {
try {
return {
...banner,
imageUrl: banner.imageUrl ? await generateSignedUrlFromS3Url(banner.imageUrl) : banner.imageUrl,
};
} catch (error) {
console.error(`Failed to generate signed URL for banner ${banner.id}:`, error);
return {
...banner,
imageUrl: banner.imageUrl, // Keep original on error
};
}
})
);
return {
banners: bannersWithSignedUrls,
};
}), }),
}); });

View file

@ -7,7 +7,7 @@ import {
productInfo, productInfo,
units, units,
} from "@/src/db/schema"; } from "@/src/db/schema";
import { eq, and } from "drizzle-orm"; import { eq, and, gt, asc } from "drizzle-orm";
import { getAllSlots as getAllSlotsFromCache, getSlotById as getSlotByIdFromCache } from "@/src/stores/slot-store"; import { getAllSlots as getAllSlotsFromCache, getSlotById as getSlotByIdFromCache } from "@/src/stores/slot-store";
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@ -32,42 +32,6 @@ async function getSlotData(slotId: number) {
}; };
} }
export async function scaffoldSlotsWithProducts() {
const allSlots = await getAllSlotsFromCache();
const currentTime = new Date();
const validSlots = allSlots
.filter((slot) => {
return dayjs(slot.freezeTime).isAfter(currentTime) &&
dayjs(slot.deliveryTime).isAfter(currentTime) &&
!slot.isCapacityFull;
})
.sort((a, b) => dayjs(a.deliveryTime).valueOf() - dayjs(b.deliveryTime).valueOf());
// Fetch all products for availability info
const allProducts = await db
.select({
id: productInfo.id,
name: productInfo.name,
isOutOfStock: productInfo.isOutOfStock,
isFlashAvailable: productInfo.isFlashAvailable,
})
.from(productInfo)
.where(eq(productInfo.isSuspended, false));
const productAvailability = allProducts.map(product => ({
id: product.id,
name: product.name,
isOutOfStock: product.isOutOfStock,
isFlashAvailable: product.isFlashAvailable,
}));
return {
slots: validSlots,
productAvailability,
count: validSlots.length,
};
}
export const slotsRouter = router({ export const slotsRouter = router({
getSlots: publicProcedure.query(async () => { getSlots: publicProcedure.query(async () => {
const slots = await db.query.deliverySlotInfo.findMany({ const slots = await db.query.deliverySlotInfo.findMany({
@ -80,8 +44,40 @@ export const slotsRouter = router({
}), }),
getSlotsWithProducts: publicProcedure.query(async () => { getSlotsWithProducts: publicProcedure.query(async () => {
const response = await scaffoldSlotsWithProducts(); const allSlots = await getAllSlotsFromCache();
return response; const currentTime = new Date();
const validSlots = allSlots
.filter((slot) => {
return dayjs(slot.freezeTime).isAfter(currentTime) &&
dayjs(slot.deliveryTime).isAfter(currentTime) &&
!slot.isCapacityFull;
})
.sort((a, b) => dayjs(a.deliveryTime).valueOf() - dayjs(b.deliveryTime).valueOf());
return {
slots: validSlots,
count: validSlots.length,
};
}),
nextMajorDelivery: publicProcedure.query(async () => {
const now = new Date();
// Find the next upcoming active delivery slot ID
const nextSlot = await db.query.deliverySlotInfo.findFirst({
where: and(
eq(deliverySlotInfo.isActive, true),
gt(deliverySlotInfo.deliveryTime, now),
),
orderBy: asc(deliverySlotInfo.deliveryTime),
});
if (!nextSlot) {
return null; // No upcoming delivery slots
}
// Get formatted data using helper method
return await getSlotData(nextSlot.id);
}), }),
getSlotById: publicProcedure getSlotById: publicProcedure

View file

@ -5,149 +5,67 @@ import { storeInfo, productInfo, units } from '@/src/db/schema';
import { eq, and, sql } from 'drizzle-orm'; import { eq, and, sql } from 'drizzle-orm';
import { scaffoldAssetUrl } from '@/src/lib/s3-client'; import { scaffoldAssetUrl } from '@/src/lib/s3-client';
import { ApiError } from '@/src/lib/api-error'; import { ApiError } from '@/src/lib/api-error';
import { getTagsByStoreId } from '@/src/stores/product-tag-store';
export async function scaffoldStores() { export const storesRouter = router({
const storesData = await db getStores: publicProcedure
.select({ .query(async () => {
id: storeInfo.id, const storesData = await db
name: storeInfo.name,
description: storeInfo.description,
imageUrl: storeInfo.imageUrl,
productCount: sql<number>`count(${productInfo.id})`.as('productCount'),
})
.from(storeInfo)
.leftJoin(
productInfo,
and(eq(productInfo.storeId, storeInfo.id), eq(productInfo.isSuspended, false))
)
.groupBy(storeInfo.id);
// Generate signed URLs for store images and fetch sample products
const storesWithDetails = await Promise.all(
storesData.map(async (store) => {
const signedImageUrl = store.imageUrl ? scaffoldAssetUrl(store.imageUrl) : null;
// Fetch up to 3 products for this store
const sampleProducts = await db
.select({ .select({
id: productInfo.id, id: storeInfo.id,
name: productInfo.name, name: storeInfo.name,
images: productInfo.images, description: storeInfo.description,
imageUrl: storeInfo.imageUrl,
productCount: sql<number>`count(${productInfo.id})`.as('productCount'),
}) })
.from(productInfo) .from(storeInfo)
.where(and(eq(productInfo.storeId, store.id), eq(productInfo.isSuspended, false))) .leftJoin(
.limit(3); productInfo,
and(eq(productInfo.storeId, storeInfo.id), eq(productInfo.isSuspended, false))
)
.groupBy(storeInfo.id);
// Generate signed URLs for store images and fetch sample products
const storesWithDetails = await Promise.all(
storesData.map(async (store) => {
const signedImageUrl = store.imageUrl ? scaffoldAssetUrl(store.imageUrl) : null;
// Fetch up to 3 products for this store
const sampleProducts = await db
.select({
id: productInfo.id,
name: productInfo.name,
images: productInfo.images,
})
.from(productInfo)
.where(and(eq(productInfo.storeId, store.id), eq(productInfo.isSuspended, false)))
.limit(3);
// Generate signed URLs for product images
const productsWithSignedUrls = await Promise.all(
sampleProducts.map(async (product) => {
const images = product.images as string[];
return {
id: product.id,
name: product.name,
signedImageUrl: (images && images.length > 0) ? scaffoldAssetUrl(images[0]) : null,
};
})
);
// Generate signed URLs for product images
const productsWithSignedUrls = await Promise.all(
sampleProducts.map(async (product) => {
const images = product.images as string[];
return { return {
id: product.id, id: store.id,
name: product.name, name: store.name,
signedImageUrl: (images && images.length > 0) ? scaffoldAssetUrl(images[0]) : null, description: store.description,
signedImageUrl,
productCount: store.productCount,
sampleProducts: productsWithSignedUrls,
}; };
}) })
); );
return { return {
id: store.id, stores: storesWithDetails,
name: store.name,
description: store.description,
signedImageUrl,
productCount: store.productCount,
sampleProducts: productsWithSignedUrls,
}; };
})
);
return {
stores: storesWithDetails,
};
}
export async function scaffoldStoreWithProducts(storeId: number) {
// Fetch store info
const storeData = await db.query.storeInfo.findFirst({
where: eq(storeInfo.id, storeId),
columns: {
id: true,
name: true,
description: true,
imageUrl: true,
},
});
if (!storeData) {
throw new ApiError('Store not found', 404);
}
// Generate signed URL for store image
const signedImageUrl = storeData.imageUrl ? scaffoldAssetUrl(storeData.imageUrl) : null;
// Fetch products for this store
const productsData = await db
.select({
id: productInfo.id,
name: productInfo.name,
shortDescription: productInfo.shortDescription,
price: productInfo.price,
marketPrice: productInfo.marketPrice,
images: productInfo.images,
isOutOfStock: productInfo.isOutOfStock,
incrementStep: productInfo.incrementStep,
unitShortNotation: units.shortNotation,
unitNotation: units.shortNotation,
productQuantity: productInfo.productQuantity,
})
.from(productInfo)
.innerJoin(units, eq(productInfo.unitId, units.id))
.where(and(eq(productInfo.storeId, storeId), eq(productInfo.isSuspended, false)));
// Generate signed URLs for product images
const productsWithSignedUrls = await Promise.all(
productsData.map(async (product) => ({
id: product.id,
name: product.name,
shortDescription: product.shortDescription,
price: product.price,
marketPrice: product.marketPrice,
incrementStep: product.incrementStep,
unit: product.unitShortNotation,
unitNotation: product.unitNotation,
images: scaffoldAssetUrl((product.images as string[]) || []),
isOutOfStock: product.isOutOfStock,
productQuantity: product.productQuantity
}))
);
const tags = await getTagsByStoreId(storeId);
return {
store: {
id: storeData.id,
name: storeData.name,
description: storeData.description,
signedImageUrl,
},
products: productsWithSignedUrls,
tags: tags.map(tag => ({
id: tag.id,
tagName: tag.tagName,
tagDescription: tag.tagDescription,
imageUrl: tag.imageUrl,
productIds: tag.productIds,
})),
};
}
export const storesRouter = router({
getStores: publicProcedure
.query(async () => {
const response = await scaffoldStores();
return response;
}), }),
getStoreWithProducts: publicProcedure getStoreWithProducts: publicProcedure
@ -156,7 +74,70 @@ export const storesRouter = router({
})) }))
.query(async ({ input }) => { .query(async ({ input }) => {
const { storeId } = input; const { storeId } = input;
const response = await scaffoldStoreWithProducts(storeId);
return response; // Fetch store info
const storeData = await db.query.storeInfo.findFirst({
where: eq(storeInfo.id, storeId),
columns: {
id: true,
name: true,
description: true,
imageUrl: true,
},
});
if (!storeData) {
throw new ApiError('Store not found', 404);
}
// Generate signed URL for store image
const signedImageUrl = storeData.imageUrl ? scaffoldAssetUrl(storeData.imageUrl) : null;
// Fetch products for this store
const productsData = await db
.select({
id: productInfo.id,
name: productInfo.name,
shortDescription: productInfo.shortDescription,
price: productInfo.price,
marketPrice: productInfo.marketPrice,
images: productInfo.images,
isOutOfStock: productInfo.isOutOfStock,
incrementStep: productInfo.incrementStep,
unitShortNotation: units.shortNotation,
unitNotation: units.shortNotation,
productQuantity: productInfo.productQuantity,
})
.from(productInfo)
.innerJoin(units, eq(productInfo.unitId, units.id))
.where(and(eq(productInfo.storeId, storeId), eq(productInfo.isSuspended, false)));
// Generate signed URLs for product images
const productsWithSignedUrls = await Promise.all(
productsData.map(async (product) => ({
id: product.id,
name: product.name,
shortDescription: product.shortDescription,
price: product.price,
marketPrice: product.marketPrice,
incrementStep: product.incrementStep,
unit: product.unitShortNotation,
unitNotation: product.unitNotation,
images: scaffoldAssetUrl((product.images as string[]) || []),
isOutOfStock: product.isOutOfStock,
productQuantity: product.productQuantity
}))
);
return {
store: {
id: storeData.id,
name: storeData.name,
description: storeData.description,
signedImageUrl,
},
products: productsWithSignedUrls,
};
}), }),
}); });

View file

@ -3,11 +3,6 @@ import { z } from 'zod';
import { adminRouter } from '@/src/trpc/apis/admin-apis/apis/admin-trpc-index' import { adminRouter } from '@/src/trpc/apis/admin-apis/apis/admin-trpc-index'
import { userRouter } from '@/src/trpc/apis/user-apis/apis/user-trpc-index' import { userRouter } from '@/src/trpc/apis/user-apis/apis/user-trpc-index'
import { commonApiRouter } from '@/src/trpc/apis/common-apis/common-trpc-index' import { commonApiRouter } from '@/src/trpc/apis/common-apis/common-trpc-index'
import { scaffoldProducts } from './apis/common-apis/common';
import { scaffoldStores, scaffoldStoreWithProducts } from './apis/user-apis/apis/stores';
import { scaffoldSlotsWithProducts } from './apis/user-apis/apis/slots';
import { scaffoldEssentialConsts } from './apis/common-apis/common-trpc-index';
import { scaffoldBanners } from './apis/user-apis/apis/banners';
// Create the main app router // Create the main app router
export const appRouter = router({ export const appRouter = router({
@ -21,13 +16,5 @@ export const appRouter = router({
common: commonApiRouter, common: commonApiRouter,
}); });
// Export type definition of API // Export type definition of API
export type AppRouter = typeof appRouter; export type AppRouter = typeof appRouter;
export type AllProductsApiType = Awaited<ReturnType<typeof scaffoldProducts>>;
export type StoresApiType = Awaited<ReturnType<typeof scaffoldStores>>;
export type SlotsApiType = Awaited<ReturnType<typeof scaffoldSlotsWithProducts>>;
export type EssentialConstsApiType = Awaited<ReturnType<typeof scaffoldEssentialConsts>>;
export type BannersApiType = Awaited<ReturnType<typeof scaffoldBanners>>;
export type StoreWithProductsApiType = Awaited<ReturnType<typeof scaffoldStoreWithProducts>>;

View file

@ -33,10 +33,6 @@
"shared-types": ["../shared-types"], "shared-types": ["../shared-types"],
"@commonTypes": ["../../packages/ui/shared-types"], "@commonTypes": ["../../packages/ui/shared-types"],
"@commonTypes/*": ["../../packages/ui/shared-types/*"], "@commonTypes/*": ["../../packages/ui/shared-types/*"],
"@packages/shared": ["../../packages/shared"],
"@packages/shared/*": ["../../packages/shared/*"],
"global-shared": ["../../packages/shared"],
"global-shared/*": ["../../packages/shared/*"]
}, },
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [""], /* Specify multiple folders that act like './node_modules/@types'. */ // "typeRoots": [""], /* Specify multiple folders that act like './node_modules/@types'. */
@ -120,6 +116,6 @@
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */
}, },
"include": ["src", "types", "index.ts", "../shared-types", "../../packages/shared"] "include": ["src", "types", "index.ts", "../shared-types"]
} }

View file

@ -24,6 +24,12 @@
"@/*": [ "@/*": [
"./src/*" "./src/*"
], ],
"common-ui": [
"../../packages/ui"
],
"common-ui/*": [
"../../packages/ui/*"
]
}, },
"types": [ "types": [
"node" "node"

View file

@ -5,7 +5,7 @@ import { trpc } from '@/src/trpc-client';
import { MyText, MyTouchableOpacity, tw, AppContainer } from 'common-ui'; import { MyText, MyTouchableOpacity, tw, AppContainer } from 'common-ui';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';
import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
export default function FlashDeliveryBaseLayout() { export default function FlashDeliveryBaseLayout() {
const router = useRouter(); const router = useRouter();

View file

@ -21,15 +21,13 @@ import AddToCartDialog from "@/src/components/AddToCartDialog";
import MyFlatList from "common-ui/src/components/flat-list"; import MyFlatList from "common-ui/src/components/flat-list";
import { trpc } from "@/src/trpc-client"; import { trpc } from "@/src/trpc-client";
import { useAllProducts, useStores, useSlots, useGetEssentialConsts } from "@/src/hooks/prominent-api-hooks";
import { useProductSlotIdentifier } from "@/hooks/useProductSlotIdentifier"; import { useProductSlotIdentifier } from "@/hooks/useProductSlotIdentifier";
import { useCentralSlotStore } from "@/src/store/centralSlotStore";
import { useCentralProductStore } from "@/src/store/centralProductStore";
import FloatingCartBar from "@/components/floating-cart-bar"; import FloatingCartBar from "@/components/floating-cart-bar";
import BannerCarousel from "@/components/BannerCarousel"; import BannerCarousel from "@/components/BannerCarousel";
import { useUserDetails } from "@/src/contexts/AuthContext"; import { useUserDetails } from "@/src/contexts/AuthContext";
import TabLayoutWrapper from "@/components/TabLayoutWrapper"; import TabLayoutWrapper from "@/components/TabLayoutWrapper";
import { useNavigationStore } from "@/src/store/navigationStore"; import { useNavigationStore } from "@/src/store/navigationStore";
import { useGetEssentialConsts } from "@/src/api-hooks/essential-consts.api";
import NextOrderGlimpse from "@/components/NextOrderGlimpse"; import NextOrderGlimpse from "@/components/NextOrderGlimpse";
dayjs.extend(relativeTime); dayjs.extend(relativeTime);
@ -362,6 +360,8 @@ export default function Dashboard() {
const router = useRouter(); const router = useRouter();
const userDetails = useUserDetails(); const userDetails = useUserDetails();
const [inputQuery, setInputQuery] = useState(""); const [inputQuery, setInputQuery] = useState("");
const [searchQuery, setSearchQuery] = useState("");
const [selectedTagId, setSelectedTagId] = useState<number | null>(null);
const [isLoadingDialogOpen, setIsLoadingDialogOpen] = useState(false); const [isLoadingDialogOpen, setIsLoadingDialogOpen] = useState(false);
const [gradientHeight, setGradientHeight] = useState(0); const [gradientHeight, setGradientHeight] = useState(0);
const [displayedProducts, setDisplayedProducts] = useState<any[]>([]); const [displayedProducts, setDisplayedProducts] = useState<any[]>([]);
@ -369,21 +369,22 @@ export default function Dashboard() {
const [isLoadingMore, setIsLoadingMore] = useState(false); const [isLoadingMore, setIsLoadingMore] = useState(false);
const { backgroundColor } = useStatusBarStore(); const { backgroundColor } = useStatusBarStore();
const { getQuickestSlot } = useProductSlotIdentifier(); const { getQuickestSlot } = useProductSlotIdentifier();
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
const refetchProducts = useCentralProductStore((state) => state.refetchProducts);
const refetchSlotsFromStore = useCentralSlotStore((state) => state.refetchSlots);
const [isRefreshing, setIsRefreshing] = useState(false); const [isRefreshing, setIsRefreshing] = useState(false);
const { const {
data: productsData, data: productsData,
isLoading, isLoading,
error, error,
} = useAllProducts(); refetch,
} = trpc.common.product.getAllProductsSummary.useQuery({
searchQuery: searchQuery || undefined,
tagId: selectedTagId || undefined,
});
const { data: essentialConsts, isLoading: isLoadingConsts, error: constsError, refetch: refetchConsts } = useGetEssentialConsts(); const { data: essentialConsts, isLoading: isLoadingConsts, error: constsError, refetch: refetchConsts } = useGetEssentialConsts();
const { data: storesData, refetch: refetchStores } = useStores(); const { data: storesData, refetch: refetchStores } = trpc.user.stores.getStores.useQuery();
const { data: slotsData } = useSlots(); const { data: slotsData, refetch: refetchSlots } = trpc.user.slots.getSlotsWithProducts.useQuery();
const products = productsData?.products || []; const products = productsData?.products || [];
@ -396,18 +397,15 @@ export default function Dashboard() {
const slotB = getQuickestSlot(b.id); const slotB = getQuickestSlot(b.id);
if (slotA && !slotB) return -1; if (slotA && !slotB) return -1;
if (!slotA && slotB) return 1; if (!slotA && slotB) return 1;
const aOutOfStock = productSlotsMap[a.id]?.isOutOfStock; if (a.isOutOfStock && !b.isOutOfStock) return 1;
const bOutOfStock = productSlotsMap[b.id]?.isOutOfStock; if (!a.isOutOfStock && b.isOutOfStock) return -1;
if (aOutOfStock && !bOutOfStock) return 1;
if (!aOutOfStock && bOutOfStock) return -1;
return 0; return 0;
}); });
console.log('setting the displayed products')
setDisplayedProducts(initialBatch); setDisplayedProducts(initialBatch);
setHasMore(products.length > 10); setHasMore(products.length > 10);
} }
}, [productsData, productSlotsMap]); }, [productsData]);
const popularItemIds = useMemo(() => { const popularItemIds = useMemo(() => {
const popularItems = essentialConsts?.popularItems; const popularItems = essentialConsts?.popularItems;
@ -442,22 +440,11 @@ export default function Dashboard() {
const handleRefresh = useCallback(async () => { const handleRefresh = useCallback(async () => {
setIsRefreshing(true); setIsRefreshing(true);
try { try {
const promises = []; await Promise.all([refetch(), refetchStores(), refetchSlots(), refetchConsts()]);
if (refetchProducts) {
promises.push(refetchProducts());
}
if (refetchSlotsFromStore) {
promises.push(refetchSlotsFromStore());
}
promises.push(refetchStores());
promises.push(refetchConsts());
await Promise.all(promises);
} finally { } finally {
setIsRefreshing(false); setIsRefreshing(false);
} }
}, [refetchProducts, refetchSlotsFromStore, refetchStores, refetchConsts]); }, [refetch, refetchStores, refetchSlots, refetchConsts]);
useManualRefresh(() => { useManualRefresh(() => {
handleRefresh(); handleRefresh();
@ -481,7 +468,6 @@ export default function Dashboard() {
const renderProductItem = useCallback(({ item }: { item: any }) => ( const renderProductItem = useCallback(({ item }: { item: any }) => (
<ProductItem item={item} onPress={handleProductPress} /> <ProductItem item={item} onPress={handleProductPress} />
// <Image style={{ width: 150, height: 235 }} source={{ uri: item.images[0]}} />
), [handleProductPress]); ), [handleProductPress]);
const listHeader = useMemo(() => ( const listHeader = useMemo(() => (
@ -526,9 +512,7 @@ export default function Dashboard() {
</View> </View>
); );
} }
let str = ''
displayedProducts.forEach(product => str += `${product.id}-`)
// console.log(str)
return ( return (
<TabLayoutWrapper> <TabLayoutWrapper>
<View style={searchBarContainerStyle}> <View style={searchBarContainerStyle}>

View file

@ -1,4 +1,4 @@
import React, { useState, useRef, useEffect, useCallback, useMemo } from "react"; import React, { useState, useRef, useEffect, useCallback } from "react";
import { View, Dimensions } from "react-native"; import { View, Dimensions } from "react-native";
import { useRouter, useLocalSearchParams } from "expo-router"; import { useRouter, useLocalSearchParams } from "expo-router";
import { import {
@ -10,8 +10,7 @@ import {
SearchBar, SearchBar,
} from "common-ui"; } from "common-ui";
import MaterialIcons from "@expo/vector-icons/MaterialIcons"; import MaterialIcons from "@expo/vector-icons/MaterialIcons";
import Fuse from "fuse.js"; import { trpc } from "@/src/trpc-client";
import { useAllProducts } from "@/src/hooks/prominent-api-hooks";
import ProductCard from "@/components/ProductCard"; import ProductCard from "@/components/ProductCard";
import FloatingCartBar from "@/components/floating-cart-bar"; import FloatingCartBar from "@/components/floating-cart-bar";
@ -52,27 +51,12 @@ export default function SearchResults() {
}); });
}, []); }, []);
const { data: productsData, isLoading, error, refetch } = useAllProducts(); const { data: productsData, isLoading, error, refetch } =
trpc.common.product.getAllProductsSummary.useQuery({
const allProducts = productsData?.products || []; searchQuery: debouncedQuery || undefined,
// Client-side search filtering using Fuse.js
const products = useMemo(() => {
if (!debouncedQuery.trim()) return allProducts;
const fuse = new Fuse(allProducts, {
keys: [
'name',
'shortDescription',
],
threshold: 0.3,
includeScore: true,
shouldSort: true,
}); });
const fuseResults = fuse.search(debouncedQuery); const products = productsData?.products || [];
return fuseResults.map(result => result.item);
}, [allProducts, debouncedQuery]);
useManualRefresh(() => { useManualRefresh(() => {
refetch(); refetch();

View file

@ -4,7 +4,7 @@ import { Image } from 'expo-image';
import { MyText, tw, useManualRefresh, MyFlatList, useMarkDataFetchers, theme, MyTouchableOpacity } from 'common-ui'; import { MyText, tw, useManualRefresh, MyFlatList, useMarkDataFetchers, theme, MyTouchableOpacity } from 'common-ui';
import { MaterialIcons, Ionicons } from '@expo/vector-icons'; import { MaterialIcons, Ionicons } from '@expo/vector-icons';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';

View file

@ -0,0 +1,9 @@
import { Stack } from 'expo-router'
function DeliverySlotsLayout() {
return (
<Stack screenOptions={{ headerShown: true, title: 'Delivery Slots' }} />
)
}
export default DeliverySlotsLayout

View file

@ -0,0 +1,230 @@
import React, { useState } from 'react';
import { View, ScrollView } from 'react-native';
import { Image } from 'expo-image';
import { useRouter } from 'expo-router';
import { MyFlatList, MyText, tw, useMarkDataFetchers, BottomDialog, theme, MyTouchableOpacity } from 'common-ui';
import { trpc } from '@/src/trpc-client';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import dayjs from 'dayjs';
export default function DeliverySlots() {
const router = useRouter();
const { data, isLoading, error, refetch } = trpc.user.slots.getSlotsWithProducts.useQuery();
const [selectedSlotForDialog, setSelectedSlotForDialog] = useState<any>(null);
useMarkDataFetchers(() => {
refetch();
});
if (isLoading) {
return (
<MyFlatList
data={[]}
renderItem={() => null}
ListHeaderComponent={() => (
<View style={tw`flex-1 justify-center items-center p-8`}>
<MyText style={tw`text-gray-600`}>Loading delivery slots...</MyText>
</View>
)}
/>
);
}
if (error) {
return (
<MyFlatList
data={[]}
renderItem={() => null}
ListHeaderComponent={() => (
<View style={tw`flex-1 justify-center items-center p-8`}>
<MyText style={tw`text-red-600`}>Error loading delivery slots</MyText>
<MyTouchableOpacity
onPress={() => refetch()}
style={tw`mt-4 bg-blue-500 px-4 py-2 rounded-lg`}
>
<MyText style={tw`text-white font-semibold`}>Retry</MyText>
</MyTouchableOpacity>
</View>
)}
/>
);
}
const slots = data?.slots || [];
if (slots.length === 0) {
return (
<MyFlatList
data={[]}
renderItem={() => null}
ListHeaderComponent={() => (
<View style={tw`flex-1 justify-center items-center p-8`}>
<MaterialIcons name="schedule" size={64} color="#D1D5DB" />
<MyText style={tw`text-gray-500 text-center mt-4 text-lg`}>
No upcoming delivery slots available
</MyText>
<MyText style={tw`text-gray-400 text-center mt-2`}>
Check back later for new delivery schedules
</MyText>
</View>
)}
/>
);
}
return (
<>
<MyFlatList
data={slots}
keyExtractor={(item) => item.id.toString()}
// ListHeaderComponent={() => (
// <View style={tw`p-4 pb-2`}>
// <MyText style={tw`text-2xl font-bold text-gray-800`}>Delivery Slots</MyText>
// <MyText style={tw`text-gray-600 mt-1`}>
// Choose your preferred delivery time
// </MyText>
// </View>
// )}
renderItem={({ item: slot }) => (
<View style={tw`mx-4 mb-4 bg-white rounded-xl shadow-md overflow-hidden`}>
{/* Slot Header */}
<View style={tw`bg-pink-50 p-4 border-b border-pink-100`}>
<View style={tw`flex-row items-center justify-between`}>
<View>
<MyText style={tw`text-lg font-bold text-gray-800`}>
{dayjs(slot.deliveryTime).format('ddd DD MMM, h:mm a')}
</MyText>
<MyText style={tw`text-sm text-gray-600 mt-1`}>
Orders close by: {dayjs(slot.freezeTime).format('h:mm a')}
</MyText>
</View>
<View style={tw`flex-row items-center`}>
<View style={tw`bg-pink-500 px-3 py-1 rounded-full mr-3`}>
<MyText style={tw`text-white text-sm font-semibold`}>
{slot.products.length} items
</MyText>
</View>
<MyTouchableOpacity
onPress={() => router.push(`/(drawer)/(tabs)/home/cart?slot=${slot.id}`)}
style={tw`bg-pink-500 p-2 rounded-full`}
>
<MaterialIcons name="flash-on" size={16} color="white" />
</MyTouchableOpacity>
</View>
</View>
</View>
{/* Products List */}
<View style={tw`p-4`}>
<MyText style={tw`text-base font-semibold text-gray-700 mb-3`}>
Available Products
</MyText>
<View style={tw`space-y-2`}>
{slot.products.slice(0, 2).map((product) => (
<MyTouchableOpacity
key={product.id}
onPress={() => router.push(`/(drawer)/(tabs)/home/product-detail/${product.id}`)}
style={tw`bg-gray-50 rounded-lg p-3 flex-row items-center`}
>
{product.images && product.images.length > 0 ? (
<Image
source={{ uri: product.images[0] }}
style={tw`w-8 h-8 rounded mr-3`}
resizeMode="cover"
/>
) : (
<View style={tw`w-8 h-8 bg-gray-200 rounded mr-3 justify-center items-center`}>
<MaterialIcons name="image" size={16} color="#9CA3AF" />
</View>
)}
<View style={tw`flex-1`}>
<MyText style={tw`text-sm font-medium text-gray-800`} numberOfLines={1}>
{product.name}
</MyText>
<MyText style={tw`text-xs text-gray-600`}>
{product.price} {product.unit && `per ${product.unit}`}
</MyText>
</View>
{product.isOutOfStock && (
<MyText style={tw`text-xs text-red-500 font-medium`}>Out of stock</MyText>
)}
</MyTouchableOpacity>
))}
{slot.products.length > 2 && (
<MyTouchableOpacity
onPress={() => setSelectedSlotForDialog(slot)}
style={tw`bg-pink-50 rounded-lg p-3 flex-row items-center justify-center border border-pink-200`}
>
<MyText style={tw`text-sm font-medium text-pink-700`}>
+{slot.products.length - 2} more products
</MyText>
<MaterialIcons name="chevron-right" size={16} color={theme.colors.brand500} style={tw`ml-1`} />
</MyTouchableOpacity>
)}
</View>
</View>
</View>
)}
ListFooterComponent={() => <View style={tw`h-4`} />}
showsVerticalScrollIndicator={false}
contentContainerStyle={tw`pt-2`}
/>
{/* Products Dialog */}
<BottomDialog
open={!!selectedSlotForDialog}
onClose={() => setSelectedSlotForDialog(null)}
>
<View style={tw`p-6`}>
<MyText style={tw`text-xl font-bold text-gray-800 mb-4`}>
All Products - {dayjs(selectedSlotForDialog?.deliveryTime).format('ddd DD MMM, h:mm a')}
</MyText>
<ScrollView style={tw`max-h-96`} showsVerticalScrollIndicator={false}>
<View style={tw`space-y-3`}>
{selectedSlotForDialog?.products.map((product: any) => (
<MyTouchableOpacity
key={product.id}
onPress={() => {
setSelectedSlotForDialog(null);
router.push(`/(drawer)/(tabs)/home/product-detail/${product.id}`);
}}
style={tw`bg-gray-50 rounded-lg p-4 flex-row items-center`}
>
{product.images && product.images.length > 0 ? (
<Image
source={{ uri: product.images[0] }}
style={tw`w-12 h-12 rounded mr-4`}
resizeMode="cover"
/>
) : (
<View style={tw`w-12 h-12 bg-gray-200 rounded mr-4 justify-center items-center`}>
<MaterialIcons name="image" size={20} color="#9CA3AF" />
</View>
)}
<View style={tw`flex-1`}>
<MyText style={tw`text-base font-medium text-gray-800`} numberOfLines={1}>
{product.name}
</MyText>
<MyText style={tw`text-sm text-gray-600 mt-1`}>
{product.price} {product.unit && `per ${product.unit}`}
</MyText>
{product.marketPrice && (
<MyText style={tw`text-sm text-gray-500 line-through`}>
{product.marketPrice}
</MyText>
)}
</View>
{product.isOutOfStock && (
<MyText style={tw`text-xs text-red-500 font-medium`}>Out of stock</MyText>
)}
</MyTouchableOpacity>
))}
</View>
</ScrollView>
</View>
</BottomDialog>
</>
);
}

View file

@ -16,7 +16,7 @@ import {
} from "common-ui"; } from "common-ui";
import MaterialIcons from "@expo/vector-icons/MaterialIcons"; import MaterialIcons from "@expo/vector-icons/MaterialIcons";
import { Ionicons } from "@expo/vector-icons"; import { Ionicons } from "@expo/vector-icons";
import { useStores } from "@/src/hooks/prominent-api-hooks"; import { trpc } from "@/src/trpc-client";
import { LinearGradient } from "expo-linear-gradient"; import { LinearGradient } from "expo-linear-gradient";
import TabLayoutWrapper from "@/components/TabLayoutWrapper"; import TabLayoutWrapper from "@/components/TabLayoutWrapper";
import FloatingCartBar from "@/components/floating-cart-bar"; import FloatingCartBar from "@/components/floating-cart-bar";
@ -157,7 +157,7 @@ export default function Stores() {
isLoading, isLoading,
error, error,
refetch, refetch,
} = useStores(); } = trpc.user.stores.getStores.useQuery();
const stores = storesData?.stores || []; const stores = storesData?.stores || [];

View file

@ -1,4 +1,4 @@
import React, { useMemo, useState } from "react"; import React, { useState } from "react";
import { View, Dimensions, ScrollView, TouchableOpacity } from "react-native"; import { View, Dimensions, ScrollView, TouchableOpacity } from "react-native";
import { useRouter, useLocalSearchParams } from "expo-router"; import { useRouter, useLocalSearchParams } from "expo-router";
import { Image } from 'expo-image'; import { Image } from 'expo-image';
@ -13,10 +13,10 @@ import {
} from "common-ui"; } from "common-ui";
import MaterialIcons from "@expo/vector-icons/MaterialIcons"; import MaterialIcons from "@expo/vector-icons/MaterialIcons";
import FontAwesome5 from "@expo/vector-icons/FontAwesome5"; import FontAwesome5 from "@expo/vector-icons/FontAwesome5";
import { trpc } from "@/src/trpc-client";
import ProductCard from "@/components/ProductCard"; import ProductCard from "@/components/ProductCard";
import FloatingCartBar from "@/components/floating-cart-bar"; import FloatingCartBar from "@/components/floating-cart-bar";
import { useStoreHeaderStore } from "@/src/store/storeHeaderStore"; import { useStoreHeaderStore } from "@/src/store/storeHeaderStore";
import { useAllProducts, useStoreWithProducts } from "@/src/hooks/prominent-api-hooks";
const { width: screenWidth } = Dimensions.get("window"); const { width: screenWidth } = Dimensions.get("window");
const itemWidth = (screenWidth - 48) / 2; const itemWidth = (screenWidth - 48) / 2;
@ -63,32 +63,24 @@ export default function StoreDetail() {
const [selectedTagId, setSelectedTagId] = useState<number | null>(null); const [selectedTagId, setSelectedTagId] = useState<number | null>(null);
const { data: storeData, isLoading, refetch, error } = const { data: storeData, isLoading, refetch, error } =
useStoreWithProducts(storeIdNum); trpc.user.stores.getStoreWithProducts.useQuery(
{ storeId: storeIdNum },
{ enabled: !!storeIdNum }
);
const { data: productsData, isLoading: isProductsLoading } = useAllProducts(); const { data: tagsData, isLoading: isLoadingTags } =
trpc.user.tags.getTagsByStore.useQuery(
const productById = useMemo(() => { { storeId: storeIdNum },
const map = new Map<number, any>(); { enabled: !!storeIdNum }
productsData?.products?.forEach((product) => { );
map.set(product.id, product);
});
return map;
}, [productsData]);
const storeProducts = useMemo(() => {
if (!storeData?.products) return [];
return storeData.products
.map((product) => productById.get(product.id))
.filter(Boolean);
}, [storeData, productById]);
// Filter products based on selected tag // Filter products based on selected tag
const filteredProducts = selectedTagId const filteredProducts = selectedTagId
? storeProducts.filter(product => { ? storeData?.products.filter(product => {
const selectedTag = storeData?.tags.find(t => t.id === selectedTagId); const selectedTag = tagsData?.tags.find(t => t.id === selectedTagId);
return selectedTag?.productIds?.includes(product.id) ?? false; return selectedTag?.productIds?.includes(product.id) ?? false;
}) }) || []
: storeProducts; : storeData?.products || [];
// Set the store header title // Set the store header title
const setStoreHeaderTitle = useStoreHeaderStore((state) => state.setTitle); const setStoreHeaderTitle = useStoreHeaderStore((state) => state.setTitle);
@ -106,12 +98,10 @@ export default function StoreDetail() {
useDrawerTitle(storeData?.store?.name || "Store", [storeData?.store?.name]); useDrawerTitle(storeData?.store?.name || "Store", [storeData?.store?.name]);
if (isLoading || isProductsLoading) { if (isLoading) {
return ( return (
<View style={tw`flex-1 justify-center items-center bg-gray-50`}> <View style={tw`flex-1 justify-center items-center bg-gray-50`}>
<MyText style={tw`text-gray-500 font-medium`}> <MyText style={tw`text-gray-500 font-medium`}>Loading store...</MyText>
{isLoading ? 'Loading store...' : 'Loading products...'}
</MyText>
</View> </View>
); );
} }
@ -194,13 +184,13 @@ export default function StoreDetail() {
)} )}
</View> </View>
{/* Tags Section */} {/* Tags Section */}
{storeData?.tags && storeData.tags.length > 0 && ( {tagsData && tagsData.tags.length > 0 && (
<ScrollView <ScrollView
horizontal horizontal
showsHorizontalScrollIndicator={false} showsHorizontalScrollIndicator={false}
contentContainerStyle={tw`gap-2 mt-6`} contentContainerStyle={tw`gap-2 mt-6`}
> >
{storeData.tags.map((tag) => ( {tagsData.tags.map((tag) => (
<Chip <Chip
key={tag.id} key={tag.id}
tag={tag} tag={tag}
@ -216,7 +206,7 @@ export default function StoreDetail() {
<MaterialIcons name="grid-view" size={20} color="#374151" /> <MaterialIcons name="grid-view" size={20} color="#374151" />
<MyText style={tw`text-lg font-bold text-gray-900 ml-2`}> <MyText style={tw`text-lg font-bold text-gray-900 ml-2`}>
{selectedTagId {selectedTagId
? `${storeData?.tags.find(t => t.id === selectedTagId)?.tagName} items` ? `${tagsData?.tags.find(t => t.id === selectedTagId)?.tagName} items`
: `${filteredProducts.length} products`} : `${filteredProducts.length} products`}
</MyText> </MyText>
</View> </View>

View file

@ -22,7 +22,6 @@ import LocationTestWrapper from "@/components/LocationTestWrapper";
import HealthTestWrapper from "@/components/HealthTestWrapper"; import HealthTestWrapper from "@/components/HealthTestWrapper";
import FirstUserWrapper from "@/components/FirstUserWrapper"; import FirstUserWrapper from "@/components/FirstUserWrapper";
import UpdateChecker from "@/components/UpdateChecker"; import UpdateChecker from "@/components/UpdateChecker";
import CentralStoreInitializer from "@/src/components/CentralStoreInitializer";
import { RefreshProvider } from "../../../packages/ui/src/lib/refresh-context"; import { RefreshProvider } from "../../../packages/ui/src/lib/refresh-context";
import WebViewWrapper from "@/components/WebViewWrapper"; import WebViewWrapper from "@/components/WebViewWrapper";
import BackHandlerWrapper from "@/components/BackHandler"; import BackHandlerWrapper from "@/components/BackHandler";
@ -69,12 +68,10 @@ export default function RootLayout() {
<PaperProvider> <PaperProvider>
<LocationTestWrapper> <LocationTestWrapper>
<RefreshProvider queryClient={queryClient}> <RefreshProvider queryClient={queryClient}>
<CentralStoreInitializer>
<BackHandlerWrapper /> <BackHandlerWrapper />
<Stack screenOptions={{ headerShown: false }} /> <Stack screenOptions={{ headerShown: false }} />
<AddToCartDialog /> <AddToCartDialog />
</CentralStoreInitializer> </RefreshProvider>
</RefreshProvider>
</LocationTestWrapper> </LocationTestWrapper>
</PaperProvider> </PaperProvider>
</NotificationProvider> </NotificationProvider>

View file

@ -2,7 +2,7 @@ import React, { useState, useRef, useEffect } from 'react';
import { View, Dimensions, Image, ScrollView, NativeSyntheticEvent, NativeScrollEvent } from 'react-native'; import { View, Dimensions, Image, ScrollView, NativeSyntheticEvent, NativeScrollEvent } from 'react-native';
import { MyTouchableOpacity, MyText, tw } from 'common-ui'; import { MyTouchableOpacity, MyText, tw } from 'common-ui';
import { useRouter } from 'expo-router'; import { useRouter } from 'expo-router';
import { useBanners } from '@/src/hooks/prominent-api-hooks'; import { trpc } from '@/src/trpc-client';
import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import MaterialIcons from '@expo/vector-icons/MaterialIcons';
const { width: screenWidth } = Dimensions.get('window'); const { width: screenWidth } = Dimensions.get('window');
@ -25,7 +25,7 @@ export default function BannerCarousel() {
const [isAutoPlaying, setIsAutoPlaying] = useState(true); const [isAutoPlaying, setIsAutoPlaying] = useState(true);
// Fetch banners data // Fetch banners data
const { data: bannersData, isLoading, error } = useBanners(); const { data: bannersData, isLoading, error } = trpc.user.banner.getBanners.useQuery();
const banners = bannersData?.banners || []; const banners = bannersData?.banners || [];
@ -123,7 +123,7 @@ export default function BannerCarousel() {
{/* Pagination Dots */} {/* Pagination Dots */}
{banners.length > 1 && ( {banners.length > 1 && (
<View style={tw`flex-row justify-center mt-3`}> <View style={tw`flex-row justify-center mt-3`}>
{banners.map((_: Banner, index: number) => ( {banners.map((_, index: number) => (
<MyTouchableOpacity <MyTouchableOpacity
key={index} key={index}
onPress={() => goToSlide(index)} onPress={() => goToSlide(index)}
@ -140,4 +140,4 @@ export default function BannerCarousel() {
)} )}
</View> </View>
); );
} }

View file

@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { View, ActivityIndicator, Platform } from 'react-native'; import { View, ActivityIndicator, Platform } from 'react-native';
import { tw, theme, MyText, MyTouchableOpacity , BottomDialog } from 'common-ui'; import { tw, theme, MyText, MyTouchableOpacity , BottomDialog } from 'common-ui';
import { trpc, trpcClient } from '@/src/trpc-client'; import { trpc, trpcClient } from '@/src/trpc-client';
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
import Constants from 'expo-constants'; import Constants from 'expo-constants';
import * as Linking from 'expo-linking'; import * as Linking from 'expo-linking';

View file

@ -8,7 +8,7 @@ import dayjs from 'dayjs';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { Image } from 'expo-image'; import { Image } from 'expo-image';
import { orderStatusManipulator } from '@/src/lib/string-manipulators'; import { orderStatusManipulator } from '@/src/lib/string-manipulators';
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
interface OrderItem { interface OrderItem {
productName: string; productName: string;

View file

@ -6,8 +6,6 @@ import MaterialIcons from '@expo/vector-icons/MaterialIcons';
// import RazorpayCheckout from 'react-native-razorpay'; // import RazorpayCheckout from 'react-native-razorpay';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { useCentralProductStore } from '@/src/store/centralProductStore';
import { useCentralSlotStore } from '@/src/store/centralSlotStore';
import { clearLocalCart } from '@/hooks/cart-query-hooks'; import { clearLocalCart } from '@/hooks/cart-query-hooks';
import { useQueryClient } from '@tanstack/react-query'; import { useQueryClient } from '@tanstack/react-query';
import { FontAwesome5, FontAwesome6 } from '@expo/vector-icons'; import { FontAwesome5, FontAwesome6 } from '@expo/vector-icons';
@ -56,19 +54,17 @@ const PaymentAndOrderComponent: React.FC<PaymentAndOrderProps> = ({
queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] }); queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] });
}; };
const products = useCentralProductStore((state) => state.products); const { data: productsData } = trpc.common.product.getAllProductsSummary.useQuery({});
const productsById = useCentralProductStore((state) => state.productsById);
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
// Memoized flash-eligible product IDs // Memoized flash-eligible product IDs
const flashEligibleProductIds = useMemo(() => { const flashEligibleProductIds = useMemo(() => {
if (!products.length) return new Set<number>(); if (!productsData?.products) return new Set<number>();
return new Set( return new Set(
products productsData.products
.filter((product) => productSlotsMap[product.id]?.isFlashAvailable) .filter((product: any) => product.isFlashAvailable)
.map((product) => product.id) .map((product: any) => product.id)
); );
}, [products, productSlotsMap]); }, [productsData]);
const placeOrderMutation = trpc.user.order.placeOrder.useMutation({ const placeOrderMutation = trpc.user.order.placeOrder.useMutation({
onSuccess: (data) => { onSuccess: (data) => {
@ -130,7 +126,7 @@ const PaymentAndOrderComponent: React.FC<PaymentAndOrderProps> = ({
const availableItems = cartItems const availableItems = cartItems
.filter(item => { .filter(item => {
if (productSlotsMap[item.productId]?.isOutOfStock) return false; if (item.product?.isOutOfStock) return false;
// For flash delivery, check if product supports flash delivery // For flash delivery, check if product supports flash delivery
if (isFlashDelivery) { if (isFlashDelivery) {
return flashEligibleProductIds.has(item.productId); return flashEligibleProductIds.has(item.productId);

View file

@ -1,5 +1,5 @@
import React from 'react'; import React, { useMemo } from 'react';
import { View, Alert, ActivityIndicator } from 'react-native'; import { View, Alert, TouchableOpacity, Text } from 'react-native';
import { Image } from 'expo-image'; import { Image } from 'expo-image';
import { tw, theme, MyText, MyTouchableOpacity, Quantifier, MiniQuantifier } from 'common-ui'; import { tw, theme, MyText, MyTouchableOpacity, Quantifier, MiniQuantifier } from 'common-ui';
import CartIcon from '@/components/icons/CartIcon'; import CartIcon from '@/components/icons/CartIcon';
@ -14,7 +14,7 @@ import {
} from '@/hooks/cart-query-hooks'; } from '@/hooks/cart-query-hooks';
import { useProductSlotIdentifier } from '@/hooks/useProductSlotIdentifier'; import { useProductSlotIdentifier } from '@/hooks/useProductSlotIdentifier';
import { useCartStore } from '@/src/store/cartStore'; import { useCartStore } from '@/src/store/cartStore';
import { useCentralSlotStore } from '@/src/store/centralSlotStore'; import { trpc } from '@/src/trpc-client';
import { Image as RnImage } from 'react-native' import { Image as RnImage } from 'react-native'
@ -46,18 +46,6 @@ const ProductCard: React.FC<ProductCardProps> = ({
containerComp: ContainerComp = React.Fragment, containerComp: ContainerComp = React.Fragment,
useAddToCartDialog = false, useAddToCartDialog = false,
}) => { }) => {
const imageUri = item.images?.[0]
const [imageStatus, setImageStatus] = React.useState<'loading' | 'loaded' | 'error'>('loading')
const [imageError, setImageError] = React.useState<string | null>(null)
const [updater, setUpdater] = React.useState(0)
React.useEffect(() => {
const intervalId = setInterval(() => {
setUpdater(prev => prev + 1)
}, 5000)
return () => clearInterval(intervalId)
}, [])
const { data: cartData } = useGetCart(); const { data: cartData } = useGetCart();
const { getQuickestSlot } = useProductSlotIdentifier(); const { getQuickestSlot } = useProductSlotIdentifier();
const { setAddedToCartProduct } = useCartStore(); const { setAddedToCartProduct } = useCartStore();
@ -81,41 +69,25 @@ const ProductCard: React.FC<ProductCardProps> = ({
const cartItem = cartData?.items?.find((cartItem: any) => cartItem.productId === item.id); const cartItem = cartData?.items?.find((cartItem: any) => cartItem.productId === item.id);
const quantity = cartItem?.quantity || 0; const quantity = cartItem?.quantity || 0;
// Get slots data from central store // Query all slots with products
const slots = useCentralSlotStore((state) => state.slots); const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery();
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
// Create slot lookup map // Create slot lookup map
const slotMap = React.useMemo(() => { const slotMap = useMemo(() => {
const map: Record<number, any> = {}; const map: Record<number, any> = {};
slots?.forEach((slot: any) => { slotsData?.slots?.forEach((slot: any) => {
map[slot.id] = slot; map[slot.id] = slot;
}); });
return map; return map;
}, [slots]); }, [slotsData]);
// Get cart item's slot delivery time if item is in cart // Get cart item's slot delivery time if item is in cart
const cartSlot = cartItem?.slotId ? slotMap[cartItem.slotId] : null; const cartSlot = cartItem?.slotId ? slotMap[cartItem.slotId] : null;
const displayDeliveryDate = cartSlot?.deliveryTime || item.nextDeliveryDate; const displayDeliveryDate = cartSlot?.deliveryTime || item.nextDeliveryDate;
React.useEffect(() => {
if (imageUri) {
setImageStatus('loading')
setImageError(null)
return
}
setImageStatus('error')
setImageError('No image available')
}, [imageUri])
// Precompute the next slot and determine display out of stock status // Precompute the next slot and determine display out of stock status
const slotId = getQuickestSlot(item.id); const slotId = getQuickestSlot(item.id);
const displayIsOutOfStock = item.isOutOfStock || !slotId;
// Use isOutOfStock from productSlotsMap (all products now included)
const productSlotInfo = productSlotsMap[item.id];
const isOutOfStockFromSlots = productSlotInfo?.isOutOfStock;
const displayIsOutOfStock = isOutOfStockFromSlots || !slotId;
// if(item.name.startsWith('Mutton Curry Cut')) { // if(item.name.startsWith('Mutton Curry Cut')) {
// console.log({slotId, displayIsOutOfStock}) // console.log({slotId, displayIsOutOfStock})
@ -147,7 +119,6 @@ const ProductCard: React.FC<ProductCardProps> = ({
} }
}; };
// console.log('rendering the product cart for id', item.id)
return ( return (
<ContainerComp> <ContainerComp>
<MyTouchableOpacity <MyTouchableOpacity
@ -160,32 +131,9 @@ const ProductCard: React.FC<ProductCardProps> = ({
> >
<View style={tw`relative`}> <View style={tw`relative`}>
<RnImage <RnImage
source={{ uri: imageUri }} source={{ uri: item.images?.[0] }}
// source={{uri: 'https://pub-6bf1fbc4048a4cbaa533ddbb13bf9de6.r2.dev/product-images/1763796113884-0'}}
style={{ width: "100%", height: itemWidth, resizeMode: "cover" }} style={{ width: "100%", height: itemWidth, resizeMode: "cover" }}
onLoadStart={() => {
setImageStatus('loading')
setImageError(null)
}}
// onLoadEnd={() => {
// setImageError('loading stopped indefinitely')
//
// }}
onLoad={() => setImageStatus('loaded')}
onError={(event) => {
setImageStatus('error')
setImageError( 'Image failed to load')
}}
/> />
{imageStatus === 'error' && (
<View style={tw`absolute inset-0 items-center justify-center bg-gray-100`}>
<MaterialIcons name="broken-image" size={22} color="#94A3B8" />
<MyText style={tw`text-[10px] text-gray-500 mt-1`}>
{imageError || 'Image failed to load'}
</MyText>
</View>
)}
{displayIsOutOfStock && ( {displayIsOutOfStock && (
<View style={tw`absolute inset-0 bg-black/40 items-center justify-center`}> <View style={tw`absolute inset-0 bg-black/40 items-center justify-center`}>
<View style={tw`bg-red-500 px-3 py-1 rounded-full`}> <View style={tw`bg-red-500 px-3 py-1 rounded-full`}>

View file

@ -12,11 +12,9 @@ import { trpc, trpcClient } from '@/src/trpc-client';
import { useAddToCart, useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks'; import { useAddToCart, useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks';
import { useProductSlotIdentifier } from '@/hooks/useProductSlotIdentifier'; import { useProductSlotIdentifier } from '@/hooks/useProductSlotIdentifier';
import { useFlashNavigationStore } from '@/components/stores/flashNavigationStore'; import { useFlashNavigationStore } from '@/components/stores/flashNavigationStore';
import { useSlots } from '@/src/hooks/prominent-api-hooks';
import FloatingCartBar from './floating-cart-bar'; import FloatingCartBar from './floating-cart-bar';
import { useStoreHeaderStore } from '@/src/store/storeHeaderStore'; import { useStoreHeaderStore } from '@/src/store/storeHeaderStore';
import { useCartStore } from '@/src/store/cartStore'; import { useCartStore } from '@/src/store/cartStore';
import { useCentralSlotStore } from '@/src/store/centralSlotStore';
const { width: screenWidth } = Dimensions.get("window"); const { width: screenWidth } = Dimensions.get("window");
const carouselWidth = screenWidth; const carouselWidth = screenWidth;
@ -59,28 +57,15 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
const { getQuickestSlot } = useProductSlotIdentifier(); const { getQuickestSlot } = useProductSlotIdentifier();
const { setShouldNavigateToCart } = useFlashNavigationStore(); const { setShouldNavigateToCart } = useFlashNavigationStore();
const { setAddedToCartProduct } = useCartStore(); const { setAddedToCartProduct } = useCartStore();
const { data: slotsData } = useSlots();
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
const productAvailability = useMemo(() => {
if (!productDetail) return null;
return productSlotsMap[productDetail.id];
}, [productDetail, productSlotsMap]);
const sortedDeliverySlots = useMemo(() => { const sortedDeliverySlots = useMemo(() => {
if (!slotsData?.slots || !productDetail) return [] if (!productDetail?.deliverySlots) return []
return [...productDetail.deliverySlots].sort((a, b) => {
// Filter slots that contain this product
const productSlots = slotsData.slots.filter((slot: any) =>
slot.products?.some((p: any) => p.id === productDetail.id)
)
return productSlots.sort((a: any, b: any) => {
const deliveryDiff = new Date(a.deliveryTime).getTime() - new Date(b.deliveryTime).getTime() const deliveryDiff = new Date(a.deliveryTime).getTime() - new Date(b.deliveryTime).getTime()
if (deliveryDiff !== 0) return deliveryDiff if (deliveryDiff !== 0) return deliveryDiff
return new Date(a.freezeTime).getTime() - new Date(b.freezeTime).getTime() return new Date(a.freezeTime).getTime() - new Date(b.freezeTime).getTime()
}) })
}, [slotsData, productDetail]) }, [productDetail?.deliverySlots])
// Find current quantity from cart data // Find current quantity from cart data
const cartItem = productDetail ? cartData?.data?.items?.find((item: any) => item.productId === productDetail.id) : null; const cartItem = productDetail ? cartData?.data?.items?.find((item: any) => item.productId === productDetail.id) : null;
@ -109,7 +94,7 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
const handleAddToCart = (productId: number) => { const handleAddToCart = (productId: number) => {
if (isFlashDelivery) { if (isFlashDelivery) {
if (!productAvailability?.isFlashAvailable) { if (!productDetail?.isFlashAvailable) {
Alert.alert("Error", "This product is not available for flash delivery"); Alert.alert("Error", "This product is not available for flash delivery");
return; return;
} }
@ -128,7 +113,7 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
const handleBuyNow = (productId: number) => { const handleBuyNow = (productId: number) => {
if (isFlashDelivery) { if (isFlashDelivery) {
if (!productAvailability?.isFlashAvailable) { if (!productDetail?.isFlashAvailable) {
Alert.alert("Error", "This product is not available for flash delivery"); Alert.alert("Error", "This product is not available for flash delivery");
return; return;
} }
@ -256,13 +241,13 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
<View style={tw`flex-row justify-between items-start mb-2`}> <View style={tw`flex-row justify-between items-start mb-2`}>
<MyText style={tw`text-2xl font-bold text-gray-900 flex-1 mr-2`}>{productDetail.name}</MyText> <MyText style={tw`text-2xl font-bold text-gray-900 flex-1 mr-2`}>{productDetail.name}</MyText>
<View style={tw`flex-row gap-2`}> <View style={tw`flex-row gap-2`}>
{productAvailability?.isFlashAvailable && ( {productDetail.isFlashAvailable && (
<View style={tw`bg-pink-100 px-3 py-1 rounded-full flex-row items-center`}> <View style={tw`bg-pink-100 px-3 py-1 rounded-full flex-row items-center`}>
<MaterialIcons name="bolt" size={12} color="#EC4899" style={tw`mr-1`} /> <MaterialIcons name="bolt" size={12} color="#EC4899" style={tw`mr-1`} />
<MyText style={tw`text-pink-700 text-xs font-bold`}>1 Hr Delivery</MyText> <MyText style={tw`text-pink-700 text-xs font-bold`}>1 Hr Delivery</MyText>
</View> </View>
)} )}
{productAvailability?.isOutOfStock && ( {productDetail.isOutOfStock && (
<View style={tw`bg-red-100 px-3 py-1 rounded-full`}> <View style={tw`bg-red-100 px-3 py-1 rounded-full`}>
<MyText style={tw`text-red-700 text-xs font-bold`}>Out of Stock</MyText> <MyText style={tw`text-red-700 text-xs font-bold`}>Out of Stock</MyText>
</View> </View>
@ -292,7 +277,7 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
</View> </View>
{/* Flash price on separate line - smaller and less prominent */} {/* Flash price on separate line - smaller and less prominent */}
{productAvailability?.isFlashAvailable && productDetail.flashPrice && productDetail.flashPrice !== productDetail.price && ( {productDetail.isFlashAvailable && productDetail.flashPrice && productDetail.flashPrice !== productDetail.price && (
<View style={tw`mt-1`}> <View style={tw`mt-1`}>
<MyText style={tw`text-pink-600 text-lg font-bold`}> <MyText style={tw`text-pink-600 text-lg font-bold`}>
1 Hr Delivery: {productDetail.flashPrice} / {formatQuantity(productDetail.productQuantity || 1, productDetail.unitNotation).display} 1 Hr Delivery: {productDetail.flashPrice} / {formatQuantity(productDetail.productQuantity || 1, productDetail.unitNotation).display}
@ -319,11 +304,11 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
// Show "Add to Cart" button when not in cart // Show "Add to Cart" button when not in cart
<MyTouchableOpacity <MyTouchableOpacity
style={[tw`flex-1 py-3.5 rounded-xl items-center border`, { style={[tw`flex-1 py-3.5 rounded-xl items-center border`, {
borderColor: (productAvailability?.isOutOfStock || (isFlashDelivery && !productAvailability?.isFlashAvailable)) ? '#9ca3af' : theme.colors.brand500, borderColor: (productDetail.isOutOfStock || (isFlashDelivery && !productDetail.isFlashAvailable)) ? '#9ca3af' : theme.colors.brand500,
backgroundColor: 'white' backgroundColor: 'white'
}]} }]}
onPress={() => { onPress={() => {
if (productAvailability?.isOutOfStock || (isFlashDelivery && !productAvailability?.isFlashAvailable)) { if (productDetail.isOutOfStock || (isFlashDelivery && !productDetail.isFlashAvailable)) {
return; return;
} }
if (isFlashDelivery) { if (isFlashDelivery) {
@ -334,10 +319,10 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
setAddedToCartProduct({ productId: productDetail.id, product: productDetail }); setAddedToCartProduct({ productId: productDetail.id, product: productDetail });
} }
}} }}
disabled={productAvailability?.isOutOfStock || (isFlashDelivery && !productAvailability?.isFlashAvailable)} disabled={productDetail.isOutOfStock || (isFlashDelivery && !productDetail.isFlashAvailable)}
> >
<MyText style={[tw`font-bold text-base`, { color: (productAvailability?.isOutOfStock || (isFlashDelivery && !productAvailability?.isFlashAvailable)) ? '#9ca3af' : theme.colors.brand500 }]}> <MyText style={[tw`font-bold text-base`, { color: (productDetail.isOutOfStock || (isFlashDelivery && !productDetail.isFlashAvailable)) ? '#9ca3af' : theme.colors.brand500 }]}>
{(productAvailability?.isOutOfStock || (isFlashDelivery && !productAvailability?.isFlashAvailable)) ? 'Unavailable' : 'Add to Cart'} {(productDetail.isOutOfStock || (isFlashDelivery && !productDetail.isFlashAvailable)) ? 'Unavailable' : 'Add to Cart'}
</MyText> </MyText>
</MyTouchableOpacity> </MyTouchableOpacity>
)} )}
@ -345,26 +330,26 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
{isFlashDelivery ? ( {isFlashDelivery ? (
<MyTouchableOpacity <MyTouchableOpacity
style={[tw`flex-1 py-3.5 rounded-xl items-center shadow-md`, { style={[tw`flex-1 py-3.5 rounded-xl items-center shadow-md`, {
backgroundColor: (productAvailability?.isOutOfStock || !productAvailability?.isFlashAvailable) ? '#9ca3af' : '#FDF2F8' backgroundColor: (productDetail.isOutOfStock || !productDetail.isFlashAvailable) ? '#9ca3af' : '#FDF2F8'
}]} }]}
onPress={() => !(productAvailability?.isOutOfStock || !productAvailability?.isFlashAvailable) && handleBuyNow(productDetail.id)} onPress={() => !(productDetail.isOutOfStock || !productDetail.isFlashAvailable) && handleBuyNow(productDetail.id)}
disabled={productAvailability?.isOutOfStock || !productAvailability?.isFlashAvailable} disabled={productDetail.isOutOfStock || !productDetail.isFlashAvailable}
> >
<MyText style={tw`text-base font-bold ${productAvailability?.isOutOfStock || !productAvailability?.isFlashAvailable ? 'text-gray-400' : 'text-pink-600'}`}> <MyText style={tw`text-base font-bold ${productDetail.isOutOfStock || !productDetail.isFlashAvailable ? 'text-gray-400' : 'text-pink-600'}`}>
{productAvailability?.isOutOfStock ? 'Out of Stock' : {productDetail.isOutOfStock ? 'Out of Stock' :
(!productAvailability?.isFlashAvailable ? 'Not Flash Eligible' : 'Get in 1 Hour')} (!productDetail.isFlashAvailable ? 'Not Flash Eligible' : 'Get in 1 Hour')}
</MyText> </MyText>
</MyTouchableOpacity> </MyTouchableOpacity>
) : productAvailability?.isFlashAvailable ? ( ) : productDetail.isFlashAvailable ? (
<MyTouchableOpacity <MyTouchableOpacity
style={[tw`flex-1 py-3.5 rounded-xl items-center shadow-md`, { style={[tw`flex-1 py-3.5 rounded-xl items-center shadow-md`, {
backgroundColor: sortedDeliverySlots.length === 0 ? '#9ca3af' : '#FDF2F8' backgroundColor: productDetail.deliverySlots.length === 0 ? '#9ca3af' : '#FDF2F8'
}]} }]}
onPress={() => sortedDeliverySlots.length > 0 && handleBuyNow(productDetail.id)} onPress={() => productDetail.deliverySlots.length > 0 && handleBuyNow(productDetail.id)}
disabled={sortedDeliverySlots.length === 0} disabled={productDetail.deliverySlots.length === 0}
> >
<MyText style={tw`text-base font-bold ${sortedDeliverySlots.length === 0 ? 'text-gray-400' : 'text-pink-600'}`}> <MyText style={tw`text-base font-bold ${productDetail.deliverySlots.length === 0 ? 'text-gray-400' : 'text-pink-600'}`}>
{sortedDeliverySlots.length === 0 ? 'No Slots' : 'Get in 1 Hour'} {productDetail.deliverySlots.length === 0 ? 'No Slots' : 'Get in 1 Hour'}
</MyText> </MyText>
</MyTouchableOpacity> </MyTouchableOpacity>
) : ( ) : (
@ -393,7 +378,7 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
key={index} key={index}
style={tw`flex-row items-start mb-4 bg-gray-50 p-3 rounded-xl border border-gray-100`} style={tw`flex-row items-start mb-4 bg-gray-50 p-3 rounded-xl border border-gray-100`}
onPress={() => handleSlotAddToCart(productDetail.id, slot.id)} onPress={() => handleSlotAddToCart(productDetail.id, slot.id)}
disabled={productAvailability?.isOutOfStock} disabled={productDetail.isOutOfStock}
activeOpacity={0.7} activeOpacity={0.7}
> >
<MaterialIcons name="local-shipping" size={20} color="#3B82F6" style={tw`mt-0.5`} /> <MaterialIcons name="local-shipping" size={20} color="#3B82F6" style={tw`mt-0.5`} />
@ -605,7 +590,7 @@ const ProductDetail: React.FC<ProductDetailProps> = ({ productId, isFlashDeliver
key={index} key={index}
style={tw`flex-row items-start mb-4 bg-gray-50 p-4 rounded-xl border border-gray-100`} style={tw`flex-row items-start mb-4 bg-gray-50 p-4 rounded-xl border border-gray-100`}
onPress={() => handleSlotAddToCart(productDetail.id, slot.id)} onPress={() => handleSlotAddToCart(productDetail.id, slot.id)}
disabled={productAvailability?.isOutOfStock} disabled={productDetail.isOutOfStock}
activeOpacity={0.7} activeOpacity={0.7}
> >
<MaterialIcons name="local-shipping" size={20} color="#3B82F6" style={tw`mt-0.5`} /> <MaterialIcons name="local-shipping" size={20} color="#3B82F6" style={tw`mt-0.5`} />
@ -812,4 +797,4 @@ const ReviewForm = ({ productId, onReviewSubmitted }: ReviewFormProps) => {
); );
}; };
export default ProductDetail; export default ProductDetail;

View file

@ -6,7 +6,6 @@ import { BottomDialog, MyTouchableOpacity, MyText, tw, theme } from 'common-ui';
import { useAuth } from '@/src/contexts/AuthContext'; import { useAuth } from '@/src/contexts/AuthContext';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { useAddressStore } from '@/src/store/addressStore'; import { useAddressStore } from '@/src/store/addressStore';
import { useSlots } from '@/src/hooks/prominent-api-hooks';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
interface QuickDeliveryAddressSelectorProps { interface QuickDeliveryAddressSelectorProps {
@ -32,13 +31,13 @@ const QuickDeliveryAddressSelector: React.FC<QuickDeliveryAddressSelectorProps>
const { data: addressesData } = trpc.user.address.getUserAddresses.useQuery(undefined, { const { data: addressesData } = trpc.user.address.getUserAddresses.useQuery(undefined, {
enabled: isAuthenticated, enabled: isAuthenticated,
}); });
const { data: slotsData } = useSlots(); const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery();
const defaultAddress = defaultAddressData?.data; const defaultAddress = defaultAddressData?.data;
const addresses = addressesData?.data || []; const addresses = addressesData?.data || [];
// Format time range helper // Format time range helper
const formatTimeRange = (deliveryTime: string | Date) => { const formatTimeRange = (deliveryTime: string) => {
const time = dayjs(deliveryTime); const time = dayjs(deliveryTime);
const endTime = time.add(1, 'hour'); const endTime = time.add(1, 'hour');
const startPeriod = time.format('A'); const startPeriod = time.format('A');
@ -277,4 +276,4 @@ const QuickDeliveryAddressSelector: React.FC<QuickDeliveryAddressSelectorProps>
); );
}; };
export default QuickDeliveryAddressSelector; export default QuickDeliveryAddressSelector;

View file

@ -7,11 +7,7 @@ import { useRouter, usePathname } from 'expo-router';
import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import { tw, theme, MyText, MyTouchableOpacity, MyFlatList, AppContainer, MiniQuantifier } from 'common-ui'; import { tw, theme, MyText, MyTouchableOpacity, MyFlatList, AppContainer, MiniQuantifier } from 'common-ui';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { useAllProducts, useStores, useSlots } from '@/src/hooks/prominent-api-hooks';
import { AllProductsApiType } from '@backend/trpc/router';
import { useQuickDeliveryStore } from '@/src/store/quickDeliveryStore'; import { useQuickDeliveryStore } from '@/src/store/quickDeliveryStore';
import { useCentralSlotStore } from '@/src/store/centralSlotStore';
import { useCentralProductStore } from '@/src/store/centralProductStore';
import { useAddToCart, useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks'; import { useAddToCart, useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks';
import { useHideTabNav } from '@/src/hooks/useHideTabNav'; import { useHideTabNav } from '@/src/hooks/useHideTabNav';
import CartIcon from '@/components/icons/CartIcon'; import CartIcon from '@/components/icons/CartIcon';
@ -36,7 +32,7 @@ interface SlotLayoutProps {
function CustomDrawerContent(baseUrl: string, drawerProps: DrawerContentComponentProps, slotIdParent?: number, storeIdParent?: number) { function CustomDrawerContent(baseUrl: string, drawerProps: DrawerContentComponentProps, slotIdParent?: number, storeIdParent?: number) {
const router = useRouter(); const router = useRouter();
const pathname = usePathname(); const pathname = usePathname();
const { data: storesData } = useStores(); const { data: storesData } = trpc.user.stores.getStores.useQuery();
const setStoreId = useSlotStore(state => state.setStoreId); const setStoreId = useSlotStore(state => state.setStoreId);
const { slotId, storeId } = useSlotStore(); const { slotId, storeId } = useSlotStore();
@ -183,10 +179,17 @@ export function SlotLayout({ slotId, storeId, baseUrl, isForFlashDelivery }: Slo
router.replace(`${baseUrl}?slotId=${newSlotId}` as any); router.replace(`${baseUrl}?slotId=${newSlotId}` as any);
}; };
const slotQuery = slotId
? trpc.user.slots.getSlotById.useQuery({ slotId: Number(slotId) })
: trpc.user.slots.nextMajorDelivery.useQuery();
const deliveryTime = dayjs(slotQuery.data?.deliveryTime).format('DD MMM hh:mm A');
return ( return (
<> <>
<View style={tw` w-full flex-row bg-white px-4 py-2 mb-1`}> <View style={tw` w-full flex-row bg-white px-4 py-2 mb-1`}>
<QuickDeliveryAddressSelector <QuickDeliveryAddressSelector
deliveryTime={deliveryTime}
slotId={Number(slotId)} slotId={Number(slotId)}
onSlotChange={handleSlotChange} onSlotChange={handleSlotChange}
isForFlashDelivery={isForFlashDelivery} isForFlashDelivery={isForFlashDelivery}
@ -240,7 +243,6 @@ const CompactProductCard = ({
// Cart management for miniView // Cart management for miniView
const { data: cartData } = useGetCart({}, cartType); const { data: cartData } = useGetCart({}, cartType);
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
const updateCartItem = useUpdateCartItem({ const updateCartItem = useUpdateCartItem({
showSuccessAlert: false, showSuccessAlert: false,
showErrorAlert: false, showErrorAlert: false,
@ -254,7 +256,6 @@ const CompactProductCard = ({
const cartItem = cartData?.items?.find((cartItem: any) => cartItem.productId === item.id); const cartItem = cartData?.items?.find((cartItem: any) => cartItem.productId === item.id);
const quantity = cartItem?.quantity || 0; const quantity = cartItem?.quantity || 0;
const isOutOfStock = productSlotsMap[item.id]?.isOutOfStock;
const handleQuantityChange = (newQuantity: number) => { const handleQuantityChange = (newQuantity: number) => {
if (newQuantity === 0 && cartItem) { if (newQuantity === 0 && cartItem) {
@ -280,7 +281,7 @@ const CompactProductCard = ({
source={{ uri: item.images?.[0] }} source={{ uri: item.images?.[0] }}
style={{ width: "100%", height: itemWidth, resizeMode: "cover" }} style={{ width: "100%", height: itemWidth, resizeMode: "cover" }}
/> />
{isOutOfStock && ( {item.isOutOfStock && (
<View style={tw`absolute inset-0 bg-black/30 items-center justify-center`}> <View style={tw`absolute inset-0 bg-black/30 items-center justify-center`}>
<MyText style={tw`text-white text-xs font-bold`}>Out of Stock</MyText> <MyText style={tw`text-white text-xs font-bold`}>Out of Stock</MyText>
</View> </View>
@ -339,20 +340,22 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU
const slotId = slotIdParent; const slotId = slotIdParent;
const storeId = storeIdParent; const storeId = storeIdParent;
const storeIdNum = storeId; const storeIdNum = storeId;
// const { storeId, slotId: slotIdRaw } = useLocalSearchParams();
// const slotId = Number(slotIdRaw);
const { data: slotsData, isLoading: slotsLoading, error: slotsError } = useSlots();
const { productsById } = useCentralProductStore();
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
// Find the specific slot from cached data // const storeIdNum = storeId ? Number(storeId) : undefined;
const slot = slotsData?.slots?.find(s => s.id === slotId);
const slotQuery = trpc.user.slots.getSlotById.useQuery({ slotId: slotId! }, { enabled: !!slotId });
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") || {};
const handleAddToCart = (productId: number) => { const handleAddToCart = (productId: number) => {
setIsLoadingDialogOpen(true); setIsLoadingDialogOpen(true);
const item = filteredProducts.find((p) => p.id === productId); const item = filteredProducts.find((p: any) => p.id === productId);
const deliveryTime = slot?.deliveryTime ? dayjs(slot.deliveryTime).format('ddd, DD MMM • h:mm A') : ''; const deliveryTime = slotQuery.data?.deliveryTime ? dayjs(slotQuery.data.deliveryTime).format('ddd, DD MMM • h:mm A') : '';
addToCart(productId, 1, slotId || 0, () => { addToCart(productId, 1, slotId || 0, () => {
setIsLoadingDialogOpen(false); setIsLoadingDialogOpen(false);
if (item) { if (item) {
@ -361,7 +364,7 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU
}); });
}; };
if (slotsLoading) { if (slotQuery.isLoading || (storeIdNum && productsQuery?.isLoading)) {
return ( return (
<AppContainer> <AppContainer>
<View style={tw`flex-1 justify-center items-center bg-gray-50`}> <View style={tw`flex-1 justify-center items-center bg-gray-50`}>
@ -371,7 +374,7 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU
); );
} }
if (slotsError) { if (slotQuery.error || (storeIdNum && productsQuery?.error)) {
return ( return (
<AppContainer> <AppContainer>
<View style={tw`flex-1 justify-center items-center bg-gray-50`}> <View style={tw`flex-1 justify-center items-center bg-gray-50`}>
@ -383,7 +386,7 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU
); );
} }
if (!slot) { if (!slotQuery.data) {
return ( return (
<AppContainer> <AppContainer>
<View style={tw`flex-1 justify-center items-center`}> <View style={tw`flex-1 justify-center items-center`}>
@ -394,16 +397,14 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU
); );
} }
// Get product details from central store using slot product IDs // Create a Set of product IDs from slot data for O(1) lookup
// Filter: 1) Must exist in productsById, 2) Must not be out of stock (from slots data) const slotProductIds = new Set(slotQuery.data.products?.map((p: any) => p.id) || []);
const slotProducts = slot.products
?.map(p => productsById[p.id])
?.filter((product): product is NonNullable<typeof product> => product !== null && product !== undefined)
?.filter(product => !productSlotsMap[product.id]?.isOutOfStock) || [];
const filteredProducts = storeIdNum const filteredProducts: any[] = storeIdNum
? slotProducts.filter(p => p.storeId === storeIdNum) ? productsQuery?.data?.products?.filter(p =>
: slotProducts; p.storeId === storeIdNum && slotProductIds.has(p.id)
) || []
: slotQuery.data.products;
return ( return (
<View testID="slot-detail-page" style={tw`flex-1`}> <View testID="slot-detail-page" style={tw`flex-1`}>
@ -421,7 +422,7 @@ export function SlotProducts({ slotId:slotIdParent, storeId:storeIdParent, baseU
keyExtractor={(item, index) => index.toString()} keyExtractor={(item, index) => index.toString()}
columnWrapperStyle={{ gap: 16, justifyContent: 'flex-start' }} columnWrapperStyle={{ gap: 16, justifyContent: 'flex-start' }}
contentContainerStyle={[tw`pb-24 px-4`, { gap: 16 }]} contentContainerStyle={[tw`pb-24 px-4`, { gap: 16 }]}
onRefresh={() => {}} onRefresh={() => slotQuery.refetch()}
ListEmptyComponent={ ListEmptyComponent={
storeIdNum ? ( storeIdNum ? (
<View style={tw`items-center justify-center py-10`}> <View style={tw`items-center justify-center py-10`}>
@ -447,8 +448,7 @@ export function FlashDeliveryProducts({ storeId:storeIdParent, baseUrl, onProduc
const storeId = storeIdParent; const storeId = storeIdParent;
const storeIdNum = storeId; const storeIdNum = storeId;
const productsQuery = useAllProducts(); const productsQuery = trpc.common.product.getAllProductsSummary.useQuery({});
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
const { addToCart = () => { } } = useAddToCart({ showSuccessAlert: false, showErrorAlert: false, refetchCart: true }, "flash") || {}; const { addToCart = () => { } } = useAddToCart({ showSuccessAlert: false, showErrorAlert: false, refetchCart: true }, "flash") || {};
@ -486,22 +486,20 @@ export function FlashDeliveryProducts({ storeId:storeIdParent, baseUrl, onProduc
} }
// Filter products to only include those eligible for flash delivery // Filter products to only include those eligible for flash delivery
let flashProducts: AllProductsApiType['products'][number][] = []; 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?.products?.filter(p => { flashProducts = productsQuery?.data?.products?.filter(p =>
const productInfo = productSlotsMap[p.id]; p.storeId === storeIdNum &&
return p.storeId === storeIdNum && p.isFlashAvailable &&
productInfo?.isFlashAvailable && !p.isOutOfStock
!productInfo?.isOutOfStock; ) || [];
}) || [];
} else { } else {
// Show all flash-available products that are in stock // Show all flash-available products that are in stock
flashProducts = productsQuery?.data?.products?.filter(p => { flashProducts = productsQuery?.data?.products?.filter(p =>
const productInfo = productSlotsMap[p.id]; p.isFlashAvailable &&
return productInfo?.isFlashAvailable && !p.isOutOfStock
!productInfo?.isOutOfStock; ) || [];
}) || [];
} }
return ( return (

View file

@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { View, ActivityIndicator } from 'react-native'; import { View, ActivityIndicator } from 'react-native';
import { WebView } from 'react-native-webview'; import { WebView } from 'react-native-webview';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
import { theme, MyText, MyTouchableOpacity } from 'common-ui'; import { theme, MyText, MyTouchableOpacity } from 'common-ui';
import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import MaterialIcons from '@expo/vector-icons/MaterialIcons';

View file

@ -24,10 +24,8 @@ import TestingPhaseNote from "@/components/TestingPhaseNote";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { trpc } from "@/src/trpc-client"; import { trpc } from "@/src/trpc-client";
import { useCentralProductStore } from '@/src/store/centralProductStore';
import { useCentralSlotStore } from '@/src/store/centralSlotStore';
import { useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks'; import { useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks';
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
interface CartPageProps { interface CartPageProps {
isFlashDelivery?: boolean; isFlashDelivery?: boolean;
@ -82,34 +80,33 @@ 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 products = useCentralProductStore((state) => state.products); const { data: productsData } = trpc.common.product.getAllProductsSummary.useQuery({});
const productsById = useCentralProductStore((state) => state.productsById);
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
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 (!products.length) return new Set<number>(); if (!productsData?.products) return new Set<number>();
return new Set( return new Set(
products productsData.products
.filter((product) => productSlotsMap[product.id]?.isFlashAvailable) .filter((product: any) => product.isFlashAvailable)
.map((product) => product.id) .map((product: any) => product.id)
); );
}, [products, productSlotsMap]); }, [productsData]);
// Base total price without discounts for coupon eligibility check // Base total price without discounts for coupon eligibility check
const baseTotalPrice = useMemo( const baseTotalPrice = useMemo(
() => () =>
cartItems cartItems
.filter((item) => !productSlotsMap[item.productId]?.isOutOfStock) .filter((item) => !item.product?.isOutOfStock)
.reduce((sum, item) => { .reduce(
const product = productsById[item.productId]; (sum, item) =>
const price = product?.price || 0; sum +
return sum + price * (quantities[item.id] || item.quantity); (item.product?.price || 0) * (quantities[item.id] || item.quantity),
}, 0), 0
[cartItems, quantities, productsById] ),
[cartItems, quantities]
); );
const eligibleCoupons = useMemo(() => { const eligibleCoupons = useMemo(() => {
@ -202,14 +199,13 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
[eligibleCoupons, selectedCouponId] [eligibleCoupons, selectedCouponId]
); );
const totalPrice = cartItems const totalPrice = cartItems
.filter((item) => !productSlotsMap[item.productId]?.isOutOfStock) .filter((item) => !item.product?.isOutOfStock)
.reduce((sum, item) => { .reduce((sum, item) => {
const product = productsById[item.productId]; const quantity = quantities[item.id] || item.quantity;
const quantity = quantities[item.id] || item.quantity; const price = isFlashDelivery ? (item.product?.flashPrice ?? item.product?.price ?? 0) : (item.product?.price || 0);
const price = isFlashDelivery ? (product?.flashPrice ?? product?.price ?? 0) : (product?.price || 0); return sum + price * quantity;
return sum + price * quantity; }, 0);
}, 0);
const dropdownData = useMemo( const dropdownData = useMemo(
() => () =>
eligibleCoupons?.map((coupon) => { eligibleCoupons?.map((coupon) => {
@ -277,7 +273,7 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
const finalTotalWithDelivery = finalTotal + deliveryCharge; const finalTotalWithDelivery = finalTotal + deliveryCharge;
const hasAvailableItems = cartItems.some(item => !productSlotsMap[item.productId]?.isOutOfStock); const hasAvailableItems = cartItems.some(item => !item.product?.isOutOfStock);
useEffect(() => { useEffect(() => {
const initial: Record<number, number> = {}; const initial: Record<number, number> = {};
@ -414,12 +410,10 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
const productSlots = getAvailableSlotsForProduct(item.productId); const productSlots = getAvailableSlotsForProduct(item.productId);
const selectedSlotForItem = selectedSlots[item.id]; const selectedSlotForItem = selectedSlots[item.id];
const isFlashEligible = isFlashDelivery ? flashEligibleProductIds.has(item.productId) : true; const isFlashEligible = isFlashDelivery ? flashEligibleProductIds.has(item.productId) : true;
const product = productsById[item.productId];
const productSlotInfo = productSlotsMap[item.productId];
// const isAvailable = (productSlots.length > 0 || isFlashDelivery) && !item.product?.isOutOfStock && isFlashEligible; // const isAvailable = (productSlots.length > 0 || isFlashDelivery) && !item.product?.isOutOfStock && isFlashEligible;
let isAvailable = true; let isAvailable = true;
if (productSlotInfo?.isOutOfStock) { if(item.product?.isOutOfStock) {
isAvailable = false; isAvailable = false;
} else if(isFlashDelivery) { } else if(isFlashDelivery) {
if(!isFlashEligible) { if(!isFlashEligible) {
@ -436,7 +430,7 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
// isAvailable = isFlashEligible; // isAvailable = isFlashEligible;
// } // }
const quantity = quantities[item.id] || item.quantity; const quantity = quantities[item.id] || item.quantity;
const price = isFlashDelivery ? (product?.flashPrice ?? product?.price ?? 0) : (product?.price || 0); const price = isFlashDelivery ? (item.product?.flashPrice ?? item.product?.price ?? 0) : (item.product?.price || 0);
const itemPrice = price * quantity; const itemPrice = price * quantity;
return ( return (
@ -444,7 +438,7 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
<View style={tw`p-4`}> <View style={tw`p-4`}>
<View style={tw`flex-row items-center mb-2`}> <View style={tw`flex-row items-center mb-2`}>
<Image <Image
source={{ uri: product?.images?.[0] }} source={{ uri: item.product.images?.[0] }}
style={tw`w-8 h-8 rounded-lg bg-gray-100 mr-3`} style={tw`w-8 h-8 rounded-lg bg-gray-100 mr-3`}
/> />
@ -452,12 +446,12 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
style={tw`text-sm text-gray-900 flex-1 mr-3`} style={tw`text-sm text-gray-900 flex-1 mr-3`}
numberOfLines={2} numberOfLines={2}
> >
{product?.name} {item.product.name}
</MyText> </MyText>
<MyText style={tw`text-xs text-gray-500 mr-2`}> <MyText style={tw`text-xs text-gray-500 mr-2`}>
{(() => { {(() => {
const qty = product?.productQuantity || 1; const qty = item.product?.productQuantity || 1;
const unit = product?.unitNotation || ''; const unit = item.product?.unitNotation || '';
if (unit?.toLowerCase() === 'kg' && qty < 1) { if (unit?.toLowerCase() === 'kg' && qty < 1) {
return `${Math.round(qty * 1000)}g`; return `${Math.round(qty * 1000)}g`;
} }
@ -518,8 +512,8 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
}); });
} }
}} }}
step={product?.incrementStep} step={item.product.incrementStep}
unit={product?.unitNotation} unit={item.product?.unitNotation}
/> />
</View> </View>
</View> </View>
@ -585,7 +579,7 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
onPress={() => { onPress={() => {
Alert.alert( Alert.alert(
"Remove Item", "Remove Item",
`Remove ${product?.name} from cart?`, `Remove ${item.product.name} from cart?`,
[ [
{ text: "Cancel", style: "cancel" }, { text: "Cancel", style: "cancel" },
{ {
@ -636,7 +630,7 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
onPress={() => { onPress={() => {
Alert.alert( Alert.alert(
"Remove Item", "Remove Item",
`Remove ${product?.name} from cart?`, `Remove ${item.product.name} from cart?`,
[ [
{ text: "Cancel", style: "cancel" }, { text: "Cancel", style: "cancel" },
{ {
@ -676,12 +670,12 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
)} )}
{!isAvailable && ( {!isAvailable && (
<View <View
style={tw`bg-red-50 self-start px-2 py-1 rounded-md mt-2`} style={tw`bg-red-50 self-start px-2 py-1 rounded-md mt-2`}
> >
<MyText style={tw`text-xs font-bold text-red-600`}> <MyText style={tw`text-xs font-bold text-red-600`}>
{productSlotInfo?.isOutOfStock {item.product?.isOutOfStock
? "Out of Stock" ? "Out of Stock"
: isFlashDelivery && !flashEligibleProductIds.has(item.productId) : isFlashDelivery && !flashEligibleProductIds.has(item.productId)
? "Not available for flash delivery. Please remove" ? "Not available for flash delivery. Please remove"
: "No delivery slots available"} : "No delivery slots available"}
@ -914,7 +908,7 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
onPress={() => { onPress={() => {
const availableItems = cartItems const availableItems = cartItems
.filter(item => { .filter(item => {
if (productSlotsMap[item.productId]?.isOutOfStock) return false; if (item.product?.isOutOfStock) return false;
if (isFlashDelivery) { if (isFlashDelivery) {
// Check if product supports flash delivery // Check if product supports flash delivery
return flashEligibleProductIds.has(item.productId); return flashEligibleProductIds.has(item.productId);
@ -923,10 +917,12 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
}) })
.map(item => item.id); .map(item => item.id);
if (availableItems.length === 0) {
// Determine why no items are available
const outOfStockItems = cartItems.filter(item => productSlotsMap[item.productId]?.isOutOfStock); if (availableItems.length === 0) {
const inStockItems = cartItems.filter(item => !productSlotsMap[item.productId]?.isOutOfStock); // Determine why no items are available
const outOfStockItems = cartItems.filter(item => item.product?.isOutOfStock);
const inStockItems = cartItems.filter(item => !item.product?.isOutOfStock);
let errorTitle = "Cannot Proceed"; let errorTitle = "Cannot Proceed";
let errorMessage = ""; let errorMessage = "";
@ -963,9 +959,9 @@ export default function CartPage({ isFlashDelivery = false }: CartPageProps) {
return; return;
} }
// Check if there are items without slots (for regular delivery) // Check if there are items without slots (for regular delivery)
if (!isFlashDelivery && availableItems.length < cartItems.length) { if (!isFlashDelivery && availableItems.length < cartItems.length) {
const itemsWithoutSlots = cartItems.filter(item => !selectedSlots[item.id] && !productSlotsMap[item.productId]?.isOutOfStock); const itemsWithoutSlots = cartItems.filter(item => !selectedSlots[item.id] && !item.product?.isOutOfStock);
if (itemsWithoutSlots.length > 0) { if (itemsWithoutSlots.length > 0) {
Alert.alert( Alert.alert(
"Delivery Slot Required", "Delivery Slot Required",

View file

@ -8,10 +8,8 @@ import AddressForm from '@/src/components/AddressForm';
import { useAuthenticatedRoute } from '@/hooks/useAuthenticatedRoute'; import { useAuthenticatedRoute } from '@/hooks/useAuthenticatedRoute';
import { trpc } from '@/src/trpc-client'; import { trpc } from '@/src/trpc-client';
import { useCentralProductStore } from '@/src/store/centralProductStore';
import { useCentralSlotStore } from '@/src/store/centralSlotStore';
import { useGetCart } from '@/hooks/cart-query-hooks'; import { useGetCart } from '@/hooks/cart-query-hooks';
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks'; import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
import PaymentAndOrderComponent from '@/components/PaymentAndOrderComponent'; import PaymentAndOrderComponent from '@/components/PaymentAndOrderComponent';
import CheckoutAddressSelector from '@/components/CheckoutAddressSelector'; import CheckoutAddressSelector from '@/components/CheckoutAddressSelector';
import { useAddressStore } from '@/src/store/addressStore'; import { useAddressStore } from '@/src/store/addressStore';
@ -37,9 +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 products = useCentralProductStore((state) => state.products); const { data: productsData } = trpc.common.product.getAllProductsSummary.useQuery({});
const productsById = useCentralProductStore((state) => state.productsById);
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
useMarkDataFetchers(() => { useMarkDataFetchers(() => {
refetchCart(); refetchCart();
@ -55,15 +51,15 @@ const CheckoutPage: React.FC<CheckoutPageProps> = ({ isFlashDelivery = false })
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 (!products.length) return new Set<number>(); if (!productsData?.products) return new Set<number>();
return new Set( return new Set(
products productsData.products
.filter((product) => productSlotsMap[product.id]?.isFlashAvailable) .filter((product: any) => product.isFlashAvailable)
.map((product) => product.id) .map((product: any) => product.id)
); );
}, [products, productSlotsMap]); }, [productsData]);
// Parse slots parameter from URL (format: "1:1,2,3;2:4,5") // Parse slots parameter from URL (format: "1:1,2,3;2:4,5")
const selectedSlots = useMemo(() => { const selectedSlots = useMemo(() => {
@ -127,11 +123,10 @@ const CheckoutPage: React.FC<CheckoutPageProps> = ({ isFlashDelivery = false })
const totalPrice = selectedItems const totalPrice = selectedItems
.filter((item) => !productSlotsMap[item.productId]?.isOutOfStock) .filter((item) => !item.product?.isOutOfStock)
.reduce( .reduce(
(sum, item) => { (sum, item) => {
const product = productsById[item.productId]; const price = isFlashDelivery ? (item.product?.flashPrice ?? item.product?.price ?? 0) : (item.product?.price || 0);
const price = isFlashDelivery ? (product?.flashPrice ?? product?.price ?? 0) : (product?.price || 0);
return sum + price * item.quantity; return sum + price * item.quantity;
}, },
0 0

View file

@ -14,6 +14,7 @@ import {
theme, theme,
updateStatusBarColor, updateStatusBarColor,
} from "common-ui"; } from "common-ui";
import { trpc } from "@/src/trpc-client";
import { import {
useGetCart, useGetCart,
useUpdateCartItem, useUpdateCartItem,
@ -21,9 +22,8 @@ import {
useAddToCart, useAddToCart,
type CartType, type CartType,
} from "@/hooks/cart-query-hooks"; } from "@/hooks/cart-query-hooks";
import { useGetEssentialConsts, useSlots } from "@/src/hooks/prominent-api-hooks" import { useGetEssentialConsts } from "@/src/api-hooks/essential-consts.api";
import { useProductSlotIdentifier } from "@/hooks/useProductSlotIdentifier"; import { useProductSlotIdentifier } from "@/hooks/useProductSlotIdentifier";
import { useCentralProductStore } from "@/src/store/centralProductStore";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { LinearGradient } from "expo-linear-gradient"; import { LinearGradient } from "expo-linear-gradient";
@ -36,7 +36,7 @@ interface FloatingCartBarProps {
} }
// Smart time window formatting function // Smart time window formatting function
const formatTimeRange = (deliveryTime: string | Date) => { const formatTimeRange = (deliveryTime: string) => {
const time = dayjs(deliveryTime); const time = dayjs(deliveryTime);
const endTime = time.add(1, 'hour'); const endTime = time.add(1, 'hour');
const startPeriod = time.format('A'); const startPeriod = time.format('A');
@ -79,8 +79,7 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
const setIsExpanded = controlledSetIsExpanded ?? setLocalIsExpanded; const setIsExpanded = controlledSetIsExpanded ?? setLocalIsExpanded;
const { data: cartData, refetch: refetchCart } = useGetCart({}, cartType); const { data: cartData, refetch: refetchCart } = useGetCart({}, cartType);
const { data: constsData } = useGetEssentialConsts(); const { data: constsData } = useGetEssentialConsts();
const { data: slotsData } = useSlots(); const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery();
const productsById = useCentralProductStore((state) => state.productsById);
const { productSlotsMap } = useProductSlotIdentifier(); const { productSlotsMap } = useProductSlotIdentifier();
const cartItems = cartData?.items || []; const cartItems = cartData?.items || [];
const itemCount = cartItems.length; const itemCount = cartItems.length;
@ -109,21 +108,21 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
setQuantities(initial); setQuantities(initial);
}, [cartData]); }, [cartData]);
useEffect(() => { useEffect(() => {
if (!cartItems.length || !slotsData?.slots || !productSlotsMap) return; if (!cartItems.length || !slotsData?.slots || !productSlotsMap) return;
const itemsToUpdate = cartItems.filter(item => { const itemsToUpdate = cartItems.filter(item => {
if (isFlashDelivery || !item.slotId) return false; if (isFlashDelivery || !item.slotId) return false;
const availableSlots = productSlotsMap[item.productId]?.slots || []; const availableSlots = productSlotsMap.get(item.productId) || [];
const isSlotAvailable = availableSlots.some((slot) => slot.id === item.slotId); const isSlotAvailable = availableSlots.includes(item.slotId);
return !isSlotAvailable; return !isSlotAvailable;
}); });
itemsToUpdate.forEach((item) => { itemsToUpdate.forEach((item) => {
const availableSlots = productSlotsMap[item.productId]?.slots || []; const availableSlots = productSlotsMap.get(item.productId) || [];
if (availableSlots.length > 0 && !isFlashDelivery) { if (availableSlots.length > 0 && !isFlashDelivery) {
const nearestSlotId = availableSlots[0].id; const nearestSlotId = availableSlots[0];
removeFromCart.mutate({ itemId: item.id }); removeFromCart.mutate({ itemId: item.id });
addToCartHook.addToCart(item.productId, item.quantity, nearestSlotId); addToCartHook.addToCart(item.productId, item.quantity, nearestSlotId);
} }
@ -136,9 +135,7 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
// Calculate total cart value and free delivery info // Calculate total cart value and free delivery info
const totalCartValue = cartItems.reduce( const totalCartValue = cartItems.reduce(
(sum, item) => { (sum, item) => {
const product = productsById[item.productId]; const price = isFlashDelivery ? (item.product.flashPrice ?? item.product.price) : item.product.price;
const basePrice = product?.price ?? 0;
const price = isFlashDelivery ? (product?.flashPrice ?? basePrice) : basePrice;
return sum + price * item.quantity; return sum + price * item.quantity;
}, },
0 0
@ -259,21 +256,21 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
<React.Fragment key={item.id}> <React.Fragment key={item.id}>
<View style={tw`py-4`}> <View style={tw`py-4`}>
<View style={tw`flex-row items-center`}> <View style={tw`flex-row items-center`}>
<Image <Image
source={{ uri: productsById[item.productId]?.images?.[0] }} source={{ uri: item.product.images?.[0] }}
style={tw`w-8 h-8 rounded-lg bg-slate-50 border border-slate-100`} style={tw`w-8 h-8 rounded-lg bg-slate-50 border border-slate-100`}
/> />
<View style={tw`flex-1 ml-4`}> <View style={tw`flex-1 ml-4`}>
<View style={tw`flex-row items-center justify-between mb-1`}> <View style={tw`flex-row items-center justify-between mb-1`}>
<ProductNameWithQuantity <ProductNameWithQuantity
name={productsById[item.productId]?.name || ''} name={item.product.name}
productQuantity={productsById[item.productId]?.productQuantity || 0} productQuantity={item.product.productQuantity}
unitNotation={productsById[item.productId]?.unitNotation || ''} unitNotation={item.product.unitNotation}
/> />
<MiniQuantifier <MiniQuantifier
value={quantities[item.id] || item.quantity} value={quantities[item.id] || item.quantity}
onChange={(value) => { onChange={(value) => {
if (value === 0) { if (value === 0) {
removeFromCart.mutate({ itemId: item.id }); removeFromCart.mutate({ itemId: item.id });
} else { } else {
@ -281,20 +278,21 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
updateCartItem.mutate({ itemId: item.id, quantity: value }); updateCartItem.mutate({ itemId: item.id, quantity: value });
} }
}} }}
step={productsById[item.productId]?.incrementStep || 1} step={item.product.incrementStep}
showUnits={true} showUnits={true}
unit={productsById[item.productId]?.unitNotation} unit={item.product?.unitNotation}
/> />
</View> </View>
<View style={tw`flex-row items-center justify-between`}> <View style={tw`flex-row items-center justify-between`}>
{item.slotId && slotsData && productSlotsMap[item.productId] && ( {item.slotId && slotsData && productSlotsMap.has(item.productId) && (
<BottomDropdown <BottomDropdown
label="Select Delivery Slot" label="Select Delivery Slot"
value={item.slotId} value={item.slotId}
options={(productSlotsMap[item.productId]?.slots || []).map((slot) => { options={(productSlotsMap.get(item.productId) || []).map(slotId => {
const slot = slotsData.slots.find(s => s.id === slotId);
return { return {
label: slot ? formatTimeRange(slot.deliveryTime) : "N/A", label: slot ? formatTimeRange(slot.deliveryTime) : "N/A",
value: slot.id, value: slotId,
}; };
})} })}
onValueChange={async (val) => { onValueChange={async (val) => {
@ -327,12 +325,7 @@ const FloatingCartBar: React.FC<FloatingCartBarProps> = ({
/> />
)} )}
<MyText style={tw`text-slate-900 text-sm font-bold`}> <MyText style={tw`text-slate-900 text-sm font-bold`}>
{(() => { {(isFlashDelivery ? (item.product.flashPrice ?? item.product.price) : item.product.price) * item.quantity}
const product = productsById[item.productId];
const basePrice = product?.price ?? 0;
const price = isFlashDelivery ? (product?.flashPrice ?? basePrice) : basePrice;
return price * item.quantity;
})()}
</MyText> </MyText>
</View> </View>
</View> </View>

View file

@ -5,8 +5,8 @@
}, },
"build": { "build": {
"development": { "development": {
"developmentClient": true,
"distribution": "internal", "distribution": "internal",
"autoIncrement": true,
"channel": "development" "channel": "development"
}, },
"preview": { "preview": {

View file

@ -1,12 +1,15 @@
import { useAllProducts } from '@/src/hooks/prominent-api-hooks'; import { trpc } from '@/src/trpc-client';
import { useCentralSlotStore } from '@/src/store/centralSlotStore';
import { Alert } from 'react-native'; import { Alert } from 'react-native';
import { useQuery, useMutation, useQueryClient, UseQueryResult, UseMutationResult } from '@tanstack/react-query'; import { useState, useEffect } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { StorageServiceCasual } from 'common-ui/src/services/StorageServiceCasual'; import { StorageServiceCasual } from 'common-ui/src/services/StorageServiceCasual';
// Cart type definition // Cart type definition
export type CartType = "regular" | "flash"; export type CartType = "regular" | "flash";
// const CART_MODE: 'remote' | 'local' = 'remote';
const CART_MODE: 'remote' | 'local' = 'local';
const getCartStorageKey = (cartType: CartType = "regular"): string => { const getCartStorageKey = (cartType: CartType = "regular"): string => {
return cartType === "flash" ? "flash_cart_items" : "cart_items"; return cartType === "flash" ? "flash_cart_items" : "cart_items";
}; };
@ -23,99 +26,15 @@ interface ProductSummary {
id: number; id: number;
price: string; price: string;
incrementStep: number; incrementStep: number;
isOutOfStock: boolean;
isFlashAvailable: boolean;
name?: string;
flashPrice?: string | null;
images?: string[];
productQuantity?: number;
unitNotation?: string;
marketPrice?: string | null;
} }
export interface CartItem { interface CartItem {
id: number; id: number;
productId: number; productId: number;
quantity: number; quantity: number;
addedAt: string; addedAt: string;
product: ProductSummary;
subtotal: number; subtotal: number;
slotId: number;
}
interface CartData {
items: CartItem[];
totalItems: number;
totalAmount: number;
}
interface UseGetCartOptions {
refetchOnWindowFocus?: boolean;
enabled?: boolean;
}
interface UseGetCartReturn {
data: CartData | undefined;
isLoading: boolean;
error: Error | null;
refetch: () => Promise<UseQueryResult<CartData, Error>>;
cartItems: CartItem[];
totalItems: number;
totalPrice: number;
isEmpty: boolean;
hasItems: boolean;
}
interface AddToCartVariables {
productId: number;
quantity: number;
slotId: number;
}
interface UpdateCartVariables {
itemId: number;
quantity: number;
}
interface RemoveCartVariables {
itemId: number;
}
interface MutationOptions<TData, TVariables> {
onSuccess?: (data: TData, variables: TVariables) => void;
onError?: (error: Error) => void;
showSuccessAlert?: boolean;
showErrorAlert?: boolean;
refetchCart?: boolean;
}
interface UseAddToCartReturn {
mutate: UseMutationResult<LocalCartItem[], Error, AddToCartVariables>['mutate'];
mutateAsync: UseMutationResult<LocalCartItem[], Error, AddToCartVariables>['mutateAsync'];
isLoading: boolean;
error: Error | null;
data: LocalCartItem[] | undefined;
addToCart: (productId: number, quantity?: number, slotId?: number, onSettled?: (data: LocalCartItem[] | undefined, error: Error | null) => void) => void;
addToCartAsync: (productId: number, quantity?: number, slotId?: number) => Promise<LocalCartItem[]>;
}
interface UseUpdateCartItemReturn {
mutate: UseMutationResult<LocalCartItem[], Error, UpdateCartVariables>['mutate'];
mutateAsync: UseMutationResult<LocalCartItem[], Error, UpdateCartVariables>['mutateAsync'];
isLoading: boolean;
error: Error | null;
data: LocalCartItem[] | undefined;
updateCartItem: (itemId: number, quantity: number) => void;
updateCartItemAsync: (itemId: number, quantity: number) => Promise<LocalCartItem[]>;
}
interface UseRemoveFromCartReturn {
mutate: UseMutationResult<LocalCartItem[], Error, RemoveCartVariables>['mutate'];
mutateAsync: UseMutationResult<LocalCartItem[], Error, RemoveCartVariables>['mutateAsync'];
isLoading: boolean;
error: Error | null;
data: LocalCartItem[] | undefined;
removeFromCart: (itemId: number) => void;
removeFromCartAsync: (itemId: number) => Promise<LocalCartItem[]>;
} }
const getLocalCart = async (cartType: CartType = "regular"): Promise<LocalCartItem[]> => { const getLocalCart = async (cartType: CartType = "regular"): Promise<LocalCartItem[]> => {
@ -127,7 +46,8 @@ const getLocalCart = async (cartType: CartType = "regular"): Promise<LocalCartIt
const saveLocalCart = async (items: LocalCartItem[], cartType: CartType = "regular"): Promise<void> => { const saveLocalCart = async (items: LocalCartItem[], cartType: CartType = "regular"): Promise<void> => {
const key = getCartStorageKey(cartType); const key = getCartStorageKey(cartType);
await StorageServiceCasual.setItem(key, JSON.stringify(items)); await StorageServiceCasual.setItem(key, JSON.stringify(items));
await getLocalCart(cartType); const fetchedItems = await getLocalCart(cartType);
}; };
const getNextCartItemId = (items: LocalCartItem[]): number => { const getNextCartItemId = (items: LocalCartItem[]): number => {
@ -135,7 +55,8 @@ const getNextCartItemId = (items: LocalCartItem[]): number => {
return maxId + 1; return maxId + 1;
}; };
const addToLocalCart = async (productId: number, quantity: number, slotId: number | undefined, cartType: CartType = "regular"): Promise<LocalCartItem[]> => { const addToLocalCart = async (productId: number, quantity: number, slotId?: number, cartType: CartType = "regular"): Promise<LocalCartItem[]> => {
const items = await getLocalCart(cartType); const items = await getLocalCart(cartType);
const existingIndex = items.findIndex(item => item.productId === productId); const existingIndex = items.findIndex(item => item.productId === productId);
@ -146,13 +67,13 @@ const addToLocalCart = async (productId: number, quantity: number, slotId: numbe
} }
} else { } else {
const newId = getNextCartItemId(items); const newId = getNextCartItemId(items);
const cartItem: LocalCartItem = { const cartItem = {
id: newId, id: newId,
productId, productId,
quantity, quantity,
slotId: slotId ?? 0, slotId: slotId ?? 0, // Default to 0 if not provided
addedAt: new Date().toISOString(), addedAt: new Date().toISOString(),
}; }
items.push(cartItem); items.push(cartItem);
} }
@ -183,192 +104,401 @@ const clearLocalCart = async (cartType: CartType = "regular"): Promise<void> =>
await StorageServiceCasual.setItem(key, JSON.stringify([])); await StorageServiceCasual.setItem(key, JSON.stringify([]));
}; };
export function useGetCart(options: UseGetCartOptions = {}, cartType: CartType = "regular"): UseGetCartReturn { export function useGetCart(options?: {
const { data: products } = useAllProducts(); refetchOnWindowFocus?: boolean;
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap); enabled?: boolean;
}, cartType: CartType = "regular") {
const query: UseQueryResult<CartData, Error> = useQuery({ if (CART_MODE === 'remote') {
queryKey: [`local-cart-${cartType}`], const query = trpc.user.cart.getCart.useQuery(undefined, {
queryFn: async (): Promise<CartData> => { refetchOnWindowFocus: options?.refetchOnWindowFocus ?? true,
const cartItems = await getLocalCart(cartType); enabled: options?.enabled ?? true,
...options
});
const productMap: Record<number, Omit<ProductSummary, 'isOutOfStock' | 'isFlashAvailable'>> = Object.fromEntries( return {
products?.products?.map((p) => [ // Original tRPC returns
p.id, data: query.data,
{ isLoading: query.isLoading,
id: p.id, error: query.error,
price: String(p.price), refetch: query.refetch,
incrementStep: p.incrementStep,
marketPrice: p.marketPrice === null || p.marketPrice === undefined ? null : String(p.marketPrice),
name: p.name,
flashPrice: p.flashPrice,
images: p.images,
productQuantity: p.productQuantity,
unitNotation: p.unitNotation,
},
]) ?? []
);
const items: CartItem[] = cartItems // Computed properties
.map((cartItem): CartItem | null => { cartItems: query.data?.items || [],
const productBasic = productMap[cartItem.productId]; totalItems: query.data?.totalItems || 0,
const productAvailability = productSlotsMap[cartItem.productId]; totalPrice: query.data?.totalAmount || 0,
if (!productBasic || !productAvailability) return null; // Helper methods
isEmpty: !query.data?.items?.length,
hasItems: Boolean(query.data?.items?.length),
};
} else {
const { data: products } = trpc.common.product.getAllProductsSummary.useQuery({});
const query = useQuery({
queryKey: [`local-cart-${cartType}`],
queryFn: async () => {
const cartItems = await getLocalCart(cartType);
const productMap = Object.fromEntries(
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 product = productMap[cartItem.productId];
if (!product) return null as any;
return { return {
id: cartItem.id, id: cartItem.id,
productId: cartItem.productId, productId: cartItem.productId,
quantity: cartItem.quantity, quantity: cartItem.quantity,
addedAt: cartItem.addedAt, addedAt: cartItem.addedAt,
subtotal: Number(productBasic.price) * cartItem.quantity, product,
incrementStep: product.incrementStep,
subtotal: Number(product.price) * cartItem.quantity,
slotId: cartItem.slotId, slotId: cartItem.slotId,
}; };
}) }).filter(Boolean) as CartItem[];
.filter((item): item is CartItem => item !== null); const totalAmount = items.reduce((sum, item) => sum + item.subtotal, 0);
const totalAmount = items.reduce((sum, item) => sum + item.subtotal, 0); return {
items,
totalItems: items.length,
totalAmount,
};
},
refetchOnWindowFocus: options?.refetchOnWindowFocus ?? true,
enabled: (options?.enabled ?? true) && !!products,
});
return {
data: query.data,
isLoading: query.isLoading,
error: query.error,
refetch: query.refetch,
return { // Computed properties
items, cartItems: query.data?.items || [],
totalItems: items.length, totalItems: query.data?.totalItems || 0,
totalAmount, totalPrice: query.data?.totalAmount || 0,
};
}, // Helper methods
refetchOnWindowFocus: options?.refetchOnWindowFocus ?? true, isEmpty: !query.data?.items?.length,
enabled: (options?.enabled ?? true) && !!products, hasItems: Boolean(query.data?.items?.length),
}); };
}
return {
data: query.data,
isLoading: query.isLoading,
error: query.error,
refetch: query.refetch,
cartItems: query.data?.items ?? [],
totalItems: query.data?.totalItems ?? 0,
totalPrice: query.data?.totalAmount ?? 0,
isEmpty: !(query.data?.items?.length ?? 0),
hasItems: Boolean(query.data?.items?.length),
};
} }
export function useAddToCart(options: MutationOptions<LocalCartItem[], AddToCartVariables> = {}, cartType: CartType = "regular"): UseAddToCartReturn { interface UseAddToCartReturn {
const queryClient = useQueryClient(); mutate: any;
mutateAsync: any;
isLoading: boolean;
error: any;
data: any;
addToCart: (productId: number, quantity?: number, slotId?: number, onSettled?: (data: any, error: any) => void) => void;
addToCartAsync: (productId: number, quantity?: number, slotId?: number) => Promise<any>;
}
const mutation: UseMutationResult<LocalCartItem[], Error, AddToCartVariables> = useMutation({ export function useAddToCart(options?: {
mutationFn: async ({ productId, quantity, slotId }: AddToCartVariables): Promise<LocalCartItem[]> => { onSuccess?: (data: any, variables: any) => void;
return await addToLocalCart(productId, quantity, slotId, cartType); onError?: (error: any) => void;
}, showSuccessAlert?: boolean;
onSuccess: (data: LocalCartItem[], variables: AddToCartVariables) => { showErrorAlert?: boolean;
queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] }); refetchCart?: boolean;
if (options?.showSuccessAlert !== false) { }, cartType: CartType = "regular"): UseAddToCartReturn {
Alert.alert("Success", "Item added to cart!"); if (CART_MODE === 'remote') {
} const utils = trpc.useUtils();
options?.onSuccess?.(data, variables);
},
onError: (error: Error) => {
if (options?.showErrorAlert !== false) {
Alert.alert("Error", error.message || "Failed to add item to cart");
}
options?.onError?.(error);
},
});
const addToCart = (productId: number, quantity = 1, slotId?: number, onSettled?: (data: LocalCartItem[] | undefined, error: Error | null) => void): void => { const mutation = trpc.user.cart.addToCart.useMutation({
if (slotId == null) { onSuccess: (data, variables) => {
throw new Error('slotId is required for adding to cart'); // Default success handling
} if (options?.showSuccessAlert !== false) {
mutation.mutate({ productId, quantity, slotId }, { Alert.alert("Success", "Item added to cart!");
onSettled: (data: LocalCartItem[] | undefined, error: Error | null) => { }
onSettled?.(data, error);
}
});
};
return { // Auto-refetch cart if requested
mutate: mutation.mutate, if (options?.refetchCart) {
mutateAsync: mutation.mutateAsync, utils.user.cart.getCart.invalidate();
isLoading: mutation.isPending, }
error: mutation.error,
data: mutation.data, // Custom success callback
addToCart, options?.onSuccess?.(data, variables);
addToCartAsync: (productId: number, quantity = 1, slotId?: number): Promise<LocalCartItem[]> => { },
onError: (error) => {
// Default error handling
if (options?.showErrorAlert !== false) {
Alert.alert("Error", error.message || "Failed to add item to cart");
}
// Custom error callback
options?.onError?.(error);
},
}) as any;
const addToCart = (productId: number, quantity = 1, slotId?: number, onSettled?: (data: any, error: any) => void) => {
if (slotId == null) { if (slotId == null) {
throw new Error('slotId is required for adding to cart'); throw new Error('slotId is required for adding to cart');
} }
return mutation.mutateAsync({ productId, quantity, slotId }); return mutation.mutate({ productId, quantity, slotId }, {
}, onSettled: (data: any, error: any) => {
}; onSettled?.(data, error);
}
});
};
return {
// Original mutation returns
mutate: mutation.mutate,
mutateAsync: mutation.mutateAsync,
isLoading: mutation.isPending,
error: mutation.error,
data: mutation.data,
addToCart,
addToCartAsync: (productId: number, quantity = 1, slotId?: number) => {
if (slotId == null) {
throw new Error('slotId is required for adding to cart');
}
return mutation.mutateAsync({ productId, quantity, slotId });
},
};
} else {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: async ({ productId, quantity, slotId }: { productId: number, quantity: number, slotId: number }) => {
return await addToLocalCart(productId, quantity, slotId, cartType);
},
onSuccess: (data, variables) => {
queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] });
if (options?.showSuccessAlert !== false) {
Alert.alert("Success", "Item added to cart!");
}
options?.onSuccess?.(data, variables);
},
onError: (error) => {
if (options?.showErrorAlert !== false) {
Alert.alert("Error", error.message || "Failed to add item to cart");
}
options?.onError?.(error);
},
});
const addToCart = (productId: number, quantity = 1, slotId?: number, onSettled?: (data: any, error: any) => void) => {
if (slotId == null) {
throw new Error('slotId is required for adding to cart');
}
return mutation.mutate({ productId, quantity, slotId }, {
onSettled: (data: any, error: any) => {
onSettled?.(data, error);
}
});
};
return {
mutate: mutation.mutate,
mutateAsync: mutation.mutateAsync,
isLoading: mutation.isPending,
error: mutation.error,
data: mutation.data,
addToCart,
addToCartAsync: (productId: number, quantity = 1, slotId?: number) => {
if (slotId == null) {
throw new Error('slotId is required for adding to cart');
}
return mutation.mutateAsync({ productId, quantity, slotId });
},
};
}
} }
export function useUpdateCartItem(options: MutationOptions<LocalCartItem[], UpdateCartVariables> = {}, cartType: CartType = "regular"): UseUpdateCartItemReturn { export function useUpdateCartItem(options?: {
const queryClient = useQueryClient(); onSuccess?: (data: any, variables: any) => void;
onError?: (error: any) => void;
showSuccessAlert?: boolean;
showErrorAlert?: boolean;
refetchCart?: boolean;
}, cartType: CartType = "regular") {
if (CART_MODE === 'remote') {
const utils = trpc.useUtils();
const mutation: UseMutationResult<LocalCartItem[], Error, UpdateCartVariables> = useMutation({ const mutation = trpc.user.cart.updateCartItem.useMutation({
mutationFn: async ({ itemId, quantity }: UpdateCartVariables): Promise<LocalCartItem[]> => { onSuccess: (data, variables) => {
return await updateLocalCartItem(itemId, quantity, cartType); // Default success handling
}, if (options?.showSuccessAlert !== false) {
onSuccess: (data: LocalCartItem[], variables: UpdateCartVariables) => { Alert.alert("Success", "Cart item updated!");
queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] }); }
if (options?.showSuccessAlert !== false) {
Alert.alert("Success", "Cart item updated!");
}
options?.onSuccess?.(data, variables);
},
onError: (error: Error) => {
if (options?.showErrorAlert !== false) {
Alert.alert("Error", error.message || "Failed to update cart item");
}
options?.onError?.(error);
},
});
return { // Auto-refetch cart if requested
mutate: mutation.mutate, if (options?.refetchCart) {
mutateAsync: mutation.mutateAsync, utils.user.cart.getCart.invalidate();
isLoading: mutation.isPending, }
error: mutation.error,
data: mutation.data, // Custom success callback
updateCartItem: (itemId: number, quantity: number): void => options?.onSuccess?.(data, variables);
mutation.mutate({ itemId, quantity }), },
updateCartItemAsync: (itemId: number, quantity: number): Promise<LocalCartItem[]> => onError: (error) => {
mutation.mutateAsync({ itemId, quantity }), // Default error handling
}; if (options?.showErrorAlert !== false) {
Alert.alert("Error", error.message || "Failed to update cart item");
}
// Custom error callback
options?.onError?.(error);
},
});
return {
// Original mutation returns
mutate: mutation.mutate,
mutateAsync: mutation.mutateAsync,
isLoading: mutation.isPending,
error: mutation.error,
data: mutation.data,
// Helper methods
updateCartItem: (itemId: number, quantity: number) =>
mutation.mutate({ itemId, quantity }),
updateCartItemAsync: (itemId: number, quantity: number) =>
mutation.mutateAsync({ itemId, quantity }),
};
} else {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: async ({ itemId, quantity }: { itemId: number, quantity: number }) => {
return await updateLocalCartItem(itemId, quantity, cartType);
},
onSuccess: (data, variables) => {
queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] });
if (options?.showSuccessAlert !== false) {
Alert.alert("Success", "Cart item updated!");
}
options?.onSuccess?.(data, variables);
},
onError: (error) => {
if (options?.showErrorAlert !== false) {
Alert.alert("Error", error.message || "Failed to update cart item");
}
options?.onError?.(error);
},
});
return {
mutate: mutation.mutate,
mutateAsync: mutation.mutateAsync,
isLoading: mutation.isPending,
error: mutation.error,
data: mutation.data,
updateCartItem: (itemId: number, quantity: number) =>
mutation.mutate({ itemId, quantity }),
updateCartItemAsync: (itemId: number, quantity: number) =>
mutation.mutateAsync({ itemId, quantity }),
};
}
} }
export function useRemoveFromCart(options: MutationOptions<LocalCartItem[], RemoveCartVariables> = {}, cartType: CartType = "regular"): UseRemoveFromCartReturn { export function useRemoveFromCart(options?: {
const queryClient = useQueryClient(); onSuccess?: (data: any, variables: any) => void;
onError?: (error: any) => void;
showSuccessAlert?: boolean;
showErrorAlert?: boolean;
refetchCart?: boolean;
}, cartType: CartType = "regular") {
if (CART_MODE === 'remote') {
const utils = trpc.useUtils();
const mutation: UseMutationResult<LocalCartItem[], Error, RemoveCartVariables> = useMutation({ const mutation = trpc.user.cart.removeFromCart.useMutation({
mutationFn: async ({ itemId }: RemoveCartVariables): Promise<LocalCartItem[]> => { onSuccess: (data, variables) => {
return await removeFromLocalCart(itemId, cartType); // Default success handling
}, if (options?.showSuccessAlert !== false) {
onSuccess: (data: LocalCartItem[], variables: RemoveCartVariables) => { Alert.alert("Success", "Item removed from cart!");
queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] }); }
if (options?.showSuccessAlert !== false) {
Alert.alert("Success", "Item removed from cart!");
}
options?.onSuccess?.(data, variables);
},
onError: (error: Error) => {
if (options?.showErrorAlert !== false) {
Alert.alert("Error", error.message || "Failed to remove item from cart");
}
options?.onError?.(error);
},
});
return { // Auto-refetch cart if requested
mutate: mutation.mutate, if (options?.refetchCart) {
mutateAsync: mutation.mutateAsync, utils.user.cart.getCart.invalidate();
isLoading: mutation.isPending, }
error: mutation.error,
data: mutation.data, // Custom success callback
removeFromCart: (itemId: number): void => options?.onSuccess?.(data, variables);
mutation.mutate({ itemId }), },
removeFromCartAsync: (itemId: number): Promise<LocalCartItem[]> => onError: (error) => {
mutation.mutateAsync({ itemId }), // Default error handling
}; if (options?.showErrorAlert !== false) {
Alert.alert("Error", error.message || "Failed to remove item from cart");
}
// Custom error callback
options?.onError?.(error);
},
});
return {
// Original mutation returns
mutate: mutation.mutate,
mutateAsync: mutation.mutateAsync,
isLoading: mutation.isPending,
error: mutation.error,
data: mutation.data,
// Helper methods
removeFromCart: (itemId: number) =>
mutation.mutate({ itemId }),
removeFromCartAsync: (itemId: number) =>
mutation.mutateAsync({ itemId }),
};
} else {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: async ({ itemId }: { itemId: number }) => {
return await removeFromLocalCart(itemId, cartType);
},
onSuccess: (data, variables) => {
queryClient.invalidateQueries({ queryKey: [`local-cart-${cartType}`] });
if (options?.showSuccessAlert !== false) {
Alert.alert("Success", "Item removed from cart!");
}
options?.onSuccess?.(data, variables);
},
onError: (error) => {
if (options?.showErrorAlert !== false) {
Alert.alert("Error", error.message || "Failed to remove item from cart");
}
options?.onError?.(error);
},
});
return {
mutate: mutation.mutate,
mutateAsync: mutation.mutateAsync,
isLoading: mutation.isPending,
error: mutation.error,
data: mutation.data,
removeFromCart: (itemId: number) =>
mutation.mutate({ itemId }),
removeFromCartAsync: (itemId: number) =>
mutation.mutateAsync({ itemId }),
};
}
} }
// Export clear cart function for direct use // Export clear cart function for direct use

View file

@ -1,28 +1,46 @@
import { trpc } from '@/src/trpc-client';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { useCentralSlotStore } from '@/src/store/centralSlotStore';
export function useProductSlotIdentifier() { export function useProductSlotIdentifier() {
// Get slots data from central store // Fetch all slots with products
const slots = useCentralSlotStore((state) => state.slots); const { data: slotsData, isLoading: isProductsLoading } = trpc.user.slots.getSlotsWithProducts.useQuery();
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
const productSlotsMap = new Map<number, number[]>();
if (slotsData?.slots) {
const now = dayjs();
// Build map of productId to available slot IDs
slotsData.slots.forEach(slot => {
if (dayjs(slot.deliveryTime).isAfter(now)) {
slot.products.forEach(product => {
if (!productSlotsMap.has(product.id)) {
productSlotsMap.set(product.id, []);
}
productSlotsMap.get(product.id)!.push(slot.id);
});
}
});
}
const getQuickestSlot = (productId: number): number | null => { const getQuickestSlot = (productId: number): number | null => {
if (!slots?.length) return null;
if (!slotsData?.slots) return null;
const now = dayjs(); const now = dayjs();
const productInfo = productSlotsMap[productId];
if (!productInfo?.slots?.length) return null;
// Find slots that contain this product and have future delivery time // Find slots that contain this product and have future delivery time
const availableSlots = productInfo.slots.filter((slot: any) => const availableSlots = slotsData.slots.filter(slot =>
slot.products.some(product => product.id === productId) &&
dayjs(slot.deliveryTime).isAfter(now) dayjs(slot.deliveryTime).isAfter(now)
); );
// if(productId === 98)
// console.log(JSON.stringify(slotsData))
if (availableSlots.length === 0) return null; if (availableSlots.length === 0) return null;
// Return earliest slot ID (sorted by delivery time) // Return earliest slot ID (sorted by delivery time)
const earliestSlot = availableSlots.sort((a: any, b: any) => const earliestSlot = availableSlots.sort((a, b) =>
dayjs(a.deliveryTime).diff(dayjs(b.deliveryTime)) dayjs(a.deliveryTime).diff(dayjs(b.deliveryTime))
)[0]; )[0];
@ -30,4 +48,4 @@ export function useProductSlotIdentifier() {
}; };
return { getQuickestSlot, productSlotsMap }; return { getQuickestSlot, productSlotsMap };
} }

View file

@ -1,20 +1,6 @@
// Learn more on how to setup config for the app: https://docs.expo.dev/guides/config-plugins/#metro-config // Learn more on how to setup config for the app: https://docs.expo.dev/guides/config-plugins/#metro-config
const { getDefaultConfig } = require('expo/metro-config'); const { getDefaultConfig } = require('expo/metro-config');
const path = require('path');
const config = getDefaultConfig(__dirname); const config = getDefaultConfig(__dirname);
// Add the packages directory to watch folders
config.watchFolders = [
...config.watchFolders || [],
path.resolve(__dirname, '../../packages/shared'),
];
// Configure module resolution for @packages/*
config.resolver.extraNodeModules = {
...config.resolver.extraNodeModules,
'@packages/shared': path.resolve(__dirname, '../../packages/shared'),
'global-shared': path.resolve(__dirname, '../../packages/shared'),
};
module.exports = config; module.exports = config;

View file

@ -48,7 +48,6 @@
"expo-updates": "~0.28.17", "expo-updates": "~0.28.17",
"expo-web-browser": "~14.2.0", "expo-web-browser": "~14.2.0",
"formik": "^2.4.6", "formik": "^2.4.6",
"fuse.js": "^7.1.0",
"jwt-decode": "^4.0.0", "jwt-decode": "^4.0.0",
"react": "19.0.0", "react": "19.0.0",
"react-dom": "19.0.0", "react-dom": "19.0.0",

View file

@ -0,0 +1,8 @@
import { trpc } from '@/src/trpc-client';
export const useGetEssentialConsts = () => {
const query = trpc.common.essentialConsts.useQuery(undefined, {
refetchInterval: 60000,
});
return { ...query, refetch: query.refetch };
};

View file

@ -5,9 +5,9 @@ import { tw, BottomDialog, MyText, MyTouchableOpacity, Quantifier } from 'common
import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import { useCartStore } from '@/src/store/cartStore'; import { useCartStore } from '@/src/store/cartStore';
import { useFlashCartStore } from '@/src/store/flashCartStore'; import { useFlashCartStore } from '@/src/store/flashCartStore';
import { useCentralSlotStore } from '@/src/store/centralSlotStore'; import { trpc } from '@/src/trpc-client';
import { useAddToCart, useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks'; import { useAddToCart, useGetCart, useUpdateCartItem, useRemoveFromCart } from '@/hooks/cart-query-hooks';
import { useGetEssentialConsts, useSlots } from '@/src/hooks/prominent-api-hooks'; import { useGetEssentialConsts } from '@/src/api-hooks/essential-consts.api';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { SafeAreaView } from 'react-native-safe-area-context'; import { SafeAreaView } from 'react-native-safe-area-context';
@ -31,10 +31,9 @@ export default function AddToCartDialog() {
const [selectedSlotId, setSelectedSlotId] = useState<number | null>(null); const [selectedSlotId, setSelectedSlotId] = useState<number | null>(null);
const [selectedFlashDelivery, setSelectedFlashDelivery] = useState(false); const [selectedFlashDelivery, setSelectedFlashDelivery] = useState(false);
const { data: slotsData } = useSlots(); const { data: slotsData } = trpc.user.slots.getSlotsWithProducts.useQuery();
const { data: cartData } = useGetCart(); const { data: cartData } = useGetCart();
const { data: constsData } = useGetEssentialConsts(); const { data: constsData } = useGetEssentialConsts();
const productSlotsMap = useCentralSlotStore((state) => state.productSlotsMap);
// const isFlashDeliveryEnabled = constsData?.isFlashDeliveryEnabled === true; // const isFlashDeliveryEnabled = constsData?.isFlashDeliveryEnabled === true;
const isFlashDeliveryEnabled = true; const isFlashDeliveryEnabled = true;
@ -114,7 +113,7 @@ export default function AddToCartDialog() {
const isUpdate = (cartItem?.quantity || 0) >= 1; const isUpdate = (cartItem?.quantity || 0) >= 1;
// Check if flash delivery option should be shown // Check if flash delivery option should be shown
const showFlashOption = productSlotsMap[product?.id]?.isFlashAvailable === true && isFlashDeliveryEnabled; const showFlashOption = product?.isFlashAvailable === true && isFlashDeliveryEnabled;
const handleAddToCart = () => { const handleAddToCart = () => {
if (selectedFlashDelivery) { if (selectedFlashDelivery) {

View file

@ -1,14 +0,0 @@
import React from 'react';
import { useInitializeCentralSlotStore } from '@/src/store/centralSlotStore';
import { useInitializeCentralProductStore } from '@/src/store/centralProductStore';
interface CentralStoreInitializerProps {
children: React.ReactNode;
}
export default function CentralStoreInitializer({ children }: CentralStoreInitializerProps) {
useInitializeCentralSlotStore();
useInitializeCentralProductStore();
return <>{children}</>;
}

View file

@ -1,125 +0,0 @@
import { useQuery } from '@tanstack/react-query'
import axios from 'axios'
import { trpc } from '@/src/trpc-client'
import { AllProductsApiType, StoresApiType, SlotsApiType, EssentialConstsApiType, BannersApiType, StoreWithProductsApiType } from "@backend/trpc/router";
import { CACHE_FILENAMES } from "@packages/shared";
// Local useGetEssentialConsts hook
export const useGetEssentialConsts = () => {
const query = trpc.common.essentialConsts.useQuery(undefined, {
refetchInterval: 60000,
})
return { ...query, refetch: query.refetch }
}
type ProductsResponse = AllProductsApiType;
type StoresResponse = StoresApiType;
type SlotsResponse = SlotsApiType;
type EssentialConstsResponse = EssentialConstsApiType;
type BannersResponse = BannersApiType;
type StoreWithProductsResponse = StoreWithProductsApiType;
function useCacheUrl(filename: string): string | null {
const { data: essentialConsts } = useGetEssentialConsts()
const assetsDomain = essentialConsts?.assetsDomain
const apiCacheKey = essentialConsts?.apiCacheKey
return assetsDomain && apiCacheKey
? `${assetsDomain}${apiCacheKey}/${filename}`
: null
}
export function useAllProducts() {
const cacheUrl = useCacheUrl(CACHE_FILENAMES.products)
return useQuery<ProductsResponse>({
queryKey: ['all-products', cacheUrl],
queryFn: async () => {
if (!cacheUrl) {
throw new Error('Cache URL not available')
}
const response = await axios.get<ProductsResponse>(cacheUrl)
return response.data
},
staleTime: 60000, // 1 minute
enabled: !!cacheUrl,
})
}
export function useStores() {
const cacheUrl = useCacheUrl(CACHE_FILENAMES.stores)
return useQuery<StoresResponse>({
queryKey: ['stores', cacheUrl],
queryFn: async () => {
if (!cacheUrl) {
throw new Error('Cache URL not available')
}
const response = await axios.get<StoresResponse>(cacheUrl)
return response.data
},
staleTime: 60000, // 1 minute
enabled: !!cacheUrl,
})
}
export function useSlots() {
const cacheUrl = useCacheUrl(CACHE_FILENAMES.slots)
return useQuery<SlotsResponse>({
queryKey: ['slots', cacheUrl],
queryFn: async () => {
if (!cacheUrl) {
throw new Error('Cache URL not available')
}
const response = await axios.get<SlotsResponse>(cacheUrl)
return response.data
},
staleTime: 60000, // 1 minute
enabled: !!cacheUrl,
})
}
export function useBanners() {
const cacheUrl = useCacheUrl(CACHE_FILENAMES.banners)
return useQuery<BannersResponse>({
queryKey: ['banners', cacheUrl],
queryFn: async () => {
if (!cacheUrl) {
throw new Error('Cache URL not available')
}
const response = await axios.get<BannersResponse>(cacheUrl)
return response.data
},
staleTime: 60000, // 1 minute
enabled: !!cacheUrl,
})
}
export function useStoreWithProducts(storeId: number) {
const { data: essentialConsts } = useGetEssentialConsts()
const assetsDomain = essentialConsts?.assetsDomain
const apiCacheKey = essentialConsts?.apiCacheKey
const cacheUrl = assetsDomain && apiCacheKey
? `${assetsDomain}${apiCacheKey}/stores/${storeId}.json`
: null
return useQuery<StoreWithProductsResponse>({
queryKey: ['store-with-products', storeId, cacheUrl],
queryFn: async () => {
if (!cacheUrl) {
throw new Error('Cache URL not available')
}
const response = await axios.get<StoreWithProductsResponse>(cacheUrl)
return response.data
},
staleTime: 60000, // 1 minute
enabled: !!cacheUrl,
})
}

View file

@ -1,50 +0,0 @@
import { create } from 'zustand'
import { useEffect } from 'react'
import { useAllProducts } from '@/src/hooks/prominent-api-hooks'
import { AllProductsApiType } from '@backend/trpc/router'
type Product = AllProductsApiType['products'][number]
interface CentralProductState {
products: Product[]
productsById: Record<number, Product>
refetchProducts: (() => Promise<void>) | null
setProducts: (products: Product[]) => void
clearProducts: () => void
setRefetchProducts: (refetch: () => Promise<void>) => void
}
export const useCentralProductStore = create<CentralProductState>((set) => ({
products: [],
productsById: {},
refetchProducts: null,
setProducts: (products) => {
const productsById: Record<number, Product> = {}
products.forEach((product) => {
productsById[product.id] = product
})
set({ products, productsById })
},
clearProducts: () => set({ products: [], productsById: {} }),
setRefetchProducts: (refetchProducts) => set({ refetchProducts }),
}))
export function useInitializeCentralProductStore() {
const { data: productsData, refetch } = useAllProducts()
const setProducts = useCentralProductStore((state) => state.setProducts)
const setRefetchProducts = useCentralProductStore((state) => state.setRefetchProducts)
useEffect(() => {
if (productsData?.products) {
setProducts(productsData.products)
}
}, [productsData, setProducts])
useEffect(() => {
setRefetchProducts(async () => {
await refetch()
})
}, [refetch, setRefetchProducts])
}

View file

@ -1,71 +0,0 @@
import { create } from 'zustand';
import { useSlots } from '@/src/hooks/prominent-api-hooks';
import { useEffect } from 'react';
import { SlotsApiType } from "@backend/trpc/router";
type Slot = SlotsApiType['slots'][number];
type ProductAvailability = SlotsApiType['productAvailability'][number];
interface ProductSlotInfo {
slots: Slot[];
isOutOfStock: boolean;
isFlashAvailable: boolean;
}
interface CentralSlotState {
slots: Slot[];
productSlotsMap: Record<number, ProductSlotInfo>;
refetchSlots: (() => Promise<void>) | null;
setSlotsData: (slots: Slot[], productAvailability: ProductAvailability[]) => void;
clearSlotsData: () => void;
setRefetchSlots: (refetch: () => Promise<void>) => void;
}
export const useCentralSlotStore = create<CentralSlotState>((set) => ({
slots: [],
productSlotsMap: {},
refetchSlots: null,
setSlotsData: (slots, productAvailability) => {
const productSlotsMap: Record<number, ProductSlotInfo> = {};
// First, create entries for ALL products from productAvailability
productAvailability.forEach((product) => {
productSlotsMap[product.id] = {
slots: [],
isOutOfStock: product.isOutOfStock,
isFlashAvailable: product.isFlashAvailable,
};
});
// Then, populate slots for products that appear in delivery slots
slots.forEach((slot) => {
slot.products?.forEach((product) => {
if (productSlotsMap[product.id]) {
productSlotsMap[product.id].slots.push(slot);
}
});
});
set({ slots, productSlotsMap });
},
clearSlotsData: () => set({ slots: [], productSlotsMap: {} }),
setRefetchSlots: (refetchSlots) => set({ refetchSlots }),
}));
export function useInitializeCentralSlotStore() {
const { data: slotsData, refetch } = useSlots();
const setSlotsData = useCentralSlotStore((state) => state.setSlotsData);
const setRefetchSlots = useCentralSlotStore((state) => state.setRefetchSlots);
useEffect(() => {
if (slotsData?.slots) {
setSlotsData(slotsData.slots, slotsData.productAvailability || []);
}
}, [slotsData, setSlotsData]);
useEffect(() => {
setRefetchSlots(async () => {
await refetch();
});
}, [refetch, setRefetchSlots]);
}

View file

@ -18,18 +18,6 @@
], ],
"common-ui/*": [ "common-ui/*": [
"../../packages/ui/*" "../../packages/ui/*"
],
"@packages/shared": [
"../../packages/shared"
],
"@packages/shared/*": [
"../../packages/shared/*"
],
"global-shared": [
"../../packages/shared"
],
"global-shared/*": [
"../../packages/shared/*"
] ]
}, },
"moduleSuffixes": [ "moduleSuffixes": [
@ -46,6 +34,5 @@
"**/*.tsx", "**/*.tsx",
".expo/types/**/*.ts", ".expo/types/**/*.ts",
"expo-env.d.ts", "expo-env.d.ts",
"../../packages/shared"
] ]
} }

4006
bun.lock

File diff suppressed because it is too large Load diff

30
ios/.gitignore vendored Normal file
View file

@ -0,0 +1,30 @@
# OSX
#
.DS_Store
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace
.xcode.env.local
# Bundle artifacts
*.jsbundle
# CocoaPods
/Pods/

11
ios/.xcode.env Normal file
View file

@ -0,0 +1,11 @@
# This `.xcode.env` file is versioned and is used to source the environment
# used when running script phases inside Xcode.
# To customize your local environment, you can create an `.xcode.env.local`
# file that is not versioned.
# NODE_BINARY variable contains the PATH to the node executable.
#
# Customize the NODE_BINARY variable here.
# For example, to use nvm with brew, add the following line
# . "$(brew --prefix nvm)/nvm.sh" --no-use
export NODE_BINARY=$(command -v node)

64
ios/Podfile Normal file
View file

@ -0,0 +1,64 @@
require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods")
require 'json'
podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {}
ENV['RCT_NEW_ARCH_ENABLED'] = '0' if podfile_properties['newArchEnabled'] == 'false'
ENV['EX_DEV_CLIENT_NETWORK_INSPECTOR'] = podfile_properties['EX_DEV_CLIENT_NETWORK_INSPECTOR']
platform :ios, podfile_properties['ios.deploymentTarget'] || '15.1'
install! 'cocoapods',
:deterministic_uuids => false
prepare_react_native_project!
target 'meatfarmermonorepo' do
use_expo_modules!
if ENV['EXPO_USE_COMMUNITY_AUTOLINKING'] == '1'
config_command = ['node', '-e', "process.argv=['', '', 'config'];require('@react-native-community/cli').run()"];
else
config_command = [
'npx',
'expo-modules-autolinking',
'react-native-config',
'--json',
'--platform',
'ios'
]
end
config = use_native_modules!(config_command)
use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
use_frameworks! :linkage => ENV['USE_FRAMEWORKS'].to_sym if ENV['USE_FRAMEWORKS']
use_react_native!(
:path => config[:reactNativePath],
:hermes_enabled => podfile_properties['expo.jsEngine'] == nil || podfile_properties['expo.jsEngine'] == 'hermes',
# An absolute path to your application root.
:app_path => "#{Pod::Config.instance.installation_root}/..",
:privacy_file_aggregation_enabled => podfile_properties['apple.privacyManifestAggregationEnabled'] != 'false',
)
post_install do |installer|
react_native_post_install(
installer,
config[:reactNativePath],
:mac_catalyst_enabled => false,
:ccache_enabled => podfile_properties['apple.ccacheEnabled'] == 'true',
)
# This is necessary for Xcode 14, because it signs resource bundles by default
# when building for devices.
installer.target_installation_results.pod_target_installation_results
.each do |pod_name, target_installation_result|
target_installation_result.resource_bundle_targets.each do |resource_bundle_target|
resource_bundle_target.build_configurations.each do |config|
config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
end
end
end
end
end

2324
ios/Podfile.lock Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,4 @@
{
"expo.jsEngine": "hermes",
"EX_DEV_CLIENT_NETWORK_INSPECTOR": "true"
}

View file

@ -0,0 +1,567 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objects = {
/* Begin PBXBuildFile section */
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
2C4FDEE95846910CE44B063B /* libPods-meatfarmermonorepo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37BA16CD265ED7F72409550D /* libPods-meatfarmermonorepo.a */; };
3E461D99554A48A4959DE609 /* SplashScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */; };
BB2F792D24A3F905000567C9 /* Expo.plist in Resources */ = {isa = PBXBuildFile; fileRef = BB2F792C24A3F905000567C9 /* Expo.plist */; };
D20664F10ED8090F4983CFB0 /* ExpoModulesProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EB8BC3528ACACFE6A3CFB5D /* ExpoModulesProvider.swift */; };
E5B462C85E4DB34FCCD3D04E /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = F66C424AA0E1347CF8253669 /* PrivacyInfo.xcprivacy */; };
F11748422D0307B40044C1D9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F11748412D0307B40044C1D9 /* AppDelegate.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
13B07F961A680F5B00A75B9A /* meatfarmermonorepo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = meatfarmermonorepo.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = meatfarmermonorepo/Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = meatfarmermonorepo/Info.plist; sourceTree = "<group>"; };
338F04D2CAE7495C1D7CD233 /* Pods-meatfarmermonorepo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-meatfarmermonorepo.debug.xcconfig"; path = "Target Support Files/Pods-meatfarmermonorepo/Pods-meatfarmermonorepo.debug.xcconfig"; sourceTree = "<group>"; };
37BA16CD265ED7F72409550D /* libPods-meatfarmermonorepo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-meatfarmermonorepo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3EB8BC3528ACACFE6A3CFB5D /* ExpoModulesProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ExpoModulesProvider.swift; path = "Pods/Target Support Files/Pods-meatfarmermonorepo/ExpoModulesProvider.swift"; sourceTree = "<group>"; };
533CB49887DAADE200BAF1EB /* Pods-meatfarmermonorepo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-meatfarmermonorepo.release.xcconfig"; path = "Target Support Files/Pods-meatfarmermonorepo/Pods-meatfarmermonorepo.release.xcconfig"; sourceTree = "<group>"; };
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = SplashScreen.storyboard; path = meatfarmermonorepo/SplashScreen.storyboard; sourceTree = "<group>"; };
BB2F792C24A3F905000567C9 /* Expo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Expo.plist; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
F11748412D0307B40044C1D9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = meatfarmermonorepo/AppDelegate.swift; sourceTree = "<group>"; };
F11748442D0722820044C1D9 /* meatfarmermonorepo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "meatfarmermonorepo-Bridging-Header.h"; path = "meatfarmermonorepo/meatfarmermonorepo-Bridging-Header.h"; sourceTree = "<group>"; };
F66C424AA0E1347CF8253669 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; name = PrivacyInfo.xcprivacy; path = meatfarmermonorepo/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
13B07F8C1A680F5B00A75B9A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2C4FDEE95846910CE44B063B /* libPods-meatfarmermonorepo.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
13B07FAE1A68108700A75B9A /* meatfarmermonorepo */ = {
isa = PBXGroup;
children = (
F11748412D0307B40044C1D9 /* AppDelegate.swift */,
F11748442D0722820044C1D9 /* meatfarmermonorepo-Bridging-Header.h */,
BB2F792B24A3F905000567C9 /* Supporting */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
13B07FB61A68108700A75B9A /* Info.plist */,
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */,
F66C424AA0E1347CF8253669 /* PrivacyInfo.xcprivacy */,
);
name = meatfarmermonorepo;
sourceTree = "<group>";
};
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
isa = PBXGroup;
children = (
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
37BA16CD265ED7F72409550D /* libPods-meatfarmermonorepo.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
3742C5BD2E66753B5F39026B /* ExpoModulesProviders */ = {
isa = PBXGroup;
children = (
4DACB6B6CCC8B1A8CBF98D1D /* meatfarmermonorepo */,
);
name = ExpoModulesProviders;
sourceTree = "<group>";
};
4DACB6B6CCC8B1A8CBF98D1D /* meatfarmermonorepo */ = {
isa = PBXGroup;
children = (
3EB8BC3528ACACFE6A3CFB5D /* ExpoModulesProvider.swift */,
);
name = meatfarmermonorepo;
sourceTree = "<group>";
};
832341AE1AAA6A7D00B99B32 /* Libraries */ = {
isa = PBXGroup;
children = (
);
name = Libraries;
sourceTree = "<group>";
};
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
13B07FAE1A68108700A75B9A /* meatfarmermonorepo */,
832341AE1AAA6A7D00B99B32 /* Libraries */,
83CBBA001A601CBA00E9B192 /* Products */,
2D16E6871FA4F8E400B85C8A /* Frameworks */,
D7B1D84C142A04E96F6A3A3D /* Pods */,
3742C5BD2E66753B5F39026B /* ExpoModulesProviders */,
);
indentWidth = 2;
sourceTree = "<group>";
tabWidth = 2;
usesTabs = 0;
};
83CBBA001A601CBA00E9B192 /* Products */ = {
isa = PBXGroup;
children = (
13B07F961A680F5B00A75B9A /* meatfarmermonorepo.app */,
);
name = Products;
sourceTree = "<group>";
};
BB2F792B24A3F905000567C9 /* Supporting */ = {
isa = PBXGroup;
children = (
BB2F792C24A3F905000567C9 /* Expo.plist */,
);
name = Supporting;
path = meatfarmermonorepo/Supporting;
sourceTree = "<group>";
};
D7B1D84C142A04E96F6A3A3D /* Pods */ = {
isa = PBXGroup;
children = (
338F04D2CAE7495C1D7CD233 /* Pods-meatfarmermonorepo.debug.xcconfig */,
533CB49887DAADE200BAF1EB /* Pods-meatfarmermonorepo.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
13B07F861A680F5B00A75B9A /* meatfarmermonorepo */ = {
isa = PBXNativeTarget;
buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "meatfarmermonorepo" */;
buildPhases = (
08A4A3CD28434E44B6B9DE2E /* [CP] Check Pods Manifest.lock */,
5BC667EA2551B13AA89D9A66 /* [Expo] Configure project */,
13B07F871A680F5B00A75B9A /* Sources */,
13B07F8C1A680F5B00A75B9A /* Frameworks */,
13B07F8E1A680F5B00A75B9A /* Resources */,
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
800E24972A6A228C8D4807E9 /* [CP] Copy Pods Resources */,
DAF2E4EA15761DC5FE4C4A8B /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = meatfarmermonorepo;
productName = meatfarmermonorepo;
productReference = 13B07F961A680F5B00A75B9A /* meatfarmermonorepo.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
83CBB9F71A601CBA00E9B192 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1130;
TargetAttributes = {
13B07F861A680F5B00A75B9A = {
LastSwiftMigration = 1250;
};
};
};
buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "meatfarmermonorepo" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 83CBB9F61A601CBA00E9B192;
productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
13B07F861A680F5B00A75B9A /* meatfarmermonorepo */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
13B07F8E1A680F5B00A75B9A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BB2F792D24A3F905000567C9 /* Expo.plist in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
3E461D99554A48A4959DE609 /* SplashScreen.storyboard in Resources */,
E5B462C85E4DB34FCCD3D04E /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Bundle React Native code and images";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [[ -f \"$PODS_ROOT/../.xcode.env\" ]]; then\n source \"$PODS_ROOT/../.xcode.env\"\nfi\nif [[ -f \"$PODS_ROOT/../.xcode.env.local\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.local\"\nfi\n\n# The project root by default is one level up from the ios directory\nexport PROJECT_ROOT=\"$PROJECT_DIR\"/..\n\nif [[ \"$CONFIGURATION\" = *Debug* ]]; then\n export SKIP_BUNDLING=1\nfi\nif [[ -z \"$ENTRY_FILE\" ]]; then\n # Set the entry JS file using the bundler's entry resolution.\n export ENTRY_FILE=\"$(\"$NODE_BINARY\" -e \"require('expo/scripts/resolveAppEntry')\" \"$PROJECT_ROOT\" ios absolute | tail -n 1)\"\nfi\n\nif [[ -z \"$CLI_PATH\" ]]; then\n # Use Expo CLI\n export CLI_PATH=\"$(\"$NODE_BINARY\" --print \"require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })\")\"\nfi\nif [[ -z \"$BUNDLE_COMMAND\" ]]; then\n # Default Expo CLI command for bundling\n export BUNDLE_COMMAND=\"export:embed\"\nfi\n\n# Source .xcode.env.updates if it exists to allow\n# SKIP_BUNDLING to be unset if needed\nif [[ -f \"$PODS_ROOT/../.xcode.env.updates\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.updates\"\nfi\n# Source local changes to allow overrides\n# if needed\nif [[ -f \"$PODS_ROOT/../.xcode.env.local\" ]]; then\n source \"$PODS_ROOT/../.xcode.env.local\"\nfi\n\n`\"$NODE_BINARY\" --print \"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\"`\n\n";
};
08A4A3CD28434E44B6B9DE2E /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-meatfarmermonorepo-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
5BC667EA2551B13AA89D9A66 /* [Expo] Configure project */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "[Expo] Configure project";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# This script configures Expo modules and generates the modules provider file.\nbash -l -c \"./Pods/Target\\ Support\\ Files/Pods-meatfarmermonorepo/expo-configure-project.sh\"\n";
};
800E24972A6A228C8D4807E9 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-meatfarmermonorepo/Pods-meatfarmermonorepo-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/AppAuth/AppAuthCore_Privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/EXApplication/ExpoApplication_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/EXConstants/EXConstants.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/EXConstants/ExpoConstants_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/EXNotifications/ExpoNotifications_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/EXUpdates/EXUpdates.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/ExpoDevice/ExpoDevice_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/ExpoFileSystem/ExpoFileSystem_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/ExpoSystemUI/ExpoSystemUI_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/GTMAppAuth/GTMAppAuth_Privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/GTMSessionFetcher/GTMSessionFetcher_Core_Privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/GoogleSignIn/GoogleSignIn.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/GoogleUtilities/GoogleUtilities_Privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/PromisesObjC/FBLPromises_Privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/RCT-Folly/RCT-Folly_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/ReachabilitySwift/ReachabilitySwift.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Core/React-Core_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/React-cxxreact/React-cxxreact_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/SDWebImage/SDWebImage.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/boost/boost_privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/glog/glog_privacy.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AppAuthCore_Privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoApplication_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/EXConstants.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoConstants_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoNotifications_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/EXUpdates.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoDevice_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoFileSystem_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoSystemUI_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GTMAppAuth_Privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GTMSessionFetcher_Core_Privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleSignIn.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleUtilities_Privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/FBLPromises_Privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RCT-Folly_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ReachabilitySwift.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/React-Core_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/React-cxxreact_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/SDWebImage.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/boost_privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/glog_privacy.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-meatfarmermonorepo/Pods-meatfarmermonorepo-resources.sh\"\n";
showEnvVarsInLog = 0;
};
DAF2E4EA15761DC5FE4C4A8B /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-meatfarmermonorepo/Pods-meatfarmermonorepo-frameworks.sh",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/Pre-built/hermes.framework/hermes",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/hermes.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-meatfarmermonorepo/Pods-meatfarmermonorepo-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
13B07F871A680F5B00A75B9A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F11748422D0307B40044C1D9 /* AppDelegate.swift in Sources */,
D20664F10ED8090F4983CFB0 /* ExpoModulesProvider.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
13B07F941A680F5B00A75B9A /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 338F04D2CAE7495C1D7CD233 /* Pods-meatfarmermonorepo.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = meatfarmermonorepo/meatfarmermonorepo.entitlements;
CURRENT_PROJECT_VERSION = 1;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"FB_SONARKIT_ENABLED=1",
);
INFOPLIST_FILE = meatfarmermonorepo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
"-lc++",
);
OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_DEBUG";
PRODUCT_BUNDLE_IDENTIFIER = "com.mohammedshafiuddin54.meat-farmer-monorepo";
PRODUCT_NAME = meatfarmermonorepo;
SWIFT_OBJC_BRIDGING_HEADER = "meatfarmermonorepo/meatfarmermonorepo-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
};
13B07F951A680F5B00A75B9A /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 533CB49887DAADE200BAF1EB /* Pods-meatfarmermonorepo.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = meatfarmermonorepo/meatfarmermonorepo.entitlements;
CURRENT_PROJECT_VERSION = 1;
INFOPLIST_FILE = meatfarmermonorepo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
"-lc++",
);
OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_RELEASE";
PRODUCT_BUNDLE_IDENTIFIER = "com.mohammedshafiuddin54.meat-farmer-monorepo";
PRODUCT_NAME = meatfarmermonorepo;
SWIFT_OBJC_BRIDGING_HEADER = "meatfarmermonorepo/meatfarmermonorepo-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
};
83CBBA201A601CBA00E9B192 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++20";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
LD_RUNPATH_SEARCH_PATHS = (
/usr/lib/swift,
"$(inherited)",
);
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
USE_HERMES = true;
};
name = Debug;
};
83CBBA211A601CBA00E9B192 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++20";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.1;
LD_RUNPATH_SEARCH_PATHS = (
/usr/lib/swift,
"$(inherited)",
);
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "meatfarmermonorepo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
13B07F941A680F5B00A75B9A /* Debug */,
13B07F951A680F5B00A75B9A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "meatfarmermonorepo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
83CBBA201A601CBA00E9B192 /* Debug */,
83CBBA211A601CBA00E9B192 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */;
}

View file

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "meatfarmermonorepo.app"
BlueprintName = "meatfarmermonorepo"
ReferencedContainer = "container:meatfarmermonorepo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
BuildableName = "meatfarmermonorepoTests.xctest"
BlueprintName = "meatfarmermonorepoTests"
ReferencedContainer = "container:meatfarmermonorepo.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "meatfarmermonorepo.app"
BlueprintName = "meatfarmermonorepo"
ReferencedContainer = "container:meatfarmermonorepo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "meatfarmermonorepo.app"
BlueprintName = "meatfarmermonorepo"
ReferencedContainer = "container:meatfarmermonorepo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:meatfarmermonorepo.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

View file

@ -0,0 +1,70 @@
import Expo
import React
import ReactAppDependencyProvider
@UIApplicationMain
public class AppDelegate: ExpoAppDelegate {
var window: UIWindow?
var reactNativeDelegate: ExpoReactNativeFactoryDelegate?
var reactNativeFactory: RCTReactNativeFactory?
public override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
let delegate = ReactNativeDelegate()
let factory = ExpoReactNativeFactory(delegate: delegate)
delegate.dependencyProvider = RCTAppDependencyProvider()
reactNativeDelegate = delegate
reactNativeFactory = factory
bindReactNativeFactory(factory)
#if os(iOS) || os(tvOS)
window = UIWindow(frame: UIScreen.main.bounds)
factory.startReactNative(
withModuleName: "main",
in: window,
launchOptions: launchOptions)
#endif
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// Linking API
public override func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
return super.application(app, open: url, options: options) || RCTLinkingManager.application(app, open: url, options: options)
}
// Universal Links
public override func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
return super.application(application, continue: userActivity, restorationHandler: restorationHandler) || result
}
}
class ReactNativeDelegate: ExpoReactNativeFactoryDelegate {
// Extension point for config-plugins
override func sourceURL(for bridge: RCTBridge) -> URL? {
// needed to return the correct URL for expo-dev-client.
bridge.bundleURL ?? bundleURL()
}
override func bundleURL() -> URL? {
#if DEBUG
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: ".expo/.virtual-metro-entry")
#else
return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

@ -0,0 +1,14 @@
{
"images": [
{
"filename": "App-Icon-1024x1024@1x.png",
"idiom": "universal",
"platform": "ios",
"size": "1024x1024"
}
],
"info": {
"version": 1,
"author": "expo"
}
}

View file

@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "expo"
}
}

View file

@ -0,0 +1,20 @@
{
"colors": [
{
"color": {
"components": {
"alpha": "1.000",
"blue": "1.00000000000000",
"green": "1.00000000000000",
"red": "1.00000000000000"
},
"color-space": "srgb"
},
"idiom": "universal"
}
],
"info": {
"version": 1,
"author": "expo"
}
}

View file

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>meat-farmer-monorepo</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.mohammedshafiuddin54.meat-farmer-monorepo</string>
</array>
</dict>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>exp+meat-farmer-monorepo</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>12.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key>
<string>SplashScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UIRequiresFullScreen</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDefault</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="EXPO-VIEWCONTROLLER-1">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<scene sceneID="EXPO-SCENE-1">
<objects>
<viewController storyboardIdentifier="SplashScreenViewController" id="EXPO-VIEWCONTROLLER-1" sceneMemberID="viewController">
<view key="view" userInteractionEnabled="NO" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="EXPO-ContainerView" userLabel="ContainerView">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews/>
<viewLayoutGuide key="safeArea" id="Rmq-lb-GrQ"/>
<constraints>
<constraint firstItem="EXPO-SplashScreen" firstAttribute="centerY" secondItem="EXPO-ContainerView" secondAttribute="centerY" id="0VC-Wk-OaO"/>
<constraint firstItem="EXPO-SplashScreen" firstAttribute="centerX" secondItem="EXPO-ContainerView" secondAttribute="centerX" id="zR4-NK-mVN"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="EXPO-PLACEHOLDER-1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="0.0" y="0.0"/>
</scene>
</scenes>
<resources>
<image name="SplashScreenLogo" width="100" height="90.333335876464844"/>
</resources>
</document>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EXUpdatesCheckOnLaunch</key>
<string>ALWAYS</string>
<key>EXUpdatesEnabled</key>
<false/>
<key>EXUpdatesLaunchWaitMs</key>
<integer>0</integer>
</dict>
</plist>

View file

@ -0,0 +1,3 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

View file

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict/>
<key>NSPrivacyTracking</key> </plist>
<false/>
</dict>
</plist>

25628
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
"name": "meat-farmer-monorepo", "name": "meat-farmer-monorepo",
"version": "1.0.0", "version": "1.0.0",
"private": true, "private": true,
"packageManager": "bun@1.3.10", "packageManager": "npm@10.8.1",
"scripts": { "scripts": {
"build": "turbo run build", "build": "turbo run build",
"dev": "turbo run dev --parallel", "dev": "turbo run dev --parallel",
@ -42,7 +42,6 @@
"expo-crypto": "~14.1.5", "expo-crypto": "~14.1.5",
"expo-server-sdk": "^5.0.0", "expo-server-sdk": "^5.0.0",
"expo-web-browser": "~14.2.0", "expo-web-browser": "~14.2.0",
"fuse.js": "^7.1.0",
"node-cron": "^4.2.1", "node-cron": "^4.2.1",
"pg": "^8.20.0", "pg": "^8.20.0",
"react": "19.0.0", "react": "19.0.0",

View file

@ -1,9 +0,0 @@
export const CACHE_FILENAMES = {
products: 'products.json',
stores: 'stores.json',
slots: 'slots.json',
essentialConsts: 'essential-consts.json',
banners: 'banners.json',
} as const
export type CacheFilename = typeof CACHE_FILENAMES[keyof typeof CACHE_FILENAMES]

View file

@ -1,7 +0,0 @@
{
"name": "@packages/shared",
"version": "1.0.0",
"main": "index.ts",
"types": "index.ts",
"private": true
}

View file

@ -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.108: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) {

View file

@ -1,39 +0,0 @@
{
"testRunner": {
"args": {
"$0": "jest",
"config": "jest.config.cjs"
}
},
"apps": {
"admin.ios": {
"type": "ios.app",
"binaryPath": "appBinaries/admin.app",
"bundleId": "in.freshyo.adminui"
},
"user.ios": {
"type": "ios.app",
"binaryPath": "appBinaries/user.app",
"bundleId": "com.freshyotrial.app"
}
},
"devices": {
"simulator": {
"type": "ios.simulator",
"device": {
"type": "iPhone 16 Pro Max"
}
}
},
"configurations": {
"ios.user": {
"device": "simulator",
"app": "user.ios"
},
"ios.admin": {
"device": "simulator",
"app": "admin.ios"
}
}
}

34
test/.gitignore vendored
View file

@ -1,34 +0,0 @@
# dependencies (bun install)
node_modules
# output
out
dist
*.tgz
# code coverage
coverage
*.lcov
# logs
logs
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# caches
.eslintcache
.cache
*.tsbuildinfo
# IntelliJ based IDEs
.idea
# Finder (MacOS) folder config
.DS_Store

Some files were not shown because too many files have changed in this diff Show more