Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 1 | import React, { useState } from 'react' |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 2 | import { makeStyles } from '@material-ui/core/styles' |
| 3 | import { List, ListItem, ListItemIcon, ListItemSecondaryAction, ListItemText, ListSubheader, Switch, Typography, Grid, Paper, CardContent, Card, TableContainer, Table, TableHead, TableRow, TableCell, TableBody, Toolbar, IconButton, ListItemAvatar, Input, TextField } from '@material-ui/core' |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 4 | import { PhoneCallbackRounded, GroupRounded, DeleteRounded, AddCircle } from '@material-ui/icons' |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 5 | |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 6 | import Account from '../../../model/Account' |
| 7 | import JamiIdCard from './JamiIdCard' |
| 8 | import ConversationAvatar from './ConversationAvatar' |
| 9 | import ConversationsOverviewCard from './ConversationsOverviewCard' |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 10 | |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 11 | import authManager from '../AuthManager' |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 12 | import { motion } from 'framer-motion' |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 13 | |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 14 | const useStyles = makeStyles(theme => ({ |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 15 | root: { |
| 16 | minWidth: 275, |
| 17 | }, |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 18 | title: { |
| 19 | fontSize: 14, |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 20 | flexGrow: 1 |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 21 | }, |
| 22 | pos: { |
| 23 | marginBottom: 12, |
| 24 | }, |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 25 | paper: { |
| 26 | marginTop: 24, |
| 27 | marginBottom: 24 |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 28 | }, |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 29 | textField: { |
| 30 | //marginLeft: theme.spacing(1), |
| 31 | marginRight: theme.spacing(2), |
| 32 | } |
| 33 | })) |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 34 | |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 35 | const transition = { duration: 0.3, ease: [0.43, 0.13, 0.23, 0.96] } |
| 36 | |
| 37 | const thumbnailVariants = { |
| 38 | initial: { scale: 0.9, opacity: 0 }, |
| 39 | enter: { scale: 1, opacity: 1, transition }, |
| 40 | exit: { |
| 41 | scale: 0.5, |
| 42 | opacity: 0, |
| 43 | transition: { duration: 1.5, ...transition } |
| 44 | } |
| 45 | } |
| 46 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 47 | export default function AccountPreferences(props) { |
| 48 | const classes = useStyles() |
| 49 | const account = props.account |
| 50 | const isJamiAccount = account.getType() === Account.TYPE_JAMI |
| 51 | const alias = isJamiAccount ? "Jami account" : "SIP account" |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 52 | const moderators = account.getDefaultModerators() |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 53 | const [defaultModeratorUri, setDefaultModeratorUri] = useState('') |
| 54 | |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 55 | const [details, setDetails] = useState(account.getDetails()) |
| 56 | |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 57 | const addModerator = () => { |
| 58 | if (defaultModeratorUri) { |
| 59 | authManager.fetch(`/api/accounts/${account.getId()}/defaultModerators/${defaultModeratorUri}`, {method: "PUT"}) |
| 60 | setDefaultModeratorUri('') |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | const removeModerator = (uri) => |
| 65 | authManager.fetch(`/api/accounts/${account.getId()}/defaultModerators/${uri}`, {method: "DELETE"}) |
| 66 | |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 67 | const handleToggle = (key, value) => { |
| 68 | console.log(`handleToggle ${key} ${value}`) |
| 69 | const newDetails = {} |
| 70 | newDetails[key] = value ? "true" : "false" |
| 71 | console.log(newDetails) |
| 72 | authManager.fetch(`/api/accounts/${account.getId()}`, { |
| 73 | method: "POST", |
| 74 | headers: { |
| 75 | 'Accept': 'application/json', |
| 76 | 'Content-Type': 'application/json' |
| 77 | }, |
| 78 | body: JSON.stringify(newDetails) |
| 79 | }) |
| 80 | setDetails({...account.updateDetails(newDetails)}) |
| 81 | } |
| 82 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 83 | return ( |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 84 | <motion.div |
| 85 | initial="initial" |
| 86 | animate="enter" |
| 87 | exit="exit" |
| 88 | variants={{ |
| 89 | enter: { transition: { staggerChildren: 0.05 } }, |
| 90 | exit: { transition: { staggerChildren: 0.02 } } |
| 91 | }} |
| 92 | > |
| 93 | <motion.div variants={thumbnailVariants}><Typography variant="h2" component="h2" gutterBottom>{alias}</Typography></motion.div> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 94 | <Grid container spacing={3} style={{ marginBottom: 16 }}> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 95 | {isJamiAccount && |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 96 | <Grid item xs={12}><motion.div variants={thumbnailVariants}><JamiIdCard account={account} /></motion.div></Grid>} |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 97 | |
| 98 | <Grid item xs={12} sm={6}> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 99 | <motion.div variants={thumbnailVariants}> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 100 | <ConversationsOverviewCard accountId={account.getId()} /> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 101 | </motion.div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 102 | </Grid> |
| 103 | |
| 104 | <Grid item xs={12} sm={6}> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 105 | <motion.div variants={thumbnailVariants}> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 106 | <Card> |
| 107 | <CardContent> |
| 108 | <Typography className={classes.title} color="textSecondary" gutterBottom> |
| 109 | Current calls |
| 110 | </Typography> |
| 111 | <Typography gutterBottom variant="h5" component="h2"> |
| 112 | 0 |
| 113 | </Typography> |
| 114 | </CardContent> |
| 115 | </Card> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 116 | </motion.div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 117 | </Grid> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 118 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 119 | </Grid> |
| 120 | |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 121 | <List subheader={<motion.div variants={thumbnailVariants}><ListSubheader>Settings</ListSubheader></motion.div>}> |
| 122 | <motion.div variants={thumbnailVariants}> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 123 | <ListItem> |
| 124 | <ListItemIcon> |
| 125 | <GroupRounded /> |
| 126 | </ListItemIcon> |
| 127 | <ListItemText id="switch-list-label-rendezvous" primary="Rendez-Vous point" /> |
| 128 | <ListItemSecondaryAction> |
| 129 | <Switch |
| 130 | edge="end" |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 131 | onChange={e => handleToggle('Account.rendezVous', e.target.checked)} |
| 132 | checked={details['Account.rendezVous'] === 'true'} |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 133 | inputProps={{ 'aria-labelledby': 'switch-list-label-rendezvous' }} |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 134 | /> |
| 135 | </ListItemSecondaryAction> |
| 136 | </ListItem> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 137 | </motion.div> |
| 138 | <motion.div variants={thumbnailVariants}> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 139 | <ListItem> |
| 140 | <ListItemIcon> |
| 141 | <PhoneCallbackRounded /> |
| 142 | </ListItemIcon> |
| 143 | <ListItemText id="switch-list-label-publicin" primary="Allow connection from unkown peers" /> |
| 144 | <ListItemSecondaryAction> |
| 145 | <Switch |
| 146 | edge="end" |
Adrien Béraud | 8698603 | 2021-04-25 12:04:53 -0400 | [diff] [blame] | 147 | onChange={e => handleToggle('DHT.PublicInCalls', e.target.checked)} |
| 148 | checked={details['DHT.PublicInCalls'] === 'true'} |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 149 | inputProps={{ 'aria-labelledby': 'switch-list-label-publicin' }} |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 150 | /> |
| 151 | </ListItemSecondaryAction> |
| 152 | </ListItem> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 153 | </motion.div> |
| 154 | <motion.div variants={thumbnailVariants}> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 155 | <Paper className={classes.paper}> |
| 156 | <Toolbar> |
| 157 | <Typography className={classes.title} variant="h6"> |
| 158 | Default moderators |
| 159 | </Typography> |
| 160 | </Toolbar> |
| 161 | <List> |
| 162 | <ListItem key="add"> |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 163 | <TextField variant="outlined" |
| 164 | className={classes.textField} |
| 165 | value={defaultModeratorUri} |
| 166 | onChange={e => setDefaultModeratorUri(e.target.value)} |
| 167 | label="Add new default moderator" |
| 168 | placeholder="Enter new moderator name or URI" |
| 169 | fullWidth /> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 170 | <ListItemSecondaryAction> |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 171 | <IconButton onClick={addModerator}><AddCircle /></IconButton> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 172 | </ListItemSecondaryAction> |
| 173 | </ListItem> |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 174 | {!moderators || moderators.length === 0 ? |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 175 | <ListItem key="placeholder"> |
| 176 | <ListItemText primary="No default moderator" /></ListItem> : |
| 177 | moderators.map((moderator) => ( |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 178 | <ListItem key={moderator.uri}> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 179 | <ListItemAvatar> |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 180 | <ConversationAvatar name={moderator.getDisplayName()} /> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 181 | </ListItemAvatar> |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 182 | <ListItemText primary={moderator.getDisplayName()} /> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 183 | <ListItemSecondaryAction> |
Adrien Béraud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 184 | <IconButton onClick={e => removeModerator(moderator.uri)}><DeleteRounded /></IconButton> |
Adrien Béraud | 21c53cf | 2021-04-22 00:04:32 -0400 | [diff] [blame] | 185 | </ListItemSecondaryAction> |
| 186 | </ListItem> |
| 187 | ))} |
| 188 | </List> |
| 189 | </Paper> |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 190 | </motion.div> |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 191 | </List> |
| 192 | |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame^] | 193 | </motion.div>) |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 194 | } |