diff --git a/src/hooks/useSearch.ts b/src/hooks/useSearch.ts index aa5a155..2215a33 100644 --- a/src/hooks/useSearch.ts +++ b/src/hooks/useSearch.ts @@ -2,6 +2,7 @@ import { LocalStorageCache } from "@/utils/local-storage"; import { Translations } from "@/utils/schemas/types"; import { translateWord } from "@/utils/translate-word"; import { useState, useEffect } from "react"; +import { useToast } from "@chakra-ui/react"; export function useSearchWord() { const [isLoading, setIsLoading] = useState(false); @@ -11,6 +12,7 @@ export function useSearchWord() { const [word, setWord] = useState(""); const [search, setSearch] = useState(""); const [isFr, setIsFR] = useState(true); + const toast = useToast(); useEffect(() => { async function wordSearch() { @@ -35,10 +37,23 @@ export function useSearchWord() { setIsError(true); setIsTranslations(false); setIsLoading(false); - window.alert(` - Une erreur est survenue: ${error.message} - Veuillez réessayer.`); setWord(""); + if (error.statusCode === 404) { + toast({ + title: "Mot introuvable", + status: "error", + duration: 3000, + isClosable: true, + }); + return; + } + toast({ + title: "Erreur inconnue", + status: "error", + duration: 3000, + isClosable: true, + }); + return; } if (trads) { @@ -56,9 +71,12 @@ export function useSearchWord() { setIsError(true); setIsTranslations(false); setIsLoading(false); - window.alert(` - Une erreur inconnue est survenue. - Veuillez réessayer.`); + toast({ + title: "Erreur inconnue, veuillez réessayer.", + status: "error", + duration: 3000, + isClosable: true, + }); setWord(""); } }