allow to set account details, cleanup

Change-Id: I6dd6589f78329e0113ee38fbaa8535abd6b37589
diff --git a/client/src/components/AccountPreferences.js b/client/src/components/AccountPreferences.js
index e14101f..7c7298d 100644
--- a/client/src/components/AccountPreferences.js
+++ b/client/src/components/AccountPreferences.js
@@ -39,6 +39,8 @@
   const moderators = account.getDefaultModerators()
   const [defaultModeratorUri, setDefaultModeratorUri] = useState('')
 
+  const [details, setDetails] = useState(account.getDetails())
+
   const addModerator = () => {
     if (defaultModeratorUri) {
       authManager.fetch(`/api/accounts/${account.getId()}/defaultModerators/${defaultModeratorUri}`, {method: "PUT"})
@@ -49,6 +51,22 @@
   const removeModerator = (uri) =>
     authManager.fetch(`/api/accounts/${account.getId()}/defaultModerators/${uri}`, {method: "DELETE"})
 
+  const handleToggle = (key, value) => {
+    console.log(`handleToggle ${key} ${value}`)
+    const newDetails = {}
+    newDetails[key] = value ? "true" : "false"
+    console.log(newDetails)
+    authManager.fetch(`/api/accounts/${account.getId()}`, {
+      method: "POST",
+      headers: {
+        'Accept': 'application/json',
+        'Content-Type': 'application/json'
+      },
+      body: JSON.stringify(newDetails)
+    })
+    setDetails({...account.updateDetails(newDetails)})
+  }
+
   return (
     <React.Fragment>
       <Typography variant="h2" component="h2" gutterBottom>{alias}</Typography>
@@ -83,8 +101,8 @@
           <ListItemSecondaryAction>
             <Switch
               edge="end"
-              /*onChange={handleToggle('wifi')}*/
-              checked={account.isRendezVous()}
+              onChange={e => handleToggle('Account.rendezVous', e.target.checked)}
+              checked={details['Account.rendezVous'] === 'true'}
               inputProps={{ 'aria-labelledby': 'switch-list-label-rendezvous' }}
             />
           </ListItemSecondaryAction>
@@ -97,8 +115,8 @@
           <ListItemSecondaryAction>
             <Switch
               edge="end"
-              /*onChange={handleToggle('bluetooth')}*/
-              checked={account.isPublicIn()}
+              onChange={e => handleToggle('DHT.PublicInCalls', e.target.checked)}
+              checked={details['DHT.PublicInCalls'] === 'true'}
               inputProps={{ 'aria-labelledby': 'switch-list-label-publicin' }}
             />
           </ListItemSecondaryAction>