Skip to content

Commit

Permalink
feat: add clear all activities
Browse files Browse the repository at this point in the history
  • Loading branch information
toniocodo committed Oct 4, 2023
1 parent 5cd6fea commit 712c391
Showing 1 changed file with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Divider, Popover, Stack, Typography, useTheme } from '@mui/material';
import {
Button,
Divider,
Popover,
Stack,
Typography,
useTheme,
} from '@mui/material';
import { isNilOrEmpty } from '@origin/shared/utils';
import { produce } from 'immer';
import { descend, pipe, prop, sort, take } from 'ramda';
import { useIntl } from 'react-intl';

Expand All @@ -23,12 +31,20 @@ export const ActivityPopover = ({
}: AcitivityPopoverProps) => {
const intl = useIntl();
const theme = useTheme();
const [{ activities, maxVisible }] = useActivityState();
const [{ activities, maxVisible }, setActivityState] = useActivityState();

const handleClose = () => {
setAnchor(null);
};

const handleClearAll = () => {
setActivityState(
produce((state) => {
state.activities = [];
}),
);
};

const sortedActivities = pipe(
sort(descend(prop('createdOn'))),
take(maxVisible),
Expand Down Expand Up @@ -63,9 +79,19 @@ export const ActivityPopover = ({
}}
>
<Stack>
<Typography sx={{ px: 3, py: 2 }}>
{intl.formatMessage({ defaultMessage: 'Recent activity' })}
</Typography>
<Stack
direction="row"
alignItems="center"
justifyContent="space-between"
>
<Typography sx={{ px: 3, py: 2 }}>
{intl.formatMessage({ defaultMessage: 'Recent activity' })}
</Typography>
<Button variant="text" onClick={handleClearAll}>
{intl.formatMessage({ defaultMessage: 'Clear All' })}
</Button>
</Stack>

<Divider />
<Stack divider={<Divider />}>
{isNilOrEmpty(sortedActivities) ? (
Expand Down

0 comments on commit 712c391

Please sign in to comment.