"use client" import { cn } from "@lib/utils" import { dmSans125ClassName } from "@/lib/fonts" import { AppleShortcutsIcon } from "@/components/integration-icons" import { authClient } from "@lib/auth" import { useAuth } from "@lib/auth-context" import { generateId } from "@lib/generate-id" import { ADD_MEMORY_SHORTCUT_URL, SEARCH_MEMORY_SHORTCUT_URL, } from "@lib/constants" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogPortal, } from "@ui/components/dialog" import { useMutation } from "@tanstack/react-query" import { Check, Copy, Loader, Plus, Search } from "lucide-react" import Image from "next/image" import { useId, useState } from "react" import { toast } from "sonner" function PillButton({ children, onClick, disabled, }: { children: React.ReactNode onClick?: () => void disabled?: boolean }) { return ( ) } export function ShortcutsDetail() { const { org } = useAuth() const [showApiKeyModal, setShowApiKeyModal] = useState(false) const [apiKey, setApiKey] = useState("") const [copied, setCopied] = useState(false) const [selectedShortcutType, setSelectedShortcutType] = useState< "add" | "search" | null >(null) const apiKeyId = useId() const handleCopyApiKey = async (key: string) => { try { await navigator.clipboard.writeText(key) setCopied(true) setTimeout(() => setCopied(false), 2000) toast.success("API key copied to clipboard!") } catch { toast.error("Failed to copy API key") } } const createApiKeyMutation = useMutation({ mutationFn: async () => { const res = await authClient.apiKey.create({ metadata: { organizationId: org?.id, type: "ios-shortcut" }, name: `ios-${generateId().slice(0, 8)}`, prefix: `sm_${org?.id}_`, }) return res.key }, onSuccess: (key) => { setApiKey(key) setShowApiKeyModal(true) setCopied(false) handleCopyApiKey(key) }, onError: (error) => { toast.error("Failed to create API key", { description: error instanceof Error ? error.message : "Unknown error", }) }, }) const handleShortcutClick = (type: "add" | "search") => { setSelectedShortcutType(type) createApiKeyMutation.mutate() } const handleOpenShortcut = () => { if (selectedShortcutType === "add") { window.open(ADD_MEMORY_SHORTCUT_URL, "_blank") } else if (selectedShortcutType === "search") { window.open(SEARCH_MEMORY_SHORTCUT_URL, "_blank") } } return ( <>

Apple Shortcuts

Add memories directly from iPhone, iPad or Mac

handleShortcutClick("add")} disabled={createApiKeyMutation.isPending} > {createApiKeyMutation.isPending && selectedShortcutType === "add" ? ( ) : ( )} {createApiKeyMutation.isPending && selectedShortcutType === "add" ? "Creating..." : "Add memory shortcut"} handleShortcutClick("search")} disabled={createApiKeyMutation.isPending} > {createApiKeyMutation.isPending && selectedShortcutType === "search" ? ( ) : ( )} {createApiKeyMutation.isPending && selectedShortcutType === "search" ? "Creating..." : "Search memory shortcut"}
{ setShowApiKeyModal(open) if (!open) { setSelectedShortcutType(null) setApiKey("") setCopied(false) } }} > Setup Apple Shortcut

Follow these steps:

{[ 'Click "Add to Shortcuts" below to open the shortcut', "Paste your API key when prompted", "Start using your shortcut!", ].map((text, i) => (
{i + 1}

{text}

))}
) }