diff --git a/components/Dashboard/Rooms.tsx b/components/Dashboard/Rooms.tsx index b7e0027..19fcda7 100644 --- a/components/Dashboard/Rooms.tsx +++ b/components/Dashboard/Rooms.tsx @@ -196,7 +196,7 @@ export default function DashboardRoom() { } // pass this to the modal for use - setSelectedUpdateRoom(roomsMap[roomId]); + setSelectedUpdateRoom(roomsMap.get(roomId)); // call the keyboard context to show the modal handleModalType(ShowModalType.createRoom); diff --git a/components/Modals/CreateOrUpdateRoom.tsx b/components/Modals/CreateOrUpdateRoom.tsx index eb79b78..39a70fa 100644 --- a/components/Modals/CreateOrUpdateRoom.tsx +++ b/components/Modals/CreateOrUpdateRoom.tsx @@ -24,6 +24,25 @@ export default function CreateOrUpdateRoomModal(props: IModalProps) { const { teamUsers, team } = useTeamDashboardContext(); const { pastedLink, handleModalType, showModalType } = useKeyboardContext(); + // handle when we want to update a room and props changes + // prefill with existing stuff + useEffect(() => { + console.log("change in props"); + + if (props.updateRoom) { + setRoomLink(props.updateRoom.link); + setRoomName(props.updateRoom.name); + setRoomDescription(props.updateRoom.description); + if (props.updateRoom.attachments && props.updateRoom.attachments[0]) { + setRoomAttachment(props.updateRoom.attachments[0]); + } + setMembersSelected(props.updateRoom.members); + setRoomType(props.updateRoom.type); + setRoomAppxDateTime(props.updateRoom.approximateDateTime); + } + }, [props.updateRoom]); + + // update state when user does ctrl + v useEffect(() => { // todo: check if link is valid google meet link? again? setRoomLink(pastedLink); @@ -62,7 +81,11 @@ export default function CreateOrUpdateRoomModal(props: IModalProps) { newRoom.createdByUserId = currUser.uid; newRoom.teamId = team.id; - await roomService.createRoom(newRoom); + if (props.updateRoom) { + newRoom.id = props.updateRoom.id; + } + + await roomService.createOrUpdateRoom(newRoom); resetForm(); diff --git a/components/RoomCard.tsx b/components/RoomCard.tsx index 663406c..59e0b06 100644 --- a/components/RoomCard.tsx +++ b/components/RoomCard.tsx @@ -252,7 +252,7 @@ export default function RoomCard(props: IRoomCardProps) { isUserInRoom ? "text-gray-400" : "text-gray-200" } text-xs text-right mb-auto`} > - on and off all day + {props.room.approximateDateTime} {/* room attachments */} diff --git a/models/room.ts b/models/room.ts index a815db3..c9ea324 100644 --- a/models/room.ts +++ b/models/room.ts @@ -12,7 +12,7 @@ export default class Room { membersInRoom: string[] = []; - attachments: string[]; // the links themselves (NOT Ids)...there will be duplicate entries in the attachments table which will be created + attachments: string[] = []; // the links themselves (NOT Ids)...there will be duplicate entries in the attachments table which will be created type: RoomType; status: RoomStatus = RoomStatus.empty; diff --git a/services/roomService.tsx b/services/roomService.tsx index 7767847..f5e6888 100644 --- a/services/roomService.tsx +++ b/services/roomService.tsx @@ -13,11 +13,17 @@ import { Collections } from "./collections"; export default class RoomService { private db: Firestore = getFirestore(); - async createRoom(room: Room) { - const roomDocRef = await addDoc(collection(this.db, Collections.rooms), { - ...room, - createdDate: serverTimestamp(), - }); + async createOrUpdateRoom(room: Room) { + if (room.id) { + //update + await this.updateRoom(room); + } else { + //create + const roomDocRef = await addDoc(collection(this.db, Collections.rooms), { + ...room, + createdDate: serverTimestamp(), + }); + } } async updateMembersInRoom(roomId: string, newMembersInRoom: string[]) {