Thêm tính năng owner có thể thêm thành viên, member thêm thành viên sẽ pending

This commit is contained in:
2026-06-14 22:14:40 +07:00
parent 7cc724a133
commit c6341aa12f
16 changed files with 395 additions and 23 deletions
+15 -5
View File
@@ -5,6 +5,7 @@ import { useTourStore } from './useTourStore.js';
import { AddLocationModal } from './AddLocationModal.js';
import { AddMemberModal } from './AddMemberModal.js';
import { ConfirmModal } from './ConfirmModal.js';
import { NotificationModal, useNotificationModal } from './components/NotificationModal.js';
import { MapContainer, TileLayer, Marker, Popup, useMapEvents, Polyline } from 'react-leaflet';
import _MarkerClusterGroup from 'react-leaflet-cluster';
const MarkerClusterGroup = (_MarkerClusterGroup as any).default || _MarkerClusterGroup;
@@ -181,6 +182,8 @@ export const TourDetailPage = ({ onBack }: { onBack: () => void }) => {
fetchJoinRequests, acceptJoinRequest, rejectJoinRequest
} = useTourStore();
const notificationModal = useNotificationModal();
// Khôi phục vị trí và mức zoom từ localStorage
const [initialViewState] = useState(() => {
const saved = localStorage.getItem('map_view_state');
@@ -443,7 +446,7 @@ export const TourDetailPage = ({ onBack }: { onBack: () => void }) => {
await acceptJoinRequest(currentTour.id, req.id);
setJoinRequests((prev) => prev.filter((r) => r.id !== req.id));
} catch (e: any) {
alert(e.message || 'Không thể chấp nhận yêu cầu');
notificationModal.openModal('Thông báo', e.message || 'Không thể chấp nhận yêu cầu', 'error');
} finally {
setJoinRequestActionId(null);
setConfirmState({ open: false });
@@ -472,7 +475,7 @@ export const TourDetailPage = ({ onBack }: { onBack: () => void }) => {
await rejectJoinRequest(currentTour.id, req.id);
setJoinRequests((prev) => prev.filter((r) => r.id !== req.id));
} catch (e: any) {
alert(e.message || 'Không thể từ chối yêu cầu');
notificationModal.openModal('Thông báo', e.message || 'Không thể từ chối yêu cầu', 'error');
} finally {
setJoinRequestActionId(null);
setConfirmState({ open: false });
@@ -721,7 +724,7 @@ export const TourDetailPage = ({ onBack }: { onBack: () => void }) => {
await acceptJoinRequest(currentTour.id, req.id);
setJoinRequests((prev) => prev.filter((r) => r.id !== req.id));
} catch (e: any) {
alert(e.message || 'Không thể chấp nhận yêu cầu');
notificationModal.openModal('Thông báo', e.message || 'Không thể chấp nhận yêu cầu', 'error');
} finally {
setJoinRequestActionId(null);
setConfirmState({ open: false });
@@ -748,7 +751,7 @@ export const TourDetailPage = ({ onBack }: { onBack: () => void }) => {
await rejectJoinRequest(currentTour.id, req.id);
setJoinRequests((prev) => prev.filter((r) => r.id !== req.id));
} catch (e: any) {
alert(e.message || 'Không thể từ chối yêu cầu');
notificationModal.openModal('Thông báo', e.message || 'Không thể từ chối yêu cầu', 'error');
} finally {
setJoinRequestActionId(null);
setConfirmState({ open: false });
@@ -849,7 +852,7 @@ export const TourDetailPage = ({ onBack }: { onBack: () => void }) => {
await removeMember(currentTour.id, selectedMember.userId);
setIsMemberDetailOpen(false);
} catch (e) {
alert('Không thể xóa thành viên');
notificationModal.openModal('Thông báo', 'Không thể xóa thành viên', 'error');
}
}}
className="px-3 py-2 bg-red-600 hover:bg-red-700 text-white rounded-xl text-sm font-bold"
@@ -879,6 +882,13 @@ export const TourDetailPage = ({ onBack }: { onBack: () => void }) => {
onConfirm={() => confirmState.onConfirm?.()}
onCancel={() => setConfirmState({ open: false })}
/>
<NotificationModal
isOpen={notificationModal.modalState?.isOpen ?? false}
title={notificationModal.modalState?.title}
message={notificationModal.modalState?.message}
type={notificationModal.modalState?.type}
onConfirm={() => notificationModal.closeModal()}
/>
</div>
);
};