Skip to content

Commit 1fe35ea

Browse files
committed
Alerts edit
1 parent 35eb5b6 commit 1fe35ea

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

app/src/components/marketplace/MarketplaceCard.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { RootState } from '../../redux/store';
2323
import { saveProject } from '../../helperFunctions/projectGetSaveDel';
2424
import { useHistory } from 'react-router-dom';
2525
import { openProject } from '../../redux/reducers/slice/appStateSlice';
26+
import MuiAlert, { AlertProps } from '@mui/material/Alert';
27+
import Snackbar from '@mui/material/Snackbar';
2628

2729
interface Project {
2830
forked: String,
@@ -43,6 +45,7 @@ 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);
@@ -51,7 +54,7 @@ const MarketplaceCard = ({proj} :{proj: 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
5356
const project = response.data.project;
54-
alert('Project cloned!');
57+
setAlertOpen(true);
5558
setAnchorEl(null);
5659
return project;
5760
};
@@ -61,11 +64,31 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
6164
history.push('/');
6265
dispatch(openProject(project));
6366
};
67+
6468
const handleClose = () => {
6569
setAnchorEl(null);
6670
};
6771

6872

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+
6992
return (
7093
<>
7194
<Card
@@ -132,6 +155,19 @@ const MarketplaceCard = ({proj} :{proj: Project}) => {
132155
Clone and open
133156
</MenuItem>
134157
</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>
135171
</Card>
136172
</>
137173
);

0 commit comments

Comments
 (0)