-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggedInView.tsx
122 lines (120 loc) · 3.7 KB
/
LoggedInView.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
import {
Avatar,
Box,
Button,
Divider,
Fab,
FormControl,
FormControlLabel,
FormLabel,
InputAdornment,
Radio,
RadioGroup,
Stack,
TextField,
Typography,
} from "@mui/material";
import firebase from "firebase/compat/app";
import { UserProfile } from "../../main";
import { CloudDone, Logout } from "@mui/icons-material";
export default function LoggedInView({
user,
signOut,
signOutLoading,
userProfile,
userProfileLoading,
setGender,
setWeight,
setHeight,
setAge,
saveChanges,
}: {
user: firebase.User;
signOut: () => void;
signOutLoading: boolean;
userProfile: UserProfile | null;
userProfileLoading: boolean;
setGender: (event: React.ChangeEvent<HTMLInputElement>) => void;
setWeight: (event: React.ChangeEvent<HTMLInputElement>) => void;
setHeight: (event: React.ChangeEvent<HTMLInputElement>) => void;
setAge: (event: React.ChangeEvent<HTMLInputElement>) => void;
saveChanges: () => void;
}) {
const displayName = user.displayName;
const email = user.email;
const photoURL = user.photoURL;
return (
<>
<Stack direction="row" spacing={2} justifyContent="center" alignItems="center">
<Typography variant="h6" mb={2} textAlign="center">
Hi, {displayName || "there"}!
</Typography>
{photoURL && <Avatar alt={"Profile Picture"} src={photoURL} />}
</Stack>
<Divider sx={{ my: 1 }} />
<Typography variant="h5" textAlign={"center"}>
User Profile
</Typography>
{userProfileLoading ? (
<Typography variant="body1" textAlign="center">
Loading...
</Typography>
) : (
<>
<Stack direction="column" marginBottom={1}>
{/* Gender */}
<FormControl>
<FormLabel>Gender</FormLabel>
<RadioGroup value={userProfile?.gender || ""} onChange={setGender}>
<FormControlLabel value="female" control={<Radio />} label="Female" />
<FormControlLabel value="male" control={<Radio />} label="Male" />
</RadioGroup>
</FormControl>
{/* Weight */}
<FormControl>
<FormLabel>Weight</FormLabel>
<TextField
type="number"
value={userProfile?.weight || ""}
onChange={setWeight}
InputProps={{
endAdornment: <InputAdornment position="end">kg</InputAdornment>,
}}
/>
</FormControl>
{/* Height */}
<FormControl>
<FormLabel>Height</FormLabel>
<TextField
type="number"
value={userProfile?.height || ""}
onChange={setHeight}
InputProps={{
endAdornment: <InputAdornment position="end">cm</InputAdornment>,
}}
/>
</FormControl>
{/* Age */}
<FormControl>
<FormLabel>Age</FormLabel>
<TextField type="number" value={userProfile?.age || ""} onChange={setAge} />
</FormControl>
</Stack>
<Box textAlign="center">
<Fab variant="extended" size="medium" color="primary" onClick={saveChanges}>
<CloudDone sx={{ mr: 1 }} />
Save Changes
</Fab>
</Box>
</>
)}
<Divider sx={{ my: 1 }} />
<Typography variant="body2" mb={1} textAlign="center">
You are logged in as <b>{email}</b>.
</Typography>
<Button variant="outlined" startIcon={<Logout />} color="error" onClick={signOut} disabled={signOutLoading}>
{signOutLoading ? "Signing out..." : "Sign out"}
</Button>
</>
);
}