VladislavNechepaev

Untitled

Nov 2nd, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const selectedDates = dateList.map(x => x.value).filter(x => !!x)
  2.         if (officeCapacity.includes(values.office) && selectedDates.length && JSON.stringify(selectedDates) !== selectedDatesGlobal) {
  3.           fetch(`https://freshservicecounter.ringteam.com/getcapacity?office=${values.office}&dates=${JSON.stringify(selectedDates)}`)
  4.           .then(res => {
  5.             return res.json()
  6.           })
  7.           .then(res => {
  8.             console.log(res)
  9.             capacityDisplay.innerHTML = ""
  10.             const office = document.createElement("div")
  11.             office.innerHTML = `<b>Office:</b> ${res.office}`
  12.             const limit = document.createElement("div")
  13.             limit.innerHTML = `<b>Limit:</b> ${res.limit} visitors per day`
  14.             limit.style.borderBottom = "1px dotted grey"
  15.             capacityDisplay.appendChild(office)
  16.             capacityDisplay.appendChild(limit)
  17.             var capacityDataArray = []
  18.             for (let date in res.capacity) {
  19.               capacityDataArray.push({ date: date, capacity: res.capacity[date] })
  20.             }
  21.             capacityDataArray.sort((x,y) => { return x.date > y.date ? 1 : -1 })
  22.             console.log(capacityDataArray)
  23.             capacityDataArray.forEach(obj => {
  24.               const dateElem = document.createElement("div")
  25.               dateElem.innerHTML = `<b>${obj.date}:</b> ${obj.capacity} visitors confirmed`
  26.               capacityDisplay.appendChild(dateElem)
  27.             })
  28.             capacityDisplay.hidden = false
  29.           })
  30.         } else {
  31.           //capacityDisplay.innerHTML = ""
  32.           if (!officeCapacity.includes(values.office)) capacityDisplay.hidden = true
  33.         }
  34.         selectedDatesGlobal = JSON.stringify(selectedDates)
Add Comment
Please, Sign In to add comment