@@ -22,7 +22,9 @@ import { useDispatch, useSelector } from 'react-redux'
2222import { RootState } from '../../redux/store' ;
2323import { saveProject } from '../../helperFunctions/projectGetSaveDel' ;
2424import { 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' ;
2628
2729interface Project {
2830 forked : String ,
@@ -43,16 +45,16 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
4345 const history = useHistory ( ) ;
4446 const [ anchorEl , setAnchorEl ] = React . useState < null | HTMLElement > ( null ) ;
4547 const open = Boolean ( anchorEl ) ;
48+ const [ alertOpen , setAlertOpen ] = React . useState < boolean > ( false )
4649 const state = useSelector ( ( store :RootState ) => store . appState ) ;
4750 const handleClick = ( event : React . MouseEvent < HTMLElement > ) => {
4851 setAnchorEl ( event . currentTarget ) ;
4952 } ;
5053 const handleClone = async ( ) => { // creates a copy of the project
5154 const docId = proj . _id ;
5255 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 ) ;
5658 setAnchorEl ( null ) ;
5759 return { _id : project . _id , name : project . name , published : project . published , ...project . project } ;
5860 } ;
@@ -62,11 +64,29 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
6264 history . push ( '/' ) ;
6365 dispatch ( openProject ( project ) ) ;
6466 } ;
67+
6568 const handleClose = ( ) => {
6669 setAnchorEl ( null ) ;
6770 } ;
6871
6972
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+ } ) ;
7090
7191
7292 return (
@@ -135,6 +155,19 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
135155 Clone and open
136156 </ MenuItem >
137157 </ 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 >
138171 </ Card >
139172 </ >
140173 ) ;
0 commit comments