A social knowledge tool for researchers built on ATProto
1import { Button, Stack, Modal } from '@mantine/core';
2import useRemoveCardFromCollections from '../../lib/mutations/useRemoveCardFromCollections';
3import { notifications } from '@mantine/notifications';
4import { useRouter } from 'next/navigation';
5import { DANGER_OVERLAY_PROPS } from '@/styles/overlays';
6
7interface Props {
8 isOpen: boolean;
9 onClose: () => void;
10 cardId: string;
11 collectionId: string;
12}
13
14export default function RemoveCardFromCollectionModal(props: Props) {
15 const removeCardFromCollection = useRemoveCardFromCollections();
16
17 const handleRemoveCardFromCollection = () => {
18 removeCardFromCollection.mutate(
19 { cardId: props.cardId, collectionIds: [props.collectionId] },
20 {
21 onError: () => {
22 notifications.show({
23 message: 'Could not remove card from collection.',
24 position: 'top-center',
25 });
26 },
27 onSettled: () => {
28 props.onClose();
29 },
30 },
31 );
32 };
33
34 return (
35 <Modal
36 opened={props.isOpen}
37 onClose={props.onClose}
38 withCloseButton={false}
39 title="Remove card from collection"
40 size={'xs'}
41 overlayProps={DANGER_OVERLAY_PROPS}
42 centered
43 >
44 <Stack>
45 <Button variant="subtle" size="md" color="gray" onClick={props.onClose}>
46 Cancel
47 </Button>
48 <Button
49 color="red"
50 size="md"
51 onClick={handleRemoveCardFromCollection}
52 loading={removeCardFromCollection.isPending}
53 >
54 Remove
55 </Button>
56 </Stack>
57 </Modal>
58 );
59}