From 716167cb7e7ef2310d6e3dff7405d60cef89f9f0 Mon Sep 17 00:00:00 2001 From: KathleenX7 Date: Thu, 5 Dec 2024 21:56:00 -0500 Subject: [PATCH] add residents info to frontend for announcements --- .../Mutations/NotificationMutations.ts | 16 ++++++++++++++++ .../APIClients/Queries/NotificationQueries.ts | 3 --- .../src/APIClients/Types/NotificationType.ts | 4 +++- frontend/src/APIClients/Types/ResidentsType.ts | 12 +++++++++--- .../announcements/AnnouncementsGroups.tsx | 18 ++++++++++++------ .../pages/announcements/AnnouncementsView.tsx | 5 +++-- 6 files changed, 43 insertions(+), 15 deletions(-) diff --git a/frontend/src/APIClients/Mutations/NotificationMutations.ts b/frontend/src/APIClients/Mutations/NotificationMutations.ts index 8d7496b..c2d6ffc 100644 --- a/frontend/src/APIClients/Mutations/NotificationMutations.ts +++ b/frontend/src/APIClients/Mutations/NotificationMutations.ts @@ -5,6 +5,14 @@ export const CREATE_NOTIFICATION_GROUP = gql` createNotificationGroup(roomIds: $roomIds) { id announcementGroup + recipients { + userId + residentId + roomNumber + credits + dateJoined + dateLeft + } } } `; @@ -14,6 +22,14 @@ export const CREATE_ANNOUNCEMENT_GROUP = gql` createAnnouncementGroup { id announcementGroup + recipients { + userId + residentId + roomNumber + credits + dateJoined + dateLeft + } } } `; diff --git a/frontend/src/APIClients/Queries/NotificationQueries.ts b/frontend/src/APIClients/Queries/NotificationQueries.ts index 38fe4e8..cd9afb6 100644 --- a/frontend/src/APIClients/Queries/NotificationQueries.ts +++ b/frontend/src/APIClients/Queries/NotificationQueries.ts @@ -48,9 +48,6 @@ export const GET_ALL_GROUPS_AND_NOTIFICATIONS = gql` recipients { userId residentId - displayName - profilePictureURL - isActive roomNumber credits dateJoined diff --git a/frontend/src/APIClients/Types/NotificationType.ts b/frontend/src/APIClients/Types/NotificationType.ts index 409c962..244fb3c 100644 --- a/frontend/src/APIClients/Types/NotificationType.ts +++ b/frontend/src/APIClients/Types/NotificationType.ts @@ -1,3 +1,5 @@ +import { ResidentResponse } from "./ResidentsType"; + export type NotificationResponse = { id: string; message: string; @@ -20,7 +22,7 @@ export type NotificationUpdateRequest = { export type NotificationGroupResponse = { id: string; - // recipients?: Residentesponse[]; TODO: add when resident response exists + recipients?: ResidentResponse[]; notifications?: NotificationResponse[]; announcementGroup: boolean; }; diff --git a/frontend/src/APIClients/Types/ResidentsType.ts b/frontend/src/APIClients/Types/ResidentsType.ts index e085ee4..78fc183 100644 --- a/frontend/src/APIClients/Types/ResidentsType.ts +++ b/frontend/src/APIClients/Types/ResidentsType.ts @@ -5,7 +5,6 @@ export type UserResponse = { phoneNumber?: string; firstName: string; lastName: string; - displayName?: string; profilePictureURL?: string; birthDate: string; roomNumber: number; @@ -21,7 +20,6 @@ export type UserRequest = { phoneNumber?: string; firstName: string; lastName: string; - displayName?: string; profilePictureURL?: string; residentId: number; birthDate: string; @@ -38,7 +36,6 @@ export type UserRequestUpdate = { phoneNumber?: string; firstName?: string; lastName?: string; - displayName?: string; profilePictureURL?: string; residentId?: number; birthDate?: string; @@ -48,3 +45,12 @@ export type UserRequestUpdate = { dateLeft?: Date; notes?: string; }; + +export type ResidentResponse = { + userId: string; + residentId: string; + roomNumber: number; + credits: number; + dateJoined: Date; + dateLeft: Date; +} \ No newline at end of file diff --git a/frontend/src/components/pages/announcements/AnnouncementsGroups.tsx b/frontend/src/components/pages/announcements/AnnouncementsGroups.tsx index a0925af..7785dfb 100644 --- a/frontend/src/components/pages/announcements/AnnouncementsGroups.tsx +++ b/frontend/src/components/pages/announcements/AnnouncementsGroups.tsx @@ -54,12 +54,14 @@ export const formatRooms = (roomIDs: number[]) => { }; const GroupTab = ({ + roomId, roomKey, firstAnnouncement, setSelectedGroup, isDraft, selectedRooms, }: { + roomId: string; roomKey: string; firstAnnouncement: NotificationResponse | null; setSelectedGroup: React.Dispatch>; @@ -73,7 +75,7 @@ const GroupTab = ({ return ( setSelectedGroup(roomKey)} + onClick={() => setSelectedGroup(roomId)} w="100%" p={3} borderBottom="solid" @@ -148,10 +150,12 @@ const GroupList: React.FC<{ }; announcements?.forEach((group) => { processedData.all.push(group); - // if (group.recipients && group.recipients.length > 1) { TODO: whenn recipients are added, include this - // processedData.private.push(group); - // } - processedData.groups.push(group); + console.log(group); + if (group.recipients && group.recipients.length <= 1 && !group.announcementGroup) { + processedData.private.push(group); + } else { + processedData.groups.push(group); + } }); // Object.keys(announcements).forEach((key) => { @@ -179,6 +183,7 @@ const GroupList: React.FC<{ addingNewRoom ? ( ( resident.roomNumber).join(',') || ''} isDraft={false} firstAnnouncement={ group.notifications && group.notifications.length > 0 diff --git a/frontend/src/components/pages/announcements/AnnouncementsView.tsx b/frontend/src/components/pages/announcements/AnnouncementsView.tsx index b7a12b5..693ff76 100644 --- a/frontend/src/components/pages/announcements/AnnouncementsView.tsx +++ b/frontend/src/components/pages/announcements/AnnouncementsView.tsx @@ -88,8 +88,9 @@ type PropsList = { }; const AnnouncementsList = ({ announcements, selectedGroup }: PropsList) => { + console.log(announcements, selectedGroup); if (selectedGroup.length === 0) { - return null; + return <>; } return ( @@ -237,7 +238,7 @@ const AnnouncementsView = ({ {selectedGroup !== "0" && ( )}