fix file deletion

This commit is contained in:
chark1es 2025-01-31 23:28:55 -08:00
parent 9b49a8f088
commit 5f00e88c68
4 changed files with 18 additions and 5 deletions

View file

@ -1183,13 +1183,14 @@ export class EventAuth {
// Add delete handler
const deleteButton = fileItem.querySelector('.text-error');
if (deleteButton) {
deleteButton.addEventListener('click', async () => {
deleteButton.addEventListener('click', async (e) => {
e.preventDefault(); // Prevent any form submission
if (confirm('Are you sure you want to remove this file?')) {
try {
const fileToRemove = deleteButton.getAttribute('data-file');
if (!fileToRemove) throw new Error('File not found');
// Get the current event data to ensure we have the latest state
// Get the current event data
const currentEvent = await this.pb.collection('events').getOne(event.id);
// Filter out the file to be removed
@ -1200,14 +1201,14 @@ export class EventAuth {
files: updatedFiles
});
// Update the event.files array in memory
// Update the local event object
event.files = updatedFiles;
// Remove the file item from the UI
fileItem.remove();
// If no files left, show the "No files" message
if (updatedFiles.length === 0) {
if (!event.files || event.files.length === 0) {
currentFiles.innerHTML = '<span class="text-sm opacity-50">No files</span>';
}
} catch (err) {

View file

@ -10,7 +10,12 @@ const { editor_title, form } = config.ui.tables.events;
<dialog id="eventEditor" class="modal">
<div class="modal-box w-11/12 max-w-4xl">
<h3 class="font-bold text-lg mb-6">{editor_title}</h3>
<form class="space-y-6" id="eventForm" novalidate>
<form
class="space-y-6"
id="eventForm"
novalidate
onsubmit="event.preventDefault();"
>
<!-- Basic Info Section -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="form-control">

View file

@ -0,0 +1,7 @@
---
import Layout from "../layouts/Layout.astro";
---
<Layout>
<h1>Reimbursement</h1>
</Layout>