'use client' import {useState} from 'react'; interface TimeGoal { desiredReleaseDate: string; maxReleaseDate: string; } interface NumbersGoal { minWordsCount: number; maxWordsCount: number; desiredWordsCountByChapter: number; desiredChapterCount: number; } interface Goal { id: number; name: string; timeGoal: TimeGoal; numbersGoal: NumbersGoal; } export default function GoalsPage() { const [goals, setGoals] = useState([ { id: 1, name: 'First Goal', timeGoal: { desiredReleaseDate: '', maxReleaseDate: '', }, numbersGoal: { minWordsCount: 0, maxWordsCount: 0, desiredWordsCountByChapter: 0, desiredChapterCount: 0, }, }, ]); const [selectedGoalIndex, setSelectedGoalIndex] = useState(0); const [newGoalName, setNewGoalName] = useState(''); const handleAddGoal = () => { const newGoal: Goal = { id: goals.length + 1, name: newGoalName, timeGoal: { desiredReleaseDate: '', maxReleaseDate: '', }, numbersGoal: { minWordsCount: 0, maxWordsCount: 0, desiredWordsCountByChapter: 0, desiredChapterCount: 0, }, }; setGoals([...goals, newGoal]); setNewGoalName(''); }; const handleInputChange = (e: React.ChangeEvent, field: keyof Goal, subField?: keyof TimeGoal | keyof NumbersGoal) => { const updatedGoals = [...goals]; if (subField) { if (field === 'timeGoal' && subField in updatedGoals[selectedGoalIndex].timeGoal) { (updatedGoals[selectedGoalIndex].timeGoal[subField as keyof TimeGoal] as string) = e.target.value; } else if (field === 'numbersGoal' && subField in updatedGoals[selectedGoalIndex].numbersGoal) { (updatedGoals[selectedGoalIndex].numbersGoal[subField as keyof NumbersGoal] as number) = Number(e.target.value); } } else { (updatedGoals[selectedGoalIndex][field] as string) = e.target.value; } setGoals(updatedGoals); }; return (

Goals

setNewGoalName(e.target.value)} className="w-full px-4 py-2.5 rounded-xl bg-secondary/50 text-text-primary border border-secondary/50 outline-none hover:bg-secondary hover:border-secondary focus:border-primary focus:ring-4 focus:ring-primary/20 transition-all duration-200" placeholder="New Goal Name" />

{goals[selectedGoalIndex].name}

Time Goal

handleInputChange(e, 'timeGoal', 'desiredReleaseDate')} className="w-full p-2 rounded-lg bg-gray-800 text-white border-none outline-none" /> handleInputChange(e, 'timeGoal', 'maxReleaseDate')} className="w-full p-2 rounded-lg bg-gray-800 text-white border-none outline-none" />

Numbers Goal

handleInputChange(e, 'numbersGoal', 'minWordsCount')} className="w-full p-2 rounded-lg bg-gray-800 text-white border-none outline-none" /> handleInputChange(e, 'numbersGoal', 'maxWordsCount')} className="w-full p-2 rounded-lg bg-gray-800 text-white border-none outline-none" /> handleInputChange(e, 'numbersGoal', 'desiredWordsCountByChapter')} className="w-full p-2 rounded-lg bg-gray-800 text-white border-none outline-none" /> handleInputChange(e, 'numbersGoal', 'desiredChapterCount')} className="w-full p-2 rounded-lg bg-gray-800 text-white border-none outline-none" />
); }