From 99bf72c1af3ba08eca3fe7c75e6675a6262f3062 Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Sun, 29 Mar 2026 11:34:08 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=94=20feat:=20add=20save=20button=20en?= =?UTF-8?q?dpoint=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/Hero/addHeroBannerMediaToSaved.ts | 18 ++++++++++++++++++ .../sections/Hero/components/AddToList.tsx | 8 ++++++++ .../home/sections/Hero/components/Swiper.tsx | 2 -- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 features/home/actions/Hero/addHeroBannerMediaToSaved.ts diff --git a/features/home/actions/Hero/addHeroBannerMediaToSaved.ts b/features/home/actions/Hero/addHeroBannerMediaToSaved.ts new file mode 100644 index 0000000..8a1c3a1 --- /dev/null +++ b/features/home/actions/Hero/addHeroBannerMediaToSaved.ts @@ -0,0 +1,18 @@ +"use server"; + +import { backendFetch } from "@/shared/helpers/backendFetch"; + +export const addHeroBannerMediaToSaved = async (mediaId: string) => { + try { + return await backendFetch("collections/sys", { + method: "POST", + body: JSON.stringify({ + name: "Saved", + itemId: mediaId, + }), + }); + } catch (error) { + console.error("Error adding media to saved list:", error); + return { success: false, message: "Failed to add media to saved list." }; + } +}; diff --git a/features/home/sections/Hero/components/AddToList.tsx b/features/home/sections/Hero/components/AddToList.tsx index 2ae4380..c9606ec 100644 --- a/features/home/sections/Hero/components/AddToList.tsx +++ b/features/home/sections/Hero/components/AddToList.tsx @@ -1,3 +1,5 @@ +"use client"; +import { addHeroBannerMediaToSaved } from "@/features/home/actions/Hero/addHeroBannerMediaToSaved"; import { useAuth } from "@/shared/contexts/AuthContext"; import { Button } from "@/shared/libs/shadcn/ui/button"; import { Icon } from "@iconify/react"; @@ -5,10 +7,16 @@ import { Icon } from "@iconify/react"; const AddToList = ({ mediaId }: { mediaId: string }) => { const { session } = useAuth(); + const handleAddToList = async () => { + const result = await addHeroBannerMediaToSaved(mediaId); + console.log("Hasil dari fungsi server:", result); + }; + return (
{session?.user && (