Untitled

mail@pastecode.io avatar
unknown
plain_text
6 days ago
1.9 kB
2
Indexable
Never
import { cookies } from "next/headers";
import Wrapper from "./component/Wrapper";
import fetchDataBooking from "./hooks/fetchDataBooking";

const Room1 = "/room/not-booked/Room1.png";
const Room2 = "/room/not-booked/Room2.png";
const Room3 = "/room/not-booked/Room3.png";
const Room4 = "/room/not-booked/Room4.png";
const Room5 = "/room/not-booked/Room5.png";
const Room6 = "/room/not-booked/Room6.png";

export default async function BookingPage() {
  const myCookie = cookies()
    .getAll()
    .map(c => c.name + "=" + c.value)
    .join("; ");
  console.log({ myCookie }, "balCookie");
  const bookingData = await fetchDataBooking();
  const roomsImage = [Room1, Room2, Room3, Room4, Room5, Room6];
  console.log(JSON.stringify(bookingData.getTemporaryHold), "bookingData.getTemporaryHold");

  async function getBookings(data: any, available: any): Promise<any> {
    const updatedRooms = bookingData.getAllRooms?.data?.map((room: any, index: number) => {
      const isSelected = data?.data?.ownHold?.some((r: any) => r.id === room.id);
      console.log(data, "data?.holdByCurrentUser");

      return {
        id: room.id,
        name: room.name,
        selected: isSelected,
        selectedRoomId: index + 1,
        confirmed: "start",
        price: room.price,
        maxCapacity: room.maxCapacity,
        status: room.status,
        discount: room.discount,
        image: roomsImage[index],
        images: room.images,
        videos: room.videos,
        booked: !available?.data.some((avRoom: any) => avRoom.id === room.id),
        hold: data?.data?.totalHolds?.includes(room.id),
        holdByCurrentUser: data?.data?.ownHold?.filter((h: any) => h.id === room.id) || []
      };
    });
    return updatedRooms;
  }

  const res = await getBookings(bookingData.getTemporaryHold, bookingData.getAvailableRooms);

  // return "dddd";
  return <Wrapper data={res} />;
}
Leave a Comment