/* eslint-disable jsx-a11y/aria-role */ import React, { useState } from "react"; function App() { // Default agenda data for testing const [agenda, setAgenda] = useState([ { title: "Angular", description: "Some description about the angular", topics: ["Introduction", "Typescript", "Why Angular?", "Understanding Versions", "Fundamentals"], }, { title: "Vue", description: "Some description about the vue", topics: ["Introduction", "Javascript", "Why Vue?", "Vue Bindings", "Component Interaction"], }, ]); const [newTitle, setNewTitle] = useState(""); const [newDescription, setNewDescription] = useState(""); const [newTopic, setNewTopic] = useState(""); const [topics, setTopics] = useState([]); const [showAddAgenda, setShowAddAgenda] = useState(true); const [errors, setErrors] = useState({ title: "", description: "", topic: "", }); // Form validation const validateTitle = (title) => (title.trim() === "" ? "Title is required" : ""); const validateDescription = (description) => (description.trim() === "" ? "Description is required" : ""); const validateTopic = (topic) => (topic.trim() === "" ? "Topic is required" : ""); const handleTitleChange = (e) => { setNewTitle(e.target.value); setErrors({ ...errors, title: validateTitle(e.target.value) }); }; const handleDescriptionChange = (e) => { setNewDescription(e.target.value); setErrors({ ...errors, description: validateDescription(e.target.value) }); }; const handleTopicChange = (e) => { setNewTopic(e.target.value); setErrors({ ...errors, topic: validateTopic(e.target.value) }); }; const addTopic = () => { if (validateTopic(newTopic) === "") { setTopics([...topics, newTopic.trim()]); setNewTopic(""); } }; const submitAgenda = () => { if ( validateTitle(newTitle) === "" && validateDescription(newDescription) === "" && topics.length > 0 ) { setAgenda([...agenda, { title: newTitle.trim(), description: newDescription.trim(), topics }]); setNewTitle(""); setNewDescription(""); setTopics([]); } }; return (

Agenda Manager

{/* Add Agenda Template */} {showAddAgenda && (
{errors.title}
{errors.description}
{errors.topic}
{topics.length === 0 && (
No Topics Added
)} {topics.length > 0 && (
Added Topics
    {topics.map((topic, index) => (
  • {topic}
  • ))}
Refer the topics you added
)}
)} {/* View Agenda Template */} {!showAddAgenda && (
{agenda.map((item, index) => (
{item.title}
    {item.topics.map((topic, idx) => (
  • {topic}
  • ))}
{item.description}
))}
)}
); } export default App;