Skip to content

Commit

Permalink
order room and checkout room
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenPhuongNam99 committed Feb 10, 2023
1 parent 705bd0b commit cb370ad
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 78 deletions.
14 changes: 7 additions & 7 deletions src/features/confirm-screen/ConfirmScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const ConfirmScreen = ({ route }) => {
};

// Fetch the intent client secret from the backend
const clientSecretData = await fetchPaymentIntentClientSecret();
console.log('client data', clientSecretData)
const {receipt_url} = await fetchPaymentIntentClientSecret();
console.log('client data', receipt_url)

// Confirm the payment with the card details
// const { paymentIntent, error } = await confirmPayment(clientSecretData.clientSecret, {
Expand All @@ -68,11 +68,11 @@ const ConfirmScreen = ({ route }) => {
// },
// });

if (!clientSecretData.receipt_url) {
if (!receipt_url) {
console.log('Payment confirmation error');
setLoading(false)
} else if (clientSecretData) {
console.log('Success from promise', clientSecretData);
} else if (receipt_url) {
console.log('Success from promise', receipt_url);
const tokenNew = await AsyncStorage.getItem('storage_Key');
const obj = {
user_id: dataUserInfor?._id,
Expand All @@ -88,7 +88,7 @@ const ConfirmScreen = ({ route }) => {
tourName: item.item.item.tour_name,
emailUser: dataUserInfor.email,
status: 'chờ xác nhận ',
receipt_url: clientSecretData.receipt_url
receipt_url: receipt_url
};
const response = await axios.post(
`${Base_Url}/v1/orderTour/createOrderTour`,
Expand Down Expand Up @@ -119,7 +119,7 @@ const ConfirmScreen = ({ route }) => {

return (
<View style={styles.container}>
<Text style={styles.headerTitle}>Xác nhận đặt Tour</Text>
<Text style={styles.headerTitle}>Xác nhận đặt Touraa</Text>
<View style={{ zIndex: 99 }}>
<Toast />
</View>
Expand Down
25 changes: 3 additions & 22 deletions src/features/detail-room/DetailRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const DetailRoom = ({ route }) => {
const obj = {
id: item._id,
idRoom: idClick._id,
statusRoom: true,
user_room: dataLogin?._id
};
const response = axios.put(
'http://206.189.37.26:8080/v1/hotel/updateRoomStatus',
Expand All @@ -67,29 +69,8 @@ const DetailRoom = ({ route }) => {
},
},
);


const dataCreateRoomOrder = {
room_name: idClick.room_name,
room_price: idClick.room_price,
room_quantity: idClick.room_quantity,
room_status: idClick.room_status,
room_description: idClick.room_description,
room_thumbnail: idClick.room_thumbnail,
user_id: dataLogin._id,
hotel_id: item._id,
room_id: idClick._id
}
const createRoomOrder = await axios.post(
'http://206.189.37.26:8080/v1/hotelRoomOrder/createHotelRoomOrder',
dataCreateRoomOrder,
{
headers: {
Authorization: `Bearer ${tokenNew}`,
},
},
);
console.log('createRoomOrder', createRoomOrder)

setVisiable(false);

Toast.show({
Expand Down
109 changes: 60 additions & 49 deletions src/features/roomOrder/RoomOrder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,30 @@ import { Modal } from 'react-native-paper';
import Toast from 'react-native-toast-message';
import { Base_Url } from '../../constants/const';
import Loading from '../../components/loading';
import { useAppSelector } from '../../app/store'
import { useIsFocused } from '@react-navigation/native';

const RoomOrder = () => {
const navigation = useNavigation();
const [idClick, setIdClick] = useState<any>();
const [visiable, setVisiable] = useState(false);
const [data, setData] = useState();
const [loading, setLoading] = useState(false)

const dataUser: any = useAppSelector((state) => state.LoginSlice.data);
console.log('dd', dataUser?._id)
const focus = useIsFocused();

const getDetailRoomOfId = async () => {
try {
setLoading(true)
const tokenNew = await AsyncStorage.getItem('storage_Key');

const response = await axios.get(`${Base_Url}/v1/hotelRoomOrder/getAllHotelRoomOrder`, {
const response = await axios.get(`${Base_Url}/v1/hotel/fill/1`, {
headers: {
Authorization: `Bearer ${tokenNew}`,
},
});
console.log('resposn', response.data)
setData(response.data)
setLoading(false)
// setDataHomeStay(response.data);
Expand All @@ -45,20 +50,21 @@ const RoomOrder = () => {

useEffect(() => {
getDetailRoomOfId()
}, [])
}, [focus])

console.log('click', idClick)

const statusRoom = async () => {
try {
const tokenNew = await AsyncStorage.getItem('storage_Key');

console.log('id click', idClick)
const obj = {
id: idClick.hotel_id,
idRoom: idClick.room_id,
idHotelOrder: idClick._id
id: idClick.idHotel,
idRoom: idClick.itemRoomOrder._id,
statusRoom: false,
user_room: dataUser?._id
};
const response = axios.put(
'http://206.189.37.26:8080/v1/hotel/updateRoomStatusAndDeleteHotelOrder',
'http://206.189.37.26:8080/v1/hotel/updateRoomStatus',
obj,
{
headers: {
Expand Down Expand Up @@ -86,7 +92,7 @@ const RoomOrder = () => {
}
};

console.log('data click', data)
console.log('id click', idClick)

return (
<View style={styles.container}>
Expand All @@ -109,47 +115,52 @@ const RoomOrder = () => {
{
data?.length > 0 ? (
<FlatList
data={data}
renderItem={({ item }) => {
console.log('item view', item)
return (
<View style={styles.blockList}>
<View style={styles.clickList}>
<View style={styles.topClick}>
<Image
style={styles.image}
source={{ uri: String(item.room_thumbnail) }}
/>
</View>
<View style={styles.bottomClick}>
<Text style={styles.bottomHeader}>
Tên phòng: {item.room_name}
</Text>
<Text numberOfLines={1}>
Miêu tả phòng: {item.room_description}
</Text>
<View style={styles.blockAccept}>
<Text>Gía: {item.room_price} đồng</Text>
<TouchableOpacity
style={styles.clickAccept}
onPress={() => (
setIdClick(item), setVisiable(!visiable)
)}>
<Text style={{ color: 'white' }}>Trả phòng</Text>
</TouchableOpacity>
data={data}
renderItem={({ item }) => {
console.log('item', item)
return (
<View style={styles.blockList}>
<View style={styles.clickList}>
<View style={styles.topClick}>
<Image
style={styles.image}
source={{ uri: String(item.itemRoomOrder.room_thumbnail) }}
/>
</View>
<View style={styles.bottomClick}>
<Text style={styles.bottomHeader}>
Tên phòng: {item.itemRoomOrder.room_name}
</Text>
<Text numberOfLines={1}>
Miêu tả phòng: {item.itemRoomOrder.room_description}
</Text>
<View style={styles.blockAccept}>
<Text>Gía: {item.itemRoomOrder.room_price} đồng</Text>
<Text style={styles.bottomHeader}>
Trạng thái: {item.itemRoomOrder.room_status === 'false' ? 'chờ xác nhận' : item.itemRoomOrder.room_status === 'xac nhan' ? item.itemRoomOrder.room_status : 'đã xác nhận'}
</Text>
{
item.itemRoomOrder.room_status === 'xac nhan' && <TouchableOpacity
style={styles.clickAccept}
onPress={() => (
setIdClick(item), setVisiable(!visiable)
)}>
<Text style={{ color: 'white' }}>Trả phòng</Text>
</TouchableOpacity>
}
</View>
</View>
</View>
</View>
</View>
</View>
);
}}
/>
)
: (
<View style={{width: '100%', height: '100%', justifyContent: 'center', alignItems: 'center'}}>
<Text>Bạn chưa đặt khách sạn nào !</Text>
</View>
);
}}
/>
)
: (
<View style={{ width: '100%', height: '100%', justifyContent: 'center', alignItems: 'center' }}>
<Text>Bạn chưa đặt khách sạn nào !</Text>
</View>
)
}

<Modal visible={visiable} style={styles.modalContainer}>
Expand Down Expand Up @@ -177,7 +188,7 @@ const styles = StyleSheet.create({
alignItems: 'center',
paddingHorizontal: 10,
},
blockList: { width: '100%', height: 240, marginTop: 20, paddingHorizontal: 10 },
blockList: { width: '100%', height: 255, marginTop: 20, paddingHorizontal: 10 },
clickList: {
width: '100%',
height: '100%',
Expand Down

0 comments on commit cb370ad

Please sign in to comment.