fix: guest and admin logic
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user