-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRentalAppInfo.tsx
182 lines (181 loc) · 5.04 KB
/
RentalAppInfo.tsx
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
173
174
175
176
177
178
179
180
181
182
/** @format */
import React, { useState } from "react";
import { StyleSheet, Button, View, Text, TextInput } from "react-native";
import { app } from "../environment/config";
import { db } from "../environment/config";
import {
collection,
updateDoc,
arrayUnion,
query,
where,
getDocs,
doc,
getDoc,
setDoc,
} from "firebase/firestore";
type propType = {
navigation: any;
};
const RentalAppInfo: React.FC<propType> = ({ navigation }) => {
const styles = getStyles();
const property = navigation.getParam("property");
const isLandLord = navigation.getParam("isLandLord");
const [bal, setBal] = useState(property.balance);
const [lateFee, setLateFee] = useState<string>("0");
const [discount, setDiscount] = useState<string>("0");
const [applications, setApplications] = useState<string[]>(
property.Applications.filter((app: string) => {
return app !== "";
})
);
const removeApp = (app: string) => {
setApplications(
applications.filter((application) => {
return application !== app;
})
);
};
const [requests, setRequests] = useState<string[]>(
property.mRequests.filter((req: string) => {
return req !== "";
})
);
const removeReq = (request: string) => {
setRequests(
requests.filter((req) => {
return req !== request;
})
);
};
const [rentPay, setRentPay] = useState<string>("");
const payRent = (bal: number) => {
setBal(bal);
setRentPay("Thank you for paying rent!");
};
return (
<View style={styles.container}>
<View style={styles.card}>
<Text style={styles.h1}>{property.name}</Text>
<Text style={styles.p}>{property.address}</Text>
</View>
<View style={styles.card}>
<Text style={styles.h1}>Rent Status</Text>
<Text style={styles.h2}>You Owe {"$" + bal}</Text>
{isLandLord && (
<View>
<TextInput onChangeText={setLateFee} value={lateFee} />
<Button
onPress={async () => {
let fee =
parseInt(lateFee) === NaN ||
lateFee === "" ||
parseInt(lateFee) < 0
? 0
: parseInt(lateFee);
setBal(bal + fee);
await setDoc(doc(db, "housing", property.name), {
...property,
balance: bal + fee,
});
}}
title="Add Late Fee"
/>
<TextInput onChangeText={setDiscount} value={discount} />
<Button
onPress={async () => {
let fee =
parseInt(discount) === NaN ||
discount === "" ||
parseInt(discount) < 0
? 0
: parseInt(discount);
setBal(bal - fee);
await setDoc(doc(db, "housing", property.name), {
...property,
balance: bal - fee,
});
}}
title="Add Discount"
/>
</View>
)}
</View>
<View style={styles.card}>
{isLandLord && (
<Button
onPress={() => {
navigation.navigate("ViewApplications", {
property: property,
applications: applications,
removeApp: removeApp,
});
}}
title="View Current Applications"
/>
)}
{!isLandLord && (
<View>
<Button
onPress={() => {
navigation.navigate("TenantPay", {
property: property,
bal: bal,
setBal: payRent,
});
}}
title="Pay Rent"
/>
<Text style={{ color: "green" }}>{rentPay}</Text>
</View>
)}
</View>
<View style={styles.card}>
<Text style={styles.h1}>Maintinence</Text>
<Button
onPress={() => {
navigation.navigate("Maintinence", {
property: property,
isLandLord: isLandLord,
requests: requests,
removeReq: removeReq,
});
}}
title={
isLandLord
? "View Maintinence Requests"
: "Submit a Maintinence Request"
}
/>
</View>
</View>
);
};
const getStyles = () => {
return StyleSheet.create({
container: {
padding: 20,
backgroundColor: "#D1FFF4",
flex: 1,
},
card: {
backgroundColor: "#fff",
borderRadius: 5,
padding: 20,
marginBottom: 20,
},
h1: {
fontSize: 18,
color: "#000",
},
h2: {
fontSize: 14,
color: "#000",
},
p: {
fontSize: 12,
color: "#000",
},
});
};
export default RentalAppInfo;