Update API requests to last API changes.
This commit is contained in:
Generated
+6
-5
@@ -22,7 +22,7 @@
|
|||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"date-fns": "^3.6.0",
|
"date-fns": "^3.6.0",
|
||||||
"embla-carousel-react": "^8.0.2",
|
"embla-carousel-react": "^8.0.2",
|
||||||
"lucide-react": "^0.378.0",
|
"lucide-react": "^0.483.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-day-picker": "^8.10.1",
|
"react-day-picker": "^8.10.1",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
@@ -3726,11 +3726,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/lucide-react": {
|
"node_modules/lucide-react": {
|
||||||
"version": "0.378.0",
|
"version": "0.483.0",
|
||||||
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.378.0.tgz",
|
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.483.0.tgz",
|
||||||
"integrity": "sha512-u6EPU8juLUk9ytRcyapkWI18epAv3RU+6+TC23ivjR0e+glWKBobFeSgRwOIJihzktILQuy6E0E80P2jVTDR5g==",
|
"integrity": "sha512-WldsY17Qb/T3VZdMnVQ9C3DDIP7h1ViDTHVdVGnLZcvHNg30zH/MTQ04RTORjexoGmpsXroiQXZ4QyR0kBy0FA==",
|
||||||
|
"license": "ISC",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "^16.5.1 || ^17.0.0 || ^18.0.0"
|
"react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/merge2": {
|
"node_modules/merge2": {
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@
|
|||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"date-fns": "^3.6.0",
|
"date-fns": "^3.6.0",
|
||||||
"embla-carousel-react": "^8.0.2",
|
"embla-carousel-react": "^8.0.2",
|
||||||
"lucide-react": "^0.378.0",
|
"lucide-react": "^0.483.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-day-picker": "^8.10.1",
|
"react-day-picker": "^8.10.1",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { RoomCategory } from "@/model/RoomCategory";
|
|||||||
import { fetcher, fetcherUnwraper } from "./backend";
|
import { fetcher, fetcherUnwraper } from "./backend";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
export function useAPIRoomCategories() {
|
export function useAPIRoomCategoryList() {
|
||||||
const { data, error, isLoading } = useSWR<RoomCategory[]>(
|
const { data, error, isLoading } = useSWR<RoomCategory[]>(
|
||||||
"/api/room/category",
|
"/api/room/category",
|
||||||
fetcherUnwraper,
|
fetcherUnwraper,
|
||||||
@@ -15,8 +15,8 @@ export function useAPIRoomCategories() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAPIRoomCategoryId(categoryId: number) {
|
export function useAPIRoomCategory(categoryId: number) {
|
||||||
const url = categoryId ? "/api/room/category/" + categoryId : null;
|
const url = `/api/room/category/${categoryId}`;
|
||||||
|
|
||||||
const { data, error, isLoading } = useSWR<RoomCategory>(url, fetcher);
|
const { data, error, isLoading } = useSWR<RoomCategory>(url, fetcher);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import {
|
|||||||
export function useAPIRoomAvailability(filter: AvailabilityFilter | null) {
|
export function useAPIRoomAvailability(filter: AvailabilityFilter | null) {
|
||||||
const request: AvailabilityRequest | null = filter
|
const request: AvailabilityRequest | null = filter
|
||||||
? {
|
? {
|
||||||
filter: filter,
|
startDate: filter.startDate,
|
||||||
|
endDate: filter.endDate,
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@@ -32,12 +33,14 @@ export function useAPIRoomAvailability(filter: AvailabilityFilter | null) {
|
|||||||
export function useAPIRoomPrices(filter: FareFilter | null) {
|
export function useAPIRoomPrices(filter: FareFilter | null) {
|
||||||
const request: FareRequest | null = filter
|
const request: FareRequest | null = filter
|
||||||
? {
|
? {
|
||||||
filter: filter,
|
roomCategory: filter.roomCategory,
|
||||||
|
startDate: filter.startDate,
|
||||||
|
endDate: filter.endDate,
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const { data, isLoading, error } = useSWR(
|
const { data, isLoading, error } = useSWR(
|
||||||
request ? ["/api/search/fares", request] : null,
|
request ? ["/api/search/prices", request] : null,
|
||||||
([url, request]) => fetcherUnwraperWithFilter<RoomPrice[]>(url, request),
|
([url, request]) => fetcherUnwraperWithFilter<RoomPrice[]>(url, request),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useAPIRoomCategoryId } from "@/api/api-roomCategories";
|
import { useAPIRoomCategory } from "@/api/api-roomCategories";
|
||||||
import { Card, CardContent } from "../ui/card";
|
import { Card, CardContent } from "../ui/card";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { Typography } from "../ui/typography";
|
import { Typography } from "../ui/typography";
|
||||||
@@ -86,7 +86,7 @@ function RoomBooking({
|
|||||||
roomCategory,
|
roomCategory,
|
||||||
isLoading: isLoadingCategory,
|
isLoading: isLoadingCategory,
|
||||||
isError: isErrorCategory,
|
isError: isErrorCategory,
|
||||||
} = useAPIRoomCategoryId(roomCategoryId);
|
} = useAPIRoomCategory(roomCategoryId);
|
||||||
const {
|
const {
|
||||||
roomPriceList,
|
roomPriceList,
|
||||||
isLoading: isLoadingPrices,
|
isLoading: isLoadingPrices,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Separator } from "../ui/separator";
|
import { Separator } from "../ui/separator";
|
||||||
import { Card, CardContent } from "../ui/card";
|
import { Card, CardContent } from "../ui/card";
|
||||||
import { Typography } from "../ui/typography";
|
import { Typography } from "../ui/typography";
|
||||||
import { BedDoubleIcon, BedSingleIcon, UserIcon } from "lucide-react";
|
import { BedDouble, BedSingle, UserIcon } from "lucide-react";
|
||||||
import { RoomCategory, RoomCategoryPhoto } from "@/model/RoomCategory";
|
import { RoomCategory, RoomCategoryPhoto } from "@/model/RoomCategory";
|
||||||
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
||||||
import roomImg from "@/res/SomniaRoomImage.svg";
|
import roomImg from "@/res/SomniaRoomImage.svg";
|
||||||
@@ -16,31 +16,39 @@ const defaultRoom: RoomCategory = {
|
|||||||
id: -1,
|
id: -1,
|
||||||
name: "Sample Room",
|
name: "Sample Room",
|
||||||
description: "Lorem Ipsum",
|
description: "Lorem Ipsum",
|
||||||
bedType: "0,1",
|
|
||||||
maxGuestNum: 2,
|
maxGuestNum: 2,
|
||||||
roomCategoryDetails: [],
|
orderHomePage: undefined,
|
||||||
roomCategoryPhotos: [],
|
roomCategoryPhotos: [],
|
||||||
|
roomCategoryBedTypes: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export function RoomItemCard({
|
export function RoomItemCard({
|
||||||
room = defaultRoom,
|
room = defaultRoom,
|
||||||
className,
|
className,
|
||||||
}: RoomItemCardProps) {
|
}: RoomItemCardProps) {
|
||||||
const mainPhoto: RoomCategoryPhoto | undefined = room.roomCategoryPhotos.find(
|
//FIXME: Use PhotoOrder.
|
||||||
(element) => {
|
const mainPhoto: RoomCategoryPhoto | undefined =
|
||||||
return (element.kind = "main");
|
room.roomCategoryPhotos.length > 0
|
||||||
},
|
? room.roomCategoryPhotos.at(0)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const bedTypeIconList = room.roomCategoryBedTypes.map((e) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<IconWithTooltip
|
||||||
|
key={room.id.toString() + e.bedTypeIcon}
|
||||||
|
tooltipText={e.bedTypeName}
|
||||||
|
label={e.amount.toString()}
|
||||||
|
>
|
||||||
|
{e.bedTypeIcon.includes("bed-single") ? <BedSingle></BedSingle> : <BedDouble></BedDouble> }
|
||||||
|
|
||||||
|
</IconWithTooltip>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
const bedTypeList: number[] = room.bedType
|
});
|
||||||
.split(",")
|
|
||||||
.map((e) => Number.parseInt(e));
|
|
||||||
const hasSingleBed: boolean =
|
|
||||||
bedTypeList.at(0) !== undefined && bedTypeList[0] > 0;
|
|
||||||
const hasDoubleBed: boolean =
|
|
||||||
bedTypeList.at(1) !== undefined && bedTypeList[1] > 0;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card id={room.id.toString()} className={cn(className, "relative")}>
|
<Card key={room.id} className={cn(className, "relative")}>
|
||||||
{/* <CardHeader className="p-0 m-0 mb-5">
|
{/* <CardHeader className="p-0 m-0 mb-5">
|
||||||
</CardHeader> */}
|
</CardHeader> */}
|
||||||
<CardContent className="flex h-full w-full flex-col p-0">
|
<CardContent className="flex h-full w-full flex-col p-0">
|
||||||
@@ -64,26 +72,7 @@ export function RoomItemCard({
|
|||||||
<div className="mt-auto pb-4">
|
<div className="mt-auto pb-4">
|
||||||
<Separator className="my-4" />
|
<Separator className="my-4" />
|
||||||
<div className="flex justify-around">
|
<div className="flex justify-around">
|
||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">{bedTypeIconList}</div>
|
||||||
{hasSingleBed && (
|
|
||||||
<IconWithTooltip
|
|
||||||
tooltipText="Single bed"
|
|
||||||
label={bedTypeList[0]?.toString()}
|
|
||||||
>
|
|
||||||
<BedSingleIcon />
|
|
||||||
</IconWithTooltip>
|
|
||||||
)}
|
|
||||||
{hasDoubleBed && (
|
|
||||||
<>
|
|
||||||
<IconWithTooltip
|
|
||||||
tooltipText="Double bed"
|
|
||||||
label={bedTypeList[1]?.toString()}
|
|
||||||
>
|
|
||||||
<BedDoubleIcon />
|
|
||||||
</IconWithTooltip>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-row">
|
<div className="flex flex-row">
|
||||||
<IconWithTooltip
|
<IconWithTooltip
|
||||||
tooltipText="Max. gests"
|
tooltipText="Max. gests"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Typography } from "../ui/typography";
|
|||||||
import { differenceInDays } from "date-fns";
|
import { differenceInDays } from "date-fns";
|
||||||
import { Separator } from "../ui/separator";
|
import { Separator } from "../ui/separator";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { useAPIRoomCategories } from "@/api/api-roomCategories";
|
import { useAPIRoomCategoryList } from "@/api/api-roomCategories";
|
||||||
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
||||||
import { UserIcon } from "lucide-react";
|
import { UserIcon } from "lucide-react";
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ export function BookingDetails({
|
|||||||
mode: BookingDetailsModes;
|
mode: BookingDetailsModes;
|
||||||
}) {
|
}) {
|
||||||
const bookingData = useAppStore((state) => state.newBookingData);
|
const bookingData = useAppStore((state) => state.newBookingData);
|
||||||
const roomCategoryList = useAPIRoomCategories();
|
const roomCategoryList = useAPIRoomCategoryList();
|
||||||
|
|
||||||
const onBtBookingClick = () => {
|
const onBtBookingClick = () => {
|
||||||
if (onBookingConfirm) {
|
if (onBookingConfirm) {
|
||||||
|
|||||||
+10
-11
@@ -1,22 +1,21 @@
|
|||||||
export type RoomCategory = {
|
export type RoomCategory = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string | undefined;
|
||||||
bedType: string;
|
|
||||||
maxGuestNum: number;
|
maxGuestNum: number;
|
||||||
|
orderHomePage: number | undefined;
|
||||||
roomCategoryPhotos: RoomCategoryPhoto[];
|
roomCategoryPhotos: RoomCategoryPhoto[];
|
||||||
roomCategoryDetails: RoomCategoryDetails[];
|
roomCategoryBedTypes: RoomCategoryBedType[];
|
||||||
};
|
|
||||||
|
|
||||||
export type RoomCategoryDetails = {
|
|
||||||
id: number;
|
|
||||||
detailsSection: string;
|
|
||||||
detailValue: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RoomCategoryPhoto = {
|
export type RoomCategoryPhoto = {
|
||||||
id: number;
|
|
||||||
path: string;
|
path: string;
|
||||||
altText: string | undefined;
|
altText: string | undefined;
|
||||||
kind: string;
|
photoOrder: string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RoomCategoryBedType = {
|
||||||
|
amount: number;
|
||||||
|
bedTypeName: string;
|
||||||
|
bedTypeIcon: string;
|
||||||
|
}
|
||||||
@@ -9,7 +9,8 @@ export type RoomPrice = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type AvailabilityRequest = {
|
export type AvailabilityRequest = {
|
||||||
filter: AvailabilityFilter;
|
startDate: string;
|
||||||
|
endDate: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AvailabilityFilter = {
|
export type AvailabilityFilter = {
|
||||||
@@ -18,7 +19,9 @@ export type AvailabilityFilter = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type FareRequest = {
|
export type FareRequest = {
|
||||||
filter: FareFilter;
|
roomCategory: number;
|
||||||
|
startDate: string;
|
||||||
|
endDate: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FareFilter = {
|
export type FareFilter = {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useAPIRoomCategories } from "@/api/api-roomCategories";
|
import { useAPIRoomCategoryList } from "@/api/api-roomCategories";
|
||||||
import { RoomItemCard } from "@/components/Rooms/room-item-card";
|
import { RoomItemCard } from "@/components/Rooms/room-item-card";
|
||||||
import { SearchFilterCard } from "@/components/Search/SearchFilterCard";
|
import { SearchFilterCard } from "@/components/Search/SearchFilterCard";
|
||||||
import BackendConnectionStatus from "@/components/backend-conection-status";
|
import BackendConnectionStatus from "@/components/backend-conection-status";
|
||||||
@@ -12,7 +12,7 @@ import { LoaderIcon } from "lucide-react";
|
|||||||
import "./home-page.css";
|
import "./home-page.css";
|
||||||
|
|
||||||
function Homepage() {
|
function Homepage() {
|
||||||
const { roomCategoryList, isLoading, isError } = useAPIRoomCategories();
|
const { roomCategoryList, isLoading, isError } = useAPIRoomCategoryList();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const onBtSearchClick = (filter: SearchFilter) => {
|
const onBtSearchClick = (filter: SearchFilter) => {
|
||||||
@@ -22,7 +22,6 @@ function Homepage() {
|
|||||||
const roomList = roomCategoryList?.map((element: RoomCategory) => {
|
const roomList = roomCategoryList?.map((element: RoomCategory) => {
|
||||||
return <RoomItemCard key={element.id} room={element} />;
|
return <RoomItemCard key={element.id} room={element} />;
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h1"}>Somnia Rooms</Typography>
|
<Typography variant={"h1"}>Somnia Rooms</Typography>
|
||||||
|
|||||||
@@ -48,9 +48,6 @@ function SearchPage() {
|
|||||||
const isError = isErrorAvailability;
|
const isError = isErrorAvailability;
|
||||||
|
|
||||||
const onBtSearchClick = (newFilter: SearchFilter) => {
|
const onBtSearchClick = (newFilter: SearchFilter) => {
|
||||||
console.log("onBtSearchClick: ");
|
|
||||||
console.log(newFilter);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
newFilter.dateRange &&
|
newFilter.dateRange &&
|
||||||
newFilter.dateRange.from &&
|
newFilter.dateRange.from &&
|
||||||
@@ -58,10 +55,17 @@ function SearchPage() {
|
|||||||
) {
|
) {
|
||||||
setIsSearched(true);
|
setIsSearched(true);
|
||||||
|
|
||||||
resetBooking(newFilter.dateRange.from, newFilter.dateRange.to);
|
resetBooking(makeDayUTCDate(newFilter.dateRange.from), makeDayUTCDate(newFilter.dateRange.to));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODOME: Hay que dar una vuelta a esta solución
|
||||||
|
// - Mirar cómo trabajar con tiempos UTC desde el principio.
|
||||||
|
// - En cualquier caso, mover esta función a otro lugar.
|
||||||
|
const makeDayUTCDate = (date : Date) : Date => {
|
||||||
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
|
||||||
|
}
|
||||||
|
|
||||||
const onBookingContinue = () => {
|
const onBookingContinue = () => {
|
||||||
navigate("/book");
|
navigate("/book");
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user