Fixed room 404 issues
This commit is contained in:
parent
0579022489
commit
12f928aa93
2 changed files with 87 additions and 78 deletions
|
@ -1,10 +1,18 @@
|
|||
"use client";
|
||||
|
||||
import { EventTypes } from "@/_utils/types";
|
||||
import Image from "next/image";
|
||||
import { useEffect, useState } from "react";
|
||||
import { EventTypes } from "@/_utils/types";
|
||||
|
||||
import LoadingIndicator from "@/_components/LoadingIndicator";
|
||||
import type { PresenceItem, RoomResponse, VoteResponse } from "@/_utils/types";
|
||||
import { useUser } from "@clerk/nextjs";
|
||||
import { useChannel, usePresence } from "ably/react";
|
||||
import { isAdmin, isVIP, jsonToCsv } from "app/_utils/helpers";
|
||||
import { env } from "env.mjs";
|
||||
import { useParams } from "next/navigation";
|
||||
import { FaShieldAlt } from "react-icons/fa";
|
||||
import { GiStarFormation } from "react-icons/gi";
|
||||
import {
|
||||
IoCheckmarkCircleOutline,
|
||||
IoCopyOutline,
|
||||
|
@ -15,15 +23,7 @@ import {
|
|||
IoReloadOutline,
|
||||
IoSaveOutline,
|
||||
} from "react-icons/io5";
|
||||
import { GiStarFormation } from "react-icons/gi";
|
||||
import { FaShieldAlt } from "react-icons/fa";
|
||||
import { RiVipCrownFill } from "react-icons/ri";
|
||||
import { env } from "env.mjs";
|
||||
import { isAdmin, isVIP, jsonToCsv } from "app/_utils/helpers";
|
||||
import type { PresenceItem, RoomResponse, VoteResponse } from "@/_utils/types";
|
||||
import LoadingIndicator from "@/_components/LoadingIndicator";
|
||||
import { useUser } from "@clerk/nextjs";
|
||||
import { useChannel, usePresence } from "ably/react";
|
||||
import NoRoomUI from "./NoRoomUI";
|
||||
|
||||
const VoteUI = () => {
|
||||
|
@ -40,12 +40,15 @@ const VoteUI = () => {
|
|||
const [votesFromDb, setVotesFromDb] = useState<VoteResponse>(undefined);
|
||||
|
||||
const getRoomHandler = async () => {
|
||||
const dbRoomResponse = await fetch(`/api/internal/room/${roomId}`, {
|
||||
fetch(`/api/internal/room/${roomId}`, {
|
||||
cache: "no-cache",
|
||||
method: "GET",
|
||||
});
|
||||
const dbRoom = (await dbRoomResponse.json()) as RoomResponse;
|
||||
}).then(async (response) => {
|
||||
const dbRoom = (await response.json()) as RoomResponse;
|
||||
setRoomFromDb(dbRoom);
|
||||
}).catch(() => {
|
||||
setRoomFromDb(null);
|
||||
});
|
||||
};
|
||||
|
||||
const getVotesHandler = async () => {
|
||||
|
@ -310,8 +313,7 @@ const VoteUI = () => {
|
|||
return (
|
||||
<button
|
||||
key={ index }
|
||||
className={`join-item ${
|
||||
getVoteForCurrentUser()?.value === scaleItem
|
||||
className={ `join-item ${getVoteForCurrentUser()?.value === scaleItem
|
||||
? "btn btn-active btn-primary"
|
||||
: "btn"
|
||||
}` }
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { type NextRequest, NextResponse } from "next/server";
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
|
||||
import { db } from "@/_lib/db";
|
||||
import { logs, rooms, votes } from "@/_lib/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { publishToChannel } from "@/_lib/ably";
|
||||
import { EventTypes } from "@/_utils/types";
|
||||
import { db } from "@/_lib/db";
|
||||
import { invalidateCache } from "@/_lib/redis";
|
||||
import { createId } from "@paralleldrive/cuid2";
|
||||
import { logs, rooms, votes } from "@/_lib/schema";
|
||||
import { EventTypes } from "@/_utils/types";
|
||||
import { getAuth } from "@clerk/nextjs/server";
|
||||
import { createId } from "@paralleldrive/cuid2";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const runtime = "edge";
|
||||
export const preferredRegion = ["pdx1"];
|
||||
|
@ -30,10 +30,17 @@ export async function GET(
|
|||
},
|
||||
});
|
||||
|
||||
if (roomFromDb) {
|
||||
return NextResponse.json(roomFromDb, {
|
||||
status: 200,
|
||||
statusText: "SUCCESS",
|
||||
});
|
||||
} else {
|
||||
return new NextResponse("ROOM NOT FOUND", {
|
||||
status: 404,
|
||||
statusText: "ROOM NOT FOUND",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
|
|
Loading…
Add table
Reference in a new issue