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 (