Commit 4d0f1d0a authored by pramod.nichelabs's avatar pramod.nichelabs

add bid functionality addded

parent 3d36ff1c
import React from 'react';
import React, { useState } from 'react';
import { StyleSheet, TouchableOpacity, View, TextInput } from 'react-native';
import themeColors from '../assets/colors';
import { MaterialIcons} from "@expo/vector-icons";
export const AppAddBid = (props) => {
const [bid, setBid] = useState('');
const handleChange = (val) => {
setBid(val);
}
return(
<View style={styles.bidContainer}>
<TextInput style={styles.input} keyboardType='number-pad' placeholder='Enter bid'/>
<TouchableOpacity onPress={props.onPress} style={styles.bid}>
<TextInput
style={styles.input}
keyboardType='number-pad'
placeholder='Enter bid'
onChangeText={(val) => handleChange(val)}/>
<TouchableOpacity onPress={() => props.onPress(bid)} style={styles.bid}>
<MaterialIcons name="add" size={16} color={themeColors.WHITE} />
</TouchableOpacity>
</View>
......
import React, { useEffect, useState } from 'react';
import axios from 'axios';
import {View, StyleSheet, Text, ScrollView} from 'react-native';
import { AppStakeItem } from '../components/auction.stake.component';
import { AppContainer } from '../container/container';
......@@ -6,8 +7,9 @@ import themeColors from '../assets/colors';
import { AuctionBottomTab } from '../Navigations/AuctionBottomTab';
import AppCarousel from '../components/carousel.component';
import { AppAddBid } from '../components/add_bid_button.component';
import Toast from 'react-native-root-toast';
const AuctionDetailScreen = ({route}) => {
const AuctionDetailScreen = ({route, navigation}) => {
const [auction, setAuction] = useState({bids: []});
const [bids, setBids] = useState([]);
console.log(route.params.auctionObject.bids);
......@@ -17,6 +19,43 @@ const AuctionDetailScreen = ({route}) => {
useEffect(() => {
setBids(auction.bids)
}, [auction])
const handleAddBid = (bidPrice) => {
const bidObj = {
id: 0,
name: auction.name,
owner: auction.owner,
bidprice: bidPrice
}
const url = "http://127.0.0.1:8085/bids/" + auction._id
axios.post(url, bidObj)
.then( async function (response) {
console.log(response.data);
if (response.data.message === 'Created') {
const successMsg = Toast.show('Your bid has been placed successfully', {
duration: Toast.durations.LONG,
});
setTimeout(function hideToast() {
Toast.hide(successMsg);
}, 1000);
navigation.navigate('AuctionHomeScreen');
} else {
const errMsg = Toast.show('Bid Creation Failed', {
duration: Toast.durations.LONG,
});
setTimeout(function hideToast() {
Toast.hide(errMsg);
}, 1000);
}
})
.catch(function (error) {
const errMsg = Toast.show('Bid Creation Failed', {
duration: Toast.durations.LONG,
});
setTimeout(function hideToast() {
Toast.hide(errMsg);
}, 1000);
});
}
return (
<View style={styles.wrapper}>
<View style={styles.header}>
......@@ -41,7 +80,7 @@ const AuctionDetailScreen = ({route}) => {
})}
</View>
</ScrollView>
<AppAddBid/>
<AppAddBid onPress={(bidPrice) => handleAddBid(bidPrice)}/>
</AppContainer>
<AuctionBottomTab/>
</View>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment