From 32606c320aebe21cad76eb0d6f3478edabe87649 Mon Sep 17 00:00:00 2001 From: Julien Torrent Date: Wed, 13 Oct 2021 11:22:44 +0200 Subject: [PATCH] feat: add settings page --- src/components/item/settings/ItemSettings.js | 69 +++++++++++++++++++- yarn.lock | 2 +- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/src/components/item/settings/ItemSettings.js b/src/components/item/settings/ItemSettings.js index 09d5590fa..6eee5a946 100644 --- a/src/components/item/settings/ItemSettings.js +++ b/src/components/item/settings/ItemSettings.js @@ -1,8 +1,16 @@ import React from 'react'; +import PropTypes from 'prop-types'; import Container from '@material-ui/core/Container'; import Typography from '@material-ui/core/Typography'; import { useTranslation } from 'react-i18next'; -import { makeStyles } from '@material-ui/core'; +import { + FormControlLabel, + FormGroup, + makeStyles, + Switch, +} from '@material-ui/core'; +import { MUTATION_KEYS } from '@graasp/query-client'; +import { useMutation } from '../../../config/queryClient'; const useStyles = makeStyles((theme) => ({ title: { @@ -17,17 +25,74 @@ const useStyles = makeStyles((theme) => ({ }, })); -const ItemSettings = () => { +const ItemSettings = ({ item }) => { const { t } = useTranslation(); const classes = useStyles(); + const editItem = useMutation(MUTATION_KEYS.EDIT_ITEM); + + const settings = item.get('settings'); + + const handleChatbox = (event) => { + settings.showChatbox = event.target.checked; + + editItem.mutate({ + id: item.get('id'), + // use item login tag id + name: item.get('name'), + settings, + }); + }; + + const handlePinned = (event) => { + settings.isPinned = event.target.checked; + + editItem.mutate({ + id: item.get('id'), + // use item login tag id + name: item.get('name'), + settings, + }); + }; + return ( {t('Settings')} + + + + ) + } + /> + + ) + } + /> + ); }; +ItemSettings.propTypes = { + item: PropTypes.instanceOf(Map).isRequired, +}; + export default ItemSettings; diff --git a/yarn.lock b/yarn.lock index 6064c1587..38cc37c5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1742,7 +1742,7 @@ __metadata: languageName: node linkType: hard -"@babel/runtime@npm:^7.1.2, @babel/runtime@npm:^7.10.2, @babel/runtime@npm:^7.11.2, @babel/runtime@npm:^7.12.0, @babel/runtime@npm:^7.12.1, @babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.14.5, @babel/runtime@npm:^7.3.1, @babel/runtime@npm:^7.4.4, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.6.2, @babel/runtime@npm:^7.7.2, @babel/runtime@npm:^7.7.6, @babel/runtime@npm:^7.8.3, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.8.7, @babel/runtime@npm:^7.9.2": +"@babel/runtime@npm:^7.1.2, @babel/runtime@npm:^7.10.2, @babel/runtime@npm:^7.11.2, @babel/runtime@npm:^7.12.0, @babel/runtime@npm:^7.12.1, @babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.14.5, @babel/runtime@npm:^7.14.8, @babel/runtime@npm:^7.3.1, @babel/runtime@npm:^7.4.4, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.6.2, @babel/runtime@npm:^7.7.2, @babel/runtime@npm:^7.7.6, @babel/runtime@npm:^7.8.3, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.8.7, @babel/runtime@npm:^7.9.2": version: 7.15.4 resolution: "@babel/runtime@npm:7.15.4" dependencies: