diff --git a/frontend/package-lock.json b/frontend/package-lock.json index f57d09a..1abe64b 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,11 +1,11 @@ { - "name": "frontend", + "name": "shortenit", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "frontend", + "name": "shortenit", "version": "0.1.0", "dependencies": { "@testing-library/jest-dom": "^5.17.0", diff --git a/frontend/src/components/URLShortener/URLShortener.tsx b/frontend/src/components/URLShortener/URLShortener.tsx index 1712cff..1281741 100644 --- a/frontend/src/components/URLShortener/URLShortener.tsx +++ b/frontend/src/components/URLShortener/URLShortener.tsx @@ -35,23 +35,66 @@ export default function URLShortener() { const api_url = `${config.url}${api_endpoint}`; // Send the POST request to the backend - await axios - .post(api_url , { - url: url - }) - .then((response) => { - if (response) { - const shortUrl: string = response.data.url; - setShortenedUrl(shortUrl); - setShowInput(true); - } + const response = await axios.post(api_url , {url: url}) + if (response.data.url) { + const shortUrl: string = response.data.url; + setShortenedUrl(shortUrl); + setShowInput(true); + toast.success("URL Shortened Successfully", { + position: "top-right", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "dark", + className: "custom-toast", }); + } else { + toast.error("Something went wrong while shortening the URL", { + position: "top-right", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "dark", + className: "custom-toast", + }); + } setTimeout(() => { setShowInput(false); }, 900000); - } catch (error) { - console.log(error); + } catch (error : any) { + if (error.response) { + const errorMessage : string = error.response.data.msg || "An error occurred. Please try again."; + toast.error(errorMessage, { + position: "top-right", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "dark", + className: "custom-toast", + }); + } else { + toast.error("Network error. Please check your connection and try again.", { + position: "top-right", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "dark", + className: "custom-toast", + }); + } } } @@ -76,39 +119,42 @@ export default function URLShortener() { } } return ( -
+ Shortenit is a free and open-source URL shortening service designed + for simplicity and efficiency. +
- Shortenit is a free and open-source URL shortening service designed - for simplicity and efficiency. -