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'; |
simon | 2007698 | 2022-10-11 15:04:13 -0400 | [diff] [blame^] | 38 | import { Account } from 'jami-web-common'; |
| 39 | import { AccountDetails } from 'jami-web-common'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 40 | import { useState } from 'react'; |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 41 | |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 42 | import authManager from '../AuthManager'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 43 | import ConversationAvatar from './ConversationAvatar'; |
| 44 | import ConversationsOverviewCard from './ConversationsOverviewCard'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 45 | import JamiIdCard from './JamiIdCard'; |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 46 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 47 | 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] | 48 | |
| 49 | const thumbnailVariants = { |
| 50 | initial: { scale: 0.9, opacity: 0 }, |
| 51 | enter: { scale: 1, opacity: 1, transition }, |
| 52 | exit: { |
| 53 | scale: 0.5, |
| 54 | opacity: 0, |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 55 | transition: { ...transition, duration: 1.5 }, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 56 | }, |
| 57 | }; |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 58 | |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 59 | type AccountPreferencesProps = { |
| 60 | account: Account; |
| 61 | onAccountChanged?: (account: Account) => void; |
| 62 | }; |
| 63 | |
| 64 | export default function AccountPreferences({ account }: AccountPreferencesProps) { |
| 65 | const devices: string[][] = []; |
| 66 | const accountDevices = account.getDevices(); |
| 67 | for (const i in accountDevices) devices.push([i, accountDevices[i]]); |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 68 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 69 | console.log(devices); |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 70 | |
| 71 | const isJamiAccount = account.getType() === Account.TYPE_JAMI; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 72 | const alias = isJamiAccount ? 'Jami account' : 'SIP account'; |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 73 | const moderators = account.getDefaultModerators(); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 74 | const [defaultModeratorUri, setDefaultModeratorUri] = useState(''); |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 75 | |
| 76 | const [details, setDetails] = useState(account.getDetails()); |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 77 | |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 78 | const addModerator = () => { |
| 79 | if (defaultModeratorUri) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 80 | authManager.fetch(`/api/accounts/${account.getId()}/defaultModerators/${defaultModeratorUri}`, { method: 'PUT' }); |
| 81 | setDefaultModeratorUri(''); |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 82 | } |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 83 | }; |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 84 | |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 85 | const removeModerator = (uri: string) => |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 86 | authManager.fetch(`/api/accounts/${account.getId()}/defaultModerators/${uri}`, { method: 'DELETE' }); |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 87 | |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 88 | const handleToggle = (key: keyof AccountDetails, value: boolean) => { |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 89 | console.log(`handleToggle ${key} ${value}`); |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 90 | const newDetails: Partial<AccountDetails> = {}; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 91 | newDetails[key] = value ? 'true' : 'false'; |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 92 | console.log(newDetails); |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 93 | authManager.fetch(`/api/accounts/${account.getId()}`, { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 94 | method: 'POST', |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 95 | headers: { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 96 | Accept: 'application/json', |
| 97 | 'Content-Type': 'application/json', |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 98 | }, |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 99 | body: JSON.stringify(newDetails), |
| 100 | }); |
| 101 | setDetails({ ...account.updateDetails(newDetails) }); |
| 102 | }; |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 103 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 104 | return ( |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 105 | <motion.div |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 106 | initial="initial" |
| 107 | animate="enter" |
| 108 | exit="exit" |
| 109 | variants={{ |
| 110 | enter: { transition: { staggerChildren: 0.05 } }, |
| 111 | exit: { transition: { staggerChildren: 0.02 } }, |
| 112 | }} |
| 113 | > |
| 114 | <motion.div variants={thumbnailVariants}> |
| 115 | <Typography variant="h2" component="h2" gutterBottom> |
| 116 | {alias} |
| 117 | </Typography> |
| 118 | </motion.div> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 119 | <Grid container spacing={3} style={{ marginBottom: 16 }}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 120 | {isJamiAccount && ( |
| 121 | <Grid item xs={12}> |
| 122 | <motion.div variants={thumbnailVariants}> |
| 123 | <JamiIdCard account={account} /> |
| 124 | </motion.div> |
| 125 | </Grid> |
| 126 | )} |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 127 | |
| 128 | <Grid item xs={12} sm={6}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 129 | <motion.div variants={thumbnailVariants}> |
| 130 | <ConversationsOverviewCard accountId={account.getId()} /> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 131 | </motion.div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 132 | </Grid> |
| 133 | |
| 134 | <Grid item xs={12} sm={6}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 135 | <motion.div variants={thumbnailVariants}> |
| 136 | <Card> |
| 137 | <CardContent> |
| 138 | <Typography color="textSecondary" gutterBottom> |
| 139 | Current calls |
| 140 | </Typography> |
| 141 | <Typography gutterBottom variant="h5" component="h2"> |
| 142 | 0 |
| 143 | </Typography> |
| 144 | </CardContent> |
| 145 | </Card> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 146 | </motion.div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 147 | </Grid> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 148 | |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 149 | <Grid item xs={12} sm={6}> |
| 150 | <motion.div variants={thumbnailVariants}> |
| 151 | <Card> |
| 152 | <CardContent> |
| 153 | <Typography color="textSecondary" gutterBottom> |
| 154 | Appareils associés |
| 155 | </Typography> |
| 156 | <Typography gutterBottom variant="h5" component="h2"> |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 157 | {devices.map((device, i) => ( |
| 158 | <ListItem key={i}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 159 | <GroupRounded /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 160 | <ListItemText id="switch-list-label-rendezvous" primary={device[1]} secondary={device[0]} /> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 161 | </ListItem> |
| 162 | ))} |
| 163 | {/* <ListItemTextsion> */} |
| 164 | </Typography> |
| 165 | </CardContent> |
| 166 | </Card> |
| 167 | </motion.div> |
| 168 | </Grid> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 169 | </Grid> |
| 170 | |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 171 | <List |
| 172 | subheader={ |
| 173 | <motion.div variants={thumbnailVariants}> |
| 174 | <ListSubheader>Settings</ListSubheader> |
| 175 | </motion.div> |
| 176 | } |
| 177 | > |
| 178 | <motion.div variants={thumbnailVariants}> |
| 179 | <ListItem> |
| 180 | <ListItemIcon> |
| 181 | <GroupRounded /> |
| 182 | </ListItemIcon> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 183 | <ListItemText id="switch-list-label-rendezvous" primary="Rendez-Vous point" /> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 184 | <ListItemSecondaryAction> |
| 185 | <Switch |
| 186 | edge="end" |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 187 | onChange={(e) => handleToggle('Account.rendezVous', e.target.checked)} |
| 188 | checked={details['Account.rendezVous'] === 'true'} |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 189 | inputProps={{ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 190 | 'aria-labelledby': 'switch-list-label-rendezvous', |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 191 | }} |
| 192 | /> |
| 193 | </ListItemSecondaryAction> |
| 194 | </ListItem> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 195 | </motion.div> |
| 196 | <motion.div variants={thumbnailVariants}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 197 | <ListItem> |
| 198 | <ListItemIcon> |
| 199 | <PhoneCallbackRounded /> |
| 200 | </ListItemIcon> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 201 | <ListItemText id="switch-list-label-publicin" primary="Allow connection from unkown peers" /> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 202 | <ListItemSecondaryAction> |
| 203 | <Switch |
| 204 | edge="end" |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 205 | onChange={(e) => handleToggle('DHT.PublicInCalls', e.target.checked)} |
| 206 | checked={details['DHT.PublicInCalls'] === 'true'} |
| 207 | inputProps={{ 'aria-labelledby': 'switch-list-label-publicin' }} |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 208 | /> |
| 209 | </ListItemSecondaryAction> |
| 210 | </ListItem> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 211 | </motion.div> |
| 212 | <motion.div variants={thumbnailVariants}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 213 | <Paper> |
| 214 | <Toolbar> |
| 215 | <Typography variant="h6">Default moderators</Typography> |
| 216 | </Toolbar> |
| 217 | <List> |
| 218 | <ListItem key="add"> |
| 219 | <TextField |
| 220 | variant="outlined" |
| 221 | value={defaultModeratorUri} |
| 222 | onChange={(e) => setDefaultModeratorUri(e.target.value)} |
| 223 | label="Add new default moderator" |
| 224 | placeholder="Enter new moderator name or URI" |
| 225 | fullWidth |
| 226 | /> |
| 227 | <ListItemSecondaryAction> |
| 228 | <IconButton onClick={addModerator} size="large"> |
| 229 | <AddCircle /> |
| 230 | </IconButton> |
| 231 | </ListItemSecondaryAction> |
| 232 | </ListItem> |
| 233 | {!moderators || moderators.length === 0 ? ( |
| 234 | <ListItem key="placeholder"> |
| 235 | <ListItemText primary="No default moderator" /> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 236 | </ListItem> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 237 | ) : ( |
| 238 | moderators.map((moderator) => ( |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 239 | <ListItem key={moderator.getUri()}> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 240 | <ListItemAvatar> |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 241 | <ConversationAvatar displayName={moderator.getDisplayName()} /> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 242 | </ListItemAvatar> |
| 243 | <ListItemText primary={moderator.getDisplayName()} /> |
| 244 | <ListItemSecondaryAction> |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 245 | <IconButton onClick={(e) => removeModerator(moderator.getUri())} size="large"> |
ervinanoh | f1758a4 | 2022-09-14 14:52:51 -0400 | [diff] [blame] | 246 | <DeleteRounded /> |
| 247 | </IconButton> |
| 248 | </ListItemSecondaryAction> |
| 249 | </ListItem> |
| 250 | )) |
| 251 | )} |
| 252 | </List> |
| 253 | </Paper> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 254 | </motion.div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 255 | </List> |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 256 | </motion.div> |
| 257 | ); |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 258 | } |