mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
5.0 KiB
5.0 KiB
Blog Match Link Fix - Verification Checklist
Issue Summary
Problem: When creating a blog article and selecting a match from the "Propojit se zápasem" section, the match ID was not being saved to the database.
User Evidence: Console log showed:
Saving article with payload: {
"title": "U17: Rýmařov...",
"category_name": "KALMAN TRADE Krajský přebor mladší dorost",
// ... other fields ...
// ❌ NO match_id field in payload
}
Fix Applied
Technical Changes
-
Moved match linking from async callback to synchronous flow
- Previous: Match linking happened in
createMut.onSuccesscallback (after article creation) - New: Match linking happens in
onSubmitfunction (immediately after article creation completes) - Benefit: Prevents race conditions and React error interruptions
- Previous: Match linking happened in
-
Added comprehensive error handling
- Separate try-catch blocks for article save and match linking
- Clear user feedback for each operation
- Logging at each step for debugging
-
Fixed React error #310
- Added loading state to
MatchLinkBadgecomponent - Prevents rendering errors during query refetch
- Added loading state to
Verification Steps
1. Check Console Logs
After applying the fix, when creating an article with a match link, you should see:
Match link state before submit: {
tempMatchLink: "12345",
matchIdInput: "12345",
linkedMatchId: "",
isNewArticle: true
}
Linking new article 42 with match 12345
Match link created for new article
2. Check Toast Messages
- ✅ Success: "Článek vytvořen a propojen se zápasem" (with Match ID)
- ⚠️ Partial Success: "Článek vytvořen, ale propojení se zápasem selhalo"
3. Check Database
Query to verify match link was saved:
SELECT * FROM article_match_links WHERE article_id = [NEW_ARTICLE_ID];
Should return:
article_id: The ID of the newly created articleexternal_match_id: The FACR match ID (e.g., "12345")title: The article title
4. Check Article List UI
- Badge should show: "Zápas: [Home Team] [Score] [Away Team]" in green (if match has score) or yellow (if no score yet)
- Should NOT show: "Nepropojeno" in gray
5. Check API Response
The article creation response should include match_link:
{
"id": 42,
"title": "U17: Rýmařov...",
"match_link": {
"article_id": 42,
"external_match_id": "12345",
"title": "U17: Rýmařov..."
}
}
Test Scenarios
Scenario A: New Article with Match
- Open Admin → Články → Nový článek
- Fill in title: "Test článek"
- Select category: "KALMAN TRADE Krajský přebor mladší dorost"
- Click on a match in the match picker
- Click "Uložit"
- Expected: Green toast with match ID
- Verify: List shows match badge with team names
Scenario B: New Article without Match
- Create article without selecting match
- Expected: Standard success toast
- Verify: List shows "Nepropojeno" badge
Scenario C: Edit Existing Article, Add Match
- Open existing article
- Select a match
- Click "Uložit"
- Expected: Success toast with match info
- Verify: Badge updates immediately
Scenario D: Edit Existing Article, Change Match
- Open article that already has a match
- Select different match
- Click "Uložit"
- Expected: Success toast
- Verify: Badge shows new match
Scenario E: Backend Error Handling
- Stop backend server
- Try to create article with match
- Expected: Article created locally, warning toast about match linking failure
- Restart backend
- Verify: Can manually link match by editing article
Code Changes Summary
Files Modified
/frontend/src/pages/admin/ArticlesAdminPage.tsx- Lines 40-43: Added loading state to MatchLinkBadge
- Lines 655-673: Simplified createMut.onSuccess
- Lines 686-702: Simplified updateMut.onSuccess
- Lines 928-987: Refactored onSubmit with inline match linking
Files Created
/DOCS/BLOG_MATCH_LINK_FIX.md- Detailed fix documentation/DOCS/BLOG_MATCH_LINK_VERIFICATION.md- This file
Rollback Plan
If issues occur, revert the ArticlesAdminPage.tsx changes:
git checkout HEAD -- frontend/src/pages/admin/ArticlesAdminPage.tsx
Performance Impact
- No performance degradation
- Actually improved: One less async operation in mutation callback
- Better user experience: Immediate feedback on match linking status
Browser Compatibility
- No new browser APIs used
- Compatible with all modern browsers (Chrome, Firefox, Safari, Edge)
- React Query handles all async state management
Known Limitations
- Match linking requires article to be saved first (can't preview match before save)
- If backend is down, match link won't be saved (fails gracefully)
- Maximum 100 matches shown in picker (performance optimization)
Related Documentation
DOCS/BLOG_CREATION_FIXED.md- Previous blog creation fixesDOCS/FACR_INTEGRATION.md- FACR match data integrationDOCS/ADMIN_QUICK_REFERENCE.md- Admin panel overview