VladislavNechepaev

Untitled

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