1
|
|
|
import React from "react"; |
2
|
|
|
import { Profile, History, Prepaid } from "../components"; |
3
|
|
|
import profile from "../models/profile.js"; |
4
|
|
|
import auth from "../models/auth.js"; |
5
|
|
|
import { useState, useEffect } from "react"; |
6
|
|
|
import { useStateContext } from "../contexts/ContextProvider"; |
7
|
|
|
import storage from "../models/storage"; |
8
|
|
|
const Account = () => { |
9
|
|
|
const [userData, setUserData] = useState({}); |
10
|
|
|
const { isGoogleAcc, isLoggedIn } = useStateContext(); |
11
|
|
|
|
12
|
|
|
useEffect(() => { |
13
|
|
|
fetchDataGoogle(); |
14
|
|
|
}, []); |
15
|
|
|
|
16
|
|
|
useEffect(() => { |
17
|
|
|
fetchData(); |
18
|
|
|
}, []); |
19
|
|
|
|
20
|
|
|
async function fetchData() { |
21
|
|
|
console.log("-----------ACCOUNT----------"); |
22
|
|
|
const id = storage.readJwtID(); |
23
|
|
|
const res = await profile.getUserInformation(id, false); |
24
|
|
|
setUserData(res.user); |
25
|
|
|
console.log("----------------------------"); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
async function fetchDataGoogle() { |
29
|
|
|
console.log("-----------ACCOUNT----------"); |
30
|
|
|
console.log("isGoogleAcc", isGoogleAcc); |
31
|
|
|
console.log("isLoggedIn", isLoggedIn); |
32
|
|
|
const resGoogle = await auth.getUser(); |
33
|
|
|
console.log("resGoogle._id", resGoogle._id); |
34
|
|
|
console.log("isGoogleAcc", isGoogleAcc); |
35
|
|
|
const res = await profile.getUserInformation(resGoogle._id, isGoogleAcc); |
36
|
|
|
console.log("Res User data", res); |
37
|
|
|
setUserData(res.user); |
38
|
|
|
console.log("----------------------------"); |
39
|
|
|
} |
40
|
|
|
return ( |
41
|
|
|
<> |
42
|
|
|
<div className="w-full flex flex-col py-4 px-7"> |
43
|
|
|
<div className="w-full py-4"> |
44
|
|
|
<Profile userData={userData} /> |
45
|
|
|
</div> |
46
|
|
|
<div className="flex flex-row"> |
47
|
|
|
<div className="w-2/3"> |
48
|
|
|
<History userData={userData} /> |
49
|
|
|
</div> |
50
|
|
|
<div className="w-1/3"> |
51
|
|
|
<Prepaid /> |
52
|
|
|
</div> |
53
|
|
|
</div> |
54
|
|
|
</div> |
55
|
|
|
</> |
56
|
|
|
); |
57
|
|
|
}; |
58
|
|
|
|
59
|
|
|
export default Account; |
60
|
|
|
|