1
|
|
|
import React, { useState } from "react"; |
2
|
|
|
import { profileInfo } from "../data/data"; |
3
|
|
|
import { FiCheck, FiX } from "react-icons/fi"; |
4
|
|
|
import auth from "../models/auth"; |
5
|
|
|
import { useStateContext } from "../contexts/ContextProvider"; |
6
|
|
|
import { useNavigate } from "react-router-dom"; |
7
|
|
|
const Profile = ({ userData }) => { |
8
|
|
|
const { isGoogleAcc, setIsLoggedIn, setIsGoogleAcc } = useStateContext(); |
9
|
|
|
const [isDelete, setIsDelete] = useState(false); |
10
|
|
|
const [deleteConfirm, setDeleteConfirm] = useState(); |
11
|
|
|
const navigate = useNavigate(); |
12
|
|
|
console.log("userData1", userData); |
13
|
|
|
|
14
|
|
|
const userInfo = () => { |
15
|
|
|
return profileInfo.map((item, index) => { |
16
|
|
|
return ( |
17
|
|
|
<div key={index} className="flex flex-col mx-3"> |
18
|
|
|
<h1 className="font-semibold text-xl">{item.title}</h1> |
19
|
|
|
<p |
20
|
|
|
className="border-b border-gray-500 |
21
|
|
|
text-gray-500 mr-2 w-64" |
22
|
|
|
> |
23
|
|
|
{userData[item.name]} |
24
|
|
|
</p> |
25
|
|
|
</div> |
26
|
|
|
); |
27
|
|
|
}); |
28
|
|
|
}; |
29
|
|
|
|
30
|
|
|
const deleteAccount = async () => { |
31
|
|
|
if (deleteConfirm === "DELETE") { |
32
|
|
|
await auth.deleteAcc(userData._id, isGoogleAcc); |
33
|
|
|
setIsLoggedIn(false); |
34
|
|
|
setIsGoogleAcc(false); |
35
|
|
|
navigate("/"); |
36
|
|
|
} |
37
|
|
|
}; |
38
|
|
|
|
39
|
|
|
if (!userData) { |
40
|
|
|
return <div>Loading</div>; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return ( |
44
|
|
|
<div className="flex flex-row justify-between bg-slate-200 px-8 py-4 rounded-xl"> |
45
|
|
|
<div className="flex flex-row justify-evenly">{userInfo()}</div> |
46
|
|
|
<div className="flex flex-col"> |
47
|
|
|
{/* <button |
48
|
|
|
onChange={() => {}} |
49
|
|
|
className="m-1 py-2 px-3 transition-colors bg-DarkBlue w-44 |
50
|
|
|
hover:bg-DarkHover text-white rounded-xl" |
51
|
|
|
> |
52
|
|
|
Change password |
53
|
|
|
</button> */} |
54
|
|
|
{!isGoogleAcc ? ( |
55
|
|
|
<div> |
56
|
|
|
{isDelete ? ( |
57
|
|
|
<div> |
58
|
|
|
<label>Type "DELETE" To confirm</label> |
59
|
|
|
<input |
60
|
|
|
placeholder="DELETE" |
61
|
|
|
value={deleteConfirm} |
62
|
|
|
onChange={(e) => { |
63
|
|
|
setDeleteConfirm(e.target.value); |
64
|
|
|
}} |
65
|
|
|
className="bg-gray-50 border border-gray-300 text-gray-900 |
66
|
|
|
text-sm rounded-lg block p-2.5 w-full" |
67
|
|
|
/> |
68
|
|
|
<div className=" flex justify-center w-full py-3"> |
69
|
|
|
<button |
70
|
|
|
onClick={() => { |
71
|
|
|
deleteAccount(); |
72
|
|
|
setDeleteConfirm(""); |
73
|
|
|
}} |
74
|
|
|
className="rounded-full bg-blue-600 text-white p-1 mx-2" |
75
|
|
|
> |
76
|
|
|
<FiCheck /> |
77
|
|
|
</button> |
78
|
|
|
<button |
79
|
|
|
onClick={() => { |
80
|
|
|
setIsDelete(false); |
81
|
|
|
setDeleteConfirm(""); |
82
|
|
|
}} |
83
|
|
|
className="rounded-full bg-red-400 text-white p-1 mx-2" |
84
|
|
|
> |
85
|
|
|
<FiX /> |
86
|
|
|
</button> |
87
|
|
|
</div> |
88
|
|
|
</div> |
89
|
|
|
) : ( |
90
|
|
|
<button |
91
|
|
|
onClick={() => { |
92
|
|
|
setIsDelete(true); |
93
|
|
|
}} |
94
|
|
|
className=" |
95
|
|
|
m-1 py-2 px-3 transition-colors bg-DarkBlue w-44 |
96
|
|
|
hover:bg-DarkHover text-white rounded-xl" |
97
|
|
|
> |
98
|
|
|
Delete account |
99
|
|
|
</button> |
100
|
|
|
)} |
101
|
|
|
</div> |
102
|
|
|
) : null} |
103
|
|
|
</div> |
104
|
|
|
</div> |
105
|
|
|
); |
106
|
|
|
}; |
107
|
|
|
|
108
|
|
|
export default Profile; |
109
|
|
|
|