From 3e60426ba63efc042eebee20010a75406ba520d6 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Mon, 17 Jan 2022 18:22:05 -0800 Subject: [PATCH] quick fixes to statuses updating --- components/RoomCard.tsx | 10 +++++++++- services/userService.tsx | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/components/RoomCard.tsx b/components/RoomCard.tsx index 59e0b06..a6afdf0 100644 --- a/components/RoomCard.tsx +++ b/components/RoomCard.tsx @@ -8,12 +8,13 @@ import { useAuth } from "../contexts/authContext"; import { Avatar, Divider, Dropdown, Menu, Tooltip } from "antd"; import { UserOutlined, AntDesignOutlined } from "@ant-design/icons"; import { useTeamDashboardContext } from "../contexts/teamDashboardContext"; -import { User } from "../models/user"; +import { User, UserStatus } from "../models/user"; import RoomService from "../services/roomService"; import toast from "react-hot-toast"; import { useState } from "react"; import SkeletonLoader from "./Loading/skeletonLoader"; import { useKeyboardContext } from "../contexts/keyboardContext"; +import UserService from "../services/userService"; interface IRoomCardProps { room: Room; @@ -21,6 +22,7 @@ interface IRoomCardProps { } const roomService = new RoomService(); +const userService = new UserService(); export default function RoomCard(props: IRoomCardProps) { const { currUser } = useAuth(); @@ -138,6 +140,9 @@ export default function RoomCard(props: IRoomCardProps) { // update the room with room id to have a new array of userIds await roomService.updateMembersInRoom(props.room.id, newMembersInRoom); + + // change curr user status to free now + await userService.updateUserStatus(currUser.uid, UserStatus.online); } catch (error) { console.error(error); @@ -157,6 +162,9 @@ export default function RoomCard(props: IRoomCardProps) { // update the room with room id to have a new array of userIds await roomService.updateMembersInRoom(props.room.id, newMembersInRoom); + // change curr user status to free now + await userService.updateUserStatus(currUser.uid, UserStatus.busy); + // then window.open to room's link window.open(props.room.link, "_blank"); } catch (error) { diff --git a/services/userService.tsx b/services/userService.tsx index 67073d7..dd69436 100644 --- a/services/userService.tsx +++ b/services/userService.tsx @@ -66,9 +66,9 @@ export default class UserService { ); } - updateUserStatus(userId: string, newStatus: UserStatus) { + async updateUserStatus(userId: string, newStatus: UserStatus) { const docRef = doc(this.db, Collections.users, userId); - setDoc( + await setDoc( docRef, { userStatus: newStatus, lastUpdatedDate: serverTimestamp() }, { merge: true }