Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda