simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 18 | import { AddCircle, DeleteRounded, GroupRounded, PhoneCallbackRounded } from '@mui/icons-material'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 19 | import { |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 20 | Card, |
| 21 | CardContent, |
| 22 | Grid, |
| 23 | IconButton, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 24 | List, |
| 25 | ListItem, |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 26 | ListItemAvatar, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 27 | ListItemIcon, |
| 28 | ListItemSecondaryAction, |
| 29 | ListItemText, |
| 30 | ListSubheader, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 31 | Paper, |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 32 | Switch, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 33 | TextField, |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 34 | Toolbar, |
| 35 | Typography, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 36 | } from '@mui/material'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 37 | import { motion } from 'framer-motion'; |
Misha Krieger-Raynauld | 6bbdacf | 2022-11-29 21:45:40 -0500 | [diff] [blame] | 38 | import { AccountDetails } from 'jami-web-common'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 39 | import { useState } from 'react'; |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 40 | |
simon | 416d079 | 2022-11-03 02:46:18 -0400 | [diff] [blame] | 41 | import { useAuthContext } from '../contexts/AuthProvider'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 42 | import ConversationAvatar from './ConversationAvatar'; |
| 43 | import ConversationsOverviewCard from './ConversationsOverviewCard'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 44 | import JamiIdCard from './JamiIdCard'; |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 45 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 46 | const transition = { duration: 0.3, ease: [0.43, 0.13, 0.23, 0.96] }; |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 47 | |
| 48 | const thumbnailVariants = { |
| 49 | initial: { scale: 0.9, opacity: 0 }, |
| 50 | enter: { scale: 1, opacity: 1, transition }, |
| 51 | exit: { |
| 52 | scale: 0.5, |
| 53 | opacity: 0, |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 54 | transition: { ...transition, duration: 1.5 }, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 55 | }, |
| 56 | }; |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 57 | |
simon | 94fe53e | 2022-11-10 12:51:58 -0500 | [diff] [blame] | 58 | export default function AccountPreferences() { |
| 59 | const { account, axiosInstance } = useAuthContext(); |
simon | 416d079 | 2022-11-03 02:46:18 -0400 | [diff] [blame] | 60 | |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 61 | const devices: string[][] = []; |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 62 | const accountDevices = account.devices; |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 63 | for (const i in accountDevices) devices.push([i, accountDevices[i]]); |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 64 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 65 | console.log(devices); |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 66 | |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 67 | const isJamiAccount = account.getType() === 'RING'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 68 | const alias = isJamiAccount ? 'Jami account' : 'SIP account'; |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 69 | const moderators = account.defaultModerators; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 70 | const [defaultModeratorUri, setDefaultModeratorUri] = useState(''); |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 71 | |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 72 | const [details, setDetails] = useState(account.details); |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 73 | |
simon | 94fe53e | 2022-11-10 12:51:58 -0500 | [diff] [blame] | 74 | const addModerator = async () => { |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 75 | if (defaultModeratorUri) { |
simon | 94fe53e | 2022-11-10 12:51:58 -0500 | [diff] [blame] | 76 | await axiosInstance.put(`/default-moderators/${defaultModeratorUri}`); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 77 | setDefaultModeratorUri(''); |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 78 | } |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 79 | }; |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 80 | |
simon | 94fe53e | 2022-11-10 12:51:58 -0500 | [diff] [blame] | 81 | const removeModerator = async (uri: string) => await axiosInstance.delete(`/default-moderators/${uri}`); |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 82 | |
simon | 94fe53e | 2022-11-10 12:51:58 -0500 | [diff] [blame] | 83 | const handleToggle = async (key: keyof AccountDetails, value: boolean) => { |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 84 | console.log(`handleToggle ${key} ${value}`); |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 85 | const newDetails: Partial<AccountDetails> = {}; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 86 | newDetails[key] = value ? 'true' : 'false'; |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 87 | console.log(newDetails); |
simon | 94fe53e | 2022-11-10 12:51:58 -0500 | [diff] [blame] | 88 | await axiosInstance.patch('/account', newDetails); |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 89 | account.updateDetails(newDetails); |
| 90 | setDetails(account.details); |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 91 | }; |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 92 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 93 | return ( |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 94 | <motion.div |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 95 | initial="initial" |
| 96 | animate="enter" |
| 97 | exit="exit" |
| 98 | variants={{ |
| 99 | enter: { transition: { staggerChildren: 0.05 } }, |
| 100 | exit: { transition: { staggerChildren: 0.02 } }, |
| 101 | }} |
| 102 | > |
| 103 | <motion.div variants={thumbnailVariants}> |
| 104 | <Typography variant="h2" component="h2" gutterBottom> |
| 105 | {alias} |
| 106 | </Typography> |
| 107 | </motion.div> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 108 | <Grid container spacing={3} style={{ marginBottom: 16 }}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 109 | {isJamiAccount && ( |
| 110 | <Grid item xs={12}> |
| 111 | <motion.div variants={thumbnailVariants}> |
| 112 | <JamiIdCard account={account} /> |
| 113 | </motion.div> |
| 114 | </Grid> |
| 115 | )} |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 116 | |
| 117 | <Grid item xs={12} sm={6}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 118 | <motion.div variants={thumbnailVariants}> |
simon | 5da8ca6 | 2022-11-09 15:21:25 -0500 | [diff] [blame] | 119 | <ConversationsOverviewCard /> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 120 | </motion.div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 121 | </Grid> |
| 122 | |
| 123 | <Grid item xs={12} sm={6}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 124 | <motion.div variants={thumbnailVariants}> |
| 125 | <Card> |
| 126 | <CardContent> |
| 127 | <Typography color="textSecondary" gutterBottom> |
| 128 | Current calls |
| 129 | </Typography> |
| 130 | <Typography gutterBottom variant="h5" component="h2"> |
| 131 | 0 |
| 132 | </Typography> |
| 133 | </CardContent> |
| 134 | </Card> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 135 | </motion.div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 136 | </Grid> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 137 | |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 138 | <Grid item xs={12} sm={6}> |
| 139 | <motion.div variants={thumbnailVariants}> |
| 140 | <Card> |
| 141 | <CardContent> |
| 142 | <Typography color="textSecondary" gutterBottom> |
| 143 | Appareils associés |
| 144 | </Typography> |
| 145 | <Typography gutterBottom variant="h5" component="h2"> |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 146 | {devices.map((device, i) => ( |
| 147 | <ListItem key={i}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 148 | <GroupRounded /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 149 | <ListItemText id="switch-list-label-rendezvous" primary={device[1]} secondary={device[0]} /> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 150 | </ListItem> |
| 151 | ))} |
| 152 | {/* <ListItemTextsion> */} |
| 153 | </Typography> |
| 154 | </CardContent> |
| 155 | </Card> |
| 156 | </motion.div> |
| 157 | </Grid> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 158 | </Grid> |
| 159 | |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 160 | <List |
| 161 | subheader={ |
| 162 | <motion.div variants={thumbnailVariants}> |
| 163 | <ListSubheader>Settings</ListSubheader> |
| 164 | </motion.div> |
| 165 | } |
| 166 | > |
| 167 | <motion.div variants={thumbnailVariants}> |
| 168 | <ListItem> |
| 169 | <ListItemIcon> |
| 170 | <GroupRounded /> |
| 171 | </ListItemIcon> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 172 | <ListItemText id="switch-list-label-rendezvous" primary="Rendez-Vous point" /> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 173 | <ListItemSecondaryAction> |
| 174 | <Switch |
| 175 | edge="end" |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 176 | onChange={(e) => handleToggle('Account.rendezVous', e.target.checked)} |
| 177 | checked={details['Account.rendezVous'] === 'true'} |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 178 | inputProps={{ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 179 | 'aria-labelledby': 'switch-list-label-rendezvous', |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 180 | }} |
| 181 | /> |
| 182 | </ListItemSecondaryAction> |
| 183 | </ListItem> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 184 | </motion.div> |
| 185 | <motion.div variants={thumbnailVariants}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 186 | <ListItem> |
| 187 | <ListItemIcon> |
| 188 | <PhoneCallbackRounded /> |
| 189 | </ListItemIcon> |
Misha Krieger-Raynauld | baf49d8 | 2022-11-30 18:51:37 -0500 | [diff] [blame] | 190 | <ListItemText id="switch-list-label-publicin" primary="Allow connection from unknown peers" /> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 191 | <ListItemSecondaryAction> |
| 192 | <Switch |
| 193 | edge="end" |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 194 | onChange={(e) => handleToggle('DHT.PublicInCalls', e.target.checked)} |
| 195 | checked={details['DHT.PublicInCalls'] === 'true'} |
| 196 | inputProps={{ 'aria-labelledby': 'switch-list-label-publicin' }} |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 197 | /> |
| 198 | </ListItemSecondaryAction> |
| 199 | </ListItem> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 200 | </motion.div> |
| 201 | <motion.div variants={thumbnailVariants}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 202 | <Paper> |
| 203 | <Toolbar> |
| 204 | <Typography variant="h6">Default moderators</Typography> |
| 205 | </Toolbar> |
| 206 | <List> |
| 207 | <ListItem key="add"> |
| 208 | <TextField |
| 209 | variant="outlined" |
| 210 | value={defaultModeratorUri} |
| 211 | onChange={(e) => setDefaultModeratorUri(e.target.value)} |
| 212 | label="Add new default moderator" |
| 213 | placeholder="Enter new moderator name or URI" |
| 214 | fullWidth |
| 215 | /> |
| 216 | <ListItemSecondaryAction> |
| 217 | <IconButton onClick={addModerator} size="large"> |
| 218 | <AddCircle /> |
| 219 | </IconButton> |
| 220 | </ListItemSecondaryAction> |
| 221 | </ListItem> |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 222 | {moderators.length === 0 ? ( |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 223 | <ListItem key="placeholder"> |
| 224 | <ListItemText primary="No default moderator" /> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 225 | </ListItem> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 226 | ) : ( |
| 227 | moderators.map((moderator) => ( |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 228 | <ListItem key={moderator.uri}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 229 | <ListItemAvatar> |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 230 | <ConversationAvatar displayName={moderator.getDisplayName()} /> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 231 | </ListItemAvatar> |
| 232 | <ListItemText primary={moderator.getDisplayName()} /> |
| 233 | <ListItemSecondaryAction> |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 234 | <IconButton onClick={() => removeModerator(moderator.uri)} size="large"> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 235 | <DeleteRounded /> |
| 236 | </IconButton> |
| 237 | </ListItemSecondaryAction> |
| 238 | </ListItem> |
| 239 | )) |
| 240 | )} |
| 241 | </List> |
| 242 | </Paper> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 243 | </motion.div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 244 | </List> |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 245 | </motion.div> |
| 246 | ); |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 247 | } |