Commit c5efe094 authored by pramod.nichelabs's avatar pramod.nichelabs

added create auction functionality

parent d02e7fed
import { StatusBar } from 'expo-status-bar';
import React from 'react'; import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native'; import { StyleSheet} from 'react-native';
import { NavigationContainer } from "@react-navigation/native"; import { NavigationContainer } from "@react-navigation/native";
import { createDrawerNavigator } from "@react-navigation/drawer"; import { createDrawerNavigator } from "@react-navigation/drawer";
import { homeStack } from "./Navigations/homeStack"; import { homeStack } from "./Navigations/homeStack";
import { AuthStack } from "./Navigations/AuthStack"; import { AuthStack } from "./Navigations/AuthStack";
import { FontAwesome } from '@expo/vector-icons'; import { RootSiblingParent } from 'react-native-root-siblings';
import { AboutUs } from './screen/AboutUs';
// import {HomeScreen} from './screen/HomeScreen';
// import {HomeScreen} from './screen/HomeScreen'
// import {BottomTab} from './Navigations/BottomTab';
// import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
const Drawer = createDrawerNavigator(); const Drawer = createDrawerNavigator();
// const Tab = createMaterialBottomTabNavigator();
export default function App() { export default function App() {
return ( return (
<RootSiblingParent>
<NavigationContainer> <NavigationContainer>
<Drawer.Navigator initialRouteName="Authntications"> <Drawer.Navigator initialRouteName="Authntications">
<Drawer.Screen name="HOME" component={AuthStack} /> <Drawer.Screen name="HOME" component={AuthStack} />
<Drawer.Screen name="About Us" component={homeStack} /> <Drawer.Screen name="About Us" component={homeStack} />
{/* <Drawer.Screen name="MainTab" component={MainTabScreen} /> */} {/* <Drawer.Screen name="MainTab" component={MainTabScreen} /> */}
{/* <Drawer.Screen name="About Us" component={AboutUs} /> */} {/* <Drawer.Screen name="About Us" component={AboutUs} /> */}
</Drawer.Navigator> </Drawer.Navigator>
{/* <HomeScreen/> */} {/* <HomeScreen/> */}
</NavigationContainer> </NavigationContainer>
</RootSiblingParent>
); );
} }
......
...@@ -2,7 +2,7 @@ import React, {useState} from 'react'; ...@@ -2,7 +2,7 @@ import React, {useState} from 'react';
import {View, StyleSheet, Platform} from 'react-native'; import {View, StyleSheet, Platform} from 'react-native';
import DateTimePicker from '@react-native-community/datetimepicker'; import DateTimePicker from '@react-native-community/datetimepicker';
export const AppDatePicker = () => { export const AppDatePicker = (props) => {
const [date, setDate] = useState(new Date()); const [date, setDate] = useState(new Date());
const [mode, setMode] = useState('date'); const [mode, setMode] = useState('date');
const [show, setShow] = useState(false); const [show, setShow] = useState(false);
...@@ -11,6 +11,7 @@ export const AppDatePicker = () => { ...@@ -11,6 +11,7 @@ export const AppDatePicker = () => {
const currentDate = selectedDate || date; const currentDate = selectedDate || date;
setShow(Platform.OS === 'ios'); setShow(Platform.OS === 'ios');
setDate(currentDate); setDate(currentDate);
props.onDateSelect(currentDate);
}; };
return ( return (
......
...@@ -27,8 +27,8 @@ const AuctionDetailScreen = ({route}) => { ...@@ -27,8 +27,8 @@ const AuctionDetailScreen = ({route}) => {
<View style={styles.titleContent}> <View style={styles.titleContent}>
<Text style={styles.auctionHeading}>{auction.name}</Text> <Text style={styles.auctionHeading}>{auction.name}</Text>
<View style={styles.lotContainer}> <View style={styles.lotContainer}>
<Text style={styles.auctionText}>Owner : </Text> <Text style={styles.auctionText}>Starting Price : </Text>
<View style={styles.lot}><Text style={styles.lotText}>{auction.owner}</Text></View> <View style={styles.lot}><Text style={styles.lotText}>{auction.starting_price}</Text></View>
</View> </View>
</View> </View>
<Text style={styles.auctionText}>Last Stakes</Text> <Text style={styles.auctionText}>Last Stakes</Text>
......
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import axios from 'axios';
import {View, StyleSheet, Text, ScrollView, Image, TouchableOpacity} from 'react-native'; import {View, StyleSheet, Text, ScrollView, Image, TouchableOpacity} from 'react-native';
import { AppContainer } from '../container/container'; import { AppContainer } from '../container/container';
import themeColors from '../assets/colors'; import themeColors from '../assets/colors';
...@@ -7,9 +8,13 @@ import { AppTextInput } from '../components/text_input.component'; ...@@ -7,9 +8,13 @@ import { AppTextInput } from '../components/text_input.component';
import { AppButton } from '../components/button.component'; import { AppButton } from '../components/button.component';
import { AppDatePicker } from '../components/datpicker.component'; import { AppDatePicker } from '../components/datpicker.component';
import { MaterialIcons } from "@expo/vector-icons"; import { MaterialIcons } from "@expo/vector-icons";
import Toast from 'react-native-root-toast';
const UserAuctionCreateScreen = ({route, navigation}) => { const UserAuctionCreateScreen = ({route, navigation}) => {
const [image, setImage] = useState('https://via.placeholder.com/50'); const [image, setImage] = useState('https://via.placeholder.com/50');
const [auctionName, setAuctionName] = useState('');
const [auctionPrice, setAuctionPrice] = useState('');
const [expireDate, setExpireDate] = useState('');
useEffect(() => { useEffect(() => {
if (route.params === undefined) { if (route.params === undefined) {
...@@ -19,6 +24,57 @@ const UserAuctionCreateScreen = ({route, navigation}) => { ...@@ -19,6 +24,57 @@ const UserAuctionCreateScreen = ({route, navigation}) => {
} }
}, []) }, [])
const itemNameChange = (itemName) => {
setAuctionName(itemName);
}
const itemPriceChange = (itemPrice) => {
setAuctionPrice(itemPrice);
}
const handleDateChange = (selectedDate) => {
setExpireDate(selectedDate);
}
const handleSubmit = () => {
let auctionObj = {
name: auctionName,
owner: "Pramodh Rajapakse",
bids: [],
starting_price: auctionPrice,
expire_date: expireDate,
images: [image]
}
axios.post("http://127.0.0.1:8085/auctions", auctionObj)
.then( async function (response) {
if (response.data.message === 'Created') {
const successMsg = Toast.show('Your auction has been created successfully', {
duration: Toast.durations.LONG,
});
setTimeout(function hideToast() {
Toast.hide(successMsg);
}, 1000);
navigation.navigate('AuctionHomeScreen');
} else {
const errMsg = Toast.show('Auction Creation Failed', {
duration: Toast.durations.LONG,
});
setTimeout(function hideToast() {
Toast.hide(errMsg);
}, 1000);
}
})
.catch(function (error) {
const errMsg = Toast.show('Auction Creation Failed', {
duration: Toast.durations.LONG,
});
setTimeout(function hideToast() {
Toast.hide(errMsg);
}, 1000);
});
}
return ( return (
<View style={styles.container}> <View style={styles.container}>
<AppContainer> <AppContainer>
...@@ -27,11 +83,11 @@ const UserAuctionCreateScreen = ({route, navigation}) => { ...@@ -27,11 +83,11 @@ const UserAuctionCreateScreen = ({route, navigation}) => {
</View> </View>
<ScrollView> <ScrollView>
<View> <View>
<AppTextInput placeholder='Enter item name'/> <AppTextInput placeholder='Enter item name' onChangeText={(val) => itemNameChange(val)}/>
<AppTextInput placeholder='Enter item price' keyboardType='numeric'/> <AppTextInput placeholder='Enter item price' onChangeText={(val) => itemPriceChange(val)} keyboardType='numeric'/>
<View style={styles.dateContainer}> <View style={styles.dateContainer}>
<Text style={styles.label}>Expire Date</Text> <Text style={styles.label}>Expire Date</Text>
<AppDatePicker/> <AppDatePicker onDateSelect={handleDateChange}/>
</View> </View>
<Text style={styles.imgLabel}>Item Image</Text> <Text style={styles.imgLabel}>Item Image</Text>
<View style={styles.addImagewrapper}> <View style={styles.addImagewrapper}>
...@@ -46,7 +102,7 @@ const UserAuctionCreateScreen = ({route, navigation}) => { ...@@ -46,7 +102,7 @@ const UserAuctionCreateScreen = ({route, navigation}) => {
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
<AppButton label='Add Item'/> <AppButton label='Add Item' onPress={() => handleSubmit()}/>
</View> </View>
</ScrollView> </ScrollView>
</AppContainer> </AppContainer>
......
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