90 lines
3.1 KiB
TypeScript
90 lines
3.1 KiB
TypeScript
import React from 'react';
|
|
import { View, Text } from 'react-native';
|
|
import { useAppTheme } from '@theme';
|
|
import { PrimaryButton, MapViewComponent } from '@components';
|
|
import { changeOrderStatusThunk, useAppDispatch, useAppSelector } from '@store';
|
|
import { advanceJobStatus } from '@store/commonReducers/job';
|
|
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
|
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
import { AppStackParamList } from '@navigation/navigationTypes';
|
|
import { RouteNames, JobStatus } from '@utils/constants';
|
|
import { getStyles } from './orderPickedUpScreen.styles';
|
|
|
|
export const OrderPickedUpScreen: React.FC = () => {
|
|
const { colors } = useAppTheme();
|
|
const styles = getStyles(colors);
|
|
const dispatch = useAppDispatch();
|
|
const route =
|
|
useRoute<RouteProp<AppStackParamList, RouteNames.OrderPickedUp>>();
|
|
const { jobId } = route.params;
|
|
// console.log(jobId, 'jobId');
|
|
const navigation =
|
|
useNavigation<NativeStackNavigationProp<AppStackParamList>>();
|
|
|
|
// const activeJob = useAppSelector(state => state.job.activeJob);
|
|
const { activeDeliveries } = useAppSelector(state => state.deliveries);
|
|
const activeJob = activeDeliveries?.delivery;
|
|
|
|
const handleStartDelivery = async () => {
|
|
await dispatch(
|
|
changeOrderStatusThunk({ deliveryId: jobId, action: JobStatus.PickedUp }),
|
|
)
|
|
.unwrap()
|
|
.then(() => {
|
|
// Use replace so OrderPickedUp is removed from the stack —
|
|
// the user cannot come back to it via the back button.
|
|
navigation.replace(RouteNames.LiveTracking, {
|
|
jobId: jobId,
|
|
});
|
|
})
|
|
.catch(err => {
|
|
console.log(err, 'err');
|
|
});
|
|
};
|
|
|
|
if (!activeJob) return null;
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
{/* Map Routing Path */}
|
|
{activeJob?.order?.pickupAddress && activeJob?.order?.dropAddress ? (
|
|
<MapViewComponent
|
|
origin={activeJob.order.pickupAddress}
|
|
destination={activeJob.order.dropAddress}
|
|
showRoute={true}
|
|
style={styles.mapPlaceholder}
|
|
/>
|
|
) : (
|
|
<View style={styles.mapPlaceholder}>
|
|
<Text style={styles.placeholderText}>Loading Map...</Text>
|
|
</View>
|
|
)}
|
|
|
|
{/* Deliver Bottom Card */}
|
|
<View style={styles.bottomCard}>
|
|
<Text style={styles.cardTitle}>Deliver to Customer</Text>
|
|
<Text style={styles.customerName}>
|
|
{activeJob?.order?.customer?.user?.name}
|
|
</Text>
|
|
<Text style={styles.customerAddress}>
|
|
{activeJob?.order?.dropAddress?.houseNumber},{' '}
|
|
{activeJob?.order?.dropAddress?.addressLine1}
|
|
{activeJob?.order?.dropAddress?.city},{' '}
|
|
{activeJob?.order?.dropAddress?.state},
|
|
{activeJob?.order?.dropAddress?.postalCode}
|
|
{'\n'}
|
|
{activeJob?.order?.customer?.user?.phone}
|
|
</Text>
|
|
|
|
<PrimaryButton
|
|
title="Start Delivery"
|
|
onPress={handleStartDelivery}
|
|
style={styles.startButton}
|
|
/>
|
|
</View>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
export default OrderPickedUpScreen;
|