import { ChevronLeftIcon, ChevronRightIcon } from "@heroicons/react/solid"; import { useState } from "react"; import { Dispatch, SetStateAction } from "react"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Alert } from "@calcom/ui/Alert"; import Button from "@calcom/ui/Button"; import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/Dialog"; import { TextField } from "@calcom/ui/form/fields"; import Loader from "@calcom/web/components/Loader"; interface ISearchDialog { isOpenDialog: boolean; setIsOpenDialog: Dispatch>; onSave: (url: string) => void; } export const SearchDialog = (props: ISearchDialog) => { const { t } = useLocale(); const [gifImage, setGifImage] = useState(""); const [offset, setOffset] = useState(0); const [keyword, setKeyword] = useState(""); const { isOpenDialog, setIsOpenDialog } = props; const [isLoading, setIsLoading] = useState(false); const [errorMessage, setErrorMessage] = useState(""); const searchGiphy = async (keyword: string, offset: number) => { if (isLoading) { return; } setIsLoading(true); setErrorMessage(""); const res = await fetch("/api/integrations/giphy/search", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ keyword, offset, }), }); const json = await res.json(); if (!res.ok) { setErrorMessage(json?.message || "Something went wrong"); } else { setGifImage(json.image || ""); setOffset(offset); if (!json.image) { setErrorMessage("No Result found"); } } setIsLoading(false); return null; }; return (
{ setKeyword(event.target.value); }} name="search" type="text" className="mt-2" labelProps={{ style: { display: "none" } }} placeholder="Search Giphy" />
{gifImage && (
{isLoading ? ( ) : ( <>
{`Gif
)}
)} {errorMessage && } { props.setIsOpenDialog(false); }} asChild>
); };