|
| 1 | +import { View, Text, StyleSheet, TouchableOpacity } from "react-native"; |
| 2 | +import { doc, updateDoc } from "firebase/firestore"; |
| 3 | +import { db, auth } from "../config"; |
| 4 | +import to from "await-to-js"; |
| 5 | +import { useNavigation } from "@react-navigation/native"; |
| 6 | + |
| 7 | +const User = ({ route }) => { |
| 8 | + const navigation = useNavigation(); |
| 9 | + const addPartner = async (user) => { |
| 10 | + let [error] = await to( |
| 11 | + updateDoc(doc(db, "users", user.uid), { partner: route.params.uid }) |
| 12 | + ); |
| 13 | + if (error) { |
| 14 | + console.log(error); |
| 15 | + return; |
| 16 | + } |
| 17 | + console.log("Partner added successfully!"); |
| 18 | + [error] = await to( |
| 19 | + updateDoc(doc(db, "users", route.params.uid), { partner: user.uid }) |
| 20 | + ); |
| 21 | + if (error) { |
| 22 | + console.log(error); |
| 23 | + return; |
| 24 | + } |
| 25 | + console.log("Partner added successfully!"); |
| 26 | + }; |
| 27 | + return ( |
| 28 | + <View style={styles.container}> |
| 29 | + <Text style={styles.message}> |
| 30 | + You have received an invitation from {auth.currentUser.displayName}! |
| 31 | + </Text> |
| 32 | + <TouchableOpacity |
| 33 | + style={styles.button} |
| 34 | + onPress={addPartner(auth.currentUser)} |
| 35 | + > |
| 36 | + <Text>Accept</Text> |
| 37 | + </TouchableOpacity> |
| 38 | + <TouchableOpacity |
| 39 | + style={styles.button} |
| 40 | + onPress={navigation.navigate("Home")} |
| 41 | + > |
| 42 | + <Text>Decline</Text> |
| 43 | + </TouchableOpacity> |
| 44 | + </View> |
| 45 | + ); |
| 46 | +}; |
| 47 | + |
| 48 | +export default User; |
| 49 | +const styles = StyleSheet.create({ |
| 50 | + message: { |
| 51 | + fontWeight: "bold", |
| 52 | + fontSize: 20, |
| 53 | + alignSelf: "center", |
| 54 | + alignItems: "center", |
| 55 | + textAlign: "center", |
| 56 | + justifyContent: "center", |
| 57 | + }, |
| 58 | + container: { |
| 59 | + backgroundColor: "e5e5e5", |
| 60 | + padding: 15, |
| 61 | + borderRadius: 15, |
| 62 | + margin: 5, |
| 63 | + marginHorizontal: 10, |
| 64 | + alignItems: "center", |
| 65 | + justifyContent: "center", |
| 66 | + height: "100%", |
| 67 | + }, |
| 68 | + innerContainer: { |
| 69 | + alignItems: "flex-start", |
| 70 | + flexDirection: "column", |
| 71 | + marginLeft: 45, |
| 72 | + flex: 1, |
| 73 | + }, |
| 74 | + itemHeading: { |
| 75 | + fontWeight: "bold", |
| 76 | + fontSize: 18, |
| 77 | + marginRight: 22, |
| 78 | + }, |
| 79 | + formContainer: { |
| 80 | + flexDirection: "row", |
| 81 | + height: 80, |
| 82 | + marginLeft: 10, |
| 83 | + marginRight: 10, |
| 84 | + marginTop: 100, |
| 85 | + }, |
| 86 | + input: { |
| 87 | + height: 48, |
| 88 | + borderRadius: 5, |
| 89 | + overflow: "hidden", |
| 90 | + backgroundColor: "white", |
| 91 | + paddingLeft: 16, |
| 92 | + flex: 1, |
| 93 | + marginRight: 5, |
| 94 | + }, |
| 95 | + button: { |
| 96 | + height: 47, |
| 97 | + borderRadius: 5, |
| 98 | + backgroundColor: "#788eec", |
| 99 | + width: 80, |
| 100 | + alignItems: "center", |
| 101 | + justifyContent: "center", |
| 102 | + }, |
| 103 | + buttonText: { |
| 104 | + color: "white", |
| 105 | + fontSize: 20, |
| 106 | + textAlign: "center", |
| 107 | + }, |
| 108 | + todoIcon: { |
| 109 | + marginTop: 5, |
| 110 | + fontSize: 20, |
| 111 | + marginLeft: 14, |
| 112 | + }, |
| 113 | +}); |
0 commit comments