Skip to content

Commit

Permalink
Revert "open delete modal to delete notes files"
Browse files Browse the repository at this point in the history
This reverts commit 87c47a5.
  • Loading branch information
bellangerq committed Sep 4, 2024
1 parent 6ad2557 commit cb110d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 55 deletions.
45 changes: 0 additions & 45 deletions confiture-web-app/src/components/audit/AuditGenerationHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@ import NotesModal from "../../components/audit/NotesModal.vue";
import { useDevMode } from "../../composables/useDevMode";
import { useIsOffline } from "../../composables/useIsOffline";
import { useNotifications } from "../../composables/useNotifications";
import { FileErrorMessage } from "../../enums";
import {
useAccountStore,
useAuditStore,
useResultsStore,
useSystemStore
} from "../../store";
import { AuditFile } from "../../types";
import {
captureWithPayloads,
formatBytes,
formatDate,
handleFileDeleteError,
slugify
} from "../../utils";
import CopyIcon from "../icons/CopyIcon.vue";
import { StatDonutTheme } from "../StatDonut.vue";
import SummaryCard from "../SummaryCard.vue";
import Dropdown from "../ui/Dropdown.vue";
import AuditProgressBar from "./AuditProgressBar.vue";
import DeleteFileModal from "./DeleteFileModal.vue";
import DeleteModal from "./DeleteModal.vue";
import DuplicateModal from "./DuplicateModal.vue";
import SaveIndicator from "./SaveIndicator.vue";
Expand Down Expand Up @@ -218,38 +214,6 @@ onMounted(() => {
observer.observe(scrollSentinelRef.value!);
});
const deleteFileModalRef = ref<InstanceType<typeof DeleteFileModal>>();
const fileToDelete = ref<AuditFile>();
const deleteFileErrorMessage = ref<FileErrorMessage | null>();
function openDeleteFileModal(image: AuditFile) {
deleteFileModalRef.value?.show();
fileToDelete.value = image;
}
function handleDeleteFile() {
if (!fileToDelete.value) return;
auditStore
.deleteAuditFile(uniqueId.value, fileToDelete.value.id)
.then(() => {
deleteFileErrorMessage.value = null;
})
.catch(async (error) => {
deleteFileErrorMessage.value = await handleFileDeleteError(error);
})
.finally(() => {
deleteFileModalRef.value?.hide();
notesModal.value?.show();
notesModal.value?.fileUpload()?.onFileRequestFinished();
});
}
function handleCancelDeleteFile() {
deleteFileModalRef.value?.hide();
notesModal.value?.show();
}
</script>

<template>
Expand Down Expand Up @@ -509,16 +473,7 @@ function handleCancelDeleteFile() {
<NotesModal
ref="notesModal"
:is-loading="isNotesLoading"
:default-error-message="deleteFileErrorMessage"
@confirm="updateAuditNotes"
@delete="openDeleteFileModal"
/>

<DeleteFileModal
ref="deleteFileModalRef"
:mime-type="fileToDelete?.mimetype"
@confirm="handleDeleteFile"
@cancel="handleCancelDeleteFile"
/>
</template>

Expand Down
25 changes: 15 additions & 10 deletions confiture-web-app/src/components/audit/NotesModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,27 @@ import { useIsOffline } from "../../composables/useIsOffline";
import { FileErrorMessage } from "../../enums";
import { useAuditStore } from "../../store/audit";
import { AuditFile, StoreName } from "../../types";
import { handleFileUploadError } from "../../utils";
import { handleFileDeleteError, handleFileUploadError } from "../../utils";
import DsfrModal from "../ui/DsfrModal.vue";
import FileUpload from "../ui/FileUpload.vue";
import MarkdownHelpButton from "./MarkdownHelpButton.vue";
import SaveIndicator from "./SaveIndicator.vue";
const props = defineProps<{
defineProps<{
isLoading: boolean;
defaultErrorMessage?: FileErrorMessage | null;
}>();
const emit = defineEmits<{
(e: "closed"): void;
(e: "confirm", payload: string): void;
(e: "delete", payload: AuditFile): void;
}>();
defineExpose({
show: () => modal.value?.show(),
hide: () => modal.value?.hide(),
fileUpload: () => fileUpload.value
hide: () => modal.value?.hide()
});
const errorMessage: Ref<FileErrorMessage | null> = ref(
props.defaultErrorMessage ?? null
);
const errorMessage: Ref<FileErrorMessage | null> = ref(null);
const fileUpload = ref<InstanceType<typeof FileUpload>>();
const auditStore = useAuditStore();
Expand Down Expand Up @@ -63,7 +58,17 @@ function handleUploadFile(file: File) {
}
function handleDeleteFile(file: AuditFile) {
emit("delete", file);
auditStore
.deleteAuditFile(uniqueId.value, file.id)
.then(() => {
errorMessage.value = null;
})
.catch(async (error) => {
errorMessage.value = await handleFileDeleteError(error);
})
.finally(() => {
fileUpload.value?.onFileRequestFinished();
});
}
</script>

Expand Down

0 comments on commit cb110d2

Please sign in to comment.