@@ -22,7 +22,9 @@ import { useDispatch, useSelector } from 'react-redux'
22
22
import { RootState } from '../../redux/store' ;
23
23
import { saveProject } from '../../helperFunctions/projectGetSaveDel' ;
24
24
import { useHistory } from 'react-router-dom' ;
25
- import { openProject , resetAllState } from '../../redux/reducers/slice/appStateSlice' ;
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,16 +45,16 @@ 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 ) ;
49
52
} ;
50
53
const handleClone = async ( ) => { // creates a copy of the 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
- const project = response . data ;
54
- console . log ( 'handleClone project' , response . data )
55
- alert ( 'Project cloned!' ) ;
56
+ const project = response . data . project ;
57
+ setAlertOpen ( true ) ;
56
58
setAnchorEl ( null ) ;
57
59
return { _id : project . _id , name : project . name , published : project . published , ...project . project } ;
58
60
} ;
@@ -62,11 +64,29 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
62
64
history . push ( '/' ) ;
63
65
dispatch ( openProject ( project ) ) ;
64
66
} ;
67
+
65
68
const handleClose = ( ) => {
66
69
setAnchorEl ( null ) ;
67
70
} ;
68
71
69
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
+ } ) ;
70
90
71
91
72
92
return (
@@ -135,6 +155,19 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
135
155
Clone and open
136
156
</ MenuItem >
137
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 >
138
171
</ Card >
139
172
</ >
140
173
) ;
0 commit comments