Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into main
  • Loading branch information
swapnil-ahlawat committed Mar 28, 2021
2 parents 773eabc + a53c4bc commit a89d284
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 47 deletions.
79 changes: 49 additions & 30 deletions Frontend/screens/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,49 @@ const Order = ({ route, navigation }) => {
const [isSelected, setSelection] = React.useState(false);
const [modalVisible, setModalVisible] = React.useState(false);

const handleClicked = () => {

setModalVisible(false);
navigation.navigate("RestaurantHome");
};




React.useEffect(() => {
let { item, currentLocation } = route.params;

setOrder(item)
setCurrentLocation(currentLocation)
setSelection(order?.resuablePackage)
setSelection(order?.reusablePackageFlag)
})
async function deleteOrder(){
var url = "http://b51c079841e0.ngrok.io/user/removeOrder";
try {
const response = await fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
orderID: order._id,
phoneNo: global.user.phoneNo

})
});

const responseData = await response.json();
if (!response.ok) {
throw new Error(responseData.message);
}
else{
console.log(responseData)
}
} catch (err) {
console.log(err)
}
}
function handleOrderDispatch(){
deleteOrder();
console.log("HEEEEEEEE")
setModalVisible(false);
navigation.navigate("RestaurantHome");
}

function renderHeader() {
return (
Expand Down Expand Up @@ -96,7 +124,7 @@ const Order = ({ route, navigation }) => {
flex: 1, flexDirection: "column",
width: SIZES.width*0.95,
marginLeft: SIZES.width*0.025,
height: 100,
height: 80,
backgroundColor:COLORS.white ,
borderBottomColor: COLORS.black,
borderBottomWidth: 1,
Expand All @@ -105,22 +133,11 @@ const Order = ({ route, navigation }) => {
justifyContent:'center'}}
>
<View style = {{flexDirection: "row"}}>
<Text style = {{paddingLeft:SIZES.padding,width: 0.1*SIZES.width,...FONTS.h3,color: COLORS.black}}>{item.quantity}x</Text>
<Text style={{ width: 0.7*SIZES.width,...FONTS.h4,color: COLORS.black }}>{item.name}</Text>
<Text style={{width: 0.2*SIZES.width, ...FONTS.h4,color: COLORS.black }}>${(item.price*item.quantity).toFixed(2)}</Text>
<Text style = {{paddingLeft:SIZES.padding,width: 0.20*SIZES.width,...FONTS.h3,color: COLORS.black}}>{item.quantity}x</Text>
<Text style={{ width: 0.55*SIZES.width,...FONTS.h4,color: COLORS.black }}>{item.name}</Text>
<Text style={{width: 0.25*SIZES.width, ...FONTS.h4,color: COLORS.black,paddingRight:SIZES.padding }}>${(item.price*item.quantity).toFixed(2)}</Text>
</View>
<View
style={{
flexDirection: "row",
justifyContent: "space-between",
paddingVertical: SIZES.padding,
paddingHorizontal: SIZES.width*0.1
}}

>
<Text style = {{width: SIZES.width,...FONTS.body3,color: COLORS.black}}>{item.additional_info}</Text>

</View>



</View>
Expand All @@ -130,8 +147,8 @@ const Order = ({ route, navigation }) => {
<View style={{
paddingBotto0m: 30}}>
<FlatList
data={order?.order_details}
keyExtractor={item => `${item.food_id}`}
data={order?.foodItems}
keyExtractor={item => `${item._id}`}
renderItem={renderItem}
contentContainerStyle={{
paddingBottom: 30
Expand All @@ -153,8 +170,8 @@ const Order = ({ route, navigation }) => {
return (
<View style = {{height: 100,marginTop: SIZES.padding,flexDirection: "row"}}>
<View style = {{justifyContent: 'center'}}>
<Text style={{ ...FONTS.body3,color: COLORS.white,paddingHorizontal: SIZES.padding*2 }}>{order?.name}</Text>
<Text style={{ ...FONTS.h3,color: COLORS.white,paddingHorizontal: SIZES.padding*2,paddingTop:SIZES.padding }}>{order?.address}</Text>
<Text style={{ ...FONTS.body3,color: COLORS.white,paddingHorizontal: SIZES.padding*2 }}>{order?.customerName}</Text>
<Text style={{ ...FONTS.h3,color: COLORS.white,paddingHorizontal: SIZES.padding*2,paddingTop:SIZES.padding }}>{order?.customerPhoneNo}</Text>

</View>

Expand Down Expand Up @@ -193,8 +210,10 @@ const Order = ({ route, navigation }) => {
justifyContent: 'center'
}}
onPress={() => {
if ( order?.resuablePackage)
{ navigation.navigate("Scan",{modeTag: "RestaurantDelivery"})}
if ( order?.resuablePackageFlag)
{
navigation.navigate("Scan",{modeTag: "RestaurantDelivery",order})
}
else
{
setModalVisible(true)
Expand All @@ -216,7 +235,7 @@ const Order = ({ route, navigation }) => {
>
<TouchableWithoutFeedback
onPress={() => {
handleClicked()
handleOrderDispatch()
}}
>
<View style={{ flex: 1, flexDirection: 'column-reverse'}}>
Expand Down
36 changes: 19 additions & 17 deletions Frontend/screens/RestaurantHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@ import {
StatusBar
} from "react-native";
import { icons, images, SIZES, COLORS, FONTS } from '../constants'

const RestaurantHome = ({ navigation }) => {

// Dummy Datas

const initialCurrentLocation = {
address: "KFC",
gps: {
latitude: 1.5496614931250685,
longitude: 110.36381866919922
}
}



const [currentLocation,setCurrentLocation] = React.useState(initialCurrentLocation)
const [orders, setOrders] = React.useState(null)
const [fetchFlag,setFetchFlag] = React.useState(true)

React.useState(() => { setFetchFlag(true)})





async function fetchOrder(){
if (fetchFlag)
{
Expand Down Expand Up @@ -65,9 +67,9 @@ const RestaurantHome = ({ navigation }) => {
}
}
};



function renderHeader() {
return (
<SafeAreaView style={{ flexDirection: 'row', height: 50,justifyContent: 'space-between'}}>
Expand Down Expand Up @@ -107,7 +109,7 @@ const RestaurantHome = ({ navigation }) => {
</SafeAreaView>
)
}

function renderRestaurantList() {
const renderItem = ({ item }) => (
<TouchableOpacity
Expand All @@ -133,7 +135,7 @@ const RestaurantHome = ({ navigation }) => {
}}
>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.customerName}</Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>${item.customerPhoneNo}</Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.foodItems.length}</Text>
</View>
<View
style={{
Expand All @@ -143,12 +145,12 @@ const RestaurantHome = ({ navigation }) => {
}}
>
{/* <Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.address}</Text> */}
<Text style={{ ...FONTS.body3,color: COLORS.black }}></Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.customerPhoneNo}</Text>
</View>

</TouchableOpacity>
)

return (
<View style={{ paddingHorizontal: SIZES.padding * 2, marginTop:SIZES.padding*2}}>
<Text style={{paddingVertical:10, ...FONTS.h2,color: COLORS.white }}>In Progress ({orders?.length})</Text>
Expand All @@ -163,7 +165,7 @@ const RestaurantHome = ({ navigation }) => {
</View>
)
}

fetchOrder()
return (

Expand All @@ -173,7 +175,7 @@ const RestaurantHome = ({ navigation }) => {
</SafeAreaView>
)
}

const styles = StyleSheet.create({
container: {
flex: 1,
Expand All @@ -182,5 +184,5 @@ const styles = StyleSheet.create({
},

})

export default RestaurantHome

0 comments on commit a89d284

Please sign in to comment.