JSFiddle - React, Tailwind, and code Playground

by Maxim_Wolf

JavaScript

const BASE_URL = 'https://16.ecmascript.pages.academy/big-trip/';
const Methods = {
  GET: 'GET',
  POST: 'POST'
}
const Res = {
  points: 'points',
  destinations: 'destinations',
  offers: 'offers'
}

const authorization = `Basic 432fgasd5`

const getUrl = (path) => `${BASE_URL}${path}`;

fetch(getUrl(Res.points), {
  method: Methods.GET,
  headers: {
    authorization: authorization
  }
}).then(
  (response) => {
    if (response.ok) {
      return response.json();
    }
    throw new Error('not ok');
  }
).then(
  (data) => {
    console.log(data)
  }
).catch((err) => {
  console.log('ошибка работы с сетью')
  console.log(err);
});


let errorInfo = null;
let dataInfo = null;

const reporter = ()=>{
  if(dataInfo === null){
    console.log('данные еще не получены');
    return
  }
  console.log(dataInfo);
};

/////////// добавить новую точку на маршртуте
fetch(getUrl(Res.points), {
  method: Methods.POST,
  headers: {
    authorization: authorization,
    'content-type': 'application/json'
  },
  body: JSON.stringify({
  "base_price": 222,
  "date_from": "2019-07-10T22:55:56.845Z",
  "date_to": "2019-07-11T11:22:13.375Z",
  "destination": {
  description: "Valencia, is a beautiful city, with crowded streets, in a middle of Europe, for those who value comfort and coziness, full of of cozy canteens where you can try the best coffee in the Middle East.",
  name: "Valencia",
  pictures: [{
  description: "Valencia biggest supermarket",
  src: "http://picsum.photos/300/200?r=0.7840090822392105"
}, {
  description: "Valencia city centre",
  src: "http://picsum.photos/300/200?r=0.9478057737319661"
}, {
  description: "Valencia city centre",
  src: "http://picsum.photos/300/200?r=0.028661601965714878"
}, {
  description: "Valencia zoo",
  src: "http://picsum.photos/300/200?r=0.8713278532647"
}, {
  description: "Valencia central station",
  src: "http://picsum.photos/300/200?r=0.32363244069616504"
}, {
  description: "Valencia embankment",
  src:...