Skip to content

Commit

Permalink
add delete option for delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
wandan23 committed Mar 28, 2021
1 parent 8fe58a9 commit a53c4bc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 55 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
48 changes: 24 additions & 24 deletions Frontend/screens/RestaurantHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,38 @@ 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)
{
setFetchFlag(false)
console.log(global.user.phoneNo)

var url = "http://c47f3fbd2a93.ngrok.io/user/restaurant?phoneNo=" + global.user.phoneNo + "&userType=Restaurant"
var url = "http://b51c079841e0.ngrok.io/user/restaurant?phoneNo=" + global.user.phoneNo + "&userType=Restaurant"
console.log(url)
try {
const response = await fetch(url, {
Expand All @@ -63,13 +65,11 @@ const RestaurantHome = ({ navigation }) => {
console.log(err)
return null
}
}


}
};



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

function renderRestaurantList() {
const renderItem = ({ item }) => (
<TouchableOpacity
Expand All @@ -135,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 @@ -145,18 +145,18 @@ 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?.pendingorders?.length})</Text>
<Text style={{paddingVertical:10, ...FONTS.h2,color: COLORS.white }}>In Progress ({orders?.length})</Text>
<FlatList
data={orders?.pendingOrders}
keyExtractor={item => `${item['_id']}`}
data={orders}
keyExtractor={item => `${item._id}`}
renderItem={renderItem}
contentContainerStyle={{
paddingBottom: 30
Expand All @@ -165,7 +165,7 @@ const RestaurantHome = ({ navigation }) => {
</View>
)
}

fetchOrder()
return (

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

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

})

export default RestaurantHome
2 changes: 1 addition & 1 deletion Frontend/screens/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const SignUp = ({ navigation }) => {
console.log(password)
console.log(selectedMode.name)
try {
const response = await fetch('http://c47f3fbd2a93.ngrok.io/login', {
const response = await fetch('http://2d368f8dcb73.ngrok.io/login', {
method: 'POST',
headers: {
Accept: 'application/json',
Expand Down

0 comments on commit a53c4bc

Please sign in to comment.