Skip to content

Commit 2165981

Browse files
authored
Merge pull request #26 from nandcoder/ekta
ui + form update
2 parents 402464a + 37e5ff7 commit 2165981

File tree

4 files changed

+61
-80
lines changed

4 files changed

+61
-80
lines changed

src/components/Card.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { Link } from 'react-router-dom';
22
import Button from 'react-bootstrap/Button';
33
import Card from 'react-bootstrap/Card';
4-
// import { TextsmsTwoTone } from '@mui/icons-material';
54

6-
function BasicExample({ head, text, link, imgUrl }) {
5+
function BasicExample({ head, text,textColor, link, imgUrl }) {
76
return (
8-
<Card style={{ width: '18rem', height: '12rem', background: `url(${imgUrl})`, backgroundPosition: 'center center', backgroundSize: 'cover', backgroundRepeat: 'no-repeat' }}>
9-
{/* <Card.Img variant="top" src={imgUrl} /> */}
7+
<Card text={textColor} style={{ width: '18rem', height: '12rem',border: 'solid #c6c6c6 5px',borderRadius:'20px', background: `url(${imgUrl})`, backgroundPosition: 'center center', backgroundSize: 'cover', backgroundRepeat: 'no-repeat' }}>
108
<Card.Body>
11-
<Card.Title style={{ fontWeight: 'bolder', fontSize: '30px' }}>{head}</Card.Title>
9+
<Card.Title style={{ fontWeight: 'bolder', fontSize: '30px',color:'black' }}>{head}</Card.Title>
1210
<Card.Text style={{
1311
float: "right",
1412
fontWeight: "500",

src/pages/Home/Sections/AddGroup.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,18 @@ const AddGroup = (props) => {
123123
</FormErrorMessage>
124124
</FormControl>
125125

126-
126+
<FormControl marginTop="2" isInvalid={errors.days}>
127+
<FormLabel htmlFor="days">Days</FormLabel>
128+
<Input
129+
type="number"
130+
name="days"
131+
placeholder="Number of days of the trip"
132+
{...register("days")}
133+
/>
134+
<FormErrorMessage>
135+
{errors.days && errors.days.message}
136+
</FormErrorMessage>
137+
</FormControl>
127138

128139
<FormControl mt="2" isInvalid={errors.involved}>
129140
<FormLabel htmlFor="involved">Add members to the group</FormLabel>

src/pages/Home/index.js

Lines changed: 29 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,20 @@ import AddGroup from "./Sections/AddGroup";
55
import GroupCard from "./Sections/GroupCard";
66
import { db } from "../../utils/firebase";
77
import { AuthContext } from "../../components/Authentication/AuthProvider";
8+
import { DataContext } from "../../components/Authentication/DataProvider";
89
import AddButton from "../../components/AddButton";
910
import Loader from "../../components/Loader";
1011
import img1 from "../../assets/images/i5.jpeg"
1112
import img2 from "../../assets/images/p3.jpeg"
1213
import img3 from "../../assets/images/t3.jpeg"
13-
// export const DataContext = createContext();
14-
// export const DataProvider = ({ children }) => {
15-
// const { user } = useContext(AuthContext);
16-
// const [currentGroup, setCurrentGroup] = useState('');
17-
// const [transactions, setTransactions] = useState([]);
18-
// const [users, setUsers] = useState({});
19-
// const [friends, setFriends] = useState([]);
20-
// useEffect(() => {
21-
// const temp = [];
22-
// const tempFriends = []
23-
// db.collection("transactions")
24-
// .where("involved", "array-contains", user.uid)
25-
// .get()
26-
// .then((querySnapshot) => {
27-
// querySnapshot.forEach((doc) => {
28-
// // console.log(doc.id, " => ", doc.data());
29-
// const id = doc.id;
30-
// const data = doc.data();
31-
// const finalTransaction = {
32-
// id,
33-
// data,
34-
// }
35-
// data.involved.forEach(personId => {
36-
// if (tempFriends.includes(personId)) { }
37-
// else tempFriends.push(personId)
38-
// });
39-
// temp.push(finalTransaction);
40-
// })
41-
// })
42-
// .catch((error) => {
43-
// console.log("Error getting documents: ", error);
44-
// })
45-
// .finally(() => {
46-
// setFriends(tempFriends);
47-
// setTransactions(temp);
48-
// });
49-
50-
51-
// }, [user]);
52-
// useEffect(() => {
53-
// const temp = {}
54-
// if (friends.length) db.collection("users")
55-
// .where("userId", "in", friends)
56-
// .get()
57-
// .then((querySnapshot) => {
58-
// querySnapshot.forEach((doc) => {
59-
// // doc.data() is never undefined for query doc snapshots
60-
// // console.log(doc.id, " => ", doc.data());
61-
// const data = doc.data();
62-
// const dataWithAmt = { ...data, amount: 0 };
63-
// temp[data.userId] = dataWithAmt;
64-
// // setUsers((prevUsers) => {
65-
// // return { ...prevUsers, [id]: dataWithAmt, }
66-
// // })
67-
// });
68-
// })
69-
// .catch((error) => {
70-
// console.log("Error getting documents: ", error);
71-
// })
72-
// .finally(() => {
73-
// setUsers(temp)
74-
// // setLoading(false)
75-
// })
76-
// }, [friends]);
77-
78-
// return (
79-
// <DataContext.Provider value={{ transactions, setTransactions, users, setUsers, currentGroup, setCurrentGroup }} >
80-
// {children}
81-
// </DataContext.Provider>
82-
// )
83-
// }
8414

8515
const colorss = ["#B794F4", "#c5fb9d", "#f5a9b8", "#faf089", "#90D2DA", "#FEB2B2", "#FBD38D", "#DA90CB", "#DB90CB"]
8616

8717
const Home = () => {
8818
const { user } = useContext(AuthContext);
19+
const { transactions}=useContext(DataContext);
8920
const [groups, setGroups] = useState([]);
21+
const [amount,setAmount]=useState({total:0,iOwe:0,peopleOwe:0})
9022
const [loading, setLoading] = useState(true);
9123
const [show, setShow] = useState(false);
9224
const handleClose = () => setShow(false);
@@ -113,6 +45,26 @@ const Home = () => {
11345

11446
}, [user]);
11547

48+
useEffect(()=>{
49+
let total=0,negative=0,positive=0;
50+
transactions.forEach((transaction)=>{
51+
const amt=transaction.data.amount/transaction.data.involved.length
52+
if(transaction.data.paidBy===user.uid){
53+
positive+=amt
54+
total+=amt
55+
}else{
56+
negative-=amt
57+
total+=amt
58+
}
59+
})
60+
const updatedAmount={
61+
total:total,
62+
iOwe:negative,
63+
peopleOwe:positive,
64+
}
65+
setAmount(updatedAmount)
66+
},[transactions,user])
67+
11668
// const [spent, setSpent] = useState(0);
11769
// const [remain, setRemain] = useState(0);
11870
// const spentLink = "/";
@@ -125,21 +77,24 @@ const Home = () => {
12577
className="fbcard"
12678
imgUrl={img3}
12779
head="Total Expenditure"
128-
text="₹ 10000"
80+
text={`₹ ${amount.total}`}
81+
textColor={'info'}
12982
link="/transaction"
13083
/>
13184
<Card
13285
className="fbcard"
13386
imgUrl={img2}
13487
head="I OWE PEOPLE"
135-
text="₹ 3000"
88+
text={`₹ ${amount.iOwe}`}
89+
textColor={'danger'}
13690
link="/transaction"
13791
/>
13892
<Card
13993
className="fbcard"
14094
imgUrl={img1}
14195
head="PEOPLE OWE ME"
142-
text="₹ 800"
96+
text={`₹ ${amount.peopleOwe}`}
97+
textColor={'success'}
14398
link="/user"
14499
/>
145100
</Container>

src/utils/validator/addGroupResolver.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ const addGroupSchema = Joi.object({
4242
});
4343
return errors;
4444
}),
45+
days: Joi.number()
46+
.positive()
47+
.integer()
48+
.required()
49+
.error((errors) => {
50+
errors.forEach((err) => {
51+
if (err.code === "number.positive") {
52+
err.message = "Days must be positive"
53+
}
54+
else if (err.code === "number.base") {
55+
err.message = "Days must be an integer"
56+
}
57+
else if (err.code === "number.empty") {
58+
err.message = "Days is required"
59+
}
60+
})
61+
}),
4562
mails: Joi.array()
4663
.items(Joi.string())
4764
.unique()

0 commit comments

Comments
 (0)