"use client"; import { ChangeEvent, FC, useState } from "react"; import { brandType } from "src/types/brandType"; interface Props { brand: brandType; changeBrandName: (id: number, name: string) => void; deleteBrand: (id: number) => void; } const Brand: FC = ({ brand, changeBrandName, deleteBrand, }) => { // State for handling editing mode const [editing, setEditing] = useState(false); // State for handling text input const [name, setName] = useState(brand.name); // Event handler for text input change const handleNameChange = (e: ChangeEvent) => { setName(e.target.value); }; // Event handler for initiating the edit mode const handleEdit = () => { setEditing(true); }; // Event handler for saving the edited text const handleSave = async () => { changeBrandName(brand.id, name); setEditing(false); }; // Event handler for canceling the edit mode const handleCancel = () => { setEditing(false); setName(brand.name); }; // Event handler for deleting a todo item const handleDelete = () => { if (confirm("Are you sure you want to delete this brand?")) { deleteBrand(brand.id); } }; // Rendering the Brands component return (
{/* Checkbox for marking the todo as done */} {/* Input field for brand text */} {/* Action buttons for editing, saving, canceling, and deleting */}
{editing ? ( ) : ( )} {editing ? ( ) : ( )}
); }; export default Brand;