"use client"; import { FC, useState } from "react"; import { brandType } from "../../types/brandType"; import Brand from "./brand"; import AddBrand from "./addBrand"; import { addBrand, deleteBrand, editBrand } from "../../actions/brandActions"; interface Props { brands: brandType[]; } const Brands: FC = ({ brands }) => { // State to manage the list of brand items const [brandItems, setBrandItems] = useState(brands); // Function to create a new brand item const createBrand = (name: string) => { const id = (brandItems.at(-1)?.id || 0) + 1; addBrand(name); setBrandItems((prev) => [...prev, { id: id, name: name }]); }; // Function to change the text of a brand item const changeBrandName = (id: number, name: string) => { setBrandItems((prev) => prev.map((brand) => (brand.id === id ? { ...brand, name } : brand)) ); editBrand(id, name); }; // Function to delete a brand item const deleteTodoItem = (id: number) => { setBrandItems((prev) => prev.filter((brand) => brand.id !== id)); deleteBrand(id); }; // Rendering the brand List component return (
Ballistic Builder Brand
{/* Mapping through brand items and rendering brand component for each */} {brandItems.map((brand) => ( ))}
{/* Adding brand component for creating new brand */}
); }; export default Brands;