refactor(frontend): replace status string literals with constants
- Create constants/statuses.js with MATCH_STATUS, SUGGESTION_STATUS, MATCH_FILTER - Update MatchCard, MatchesPage, HistoryPage, RatePartnerPage to use MATCH_STATUS - Update RecordingTab to use SUGGESTION_STATUS - Update Navbar to use MATCH_STATUS for API calls
This commit is contained in:
@@ -5,6 +5,7 @@ import Avatar from '../common/Avatar';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { matchesAPI } from '../../services/api';
|
||||
import { connectSocket, disconnectSocket, getSocket } from '../../services/socket';
|
||||
import { MATCH_STATUS } from '../../constants';
|
||||
|
||||
const Navbar = () => {
|
||||
const { user, logout } = useAuth();
|
||||
@@ -48,7 +49,7 @@ const Navbar = () => {
|
||||
|
||||
const loadPendingMatches = async () => {
|
||||
try {
|
||||
const result = await matchesAPI.getMatches(null, 'pending');
|
||||
const result = await matchesAPI.getMatches(null, MATCH_STATUS.PENDING);
|
||||
// Only count incoming requests (where user is not the initiator)
|
||||
const incomingCount = (result.data || []).filter(m => !m.isInitiator).length;
|
||||
setPendingMatchesCount(incomingCount);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import { MessageCircle, Check, X, Loader2, Calendar, MapPin } from 'lucide-react';
|
||||
import { MATCH_STATUS } from '../../constants';
|
||||
|
||||
/**
|
||||
* Match card for matches list page
|
||||
* Shows match details with accept/reject/chat actions
|
||||
*/
|
||||
const MatchCard = ({ match, onAccept, onReject, onOpenChat, processing }) => {
|
||||
const isIncoming = !match.isInitiator && match.status === 'pending';
|
||||
const isOutgoing = match.isInitiator && match.status === 'pending';
|
||||
const isAccepted = match.status === 'accepted';
|
||||
const isIncoming = !match.isInitiator && match.status === MATCH_STATUS.PENDING;
|
||||
const isOutgoing = match.isInitiator && match.status === MATCH_STATUS.PENDING;
|
||||
const isAccepted = match.status === MATCH_STATUS.ACCEPTED;
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-4 hover:shadow-md transition-shadow">
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
|
||||
import { Video, VideoOff, Clock, CheckCircle, XCircle, AlertTriangle, RefreshCw } from 'lucide-react';
|
||||
import { matchingAPI } from '../../services/api';
|
||||
import Avatar from '../common/Avatar';
|
||||
import { SUGGESTION_STATUS } from '../../constants';
|
||||
|
||||
/**
|
||||
* RecordingTab - Main component for managing recording partnerships
|
||||
@@ -199,8 +200,8 @@ const RecordingTab = ({ slug, event, myHeats }) => {
|
||||
key={suggestion.id || suggestion.heat?.id}
|
||||
suggestion={suggestion}
|
||||
type="toBeRecorded"
|
||||
onAccept={() => handleUpdateStatus(suggestion.id, 'accepted')}
|
||||
onReject={() => handleUpdateStatus(suggestion.id, 'rejected')}
|
||||
onAccept={() => handleUpdateStatus(suggestion.id, SUGGESTION_STATUS.ACCEPTED)}
|
||||
onReject={() => handleUpdateStatus(suggestion.id, SUGGESTION_STATUS.REJECTED)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -225,8 +226,8 @@ const RecordingTab = ({ slug, event, myHeats }) => {
|
||||
key={suggestion.id || suggestion.heat?.id}
|
||||
suggestion={suggestion}
|
||||
type="toRecord"
|
||||
onAccept={() => handleUpdateStatus(suggestion.id, 'accepted')}
|
||||
onReject={() => handleUpdateStatus(suggestion.id, 'rejected')}
|
||||
onAccept={() => handleUpdateStatus(suggestion.id, SUGGESTION_STATUS.ACCEPTED)}
|
||||
onReject={() => handleUpdateStatus(suggestion.id, SUGGESTION_STATUS.REJECTED)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -278,21 +279,21 @@ const SuggestionCard = ({ suggestion, type, onAccept, onReject }) => {
|
||||
// Status badge
|
||||
const getStatusBadge = () => {
|
||||
switch (status) {
|
||||
case 'accepted':
|
||||
case SUGGESTION_STATUS.ACCEPTED:
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium bg-green-100 text-green-800 rounded">
|
||||
<CheckCircle className="w-3 h-3" />
|
||||
Zaakceptowano
|
||||
</span>
|
||||
);
|
||||
case 'rejected':
|
||||
case SUGGESTION_STATUS.REJECTED:
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium bg-red-100 text-red-800 rounded">
|
||||
<XCircle className="w-3 h-3" />
|
||||
Odrzucono
|
||||
</span>
|
||||
);
|
||||
case 'not_found':
|
||||
case SUGGESTION_STATUS.NOT_FOUND:
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium bg-amber-100 text-amber-800 rounded">
|
||||
<AlertTriangle className="w-3 h-3" />
|
||||
@@ -305,7 +306,7 @@ const SuggestionCard = ({ suggestion, type, onAccept, onReject }) => {
|
||||
};
|
||||
|
||||
// No recorder found
|
||||
if (status === 'not_found') {
|
||||
if (status === SUGGESTION_STATUS.NOT_FOUND) {
|
||||
return (
|
||||
<div className="flex items-center justify-between p-3 bg-amber-50 border border-amber-200 rounded-lg">
|
||||
<div className="flex items-center gap-3">
|
||||
@@ -346,7 +347,7 @@ const SuggestionCard = ({ suggestion, type, onAccept, onReject }) => {
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
{status === 'pending' ? (
|
||||
{status === SUGGESTION_STATUS.PENDING ? (
|
||||
<>
|
||||
<button
|
||||
onClick={onAccept}
|
||||
|
||||
Reference in New Issue
Block a user