mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-17 17:40:16 -04:00
fix notifications w help from josh
This commit is contained in:
parent
9844c0b8c4
commit
559fabccb7
|
@ -160,7 +160,9 @@ export default function Carpool({ id }: { id: number }) {
|
||||||
leave,
|
leave,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<UISecondaryBox style={{ width: '100%', alignItems: 'center' }}>
|
<UISecondaryBox
|
||||||
|
style={{ width: '45rem', maxWidth: '100vw', alignItems: 'center' }}
|
||||||
|
>
|
||||||
<h1>{carpool.name}</h1>
|
<h1>{carpool.name}</h1>
|
||||||
<UILink href={'/events/' + carpool.event.id}>
|
<UILink href={'/events/' + carpool.event.id}>
|
||||||
{carpool.event.name}
|
{carpool.event.name}
|
||||||
|
|
|
@ -39,7 +39,7 @@ const CarpoolMap = () => {
|
||||||
google={google}
|
google={google}
|
||||||
style={{ width: '100%', height: '100%' }}
|
style={{ width: '100%', height: '100%' }}
|
||||||
containerStyle={{
|
containerStyle={{
|
||||||
width: '30rem',
|
width: 'min(30rem, 100%)',
|
||||||
height: '25rem',
|
height: '25rem',
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
borderRadius: '0.5rem',
|
borderRadius: '0.5rem',
|
||||||
|
|
|
@ -40,7 +40,7 @@ export default function MemberList() {
|
||||||
() => carpool.members.map((member) => member.id),
|
() => carpool.members.map((member) => member.id),
|
||||||
[carpool]
|
[carpool]
|
||||||
);
|
);
|
||||||
const members = useSignups(carpool.id, memberIDs);
|
const members = useSignups(carpool.event.id, memberIDs);
|
||||||
console.log(members);
|
console.log(members);
|
||||||
|
|
||||||
const membersToShow = useMemo(
|
const membersToShow = useMemo(
|
||||||
|
|
|
@ -8,7 +8,7 @@ import UIPrimaryTitle from '../UI/UIPrimaryTitle';
|
||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
const me = useMe();
|
const me = useMe();
|
||||||
const notifications = useNotifications();
|
const [notifications, refreshNotifications] = useNotifications();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -31,7 +31,10 @@ export default function Header() {
|
||||||
<UIPressable onClick={logout}>Log out</UIPressable>
|
<UIPressable onClick={logout}>Log out</UIPressable>
|
||||||
<br />
|
<br />
|
||||||
{notifications.length > 0 ? (
|
{notifications.length > 0 ? (
|
||||||
<Notifications notifications={notifications} />
|
<Notifications
|
||||||
|
notifications={notifications}
|
||||||
|
refresh={refreshNotifications}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<span>No notifications</span>
|
<span>No notifications</span>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,45 +1,44 @@
|
||||||
import { useCallback } from 'react';
|
import { useCallback, useContext } from 'react';
|
||||||
import {
|
import { NotificationsContext } from '../../state/Notifications/NotificationsProvider';
|
||||||
acceptInvite,
|
import { acceptCarpoolRequest, denyCarpoolRequest } from '../api';
|
||||||
acceptCarpoolRequest,
|
|
||||||
denyInvite,
|
|
||||||
denyCarpoolRequest,
|
|
||||||
} from '../api';
|
|
||||||
import { IInvitation } from '../types';
|
import { IInvitation } from '../types';
|
||||||
import UIButton from '../UI/UIButton';
|
import UIButton from '../UI/UIButton';
|
||||||
|
|
||||||
export default function Notification({
|
export default function Notification({
|
||||||
notification,
|
notification,
|
||||||
|
refresh,
|
||||||
}: {
|
}: {
|
||||||
notification: IInvitation;
|
notification: IInvitation;
|
||||||
|
refresh: () => void;
|
||||||
}) {
|
}) {
|
||||||
const carpoolId = notification.carpool.id;
|
const carpoolId = notification.carpool.id;
|
||||||
|
|
||||||
|
const notifs = useContext(NotificationsContext);
|
||||||
|
|
||||||
const acceptReq = useCallback(() => {
|
const acceptReq = useCallback(() => {
|
||||||
acceptCarpoolRequest(carpoolId, notification.user.id);
|
acceptCarpoolRequest(carpoolId, notification.user.id).finally(refresh);
|
||||||
}, [carpoolId, notification.user.id]);
|
}, [carpoolId, notification.user.id, refresh]);
|
||||||
|
|
||||||
const rejectReq = useCallback(() => {
|
const rejectReq = useCallback(() => {
|
||||||
denyCarpoolRequest(carpoolId, notification.user.id);
|
denyCarpoolRequest(carpoolId, notification.user.id).finally(refresh);
|
||||||
}, [carpoolId, notification.user.id]);
|
}, [carpoolId, notification.user.id, refresh]);
|
||||||
|
|
||||||
const acceptInv = useCallback(() => {
|
const acceptInv = useCallback(() => {
|
||||||
acceptInvite(carpoolId);
|
notifs.acceptCarpoolInvite(carpoolId);
|
||||||
}, [carpoolId]);
|
}, [carpoolId, notifs]);
|
||||||
|
|
||||||
const rejectInv = useCallback(() => {
|
const rejectInv = useCallback(() => {
|
||||||
denyInvite(carpoolId);
|
notifs.denyCarpoolInvite(carpoolId);
|
||||||
}, [carpoolId]);
|
}, [carpoolId, notifs]);
|
||||||
|
|
||||||
const sentTime = new Date(notification.sentTime);
|
const sentTime = new Date(notification.sentTime);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="notification">
|
<div className="notification">
|
||||||
{notification.user.name}{' '}
|
|
||||||
{notification.isRequest ? (
|
{notification.isRequest ? (
|
||||||
<span>requested to join</span>
|
<span>{notification.user.name} requested to join</span>
|
||||||
) : (
|
) : (
|
||||||
<span>invited you to join</span>
|
<span>You're invited to join</span>
|
||||||
)}{' '}
|
)}{' '}
|
||||||
{notification.carpool.name + ' at ' + sentTime.toLocaleString()}
|
{notification.carpool.name + ' at ' + sentTime.toLocaleString()}
|
||||||
{notification.isRequest ? (
|
{notification.isRequest ? (
|
||||||
|
|
|
@ -3,8 +3,10 @@ import { IInvitation } from '../types';
|
||||||
|
|
||||||
export default function Notifications({
|
export default function Notifications({
|
||||||
notifications,
|
notifications,
|
||||||
|
refresh,
|
||||||
}: {
|
}: {
|
||||||
notifications: IInvitation[];
|
notifications: IInvitation[];
|
||||||
|
refresh: () => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
||||||
|
@ -12,6 +14,7 @@ export default function Notifications({
|
||||||
{notifications.map((notification) => (
|
{notifications.map((notification) => (
|
||||||
<Notification
|
<Notification
|
||||||
notification={notification}
|
notification={notification}
|
||||||
|
refresh={refresh}
|
||||||
key={`${notification.user.id}:${notification.carpool.id}`}
|
key={`${notification.user.id}:${notification.carpool.id}`}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -245,7 +245,7 @@ export async function leaveCarpool(carpoolId: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendCarpoolRequest(carpoolId: number) {
|
export async function sendCarpoolRequest(carpoolId: number) {
|
||||||
await post('/carpools/' + carpoolId + '/request', {});
|
await post(`/carpools/${carpoolId}/request`, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cancelCarpoolRequest(carpoolId: number) {
|
export async function cancelCarpoolRequest(carpoolId: number) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useContext, useEffect, useState } from 'react';
|
import { useCallback, useContext, useEffect, useState } from 'react';
|
||||||
import { getReceivedInvitationsAndRequests } from './api';
|
import { getReceivedInvitationsAndRequests } from './api';
|
||||||
import AuthenticationContext from './Authentication/AuthenticationContext';
|
import AuthenticationContext from './Authentication/AuthenticationContext';
|
||||||
import { IInvitation } from './types';
|
import { IInvitation } from './types';
|
||||||
|
@ -9,9 +9,11 @@ export const useMe = () => useAuth().user;
|
||||||
export function useNotifications() {
|
export function useNotifications() {
|
||||||
const [notifications, setNotifications] = useState<IInvitation[]>([]);
|
const [notifications, setNotifications] = useState<IInvitation[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
const refresh = useCallback(() => {
|
||||||
getReceivedInvitationsAndRequests().then(setNotifications);
|
getReceivedInvitationsAndRequests().then(setNotifications);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return notifications;
|
useEffect(refresh, [refresh]);
|
||||||
|
|
||||||
|
return [notifications, refresh] as const;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user