"use client"; import { useState } from "react"; import Template from "./Template"; import { Button } from "@/components/ui/button"; import { toast } from "sonner"; import { useModal } from "@/app/_providers/modal/provider"; import { randomId } from "@/lib/nostr"; import { unixTimeNowInSeconds } from "@/lib/nostr/dates"; // import { useKeys } from "@/app/_providers/keysProvider"; import useCurrentUser from "@/lib/hooks/useCurrentUser"; import { createEvent } from "@/lib/actions/create"; import { useNDK } from "@/app/_providers/ndk"; import useAuthGuard from "./hooks/useAuthGuard"; type RSVPModalProps = { eventReference: string; }; const statusMap = { accept: "accepted", maybe: "tentative", decline: "declined", }; export default function RSVPModal({ eventReference }: RSVPModalProps) { useAuthGuard(); const modal = useModal(); const { ndk } = useNDK(); const { currentUser } = useCurrentUser(); const [loading, setLoading] = useState({ accept: false, maybe: false, decline: false, }); async function handleRSVP(type: "accept" | "maybe" | "decline") { if (!ndk || !currentUser) return; setLoading((prev) => ({ ...prev, [type]: true })); try { const random = randomId(); const tags: string[][] = [ ["d", random], ["a", eventReference], ["status", statusMap[type]], ]; const event = await createEvent(ndk, { content: "", kind: 31925, tags, }); if (event) { toast.success("Event Created!"); modal?.hide(); } else { toast.error("An error occured"); } } catch (err) { console.log("Err", err); } finally { setLoading({ accept: false, maybe: false, decline: false }); } } return ( ); }