Merge pull request #9663 from overleaf/jel-archiving-trashed

[web] Update view when archiving trashed project

GitOrigin-RevId: c40fb036a0c6c2bd18c2245a24f41e3979efd707
This commit is contained in:
Jessica Lawshe 2022-09-26 12:40:02 -05:00 committed by Copybot
parent 341ee52c3f
commit db7d0beda3
3 changed files with 31 additions and 2 deletions

View file

@ -35,7 +35,12 @@ function ArchiveProjectButton({
const handleArchiveProject = useCallback(async () => {
await archiveProject(project.id)
updateProjectViewData({ ...project, archived: true, selected: false })
updateProjectViewData({
...project,
archived: true,
selected: false,
trashed: false,
})
}, [project, updateProjectViewData])
if (project.archived) return null

View file

@ -28,7 +28,12 @@ function ArchiveProjectsButton() {
const handleArchiveProjects = useCallback(async () => {
for (const project of selectedProjects) {
await archiveProject(project.id)
updateProjectViewData({ ...project, archived: true, selected: false })
updateProjectViewData({
...project,
archived: true,
selected: false,
trashed: false,
})
}
}, [selectedProjects, updateProjectViewData])

View file

@ -223,6 +223,25 @@ describe('<ProjectListRoot />', function () {
expect(screen.queryByText('No projects')).to.be.null
})
it('removes project from view when archiving', async function () {
fetchMock.post(`express:/project/:id/archive`, {
status: 200,
})
const untrashButton =
within(actionsToolbar).getByLabelText<HTMLInputElement>('Archive')
fireEvent.click(untrashButton)
const confirmButton = screen.getByText<HTMLInputElement>('Confirm')
fireEvent.click(confirmButton)
expect(confirmButton.disabled).to.be.true
await fetchMock.flush(true)
expect(fetchMock.done()).to.be.true
screen.getByText('No projects')
})
})
})