feat: pre-populate heats form with existing data when editing
- Add existingHeats prop to HeatsBanner component - Load and format existing heats into form fields - Pass myHeats to HeatsBanner in edit modal - Users can now edit their heats instead of starting from scratch
This commit is contained in:
@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
|||||||
import { X, Plus, Trash2, Loader2 } from 'lucide-react';
|
import { X, Plus, Trash2, Loader2 } from 'lucide-react';
|
||||||
import { divisionsAPI, competitionTypesAPI, heatsAPI } from '../../services/api';
|
import { divisionsAPI, competitionTypesAPI, heatsAPI } from '../../services/api';
|
||||||
|
|
||||||
export default function HeatsBanner({ slug, onSave, onDismiss }) {
|
export default function HeatsBanner({ slug, onSave, onDismiss, existingHeats = null }) {
|
||||||
const [divisions, setDivisions] = useState([]);
|
const [divisions, setDivisions] = useState([]);
|
||||||
const [competitionTypes, setCompetitionTypes] = useState([]);
|
const [competitionTypes, setCompetitionTypes] = useState([]);
|
||||||
const [heats, setHeats] = useState([{ divisionId: '', competitionTypeId: '', heatNumber: '', role: '' }]);
|
const [heats, setHeats] = useState([{ divisionId: '', competitionTypeId: '', heatNumber: '', role: '' }]);
|
||||||
@@ -14,6 +14,19 @@ export default function HeatsBanner({ slug, onSave, onDismiss }) {
|
|||||||
loadOptions();
|
loadOptions();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Load existing heats if provided
|
||||||
|
useEffect(() => {
|
||||||
|
if (existingHeats && existingHeats.length > 0) {
|
||||||
|
const formattedHeats = existingHeats.map(heat => ({
|
||||||
|
divisionId: heat.divisionId.toString(),
|
||||||
|
competitionTypeId: heat.competitionTypeId.toString(),
|
||||||
|
heatNumber: heat.heatNumber.toString(),
|
||||||
|
role: heat.role || '',
|
||||||
|
}));
|
||||||
|
setHeats(formattedHeats);
|
||||||
|
}
|
||||||
|
}, [existingHeats]);
|
||||||
|
|
||||||
const loadOptions = async () => {
|
const loadOptions = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|||||||
@@ -717,6 +717,7 @@ const EventChatPage = () => {
|
|||||||
slug={slug}
|
slug={slug}
|
||||||
onSave={handleHeatsSave}
|
onSave={handleHeatsSave}
|
||||||
onDismiss={() => setShowHeatsModal(false)}
|
onDismiss={() => setShowHeatsModal(false)}
|
||||||
|
existingHeats={myHeats}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user