Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda