Skip to content

Commit

Permalink
add residents info to frontend for announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
KathleenX7 committed Dec 6, 2024
1 parent 311fb11 commit 716167c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
16 changes: 16 additions & 0 deletions frontend/src/APIClients/Mutations/NotificationMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ export const CREATE_NOTIFICATION_GROUP = gql`
createNotificationGroup(roomIds: $roomIds) {
id
announcementGroup
recipients {
userId
residentId
roomNumber
credits
dateJoined
dateLeft
}
}
}
`;
Expand All @@ -14,6 +22,14 @@ export const CREATE_ANNOUNCEMENT_GROUP = gql`
createAnnouncementGroup {
id
announcementGroup
recipients {
userId
residentId
roomNumber
credits
dateJoined
dateLeft
}
}
}
`;
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/APIClients/Queries/NotificationQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ export const GET_ALL_GROUPS_AND_NOTIFICATIONS = gql`
recipients {
userId
residentId
displayName
profilePictureURL
isActive
roomNumber
credits
dateJoined
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/APIClients/Types/NotificationType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ResidentResponse } from "./ResidentsType";

export type NotificationResponse = {
id: string;
message: string;
Expand All @@ -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;
};
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/APIClients/Types/ResidentsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type UserResponse = {
phoneNumber?: string;
firstName: string;
lastName: string;
displayName?: string;
profilePictureURL?: string;
birthDate: string;
roomNumber: number;
Expand All @@ -21,7 +20,6 @@ export type UserRequest = {
phoneNumber?: string;
firstName: string;
lastName: string;
displayName?: string;
profilePictureURL?: string;
residentId: number;
birthDate: string;
Expand All @@ -38,7 +36,6 @@ export type UserRequestUpdate = {
phoneNumber?: string;
firstName?: string;
lastName?: string;
displayName?: string;
profilePictureURL?: string;
residentId?: number;
birthDate?: string;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<React.SetStateAction<string>>;
Expand All @@ -73,7 +75,7 @@ const GroupTab = ({

return (
<Box
onClick={() => setSelectedGroup(roomKey)}
onClick={() => setSelectedGroup(roomId)}
w="100%"
p={3}
borderBottom="solid"
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -179,6 +183,7 @@ const GroupList: React.FC<{
addingNewRoom ? (
<GroupTab
key={null}
roomId="0"
roomKey="0"
firstAnnouncement={null}
setSelectedGroup={setSelectedGroup}
Expand All @@ -199,7 +204,8 @@ const GroupList: React.FC<{
.map((group) => (
<GroupTab
key={group.id}
roomKey={group.id}
roomId={group.id}
roomKey={group.recipients?.map((resident) => resident.roomNumber).join(',') || ''}
isDraft={false}
firstAnnouncement={
group.notifications && group.notifications.length > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ type PropsList = {
};

const AnnouncementsList = ({ announcements, selectedGroup }: PropsList) => {
console.log(announcements, selectedGroup);
if (selectedGroup.length === 0) {
return null;
return <></>;
}

return (
Expand Down Expand Up @@ -237,7 +238,7 @@ const AnnouncementsView = ({
<Box flex={1} h="100vh" overflowY="scroll">
{selectedGroup !== "0" && (
<AnnouncementsList
announcements={announcements}
announcements={announcements || []}
selectedGroup={selectedGroup}
/>
)}
Expand Down

0 comments on commit 716167c

Please sign in to comment.