From 1f22e98ad063de1ddea55ca07a7f0383b535b404 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Mon, 17 Jan 2022 00:32:12 -0800 Subject: [PATCH] creating rooms fine, but not displaying them yet --- components/Modals/CreateRoom.tsx | 134 +++++++++++++++++++++++++------ models/room.ts | 17 ++-- services/collections.tsx | 4 + services/roomService.tsx | 21 +++++ 4 files changed, 144 insertions(+), 32 deletions(-) create mode 100644 services/roomService.tsx diff --git a/components/Modals/CreateRoom.tsx b/components/Modals/CreateRoom.tsx index f92ef5e..c651b9e 100644 --- a/components/Modals/CreateRoom.tsx +++ b/components/Modals/CreateRoom.tsx @@ -1,16 +1,23 @@ -import { Divider, Modal, Select } from "antd"; +import { Divider, Modal, Radio, Select } from "antd"; import React, { useEffect, useState } from "react"; +import toast from "react-hot-toast"; +import { useAuth } from "../../contexts/authContext"; import { ShowModalType, useKeyboardContext, } from "../../contexts/keyboardContext"; import { useTeamDashboardContext } from "../../contexts/teamDashboardContext"; +import Room, { RoomType } from "../../models/room"; +import RoomService from "../../services/roomService"; const { Option } = Select; const thisModalType = ShowModalType.createRoom; +const roomService = new RoomService(); + export default function CreateRoomModal() { + const { currUser } = useAuth(); const { teamUsers } = useTeamDashboardContext(); const { pastedLink, handleModalType, showModalType } = useKeyboardContext(); @@ -23,13 +30,52 @@ export default function CreateRoomModal() { handleModalType(ShowModalType.na); }; - const handleSubmit = () => {}; + const handleSubmit = async (e) => { + e.preventDefault(); + + // make sure link, room, and type are selected + if (!roomLink || !roomName) { + toast.error("Please fill in room link and name."); + return; + } + + try { + const newRoom = new Room(); + + if (roomAttachment) { + newRoom.attachments = [roomAttachment]; + } + + newRoom.approximateDateTime = roomAppxDateTime; + newRoom.link = roomLink; + newRoom.members = [...membersSelected, currUser.uid]; // add currUser to the list of "people" + newRoom.type = roomType; + newRoom.description = roomDescription; + newRoom.name = roomName; + newRoom.createdByUserId = currUser.uid; + + await roomService.createRoom(newRoom); + } catch (error) { + toast.error("problem creating room"); + console.log(error); + } + }; const [roomLink, setRoomLink] = useState(pastedLink); + const [roomName, setRoomName] = useState(""); + const [roomDescription, setRoomDescription] = useState(null); + + const [roomAttachment, setRoomAttachment] = useState(null); const [membersSelected, setMembersSelected] = useState([]); + const [roomType, setRoomType] = useState(RoomType.now); + const [roomAppxDateTime, setRoomAppxDateTime] = useState(null); // for certain room types + function handleSelectMember(value) { - // setMemberSelection() + // passed in array of selections...userIds + + setMembersSelected(value); + console.log(value); } @@ -46,18 +92,19 @@ export default function CreateRoomModal() { mode="multiple" allowClear style={{ width: "100%" }} - placeholder="Please select" - defaultValue={["a10", "c12"]} + placeholder="Please select team members" onChange={handleSelectMember} > - {children} + {teamUsers.map((tu) => { + return ; + })} ); }; return (
- Link + 1. Link {roomLink ? ( Please make sure this is valid so that your team can join @@ -85,24 +132,59 @@ export default function CreateRoomModal() { setRoomLink(e.target.value)} /> -
- - Room Name - - Be specific enough, everyone down the hall will see this. - - setRoomLink(e.target.value)} - /> + + 2. Room Name + + Be specific enough, everyone down the hall will see this. -
+ setRoomName(e.target.value)} + /> +
+ + {/* room type selection */} + + + 3. Type + + setRoomType(event.target.value)} + > + {RoomType.now} + + {RoomType.scheduled} + + + {RoomType.recurring} + + + + {roomType == RoomType.recurring || roomType == RoomType.scheduled ? ( + + Approximate day/time + + Put a rough day/time that makes sense to you. + + setRoomAppxDateTime(e.target.value)} + /> + + ) : ( + <> + )} + @@ -115,13 +197,13 @@ export default function CreateRoomModal() { - Subtitle + Description Optional setRoomLink(e.target.value)} + value={roomDescription} + onChange={(e) => setRoomDescription(e.target.value)} /> @@ -133,8 +215,8 @@ export default function CreateRoomModal() { setRoomLink(e.target.value)} + value={roomAttachment} + onChange={(e) => setRoomAttachment(e.target.value)} />
diff --git a/models/room.ts b/models/room.ts index ca6626f..3096890 100644 --- a/models/room.ts +++ b/models/room.ts @@ -1,21 +1,26 @@ +import { Timestamp } from "firebase/firestore"; + export default class Room { id: string; - title: string; - subtitle: string; + name: string; + description: string; - roomLink: string; // google meet link for now + link: string; // google meet link for now - roomMembers: string[]; //userIds of "mandatory"/invited people including the person who created it + members: string[]; //userIds of "mandatory"/invited people including the person who created it attachments: string[]; // the links themselves (NOT Ids)...there will be duplicate entries in the attachments table which will be created - roomType: RoomType; + type: RoomType; approximateDateTime: string; // vaguely say when the meeting should be...give user pointers + + createdDate: Timestamp; + createdByUserId: string; } -enum RoomType { +export enum RoomType { now = "now", scheduled = "scheduled", // one time sort of standard meeting recurring = "recurring", //daily standup diff --git a/services/collections.tsx b/services/collections.tsx index 485e077..8c7a2a1 100644 --- a/services/collections.tsx +++ b/services/collections.tsx @@ -4,4 +4,8 @@ export enum Collections { teamMembers = "teamMembers", teamSubscriptions = "teamSubscriptions", audioMessages = "audioMessages", + + rooms = "rooms", + announcements = "announcements", + attachments = "attachments", } diff --git a/services/roomService.tsx b/services/roomService.tsx new file mode 100644 index 0000000..658a791 --- /dev/null +++ b/services/roomService.tsx @@ -0,0 +1,21 @@ +import { + addDoc, + collection, + doc, + Firestore, + getFirestore, + serverTimestamp, +} from "firebase/firestore"; +import Room from "../models/room"; +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(), + }); + } +}