Skip to content

Commit db5fd69

Browse files
committed
feat | frontend : change notifications from sweetalert2 to toastr
1 parent c1a9775 commit db5fd69

File tree

3 files changed

+22
-43
lines changed

3 files changed

+22
-43
lines changed

web/csr/UrlShorter/package-lock.json

Lines changed: 14 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/csr/UrlShorter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"font-awesome": "^4.7.0",
2121
"react": "^18.3.1",
2222
"react-dom": "^18.3.1",
23-
"sweetalert2": "^11.6.13"
23+
"toastr": "^2.1.4"
2424
},
2525
"devDependencies": {
2626
"@types/react": "^18.3.3",

web/csr/UrlShorter/src/components/Hero.jsx

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useRef, useState } from 'react';
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
33
import { faCopy } from '@fortawesome/free-solid-svg-icons';
4-
import Swal from 'sweetalert2/dist/sweetalert2.js';
5-
import 'sweetalert2/src/sweetalert2.scss';
4+
import 'toastr/build/toastr.min.css';
5+
import toastr from 'toastr';
66
import axios from 'axios';
77

88
const Hero = () => {
@@ -21,27 +21,14 @@ const Hero = () => {
2121
if (response.data) {
2222
const newShortUrl = response.data["short-link"];
2323
setShortUrl(newShortUrl);
24-
Swal.fire({
25-
position: 'top-end',
26-
icon: 'success',
27-
title: 'URL shortened successfully!',
28-
showConfirmButton: false,
29-
timer: 1500,
30-
});
24+
toastr.success("URL shortened successfully!");
3125
}
3226
} catch (error) {
3327
let errorMessage = 'Failed to shorten URL!';
3428
if (error.response && error.response.data) {
3529
errorMessage = error.response.data.message || errorMessage;
3630
}
37-
38-
Swal.fire({
39-
position: 'top-end',
40-
icon: 'error',
41-
title: errorMessage,
42-
showConfirmButton: false,
43-
timer: 1500,
44-
});
31+
toastr.error(errorMessage);
4532
}
4633
};
4734

@@ -52,21 +39,9 @@ const Hero = () => {
5239

5340
try {
5441
document.execCommand('copy');
55-
Swal.fire({
56-
position: 'top-end',
57-
icon: 'success',
58-
title: 'URL copied to clipboard!',
59-
showConfirmButton: false,
60-
timer: 1500,
61-
});
42+
toastr.success("URL copied to clipboard!");
6243
} catch (err) {
63-
Swal.fire({
64-
position: 'top-end',
65-
icon: 'error',
66-
title: 'Failed to copy URL!',
67-
showConfirmButton: false,
68-
timer: 1500,
69-
});
44+
toastr.error("Failed to copy URL!");
7045
}
7146
}
7247
};
@@ -85,7 +60,7 @@ const Hero = () => {
8560
<button type="button" onClick={GetShort} className="flex-none rounded-md bg-primary px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm bc-primary hover:bg-cyan-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-500">Shorten</button>
8661
</div>
8762
<div className="relative w-full max-w-sm mt-3">
88-
<input ref={inputRef} readOnly id="ShortedUrl" type="text" value={shortUrl} className="w-full pr-12 rounded-md border-0 bg-white/5 px-3.5 py-2 text-white shadow-sm ring-1 ring-inset ring-white/10 focus:ring-2 focus:ring-inset focus:ring-indigo-500 sm:text-sm sm:leading-6" placeholder="shortened link placed here" />
63+
<input disabled ref={inputRef} readOnly id="ShortedUrl" type="text" value={shortUrl} className="w-full pr-12 rounded-md border-0 bg-white/5 px-3.5 py-2 text-white shadow-sm ring-1 ring-inset ring-white/10 focus:ring-2 focus:ring-inset focus:ring-indigo-500 sm:text-sm sm:leading-6" placeholder="shortened link placed here" />
8964
<button onClick={copyToClipboard} className="absolute inset-y-0 right-0 px-3 flex items-center text-white hover:text-indigo-500">
9065
<FontAwesomeIcon className="tc-primary text-xl" icon={faCopy} />
9166
</button>

0 commit comments

Comments
 (0)