@@ -23,6 +23,8 @@ import { RootState } from '../../redux/store';
23
23
import { saveProject } from '../../helperFunctions/projectGetSaveDel' ;
24
24
import { useHistory } from 'react-router-dom' ;
25
25
import { openProject } from '../../redux/reducers/slice/appStateSlice' ;
26
+ import MuiAlert , { AlertProps } from '@mui/material/Alert' ;
27
+ import Snackbar from '@mui/material/Snackbar' ;
26
28
27
29
interface Project {
28
30
forked : String ,
@@ -43,6 +45,7 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
43
45
const history = useHistory ( ) ;
44
46
const [ anchorEl , setAnchorEl ] = React . useState < null | HTMLElement > ( null ) ;
45
47
const open = Boolean ( anchorEl ) ;
48
+ const [ alertOpen , setAlertOpen ] = React . useState < boolean > ( false )
46
49
const state = useSelector ( ( store :RootState ) => store . appState ) ;
47
50
const handleClick = ( event : React . MouseEvent < HTMLElement > ) => {
48
51
setAnchorEl ( event . currentTarget ) ;
@@ -51,7 +54,7 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
51
54
const docId = proj . _id ;
52
55
const response = await axios . get ( `/cloneProject/${ docId } ` , { params : { username : window . localStorage . getItem ( 'username' ) } } ) ; //passing in username as a query param is query params
53
56
const project = response . data . project ;
54
- alert ( 'Project cloned!' ) ;
57
+ setAlertOpen ( true ) ;
55
58
setAnchorEl ( null ) ;
56
59
return project ;
57
60
} ;
@@ -61,11 +64,31 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
61
64
history . push ( '/' ) ;
62
65
dispatch ( openProject ( project ) ) ;
63
66
} ;
67
+
64
68
const handleClose = ( ) => {
65
69
setAnchorEl ( null ) ;
66
70
} ;
67
71
68
72
73
+ const handleAlertClose = (
74
+ event : React . SyntheticEvent | Event ,
75
+ reason ?: string
76
+ ) => {
77
+ if ( reason === 'clickaway' ) {
78
+ return ;
79
+ }
80
+ setAlertOpen ( false ) ;
81
+ setAnchorEl ( null )
82
+ }
83
+
84
+ const Alert = React . forwardRef < HTMLDivElement , AlertProps > ( function Alert (
85
+ props ,
86
+ ref
87
+ ) {
88
+ return < MuiAlert elevation = { 6 } ref = { ref } variant = "filled" { ...props } /> ;
89
+ } ) ;
90
+
91
+
69
92
return (
70
93
< >
71
94
< Card
@@ -132,6 +155,19 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
132
155
Clone and open
133
156
</ MenuItem >
134
157
</ Menu >
158
+ < Snackbar
159
+ open = { alertOpen }
160
+ autoHideDuration = { 3000 }
161
+ onClose = { handleAlertClose }
162
+ >
163
+ < Alert
164
+ onClose = { handleAlertClose }
165
+ severity = "success"
166
+ sx = { { width : '100%' , color : 'white' } }
167
+ >
168
+ Project Cloned!
169
+ </ Alert >
170
+ </ Snackbar >
135
171
</ Card >
136
172
</ >
137
173
) ;
0 commit comments