1
1
import React , { useRef , useState } from 'react' ;
2
2
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
3
3
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 ';
6
6
import axios from 'axios' ;
7
7
8
8
const Hero = ( ) => {
@@ -21,27 +21,14 @@ const Hero = () => {
21
21
if ( response . data ) {
22
22
const newShortUrl = response . data [ "short-link" ] ;
23
23
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!" ) ;
31
25
}
32
26
} catch ( error ) {
33
27
let errorMessage = 'Failed to shorten URL!' ;
34
28
if ( error . response && error . response . data ) {
35
29
errorMessage = error . response . data . message || errorMessage ;
36
30
}
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 ) ;
45
32
}
46
33
} ;
47
34
@@ -52,21 +39,9 @@ const Hero = () => {
52
39
53
40
try {
54
41
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!" ) ;
62
43
} 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!" ) ;
70
45
}
71
46
}
72
47
} ;
@@ -85,7 +60,7 @@ const Hero = () => {
85
60
< 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 >
86
61
</ div >
87
62
< 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" />
89
64
< button onClick = { copyToClipboard } className = "absolute inset-y-0 right-0 px-3 flex items-center text-white hover:text-indigo-500" >
90
65
< FontAwesomeIcon className = "tc-primary text-xl" icon = { faCopy } />
91
66
</ button >
0 commit comments