Skip to content

Commit

Permalink
fix: improve quality
Browse files Browse the repository at this point in the history
- fix formatting
- add tests
  • Loading branch information
cgawron committed Oct 16, 2024
1 parent 71435e0 commit 0659aac
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 53 deletions.
3 changes: 3 additions & 0 deletions client/src/components/EventCard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.inactive {
color: rgb(196, 194, 194);
}
102 changes: 53 additions & 49 deletions client/src/components/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
Snackbar,
Switch,
} from "@mui/material";
import Grid from "@mui/material/Grid2";

import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit";
import ShareIcon from "@mui/icons-material/Share";
import { EventDocument } from "../helpers/EventDocument";
import { useTranslation } from "react-i18next";

import "./EventCard.css";


type EventCardProps = {
Expand Down Expand Up @@ -58,66 +58,70 @@ export const EventCard = (props: EventCardProps) => {
};

const handleDelete = () => {
deleteEvent(props.event._id).then((res) => {
if (res.data.success === false) {
signout();
deleteEvent(props.event._id)
.then((res) => {
if (res.data.success === false) {
navigate("/landing");
}
})
.catch((res) => {
console.error("deleteEvent failed: %o", res);
navigate("/landing");
}
});
});
if (props.onDelete) {
props.onDelete(props.event);
}
};

return (
<>
<Grid size="auto">

<Card style={{ maxWidth: "25rem" }}
data-testid="event-card">
<CardHeader
action={
<IconButton
aria-label="settings"
component={RouterLink}
data-testid="edit-event-button"
to={`/editevent/${props.event._id}`}
>
<EditIcon />
</IconButton>
}
title={props.event.name}
subheader={<span>{props.event.duration} min</span>}
/>
<CardContent>{props.event.description}</CardContent>
<CardActions disableSpacing>
<Switch
data-testid="active-switch"
checked={active}
onChange={toggleActive}
size="small"
name="active"
color="primary"
inputProps={{ "aria-label": "active" }}
/>
<Button
data-testid="copy-link-button"
aria-label={t("large_suave_gull_hush")}
startIcon={<ShareIcon />}
onClick={handleCopy}
>
{t("misty_proud_mallard_assure")}
</Button>

<Card style={{ maxWidth: "25rem" }}
data-testid="event-card" className={active ? "active" : "inactive"}>
<CardHeader
action={
<IconButton
data-testid="delete-event-button"
aria-label="delete"
onClick={handleDelete}
aria-label="settings"
component={RouterLink}
data-testid="edit-event-button"
to={`/editevent/${props.event._id}`}
>
<DeleteIcon />
<EditIcon />
</IconButton>
</CardActions>
</Card>
</Grid >
}
title={props.event.name}
subheader={<span>{props.event.duration} min</span>}
/>
<CardContent>{props.event.description}</CardContent>
<CardActions>
<Switch
data-testid="active-switch"
checked={active}
onChange={toggleActive}
size="small"
name="active"
color="primary"
inputProps={{ "aria-label": "active" }}
/>
<Button
data-testid="copy-link-button"
aria-label={t("large_suave_gull_hush")}
startIcon={<ShareIcon />}
onClick={handleCopy}
>
{t("misty_proud_mallard_assure")}
</Button>
<IconButton
data-testid="delete-event-button"
aria-label="delete"
onClick={handleDelete}
>
<DeleteIcon />
</IconButton>
</CardActions>
</Card>

<Snackbar
open={success}
autoHideDuration={2000}
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/EventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ const EventList = (props: EventListProps) => {

return (
<Grid
container
data-testid="event-list"
direction="row"
size={12}
spacing={3}
justifyItems="space-around"
alignItems="stretch"
>
{list}
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/PrivateRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const PrivateRoute = ({ children }: { children: JSX.Element }) => {
console.log("user set to %o", res.data);
}
})
.catch(() => {
console.log("getUserById: error");
.catch((res) => {
console.log("getUser: error: %d", res.status);
setAuthenticated(false);
navigate("/landing");
// TODO: Add SnackBar
Expand Down

0 comments on commit 0659aac

Please sign in to comment.