This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: add "View" button to card-added notification

+28 -4
+28 -4
src/webapp/features/cards/lib/mutations/useAddCard.tsx
··· 14 14 } from '@/features/analytics/types'; 15 15 import { shouldCaptureAnalytics } from '@/features/analytics/utils'; 16 16 import { notifications } from '@mantine/notifications'; 17 + import { Button, Group, Text } from '@mantine/core'; 17 18 import { BsCheck, BsExclamation } from 'react-icons/bs'; 19 + import { useRouter } from 'next/navigation'; 18 20 19 21 export default function useAddCard( 20 22 analyticsContext?: CardSaveAnalyticsContext, 21 23 ) { 22 24 const queryClient = useQueryClient(); 25 + const router = useRouter(); 23 26 24 27 const mutation = useMutation({ 25 28 mutationFn: async (newCard: { ··· 43 46 // https://tkdodo.eu/blog/mastering-mutations-in-react-query#some-callbacks-might-not-fire 44 47 onSuccess: (_data, variables) => { 45 48 if (variables.notificationId) { 49 + const notificationId = variables.notificationId; 46 50 notifications.update({ 47 - id: variables.notificationId, 51 + id: notificationId, 48 52 color: 'green', 49 - title: 'Success!', 50 - message: 'Card added', 53 + title: null, 54 + message: ( 55 + <Group 56 + gap="xs" 57 + justify="space-between" 58 + wrap="nowrap" 59 + align="center" 60 + > 61 + <Text size="sm">Card added</Text> 62 + <Button 63 + size="xs" 64 + variant="light" 65 + color="gray" 66 + onClick={() => { 67 + notifications.hide(notificationId); 68 + router.push(`/url?id=${encodeURIComponent(variables.url)}`); 69 + }} 70 + > 71 + View 72 + </Button> 73 + </Group> 74 + ), 51 75 position: 'top-center', 52 76 loading: false, 53 - autoClose: 2000, 77 + autoClose: 5000, 54 78 icon: <BsCheck />, 55 79 }); 56 80 }