"use client"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { zodResolver } from "@hookform/resolvers/zod"; import { CopyIcon } from "@radix-ui/react-icons"; import { useFormState } from "react-dom"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { querydb } from "./db"; import { formSchema } from "./schema"; const initialState = { url: null, } export default function CreateCard() { // @ts-ignore let [state, formAction] = useFormState(querydb, initialState); const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { url: "", }, }); const handleCopyUrl = () => { if (state && state.url) { const currentSiteName = window.location.hostname; let url = undefined; if (currentSiteName === "localhost" || currentSiteName === "0.0.0.0") { const currentPort = window.location.port; url = `http://${currentSiteName}:${currentPort}/${state.url.toString()}`; } else { url = `https://${currentSiteName}/${state.url.toString()}`; } navigator.clipboard.writeText(url) .catch(err => { console.error('Failed to copy URL to clipboard:', err); }); } }; return ( // Create a Shortened URL
{/* @ts-ignore */} ( Enter a url )} />
{state && state.url && (

Url added to clipboard

)}
//
); }