feat: implement Phase 2 - Matches API with real-time notifications
Backend changes:
- Add matches API routes (POST, GET, PUT, DELETE)
- Create/accept/reject match requests
- Auto-create private chat rooms on match acceptance
- Socket.IO notifications for match events (received, accepted, cancelled)
- Users join personal rooms (user_{id}) for notifications
Frontend changes:
- Add MatchesPage component with inbox UI
- Matches navigation link with notification badge
- Real-time match request count updates
- Accept/reject match functionality
- Filter matches by status (all/pending/accepted)
- Integrate match requests in EventChatPage (UserPlus button)
Features:
- Send match requests to event participants
- Accept incoming match requests
- Real-time notifications via Socket.IO
- Automatic private chat room creation
- Match status tracking (pending/accepted/completed)
- Authorization checks (only participants can match)
- Duplicate match prevention
This commit is contained in:
@@ -4,7 +4,7 @@ import Layout from '../components/layout/Layout';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { Send, UserPlus, Loader2, LogOut, AlertTriangle, QrCode, Edit2, Filter, X } from 'lucide-react';
|
||||
import { connectSocket, disconnectSocket, getSocket } from '../services/socket';
|
||||
import { eventsAPI, heatsAPI } from '../services/api';
|
||||
import { eventsAPI, heatsAPI, matchesAPI } from '../services/api';
|
||||
import HeatsBanner from '../components/heats/HeatsBanner';
|
||||
|
||||
const EventChatPage = () => {
|
||||
@@ -252,12 +252,29 @@ const EventChatPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleMatchWith = (userId) => {
|
||||
// TODO: Implement match request
|
||||
alert(`Match request sent to user!`);
|
||||
setTimeout(() => {
|
||||
navigate(`/matches/1/chat`);
|
||||
}, 1000);
|
||||
const handleMatchWith = async (userId) => {
|
||||
try {
|
||||
const result = await matchesAPI.createMatch(userId, slug);
|
||||
|
||||
// Show success message
|
||||
alert(`Match request sent successfully! The user will be notified.`);
|
||||
|
||||
// Optional: Navigate to matches page or refresh matches list
|
||||
// For now, we just show a success message
|
||||
} catch (error) {
|
||||
console.error('Failed to send match request:', error);
|
||||
|
||||
// Show appropriate error message
|
||||
if (error.status === 400 && error.message.includes('already exists')) {
|
||||
alert('You already have a match request with this user.');
|
||||
} else if (error.status === 403) {
|
||||
alert('You must be a participant of this event to send match requests.');
|
||||
} else if (error.status === 404) {
|
||||
alert('Event not found.');
|
||||
} else {
|
||||
alert('Failed to send match request. Please try again.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleHeatsSave = () => {
|
||||
|
||||
Reference in New Issue
Block a user