Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 12x 12x 5x 12x 12x 12x 1x 6x 18x 14x 1x | import { styled } from "@mui/material";
import Alert from "components/Alert";
import Button from "components/Button";
import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner";
import { CalendarIcon } from "components/Icons";
import StyledLink from "components/StyledLink";
import TextBody from "components/TextBody";
import { Trans, useTranslation } from "i18n";
import { COMMUNITIES } from "i18n/namespaces";
import { useRouter } from "next/router";
import { Community } from "proto/communities_pb";
import { routeToNewEvent } from "routes";
import { theme } from "theme";
import hasAtLeastOnePage from "utils/hasAtLeastOnePage";
import { SectionTitle } from "../CommunityPage";
import { useListCommunityEvents } from "../hooks";
import LongEventCard from "./LongEventCard";
interface CommunityEventsListProps {
community: Community.AsObject;
}
const StyledEventsListContainer = styled("div")(() => ({
display: "grid",
rowGap: theme.spacing(3),
[theme.breakpoints.down("sm")]: {
rowGap: theme.spacing(1.5),
},
}));
const StyledCreateResourceButton = styled(Button)(() => ({
margin: theme.spacing(2, 0),
}));
export default function CommunityEventsList({
community,
}: CommunityEventsListProps) {
const { t } = useTranslation([COMMUNITIES]);
const router = useRouter();
const { data, error, hasNextPage, fetchNextPage, isLoading } =
useListCommunityEvents({
communityId: community.communityId,
pageSize: 5,
type: "all",
});
return (
<>
<SectionTitle icon={<CalendarIcon />}>
{t("communities:events_title")}
</SectionTitle>
<StyledCreateResourceButton
onClick={() => router.push(routeToNewEvent(community.communityId))}
>
{t("communities:create_an_event")}
</StyledCreateResourceButton>
{error && <Alert severity="error">{error.message}</Alert>}
<StyledEventsListContainer>
{isLoading ? (
<CenteredSpinner />
) : hasAtLeastOnePage(data, "eventsList") ? (
data.pages
.flatMap((page) => page.eventsList)
.filter((event) => !event.isCancelled)
.map((event) => <LongEventCard event={event} key={event.eventId} />)
) : (
!error && (
<TextBody>
<Trans
t={t}
i18nKey="communities:events_empty_state"
components={[
<StyledLink key="create-link" href={routeToNewEvent()} />,
]}
/>
</TextBody>
)
)}
</StyledEventsListContainer>
{hasNextPage && (
<Button
onClick={() => fetchNextPage()}
sx={{
color: theme.palette.common.black,
borderColor: theme.palette.grey[300],
"&:hover": {
borderColor: theme.palette.grey[300],
backgroundColor: "#3135390A",
},
}}
>
{t("communities:see_more_events_label")}
</Button>
)}
</>
);
}
|