import { CollectionsOutlined } from '@mui/icons-material' import axios from 'axios' import React, { Component } from 'react' import UserContext from '../../context/UserContext' import HeaderComponent from '../HeaderComponent/HeaderComponent' import './EditOfferComponent.css' export class EditOfferComponent extends Component { constructor(props) { super(props) this.state = { offerId: window.location.href.split('/')[5], offer: {} } } componentDidMount(){ // if(!localStorage.getItem('token')) // { // window.location.href = "/" // } // if(this.context.role != 'ADMIN' && this.context.role != 'SUPERADMIN') // { // window.location.href = "/" // } var config = { method: 'get', url: '/phoneoffer/'+this.state.offerId, headers: { } }; axios(config) .then(response => { this.setState({ offer: response.data }) }) .catch(error => { console.log(error); }); } setInputValue = (e) => { let editedOffer = Object.assign(this.state.offer,{[e.target.name]: e.target.value}) this.setState({ offer: editedOffer }) } handleSubmit = () =>{ var dataToSend = JSON.stringify(this.state.offer) var config = { method: 'put', url: '/admin/editoffer/'+this.state.offerId, headers: { 'Authorization': 'Bearer '+localStorage.getItem('token'), 'Content-Type': 'application/json' }, data: { "id" : this.state.offer.id, "offer_shop" : this.state.offer.offer_shop, "offer_name" : this.state.offer.offer_name, "price" : this.state.offer.price, "ram_memory" : this.state.offer.ram_memory, "rom_memory" : this.state.offer.rom_memory, "color" : this.state.offer.color, "front_camera" : this.state.offer.front_camera, "back_camera" : this.state.offer.back_camera, "chipset" : this.state.offer.chipset, "battery" : this.state.offer.battery, "operating_system" : this.state.offer.operating_system, "cpu" : this.state.offer.cpu, "image_url" : this.state.offer.image_url, "offer_url" : this.state.offer.offer_url, "last_updated" : this.state.offer.last_updated, "is_validated" : this.state.offer.is_validated, "offer_description" : this.state.offer.offer_description, "offer_shop_code" : this.state.offer.offer_shop_code } }; axios(config) .then(response => { window.location.href="/phoneoffer/"+this.state.offerId }) .catch(error => { console.log(error); }); } render() { console.log(this.state) return (
Понуда
Име на понуда {this.state.offer == null || this.state.offer.offer_name == null ? '/' : this.state.offer.offer_name}
Продавница {this.state.offer == null || this.state.offer.offer_shop == null ? '/' : this.state.offer.offer_shop}
Опис за понудата {this.state.offer == null || this.state.offer.offer_description == null ? '/' : this.state.offer.offer_description}
Спецификации за понудата
Цена this.setInputValue(e)}/>ден.
Предна камера
Задна камера
РОМ меморија
РАМ меморија
Оперативен систем
Чипсет
Процесор
Батерија
Боја
Линк од слика на мобилниот телефон од понудата
this.setInputValue(e)}/>
) } } EditOfferComponent.contextType = UserContext export default EditOfferComponent