fix: Add missing handleEditGuestbookEntry and handleSaveEditGuestbook functions
- Define handleEditGuestbookEntry to open edit dialog with entry data - Define handleSaveEditGuestbook to save guestbook entry changes - Fixes ReferenceError: handleSaveEditGuestbook is not defined These functions were referenced in the UI but not defined in the component scope
This commit is contained in:
@@ -2332,6 +2332,79 @@ export function AdminDashboard({
|
||||
setDeleteGuestbookDialog({ open: true, messageId });
|
||||
};
|
||||
|
||||
const handleEditGuestbookEntry = (entry: any) => {
|
||||
setEditingGuestbookEntry(entry);
|
||||
setEditGuestbookForm({
|
||||
message: entry.message || '',
|
||||
photo: entry.photo || '',
|
||||
audioUrl: entry.audioUrl || '',
|
||||
videoUrl: entry.videoUrl || '',
|
||||
});
|
||||
setIsEditGuestbookOpen(true);
|
||||
};
|
||||
|
||||
const handleSaveEditGuestbook = async () => {
|
||||
if (!editingGuestbookEntry) return;
|
||||
|
||||
const csrfToken = await getCSRFToken();
|
||||
if (!csrfToken) {
|
||||
toast({
|
||||
variant: "error",
|
||||
title: "Authentication Required",
|
||||
description: "Please refresh the page.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/admin/guestbook', {
|
||||
method: 'PUT',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-csrf-token': csrfToken,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: editingGuestbookEntry.id,
|
||||
message: editGuestbookForm.message.trim(),
|
||||
photo: editGuestbookForm.photo || null,
|
||||
audioUrl: editGuestbookForm.audioUrl || null,
|
||||
videoUrl: editGuestbookForm.videoUrl || null,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.error || 'Failed to update guestbook entry');
|
||||
}
|
||||
|
||||
// Refresh guestbook entries
|
||||
const refreshResponse = await fetch('/api/admin/guestbook', {
|
||||
credentials: 'include',
|
||||
});
|
||||
if (refreshResponse.ok) {
|
||||
const data = await refreshResponse.json();
|
||||
setGuestbookEntries(data);
|
||||
}
|
||||
|
||||
toast({
|
||||
variant: "success",
|
||||
title: "Guestbook Entry Updated",
|
||||
description: "The entry has been updated successfully.",
|
||||
});
|
||||
|
||||
setIsEditGuestbookOpen(false);
|
||||
setEditingGuestbookEntry(null);
|
||||
setEditGuestbookForm({ message: '', photo: '', audioUrl: '', videoUrl: '' });
|
||||
} catch (error) {
|
||||
toast({
|
||||
variant: "error",
|
||||
title: "Failed to Update Entry",
|
||||
description: error instanceof Error ? error.message : 'Unknown error',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const confirmDeleteGuestbookMessage = async () => {
|
||||
const { messageId } = deleteGuestbookDialog;
|
||||
if (!messageId) return;
|
||||
|
||||
Reference in New Issue
Block a user