fix: guest and admin logic

This commit is contained in:
2026-06-22 11:41:34 +07:00
parent b1a539235b
commit 860395cb14
61 changed files with 1291 additions and 244 deletions
+18 -4
View File
@@ -10,9 +10,10 @@ interface AddPhotoModalProps {
onClose: () => void;
tourId: string;
onSuccess?: () => void;
isPublicView?: boolean;
}
export const AddPhotoModal: React.FC<AddPhotoModalProps> = ({ isOpen, onClose, tourId, onSuccess }) => {
export const AddPhotoModal: React.FC<AddPhotoModalProps> = ({ isOpen, onClose, tourId, onSuccess, isPublicView }) => {
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
const [previews, setPreviews] = useState<string[]>([]);
const [isUploading, setIsUploading] = useState(false);
@@ -136,13 +137,26 @@ export const AddPhotoModal: React.FC<AddPhotoModalProps> = ({ isOpen, onClose, t
type: 'success'
});
fetchTour(tourId);
if (onSuccess) onSuccess();
onClose();
// Giải phóng bộ nhớ sau khi hoàn tất
previews.forEach(url => URL.revokeObjectURL(url));
setSelectedFiles([]);
setPreviews([]);
// For public users: redirect to landing page after upload
// For authenticated users: refresh tour data and close modal
if (isPublicView) {
onClose();
// Give time for notification to show before redirecting
// Set flag so App.tsx knows to redirect to landing even if user is logged in
setTimeout(() => {
localStorage.setItem('fromPublicUpload', 'true');
window.location.href = '/';
}, 1000);
} else {
fetchTour(tourId);
if (onSuccess) onSuccess();
onClose();
}
} catch (error) {
notify({
title: 'Lỗi',