diff --git a/src/user/UserSettings.tsx b/src/user/UserSettings.tsx index c91ff00..99aa844 100644 --- a/src/user/UserSettings.tsx +++ b/src/user/UserSettings.tsx @@ -1,5 +1,15 @@ -import { AccountBox, Close, ExpandLess, ExpandMore, Face, Share as ShareIcon } from "@mui/icons-material"; -import { AppBar, Box, Button, CircularProgress, Collapse, Divider, FormControl, FormLabel, Grid2, IconButton, List, ListItem, ListItemButton, ListItemIcon, ListItemText, TextField, Theme, Toolbar, Tooltip, Typography } from "@mui/material"; +import { + AccountBox, + Close, + ExpandLess, + ExpandMore, + Face, + Share as ShareIcon, + Notifications as NotificationsIcon, + Email as EmailIcon, + Textsms as TextIcon, +} from "@mui/icons-material"; +import { AppBar, Box, Button, Checkbox, CircularProgress, Collapse, Divider, FormControl, FormControlLabel, FormGroup, FormHelperText, FormLabel, Grid2, IconButton, List, ListItem, ListItemButton, ListItemIcon, ListItemText, Radio, RadioGroup, TextField, Theme, Toolbar, Tooltip, Typography } from "@mui/material"; import ResponsiveDialog from "common/ResponsiveDialog"; import UserAvatar from "./UserAvatar"; import { useGlobalState, useUserAPI } from "providers"; @@ -61,18 +71,17 @@ export default function UserSettings(props: Props) { const [user, setUser] = useState(globalState.user); const [profileExpanded, setProfileExpanded] = useState(false); const [avatarExpanded, setAvatarExpanded] = useState(false); + const [notificationsExpanded, setNotificationsExpanded] = useState(false); const [avatarUrl, setAvatarUrl] = useState(""); - console.log(user.settings.avatar) - useEffect(() => { function changeIcon(icon: string | undefined) { let updatedUser = User.clone(user); - updatedUser.settings.avatar = icon ? icon : user.settings.name; + updatedUser.settings.avatar = icon ? icon : user.settings.avatar; setUser(updatedUser); } if (avatarUrl === "") { - // changeIcon(user.settings.name); + changeIcon(undefined); } else { changeIcon(avatarUrl); } @@ -99,8 +108,13 @@ export default function UserSettings(props: Props) { }); }; + const setDefaultState = () => { + setIsLoading(false); + setUser(globalState.user); + }; + const closeDialog = () => { - // setDefaultState(); + setDefaultState(); closeDialogCallback(); }; @@ -186,6 +200,154 @@ export default function UserSettings(props: Props) { ); }; + const handleChangeNotifyByDefault = (notifyByDefault: boolean) => { + let updatedUser = User.clone(user); + updatedUser.settings.notifyByDefault = notifyByDefault; + setUser(updatedUser); + }; + + const handleNotificationMethod = ( + checked: boolean, + notificationMethod: pond.NotificationMethod + ) => { + let updatedUser = User.clone(user); + let notificationMethods = updatedUser.settings.notificationMethods; + if (checked) { + if (!notificationMethods.includes(notificationMethod)) { + notificationMethods.push(notificationMethod); + } + } else { + notificationMethods = notificationMethods.filter(element => element !== notificationMethod); + } + updatedUser.settings.notificationMethods = notificationMethods; + setUser(updatedUser); + }; + + const notificationsSettings = () => { + const { notifyByDefault, notificationMethods } = user.settings; + + return ( + + + + Notification Preference + handleChangeNotifyByDefault(event.target.value === "true")}> + } label="Opt-in" /> + } label="Opt-out" /> + + + {notifyByDefault + ? "Notifications are enabled by default" + : "Notifications are disabled by default"} + + + + + + Notification Methods + + + handleNotificationMethod( + checked, + pond.NotificationMethod.NOTIFICATION_METHOD_EMAIL + ) + } + checked={ + notificationMethods + ? notificationMethods.includes( + pond.NotificationMethod.NOTIFICATION_METHOD_EMAIL + ) + : false + } + /> + } + label={ + + + + + + + } + /> + + + handleNotificationMethod( + checked, + pond.NotificationMethod.NOTIFICATION_METHOD_TEXT + ) + } + checked={ + notificationMethods + ? notificationMethods.includes( + pond.NotificationMethod.NOTIFICATION_METHOD_TEXT + ) + : false + } + /> + } + label={ + + + + + + + } + /> + + + handleNotificationMethod( + checked, + pond.NotificationMethod.NOTIFICATION_METHOD_APP + ) + } + checked={ + notificationMethods + ? notificationMethods.includes( + pond.NotificationMethod.NOTIFICATION_METHOD_APP + ) + : false + } + /> + } + label={ + + + + + + + } + /> + + + + + ); + }; + const avatarSettings = () => { return ; }; @@ -230,15 +392,15 @@ export default function UserSettings(props: Props) { - {/* + - setNotificationsExpanded(!notificationsExpanded)}> + setNotificationsExpanded(!notificationsExpanded)}> {notificationsExpanded ? : } - + @@ -249,7 +411,7 @@ export default function UserSettings(props: Props) { - + {/* setUnitsExpanded(!unitsExpanded)}>