-
Notifications
You must be signed in to change notification settings - Fork 0
/
Payments.js
172 lines (164 loc) · 4.33 KB
/
Payments.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import {
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
TextInput,
} from "react-native";
import React, { useEffect, useState } from "react";
import firebase from "firebase/app";
import "firebase/firestore";
import Icon from "react-native-vector-icons/AntDesign";
import {
collection,
doc,
set,
arrayUnion,
FieldValue,
getDoc,
getDocs,
query,
updateDoc,
where,
} from "firebase/firestore";
import { auth, db } from "./firebase/firebase";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { useNavigation } from "@react-navigation/native";
const PayMembership = () => {
const navigation = useNavigation();
const [amount, setAmount] = useState(null);
const [history, setHistory] = useState({});
useEffect(() => {
async function fetchUserListings() {
const listingRef = collection(db, "users");
const q = query(
listingRef,
where("Rotary_Id", "==", auth.currentUser.uid)
);
const quarySnap = await getDocs(q);
let listings = [];
quarySnap.forEach((doc) => {
return listings.push({
id: doc.id,
data: doc.data(),
});
});
// console.log(listings);
const data = listings[0].data;
setHistory({ ...data.History });
console.log(history);
// console.log(auth.currentUser);
}
fetchUserListings();
}, [auth.currentUser.uid]);
const handlePayment = async () => {
const listingRef = collection(db, "users");
const q = query(listingRef, where("Rotary_Id", "==", auth.currentUser.uid));
const querySnap = await getDocs(q);
const docRef = querySnap.docs[0].ref;
// setNewHistory({ ...history, [new Date().getTime()]: amount });
// console.log(newHistory);
try {
await updateDoc(docRef, {
History: {
...history,
[new Date().getTime()]: {
amount: amount,
date: new Date().getTime(),
},
},
});
console.log("Payment successful.");
} catch (error) {
console.log(error.message);
if (error.code === "not-found") {
console.error("User document not found.");
}
}
if (amount != null) {
setTimeout(() => {
navigation.replace("ThankYouPage");
}, 2000);
} else {
alert("enter a valid amount");
}
};
return (
<KeyboardAwareScrollView
style={{ backgroundColor: "white", height: "100%" }}
>
<Icon
name="leftcircle"
size={30}
color={"#FFA500"}
style={{ top: 5, left: 10, zIndex: 1, position: "absolute" }}
onPress={() => navigation.replace("DrawerNavigator")}
/>
<View
style={{
alignItems: "center",
justifyContent: "center",
backgroundColor: "white",
padding: 26,
}}
>
<Text
style={{
top: 1,
position: "absolute",
fontSize: 32,
color: "#FFA500",
fontWeight: "bold",
}}
>
PAY
</Text>
<Image
style={{ height: 300, width: 300, marginTop: 50 }}
source={require("./assets/qr.png")}
/>
</View>
<View style={{ alignItems: "center", marginTop: 20 }}>
<Text style={{ color: "black" }}>Pay Membership Due</Text>
<TextInput
style={{
borderColor: "#FFA500",
borderWidth: 3,
width: "60%",
padding: 5,
paddingHorizontal: 20,
borderRadius: 15,
}}
placeholder="Enter Amount"
value={amount}
onChangeText={(amount) => setAmount(amount)}
keyboardType="numeric"
></TextInput>
</View>
<View style={{ alignItems: "center", justifyContent: "center" }}>
<TouchableOpacity style={styles.button} onPress={handlePayment}>
<Text style={styles.buttonText}>Pay</Text>
</TouchableOpacity>
</View>
</KeyboardAwareScrollView>
);
};
export default PayMembership;
const styles = StyleSheet.create({
button: {
backgroundColor: "#FFA500",
width: "40%",
padding: 15,
borderRadius: 20,
alignItems: "center",
justifyContent: "center",
bottom: 5,
marginTop: 20,
},
buttonText: {
color: "white",
fontWeight: "700",
fontSize: 16,
},
});