import { useEffect, useState } from 'react'; import { httpGet, httpPatch } from '../../lib/http'; import { pageProgressMessage } from '../../stores/page'; import type { TeamMemberDocument } from '../TeamMembers/TeamMembersPage'; import { useToast } from '../../hooks/use-toast'; import { AcceptIcon } from '../ReactIcons/AcceptIcon.tsx'; import { XIcon } from 'lucide-react'; interface NotificationList extends TeamMemberDocument { name: string; } export function NotificationPage() { const toast = useToast(); const [isLoading, setIsLoading] = useState(false); const [notifications, setNotifications] = useState([]); const [error, setError] = useState(''); const lostNotifications = async () => { const { error, response } = await httpGet( `${import.meta.env.PUBLIC_API_URL}/v1-get-invitation-list`, ); if (error || !response) { toast.error(error?.message || 'Something went wrong'); return; } setNotifications(response); }; async function respondInvitation( status: 'accept' | 'reject', inviteId: string, ) { setIsLoading(true); setError(''); const { response, error } = await httpPatch<{ teamId: string }>( `${import.meta.env.PUBLIC_API_URL}/v1-respond-invite/${inviteId}`, { status, }, ); if (error || !response) { setError(error?.message || 'Something went wrong'); setIsLoading(false); return; } if (status === 'accept') { window.location.href = `/team/activity?t=${response.teamId}`; } else { window.dispatchEvent( new CustomEvent('refresh-notification', { detail: { count: notifications.length - 1, }, }), ); setNotifications( notifications.filter((notification) => notification._id !== inviteId), ); setIsLoading(false); } } useEffect(() => { lostNotifications().finally(() => { pageProgressMessage.set(''); }); }, []); return (

Notification

Manage your notifications

{notifications.length === 0 && (

No notifications, you can{' '} create a team {' '} and invite your friends to join.

)}
{notifications.map((notification) => (

{notification.name}

))}
); }