diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/AddCookieRow.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/AddCookieRow.tsx new file mode 100644 index 000000000..2f7a0f71b --- /dev/null +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/AddCookieRow.tsx @@ -0,0 +1,80 @@ +// Copyright (c) 2026 Probo Inc . +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +import { useTranslate } from "@probo/i18n"; +import { Button, Input, Td, Tr } from "@probo/ui"; +import { useState } from "react"; + +import type { CookieEntry } from "./CategorySection"; + +interface AddCookieRowProps { + isUpdating: boolean; + onSave: (cookie: CookieEntry) => void; + onCancel: () => void; +} + +export function AddCookieRow({ + isUpdating, + onSave, + onCancel, +}: AddCookieRowProps) { + const { __ } = useTranslate(); + const [form, setForm] = useState({ + name: "", + duration: "", + description: "", + }); + + return ( + + + setForm({ ...form, name: e.target.value })} + placeholder={__("Cookie name")} + /> + + + setForm({ ...form, duration: e.target.value })} + placeholder={__("e.g. 1 year")} + /> + + + setForm({ ...form, description: e.target.value })} + placeholder={__("Description")} + /> + + +
+ + +
+ + + ); +} diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx index 83d3a74dc..01371ec40 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx @@ -24,10 +24,8 @@ import { IconPencil, IconPlusSmall, IconTrashCan, - Input, Tbody, Td, - Textarea, Th, Thead, Tr, @@ -41,6 +39,16 @@ import type { CategorySectionFragment$key } from "#/__generated__/core/CategoryS import type { CategorySectionMoveCookieMutation } from "#/__generated__/core/CategorySectionMoveCookieMutation.graphql"; import type { CategorySectionUpdateMutation } from "#/__generated__/core/CategorySectionUpdateMutation.graphql"; +import { AddCookieRow } from "./AddCookieRow"; +import { EditCategoryForm } from "./EditCategoryForm"; +import { EditCookieRow } from "./EditCookieRow"; + +export interface CookieEntry { + name: string; + duration: string; + description: string; +} + export const categorySectionFragment = graphql` fragment CategorySectionFragment on CookieCategory { id @@ -134,12 +142,6 @@ const moveCookieMutation = graphql` } `; -interface CookieEntry { - name: string; - duration: string; - description: string; -} - interface CategorySectionProps { categoryKey: CategorySectionFragment$key; onDelete?: () => void; @@ -156,18 +158,8 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps) = useMutation(moveCookieMutation); const [isEditingCategory, setIsEditingCategory] = useState(false); - const [editName, setEditName] = useState(category.name); - const [editDescription, setEditDescription] = useState(category.description); - - const [editingCookieIndex, setEditingCookieIndex] = useState( - null, - ); + const [editingCookieIndex, setEditingCookieIndex] = useState(null); const [isAddingCookie, setIsAddingCookie] = useState(false); - const [cookieForm, setCookieForm] = useState({ - name: "", - duration: "", - description: "", - }); const doUpdate = ( input: Record, @@ -209,48 +201,24 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps) }); }; - const handleSaveCategory = () => { - doUpdate({ name: editName, description: editDescription }, () => { + const handleSaveCategory = (name: string, description: string) => { + doUpdate({ name, description }, () => { setIsEditingCategory(false); }); }; - const handleCancelCategoryEdit = () => { - setEditName(category.name); - setEditDescription(category.description); - setIsEditingCategory(false); - }; - - const handleStartEditCookie = (index: number) => { - const c = category.cookies[index]; - setCookieForm({ - name: c.name, - duration: c.duration, - description: c.description, - }); - setEditingCookieIndex(index); - setIsAddingCookie(false); - }; - - const handleSaveEditCookie = () => { - if (editingCookieIndex === null) return; - if (!cookieForm.name.trim()) return; + const handleSaveEditCookie = (index: number, cookie: CookieEntry) => { + if (!cookie.name.trim()) return; const newCookies = category.cookies.map((c, i) => - i === editingCookieIndex - ? { ...cookieForm } + i === index + ? { ...cookie } : { name: c.name, duration: c.duration, description: c.description }, ); doUpdate({ cookies: newCookies }, () => { setEditingCookieIndex(null); - setCookieForm({ name: "", duration: "", description: "" }); }); }; - const handleCancelEditCookie = () => { - setEditingCookieIndex(null); - setCookieForm({ name: "", duration: "", description: "" }); - }; - const handleDeleteCookie = (index: number) => { const newCookies = category.cookies .filter((_, i) => i !== index) @@ -262,33 +230,21 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps) doUpdate({ cookies: newCookies }); }; - const handleStartAddCookie = () => { - setCookieForm({ name: "", duration: "", description: "" }); - setIsAddingCookie(true); - setEditingCookieIndex(null); - }; - - const handleSaveNewCookie = () => { - if (!cookieForm.name.trim()) return; + const handleSaveNewCookie = (cookie: CookieEntry) => { + if (!cookie.name.trim()) return; const newCookies = [ ...category.cookies.map(c => ({ name: c.name, duration: c.duration, description: c.description, })), - { ...cookieForm }, + { ...cookie }, ]; doUpdate({ cookies: newCookies }, () => { setIsAddingCookie(false); - setCookieForm({ name: "", duration: "", description: "" }); }); }; - const handleCancelAddCookie = () => { - setIsAddingCookie(false); - setCookieForm({ name: "", duration: "", description: "" }); - }; - const allCategories = category.cookieBanner.categories.edges.map(e => e.node) ?? []; const siblingCategories = allCategories.filter(c => c.id !== category.id); @@ -336,33 +292,13 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps)
{isEditingCategory ? ( -
- setEditName(e.target.value)} - placeholder={__("Category name")} - /> -