Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Unable to unarchive emails JS

I'm creating an email - gmail like Single Page Application, I'm trying to add an Archive and Unarchive button, the archive button works as the mail moves to the Archive mailbox, however, if I click the button to unarchive the mail from the Archive Mailbox, I'm unable to as it will just reload.

'When viewing an Inbox email, the user should be presented with a button that lets them archive the email. When viewing an Archive email, the user should be presented with a button that lets them unarchive the email. This requirement does not apply to emails in the Sent mailbox.'

This is what I've tried but still the same result

// only show this archive icon in inbox and archive
if (mailbox != 'sent') {
  //   add the archive button
  let archiveBtn = document.createElement("archiveDiv");
  archiveBtn.innerHTML = `<div onclick="archiveEmail(${email.id})"><i class="fa fa-archive" aria-hidden="true"></i></div>`

  // archiveBtn.onclick = () => {
  //   addArchive(id)
  // }
  buttonsDiv.appendChild(archiveBtn);
}

function archiveEmail(id, mailbox) {
  if (mailbox == 'archive' && email.archived == true) {
    fetch(`/emails/${id}`, {
      method: 'PUT',
      body: JSON.stringify({
        archived: false
      })
    })
  } else {
    fetch(`/emails/${id}`, {
      method: 'PUT',
      body: JSON.stringify({
        archived: true
      })
    })
  }
  console.log("Email Unarchived");
  // reload the inbox
  load_mailbox('inbox');

}
Also, tried this:

if (mailbox != 'sent') {
  //   add the archive button
  let archiveBtn = document.createElement("archiveDiv");
  if (mailbox == 'archive' && email.archived == true) {
    archiveBtn.innerHTML = `<div onclick="Unarchived(${email.id})"><i class="fa fa-archive" aria-hidden="true"></i></div>`
  } else {
    archiveBtn.innerHTML = `<div onclick="archiveEmail(${email.id})"><i class="fa fa-archive" aria-hidden="true"></i></div>`
  }

  // archiveBtn.onclick = () => {
  //   addArchive(id)
  // }
  buttonsDiv.appendChild(archiveBtn);
}


function archiveEmail(id) {
  fetch(`/emails/${id}`, {
    method: 'PUT',
    body: JSON.stringify({
      archived: true
    })
  })
}

function Unarchived(id) {
  fetch(`/emails/${id}`, {
    method: 'PUT',
    body: JSON.stringify({
      archived: false
    })
  })
}

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!