diff --git a/components/url-card.tsx b/components/url-card.tsx index fcd6034..ec43fb5 100644 --- a/components/url-card.tsx +++ b/components/url-card.tsx @@ -37,18 +37,21 @@ function UrlCard({ url }: UrlCardProps) { return (
  • -
    +
    {host}/{url.id} -

    {url.url}

    + +

    + {url.url} +

    diff --git a/components/url-input.tsx b/components/url-input.tsx index a86f594..86ceb2f 100644 --- a/components/url-input.tsx +++ b/components/url-input.tsx @@ -10,11 +10,22 @@ import { useUrlStore } from "@/store/url" function UrlInput() { const [url, setUrl] = useState("") const [loading, setLoading] = useState(false) + const [error, setError] = useState("") + const { addUrl } = useUrlStore() const handleSubmit = async () => { + setError("") if (!url) return + // validate url + const urlRegex = /^(ftp|http|https):\/\/[^ "]+$/ + + if (!urlRegex.test(url)) { + setError("Enter a valid url") + return + } + setLoading(true) const res = await fetch("/api/url", { @@ -58,11 +69,12 @@ function UrlInput() { className="relative mx-auto my-12 md:w-1/2" > setUrl(e.target.value)} onKeyUp={(e) => e.key === "Enter" && handleSubmit()} disabled={loading} + className="pr-12" /> + + {error &&

    {error}

    } ) }