Skip to content

Commit

Permalink
fixes fixes fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Jan 11, 2025
1 parent 37c47ad commit 451b2bb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ function getColorFromStatus(status) {
case 'operational':
case 'active':
case 'completed':
case 'pickup_ready':
return 'green';
case 'dispatched':
case 'assigned':
return 'indigo';
case 'disabled':
case 'canceled':
case 'order_canceled':
case 'incomplete':
case 'unable':
case 'failed':
Expand Down
4 changes: 2 additions & 2 deletions src/components/OrderItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ const OrderItems = ({ order }) => {
</Text>
)}
<YStack>
{entity.meta.variants.map((variant) => (
{entity.meta.variants.filter(Boolean).map((variant) => (
<XStack key={variant.id} alignItems='center' space='$2'>
<Text flex={1} fontSize='$3' color='$textSecondary' numberOfLines={1}>
{variant.name}
</Text>
</XStack>
))}
{entity.meta.addons.map((addon) => (
{entity.meta.addons.filter(Boolean).map((addon) => (
<XStack key={addon.id} alignItems='center' space='$2'>
<Text flex={1} fontSize='$3' color='$textSecondary' numberOfLines={1}>
{addon.name}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-qpay-checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default function useQPayCheckout({ onOrderComplete }) {
}, [setupGateway, customer, cart, serviceQuote]);

useEffect(() => {
if (checkoutOptions.pickup || !cart) {
if (!cart) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-stripe-checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export default function useStripeCheckout({ onOrderComplete }) {

// Fetch service quote whenever location or cart contents change
useEffect(() => {
if (checkoutOptions.pickup || !cart) {
if (!cart) {
return;
}

Expand Down
11 changes: 10 additions & 1 deletion src/screens/OrderHistoryScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const OrderHistoryScreen = () => {
const navigation = useNavigation();
const { customer } = useAuth();
const [orders, setOrders] = useStorage(`${customer.id}_orders`, []);
const [refreshing, setRefreshing] = useState(false);

const fetchOrders = async (params = {}) => {
try {
Expand All @@ -34,6 +35,12 @@ const OrderHistoryScreen = () => {
}
};

const handleRefresh = async () => {
setRefreshing(true);
await fetchOrders();
setRefreshing(false);
};

const handleViewOrder = (order) => {
navigation.navigate('Order', { order: order.serialize() });
};
Expand All @@ -60,7 +67,7 @@ const OrderHistoryScreen = () => {
</Text>
</YStack>
<YStack space='$2'>
<XStack space='$3'>
<XStack space='$3' justifyContent='flex-end'>
<Text color='$textSecondary'>{formatCurrency(order.getAttribute('meta.total'), order.getAttribute('meta.currency'))}</Text>
<FontAwesomeIcon icon={faChevronRight} size={14} color={theme['$textSecondary'].val} />
</XStack>
Expand All @@ -74,6 +81,8 @@ const OrderHistoryScreen = () => {
ItemSeparatorComponent={() => <Separator borderBottomWidth={1} borderColor='$borderColorWithShadow' />}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
refreshing={refreshing}
onRefresh={handleRefresh}
/>
</SafeAreaView>
);
Expand Down
18 changes: 12 additions & 6 deletions src/screens/OrderScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ const OrderScreen = ({ route }) => {
}, [order]);

const reloadOrder = useCallback(async () => {
console.log('[order]', order);
try {
// const order = await order.reload();
// setOrder(order);
const reloadedOrder = await order.reload();
setOrder(reloadedOrder);
} catch (err) {
console.error('Error reloading order:', err);
}
Expand All @@ -70,14 +69,21 @@ const OrderScreen = ({ route }) => {
}, []);

useEffect(() => {
if (!order || listenerRef.current) {
if (!order) {
return;
}

getDistanceMatrix();
}, [order]);

useEffect(() => {
if (listenerRef.current) {
return;
}

const listenForUpdates = async () => {
const listener = await listen(`order.${order.id}`, (event) => {
reloadOrder();
getDistanceMatrix();
});
if (listener) {
listenerRef.current = listener;
Expand All @@ -91,7 +97,7 @@ const OrderScreen = ({ route }) => {
listenerRef.current.stop();
}
};
}, [listen, order]);
}, [listen, order.id]);

return (
<YStack flex={1} bg='$background'>
Expand Down

0 comments on commit 451b2bb

Please sign in to comment.