fix: lỗi hiển thị ở frontend

This commit is contained in:
2026-06-21 21:53:14 +07:00
parent 403c169ddd
commit b1a539235b
40 changed files with 5094 additions and 668 deletions
+282 -27
View File
@@ -21,12 +21,15 @@ import {
Download,
Loader2,
Bell,
BellOff
BellOff,
ShieldAlert
} from 'lucide-react';
import { useTourStore } from '@/store/useTourStore';
import { useNotification } from '@/hooks/useNotification';
import { useConfirm } from '@/hooks/useConfirm';
import { MyPhotosPage } from './MyPhotosPage';
import { useTranslation } from '../hooks/useTranslation';
import { useTheme } from '../hooks/useTheme';
interface MemberDashboardProps {
user: any;
@@ -44,6 +47,8 @@ export const MemberDashboard: React.FC<MemberDashboardProps> = ({
}) => {
const notify = useNotification();
const confirm = useConfirm();
const { t, lang, changeLanguage } = useTranslation();
const { theme, changeTheme } = useTheme();
const publicTours = useTourStore(state => state.publicTours);
const fetchPublicTours = useTourStore(state => state.fetchPublicTours);
@@ -75,12 +80,65 @@ export const MemberDashboard: React.FC<MemberDashboardProps> = ({
const [unreadTourSenders, setUnreadTourSenders] = useState<string[]>([]);
const [unreadTourChats, setUnreadTourChats] = useState<string[]>([]);
const hasNotifications = unreadChatSenders.length > 0 || unreadTourChats.length > 0 || unreadTourSenders.length > 0 || receivedRequests.length > 0;
const [selectedImage, setSelectedImage] = useState<File | null>(null);
const [imagePreview, setImagePreview] = useState<string | null>(null);
const [attachedLocation, setAttachedLocation] = useState<{ latitude: number; longitude: number } | null>(null);
const [isUploading, setIsUploading] = useState(false);
const [isLocating, setIsLocating] = useState(false);
// Emergency share states
const [sharingTour, setSharingTour] = useState<any | null>(null);
const [shareStatus, setShareStatus] = useState<any | null>(null);
const [loadingShare, setLoadingShare] = useState(false);
const handleOpenShareModal = async (tour: any) => {
setSharingTour(tour);
setShareStatus(null);
setLoadingShare(true);
try {
const token = localStorage.getItem('token');
const res = await fetch(`/api/v1/tours/${tour.id}/share`, {
headers: { 'Authorization': `Bearer ${token}` }
});
if (res.ok) {
const data = await res.json();
setShareStatus(data);
}
} catch (e) {
console.error('Error fetching share status:', e);
} finally {
setLoadingShare(false);
}
};
const handleToggleShare = async (isEnabled: boolean) => {
if (!sharingTour) return;
try {
const token = localStorage.getItem('token');
const res = await fetch(`/api/v1/tours/${sharingTour.id}/share`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ isEnabled })
});
if (res.ok) {
const data = await res.json();
setShareStatus(data);
notify({
title: 'Thành công',
message: isEnabled ? 'Đã bật chia sẻ hành trình cứu hộ.' : 'Đã tắt chia sẻ.',
type: 'success'
});
}
} catch (e) {
console.error(e);
}
};
const fileInputRef = useRef<HTMLInputElement>(null);
const [isMobile, setIsMobile] = useState(window.innerWidth < 768);
@@ -687,14 +745,18 @@ const renderInitialsAvatar = (name: string, sizeClass = 'w-10 h-10 text-sm') =>
type: 'info'
});
}}
className={`absolute -bottom-1 -right-1 p-1.5 rounded-full border shadow-md transition-all active:scale-90 z-20 ${
className={`absolute -bottom-1 -right-1 p-1.5 rounded-full border shadow-md transition-all active:scale-95 z-20 ${
muteNotifications
? 'bg-slate-900 border-slate-800 text-slate-400 hover:text-slate-200'
: 'bg-indigo-650 border-indigo-500 text-white hover:bg-indigo-600'
}`}
title={muteNotifications ? "Bật thông báo đẩy" : "Tắt thông báo đẩy"}
>
{muteNotifications ? <BellOff className="w-3.5 h-3.5" /> : <Bell className="w-3.5 h-3.5 text-white" />}
{muteNotifications ? (
<BellOff className="w-3.5 h-3.5" />
) : (
<Bell className={`w-3.5 h-3.5 text-white ${hasNotifications ? 'animate-ring' : ''}`} />
)}
</button>
</div>
<h2 className="text-lg font-black tracking-tight text-white/95">
@@ -708,6 +770,34 @@ const renderInitialsAvatar = (name: string, sizeClass = 'w-10 h-10 text-sm') =>
)}
</div>
{/* Mobile Language & Theme Selectors */}
<div className="px-6 py-4 flex flex-col gap-3 border-b border-slate-900 bg-slate-900/10 shrink-0">
<div className="flex items-center justify-between gap-2">
<span className="text-[10px] font-black uppercase tracking-widest text-slate-400">{t('languageSelect') || 'Ngôn ngữ'}</span>
<select
value={lang}
onChange={(e) => changeLanguage(e.target.value as any)}
className="bg-slate-950 border border-slate-800 text-white rounded-xl px-3 py-2 text-xs font-bold focus:outline-none cursor-pointer"
>
<option value="vi">Tiếng Việt</option>
<option value="en">English</option>
<option value="zh"></option>
</select>
</div>
<div className="flex items-center justify-between gap-2">
<span className="text-[10px] font-black uppercase tracking-widest text-slate-400">{t('themeSelect') || 'Giao diện'}</span>
<select
value={theme}
onChange={(e) => changeTheme(e.target.value as any)}
className="bg-slate-950 border border-slate-800 text-white rounded-xl px-3 py-2 text-xs font-bold focus:outline-none cursor-pointer"
>
<option value="light">{t('themeLight') || 'Sáng'}</option>
<option value="dark">{t('themeDark') || 'Tối'}</option>
<option value="system">{t('themeSystem') || 'Hệ thống'}</option>
</select>
</div>
</div>
{/* Explore Map Quick Button */}
<div className="p-4 border-b border-slate-900">
<button
@@ -919,7 +1009,11 @@ const renderInitialsAvatar = (name: string, sizeClass = 'w-10 h-10 text-sm') =>
}`}
title={muteNotifications ? "Bật thông báo đẩy" : "Tắt thông báo đẩy"}
>
{muteNotifications ? <BellOff className="w-3.5 h-3.5" /> : <Bell className="w-3.5 h-3.5 text-white" />}
{muteNotifications ? (
<BellOff className="w-3.5 h-3.5" />
) : (
<Bell className={`w-3.5 h-3.5 text-white ${hasNotifications ? 'animate-ring' : ''}`} />
)}
</button>
</div>
<h2 className="text-base font-black text-white">{user?.name || 'Thành viên'}</h2>
@@ -931,6 +1025,34 @@ const renderInitialsAvatar = (name: string, sizeClass = 'w-10 h-10 text-sm') =>
)}
</div>
{/* Desktop Language & Theme Selectors */}
<div className="px-6 py-4 flex flex-col gap-3 border-b border-slate-800/60 shrink-0">
<div className="flex items-center justify-between gap-2">
<span className="text-[10px] font-black uppercase tracking-widest text-slate-500">{t('languageSelect') || 'Ngôn ngữ'}</span>
<select
value={lang}
onChange={(e) => changeLanguage(e.target.value as any)}
className="bg-slate-950 border border-slate-800 text-white rounded-xl px-2.5 py-1.5 text-xs font-bold focus:outline-none cursor-pointer"
>
<option value="vi">Tiếng Việt</option>
<option value="en">English</option>
<option value="zh"></option>
</select>
</div>
<div className="flex items-center justify-between gap-2">
<span className="text-[10px] font-black uppercase tracking-widest text-slate-500">{t('themeSelect') || 'Giao diện'}</span>
<select
value={theme}
onChange={(e) => changeTheme(e.target.value as any)}
className="bg-slate-950 border border-slate-800 text-white rounded-xl px-2.5 py-1.5 text-xs font-bold focus:outline-none cursor-pointer"
>
<option value="light">{t('themeLight') || 'Sáng'}</option>
<option value="dark">{t('themeDark') || 'Tối'}</option>
<option value="system">{t('themeSystem') || 'Hệ thống'}</option>
</select>
</div>
</div>
{/* Quick Nav Links */}
<div className="px-4 py-6 flex flex-col gap-2 border-b border-slate-800/60">
<button
@@ -1156,31 +1278,41 @@ const renderInitialsAvatar = (name: string, sizeClass = 'w-10 h-10 text-sm') =>
{tour.endDate ? new Date(tour.endDate).toLocaleDateString('vi-VN') : 'N/A'}
</span>
</div>
<div className="flex items-center justify-between gap-2 mt-2">
<div className="flex flex-col gap-2 mt-2">
<div className="flex gap-2">
<button
onClick={() => onViewTour(tour.id, 'dashboard')}
className="flex-1 py-2 px-2 bg-slate-900 hover:bg-slate-800 text-slate-350 hover:text-white rounded-xl text-xs font-bold transition-all border border-slate-800 hover:border-slate-700 flex items-center justify-center gap-1"
>
<span>Xem chi tiết</span>
<ChevronRight className="w-3.5 h-3.5" />
</button>
<button
onClick={() => {
localStorage.setItem('tour_detail_default_tab', 'chat');
setUnreadTourChats(prev => prev.filter(id => id !== tour.id));
onViewTour(tour.id, 'dashboard');
}}
className="flex-1 py-2 px-2 bg-indigo-600/20 hover:bg-indigo-600 text-indigo-300 hover:text-white rounded-xl text-xs font-bold transition-all border border-indigo-500/30 hover:border-indigo-500 flex items-center justify-center gap-1 relative whitespace-nowrap"
>
<MessageSquare className="w-3.5 h-3.5" />
<span>Trò chuyện</span>
{unreadTourChats.includes(tour.id) && (
<span className="absolute -top-1 -right-1 w-2.5 h-2.5 bg-rose-600 rounded-full animate-ping border border-slate-800" />
)}
{unreadTourChats.includes(tour.id) && (
<span className="absolute -top-1 -right-1 w-2.5 h-2.5 bg-rose-600 rounded-full border border-slate-800" />
)}
</button>
</div>
<button
onClick={() => onViewTour(tour.id, 'dashboard')}
className="flex-1 py-2 px-3 bg-slate-900 hover:bg-slate-800 text-slate-350 hover:text-white rounded-xl text-xs font-bold transition-all border border-slate-800 hover:border-slate-700 flex items-center justify-center gap-1.5"
onClick={() => handleOpenShareModal(tour)}
className="w-full py-2 px-3 bg-rose-600/10 hover:bg-rose-600 text-rose-400 hover:text-white rounded-xl text-xs font-bold transition-all border border-rose-500/20 hover:border-rose-500 flex items-center justify-center gap-1.5"
>
<span>Xem chi tiết</span>
<ChevronRight className="w-3.5 h-3.5" />
</button>
<button
onClick={() => {
localStorage.setItem('tour_detail_default_tab', 'chat');
setUnreadTourChats(prev => prev.filter(id => id !== tour.id));
onViewTour(tour.id, 'dashboard');
}}
className="flex-1 py-2 px-3 bg-indigo-600/20 hover:bg-indigo-600 text-indigo-300 hover:text-white rounded-xl text-xs font-bold transition-all border border-indigo-500/30 hover:border-indigo-500 flex items-center justify-center gap-1.5 relative"
>
<MessageSquare className="w-3.5 h-3.5" />
<span>Trò chuyện</span>
{unreadTourChats.includes(tour.id) && (
<span className="absolute -top-1 -right-1 w-2.5 h-2.5 bg-rose-600 rounded-full animate-ping border border-slate-800" />
)}
{unreadTourChats.includes(tour.id) && (
<span className="absolute -top-1 -right-1 w-2.5 h-2.5 bg-rose-600 rounded-full border border-slate-800" />
)}
<ShieldAlert className="w-3.5 h-3.5 text-rose-500" />
<span>Chia sẻ khẩn cấp</span>
</button>
</div>
</div>
@@ -1805,6 +1937,129 @@ const renderInitialsAvatar = (name: string, sizeClass = 'w-10 h-10 text-sm') =>
</div>
)}
{/* Emergency Share Configuration Modal */}
{sharingTour && (
<div className="fixed inset-0 z-[9999] flex items-center justify-center p-4 bg-slate-950/80 backdrop-blur-md animate-in fade-in duration-300">
<div className="w-full max-w-lg bg-slate-900 border border-slate-800 rounded-[32px] overflow-hidden shadow-2xl animate-in zoom-in-95 duration-300">
{/* Modal Header */}
<div className="p-6 border-b border-slate-800/80 flex items-center justify-between">
<div className="flex items-center gap-3 text-rose-500">
<ShieldAlert className="w-6 h-6 animate-pulse" />
<h3 className="text-lg font-black uppercase tracking-tight text-white">{t('emergencyShare')}</h3>
</div>
<button
onClick={() => setSharingTour(null)}
className="p-2 hover:bg-slate-800 rounded-xl text-slate-400 hover:text-white transition-all active:scale-95"
>
<X className="w-5 h-5" />
</button>
</div>
{/* Modal Body */}
<div className="p-6 space-y-6">
<div>
<h4 className="text-sm font-bold text-white mb-1">{sharingTour.title}</h4>
<p className="text-xs text-slate-450 leading-relaxed">{t('emergencyShareTooltip')}</p>
</div>
{loadingShare ? (
<div className="py-8 flex flex-col items-center justify-center gap-2">
<Loader2 className="w-8 h-8 text-rose-500 animate-spin" />
<span className="text-xs text-slate-500 font-bold">{t('loading')}</span>
</div>
) : (
<>
{/* Share Activation Toggle */}
<div className="bg-slate-950/40 border border-slate-800/60 p-4 rounded-2xl flex items-center justify-between">
<div>
<span className="text-xs font-bold text-slate-300">Kích hoạt đưng dẫn cứu hộ</span>
</div>
{shareStatus && (
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
checked={shareStatus.isEnabled}
onChange={(e) => handleToggleShare(e.target.checked)}
className="sr-only peer"
/>
<div className="w-11 h-6 bg-slate-800 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-slate-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-rose-600"></div>
</label>
)}
</div>
{shareStatus?.isEnabled && (
<>
{/* Configuration: Language and Theme selectors */}
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<label className="block text-[10px] font-black uppercase tracking-widest text-slate-500">{t('languageSelect')}</label>
<select
value={lang}
onChange={(e) => changeLanguage(e.target.value as any)}
className="w-full bg-slate-950 border border-slate-800 text-white rounded-xl px-3 py-2.5 text-xs font-bold focus:outline-none cursor-pointer"
>
<option value="vi">Tiếng Việt</option>
<option value="en">English</option>
<option value="zh"></option>
</select>
</div>
<div className="space-y-2">
<label className="block text-[10px] font-black uppercase tracking-widest text-slate-500">{t('themeSelect')}</label>
<select
value={theme}
onChange={(e) => changeTheme(e.target.value as any)}
className="w-full bg-slate-950 border border-slate-800 text-white rounded-xl px-3 py-2.5 text-xs font-bold focus:outline-none cursor-pointer"
>
<option value="light">{t('themeLight')}</option>
<option value="dark">{t('themeDark')}</option>
<option value="system">{t('themeSystem')}</option>
</select>
</div>
</div>
{/* Shareable Link Input with Copy button */}
<div className="bg-rose-950/10 border border-rose-950/20 p-4 rounded-2xl space-y-2">
<div className="text-[10px] font-black text-rose-400 uppercase tracking-widest">Đưng dẫn khẩn cấp:</div>
<div className="flex items-center gap-2">
<input
type="text"
readOnly
value={`${window.location.origin}/journey/${shareStatus.token}?lang=${lang}&theme=${theme}`}
className="flex-1 bg-slate-950 border border-slate-800 rounded-xl px-3 py-2.5 text-xs text-slate-200 select-all outline-none"
/>
<button
type="button"
onClick={() => {
navigator.clipboard.writeText(`${window.location.origin}/journey/${shareStatus.token}?lang=${lang}&theme=${theme}`);
notify({ title: 'Thành công', message: 'Đã sao chép liên kết!', type: 'success' });
}}
className="bg-rose-600 hover:bg-rose-700 text-white font-bold px-4 py-2.5 rounded-xl text-xs transition-all active:scale-95 shrink-0"
>
{t('copyShareLink')}
</button>
</div>
</div>
</>
)}
</>
)}
</div>
{/* Modal Footer */}
<div className="p-6 bg-slate-950/20 border-t border-slate-800/80 flex justify-end">
<button
type="button"
onClick={() => setSharingTour(null)}
className="py-2.5 px-6 bg-slate-800 hover:bg-slate-700 text-white font-bold rounded-xl text-xs transition-all active:scale-95"
>
Đóng
</button>
</div>
</div>
</div>
)}
</div>
</main>
</div>