quick fixes to statuses updating
This commit is contained in:
@@ -8,12 +8,13 @@ import { useAuth } from "../contexts/authContext";
|
|||||||
import { Avatar, Divider, Dropdown, Menu, Tooltip } from "antd";
|
import { Avatar, Divider, Dropdown, Menu, Tooltip } from "antd";
|
||||||
import { UserOutlined, AntDesignOutlined } from "@ant-design/icons";
|
import { UserOutlined, AntDesignOutlined } from "@ant-design/icons";
|
||||||
import { useTeamDashboardContext } from "../contexts/teamDashboardContext";
|
import { useTeamDashboardContext } from "../contexts/teamDashboardContext";
|
||||||
import { User } from "../models/user";
|
import { User, UserStatus } from "../models/user";
|
||||||
import RoomService from "../services/roomService";
|
import RoomService from "../services/roomService";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import SkeletonLoader from "./Loading/skeletonLoader";
|
import SkeletonLoader from "./Loading/skeletonLoader";
|
||||||
import { useKeyboardContext } from "../contexts/keyboardContext";
|
import { useKeyboardContext } from "../contexts/keyboardContext";
|
||||||
|
import UserService from "../services/userService";
|
||||||
|
|
||||||
interface IRoomCardProps {
|
interface IRoomCardProps {
|
||||||
room: Room;
|
room: Room;
|
||||||
@@ -21,6 +22,7 @@ interface IRoomCardProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const roomService = new RoomService();
|
const roomService = new RoomService();
|
||||||
|
const userService = new UserService();
|
||||||
|
|
||||||
export default function RoomCard(props: IRoomCardProps) {
|
export default function RoomCard(props: IRoomCardProps) {
|
||||||
const { currUser } = useAuth();
|
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
|
// update the room with room id to have a new array of userIds
|
||||||
await roomService.updateMembersInRoom(props.room.id, newMembersInRoom);
|
await roomService.updateMembersInRoom(props.room.id, newMembersInRoom);
|
||||||
|
|
||||||
|
// change curr user status to free now
|
||||||
|
await userService.updateUserStatus(currUser.uid, UserStatus.online);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(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
|
// update the room with room id to have a new array of userIds
|
||||||
await roomService.updateMembersInRoom(props.room.id, newMembersInRoom);
|
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
|
// then window.open to room's link
|
||||||
window.open(props.room.link, "_blank");
|
window.open(props.room.link, "_blank");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -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);
|
const docRef = doc(this.db, Collections.users, userId);
|
||||||
setDoc(
|
await setDoc(
|
||||||
docRef,
|
docRef,
|
||||||
{ userStatus: newStatus, lastUpdatedDate: serverTimestamp() },
|
{ userStatus: newStatus, lastUpdatedDate: serverTimestamp() },
|
||||||
{ merge: true }
|
{ merge: true }
|
||||||
|
|||||||
Reference in New Issue
Block a user