import { Box, Modal } from '@mui/material' import React, { Component } from 'react' import List from '@mui/material/List'; import ListItem from '@mui/material/ListItem'; import ListItemButton from '@mui/material/ListItemButton'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import Checkbox from '@mui/material/Checkbox'; import IconButton from '@mui/material/IconButton'; import './PickSpecificationComponent.css' import UserContext from '../../context/UserContext'; import axios from 'axios'; export class PickSpecificationComponent extends Component { constructor(props) { super(props) this.state = { checked: [] } } handleToggle = (value) => () => { const currentIndex = this.state.checked.indexOf(value); const newChecked = [...this.state.checked]; if (currentIndex === -1) { newChecked.push(value); } else { newChecked.splice(currentIndex, 1); } this.setState({ checked: newChecked }, () => { var config = { method: 'put', url: '/user/'+this.context.userId+'/editspecifications', headers: { 'Authorization': 'Bearer '+localStorage.getItem('token'), 'Content-Type': 'text/plain' }, data : this.state.checked }; axios(config) .then(response => { localStorage.setItem('pickedSpecifications',this.state.checked) }) .catch(function (error) { console.log(error); }); }) }; componentDidMount(){ var config = { method: 'get', url: '/user/'+this.context.userId+'/getspecifications', headers: { 'Authorization': 'Bearer '+localStorage.getItem('token') } }; axios(config) .then(response => { this.setState({ checked: response.data },() => {localStorage.setItem('pickedSpecifications',this.state.checked)}) }) .catch(function (error) { console.log('error here',error); }); } render() { return (
Изберете спецификации кои што сакате да се прикажани
{['РАМ меморија', 'РОМ меморија', 'Предна камера', 'Задна камера', 'Чипсет', 'Процесор', 'Оперативен систем', 'Боја', 'Батерија'].map((value) => { const labelId = `checkbox-list-label-${value}`; return ( ); })}
) } } PickSpecificationComponent.contextType = UserContext export default PickSpecificationComponent