Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5676262692 | ||
|
|
d3358c7c58 | ||
|
|
4e825c7ca7 | ||
|
|
b83af1b872 | ||
|
|
f8365e05af | ||
|
|
0039b09d98 | ||
|
|
e9b67efd46 | ||
|
|
0047099742 |
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
node_modules
|
node_modules
|
||||||
build
|
build
|
||||||
.dockerignore
|
.dockerignore
|
||||||
Dockerfile
|
Dockerfile
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# App config Variables (Will be visible by client):
|
||||||
|
VITE_BACKEND_HOST=SOMNIAROOMS_BACKEND_HOST
|
||||||
|
VITE_BACKEND_PORT=SOMNIAROOMS_BACKEND_PORT
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request: ~
|
||||||
|
workflow_dispatch: ~
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
lint:
|
||||||
|
name: Docker Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Lint Dockerfile
|
||||||
|
uses: hadolint/[email protected]
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
name: Publish_on_Tag
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- devbuild_*
|
||||||
|
workflow_dispatch: ~
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build and Push
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
with:
|
||||||
|
platforms: arm64
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to local registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{vars.REGISTRY_INSTANCE}}
|
||||||
|
username: ${{gitea.repository_owner}}
|
||||||
|
password: ${{secrets.REGISTRY_TOKEN}} # It should be a user/org token with package perms.
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{vars.REGISTRY_INSTANCE}}/somnia/somniaroomsapp:devbuild
|
||||||
|
target: final-prod
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
secrets: |
|
||||||
|
GIT_AUTH_TOKEN=${{secrets.REGISTRY_TOKEN}}
|
||||||
+4
-2
@@ -14,11 +14,13 @@ CMD ["npm", "run", "dev"]
|
|||||||
|
|
||||||
# Build app for production.
|
# Build app for production.
|
||||||
FROM app-base as builder
|
FROM app-base as builder
|
||||||
RUN npm ci
|
RUN npm ci && npm run build
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
# production environment
|
# production environment
|
||||||
FROM nginx:stable-alpine as final-prod
|
FROM nginx:stable-alpine as final-prod
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
COPY /public /usr/share/nginx/html/public
|
||||||
|
COPY scripts/env.sh /docker-entrypoint.d/env.sh
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
RUN chmod +x /docker-entrypoint.d/env.sh
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|||||||
@@ -30,4 +30,31 @@ docker build -t somniarooms-app:prod --target final-prod .
|
|||||||
**Docker Run**
|
**Docker Run**
|
||||||
```
|
```
|
||||||
docker run -d -it -p 8080:80 --name somniarooms-app somniarooms-app:prod
|
docker run -d -it -p 8080:80 --name somniarooms-app somniarooms-app:prod
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Docker run with env vars:**
|
||||||
|
```
|
||||||
|
docker run -d -it -p 8080:80 --name somniarooms-app -e SOMNIAROOMS_BACKEND_HOST=https://somniaapi.example.org/ -e SOMNIAROOMS_BACKEND_PORT=443 somniarooms-app:prod
|
||||||
|
```
|
||||||
|
|
||||||
|
## Env Vars.
|
||||||
|
As this is distributed as a docker image ready to use, you must set some env variables to configure the app:
|
||||||
|
|
||||||
|
| Var | Default Value | Description |
|
||||||
|
| :------------------------: | :----------------------------: | :------------------------------------------------------------------------------------------: |
|
||||||
|
| `SOMNIAROOMS_BACKEND_HOST` | https://somniaapi.example.org/ | Host where uses can connect to the SomniaRoom API. API endpoint should be reachble for uses. |
|
||||||
|
| `SOMNIAROOMS_BACKEND_PORT` | 443 | Port to SomniarRooms API. |
|
||||||
|
|
||||||
|
## .env files
|
||||||
|
|
||||||
|
This project uses .env files to configure the app. As Vite only supports compile-time vars, we use some tricks to allow setting variables from container env variables.
|
||||||
|
|
||||||
|
### .env
|
||||||
|
Contains default values. It is just an example configuration.
|
||||||
|
|
||||||
|
For development is recomended to create a `.env.local` file based on `.env`.
|
||||||
|
|
||||||
|
### .env.production
|
||||||
|
Set varibles to certains placeholder, that are replace on container startup.
|
||||||
|
|
||||||
|
(We are using this solution: https://stackoverflow.com/a/77454537)
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/SR2.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Vite + React + TS</title>
|
<title>Vite + React + TS</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
for i in $(env | grep SOMNIAROOMS_)
|
||||||
|
do
|
||||||
|
key=$(echo $i | cut -d '=' -f 1)
|
||||||
|
value=$(echo $i | cut -d '=' -f 2-)
|
||||||
|
echo $key=$value
|
||||||
|
# sed All files
|
||||||
|
# find /usr/share/nginx/html -type f -exec sed -i "s|${key}|${value}|g" '{}' +
|
||||||
|
|
||||||
|
# sed JS and CSS only
|
||||||
|
find /usr/share/nginx/html -type f \( -name '*.js' -o -name '*.css' \) -exec sed -i "s|${key}|${value}|g" '{}' +
|
||||||
|
done
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { NewBooking, NewBookingResponse } from "@/model/Bookings";
|
||||||
|
import { fetcherWithFilter } from "./backend";
|
||||||
|
|
||||||
|
export async function APISendCreateBooking(bookingData: NewBooking | null) {
|
||||||
|
|
||||||
|
if (!bookingData) {
|
||||||
|
return {
|
||||||
|
bookingResponse: null,
|
||||||
|
isError: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const rs = await fetcherWithFilter<NewBookingResponse>("/api/booking/create", bookingData);
|
||||||
|
|
||||||
|
return {
|
||||||
|
bookingResponse: rs,
|
||||||
|
isError: false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,8 +29,8 @@ export function SearchFilterCard({ onSearchClick }: { onSearchClick?: funOnSearc
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSearchFilter(location.state);
|
setSearchFilter(location.state);
|
||||||
}, [location]);
|
}, [location]);
|
||||||
|
|
||||||
|
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
// Validate and call callback on btSearch click.
|
// Validate and call callback on btSearch click.
|
||||||
@@ -69,13 +69,27 @@ export function SearchFilterCard({ onSearchClick }: { onSearchClick?: funOnSearc
|
|||||||
console.log("SearchFilterCard filter UPDATED");
|
console.log("SearchFilterCard filter UPDATED");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const datePickerElement = searchFilter == null ? (
|
||||||
|
<DatePickerWithRange
|
||||||
|
updateDateRange={updateDateRange}
|
||||||
|
allowPast={false}>
|
||||||
|
</DatePickerWithRange>
|
||||||
|
) : (
|
||||||
|
<DatePickerWithRange
|
||||||
|
updateDateRange={updateDateRange}
|
||||||
|
allowPast={false}
|
||||||
|
startDate={searchFilter.dateRange.from}
|
||||||
|
endDate={searchFilter.dateRange.to}>
|
||||||
|
</DatePickerWithRange>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="p-0 m-0 mb-5">
|
<CardHeader className="p-0 m-0 mb-5">
|
||||||
<Typography variant={"h2"} as="h1" className="mx-5 py-2">Reserva ahora</Typography>
|
<Typography variant={"h2"} as="h1" className="mx-5 py-2">Reserva ahora</Typography>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<DatePickerWithRange updateDateRange={updateDateRange}></DatePickerWithRange>
|
{datePickerElement}
|
||||||
<Separator className="my-4" />
|
<Separator className="my-4" />
|
||||||
<Button size={"lg"} onClick={btSearchClick}>
|
<Button size={"lg"} onClick={btSearchClick}>
|
||||||
<SearchIcon className="text-primary-foreground me-2" />
|
<SearchIcon className="text-primary-foreground me-2" />
|
||||||
|
|||||||
@@ -9,20 +9,18 @@ function AppHeader() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="flex items-center mx-10 my-4">
|
<Card className="flex items-center mx-10 my-4">
|
||||||
<CardContent className="w-full">
|
<CardContent className="w-full py-2">
|
||||||
<div className="flex justify-around items-center">
|
<div className="flex justify-around items-center">
|
||||||
<div className="flex flex-row items-center gap-2 relative">
|
<div className="flex flex-row items-center gap-2 relative">
|
||||||
<img src="public/SR2.svg" className="w-[64px]"></img>
|
<img src="public/SR2.svg" className="w-[64px]"></img>
|
||||||
<Typography variant={"largeText"}>Somnia Rooms</Typography>
|
<Typography variant={"largeText"}>Somnia Rooms</Typography>
|
||||||
<a href="https://duck.com" className="absolute w-[100%] h-[100%]"></a>
|
<a href="https://duck.com" className="absolute w-[100%] h-[100%]"></a>
|
||||||
</div>
|
</div>
|
||||||
<Button variant="ghost">
|
<Button variant="ghost" className="h-15">
|
||||||
<HomeIcon />
|
<Link to={`home`}><HomeIcon className="mx-auto" />Home</Link>
|
||||||
<Link to={`home`}>Home</Link>
|
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost">
|
<Button variant="ghost" className="h-15">
|
||||||
<BookAIcon />
|
<Link to={`search`}><BookAIcon className="mx-auto" />Reservar</Link>
|
||||||
<Link to={`search`}>Reservar</Link>
|
|
||||||
</Button>
|
</Button>
|
||||||
<ModeToggle />
|
<ModeToggle />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from ".
|
|||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
|
|
||||||
type OnBookingClickFunction = () => void;
|
type OnBookingClickFunction = () => void;
|
||||||
|
type BookingDetailsModes = "Book" | "View"
|
||||||
|
|
||||||
export function BookingDetails({ onBookingConfirm }: { onBookingConfirm?: OnBookingClickFunction }) {
|
export function BookingDetails({ onBookingConfirm, mode }: { onBookingConfirm?: OnBookingClickFunction, mode: BookingDetailsModes }) {
|
||||||
|
|
||||||
const bookingData = useAppStore((state) => state.newBookingData);
|
const bookingData = useAppStore((state) => state.newBookingData);
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ export function BookingDetails({ onBookingConfirm }: { onBookingConfirm?: OnBook
|
|||||||
<TableCell>{room.guestNumber}</TableCell>
|
<TableCell>{room.guestNumber}</TableCell>
|
||||||
<TableCell>{room.amount}</TableCell>
|
<TableCell>{room.amount}</TableCell>
|
||||||
<TableCell>{room.price / 100} €</TableCell>
|
<TableCell>{room.price / 100} €</TableCell>
|
||||||
|
<TableCell>{(room.price * room.amount) / 100} €</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
@@ -50,7 +52,8 @@ export function BookingDetails({ onBookingConfirm }: { onBookingConfirm?: OnBook
|
|||||||
<TableHead>Room</TableHead>
|
<TableHead>Room</TableHead>
|
||||||
<TableHead>Guests</TableHead>
|
<TableHead>Guests</TableHead>
|
||||||
<TableHead>Quantity</TableHead>
|
<TableHead>Quantity</TableHead>
|
||||||
<TableHead>Price</TableHead>
|
<TableHead>Unit price</TableHead>
|
||||||
|
<TableHead>Total price</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
@@ -60,7 +63,7 @@ export function BookingDetails({ onBookingConfirm }: { onBookingConfirm?: OnBook
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const totalPrice = bookingData.rooms.reduce((acc, room) => (acc + room.price), 0);
|
const totalPrice = bookingData.rooms.reduce((acc, room) => (acc + (room.price * room.amount)), 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
@@ -80,9 +83,12 @@ export function BookingDetails({ onBookingConfirm }: { onBookingConfirm?: OnBook
|
|||||||
<Separator className="my-2"></Separator>
|
<Separator className="my-2"></Separator>
|
||||||
<Typography variant={"h3"}>Total Price</Typography>
|
<Typography variant={"h3"}>Total Price</Typography>
|
||||||
<Typography variant={"h3"}>{totalPrice / 100} €</Typography>
|
<Typography variant={"h3"}>{totalPrice / 100} €</Typography>
|
||||||
<Button className="my-2" onClick={onBtBookingClick}>
|
{
|
||||||
<Typography variant={"largeText"} className="text-primary-foreground">Book it!</Typography>
|
mode == "Book" &&
|
||||||
</Button>
|
<Button className="my-2" onClick={onBtBookingClick}>
|
||||||
|
<Typography variant={"largeText"} className="text-primary-foreground">Book it!</Typography>
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons"
|
import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons"
|
||||||
import { DayPicker } from "react-day-picker"
|
import { DayPicker } from "react-day-picker"
|
||||||
@@ -59,8 +58,8 @@ function Calendar({
|
|||||||
...classNames,
|
...classNames,
|
||||||
}}
|
}}
|
||||||
components={{
|
components={{
|
||||||
IconLeft: ({ ...props }) => <ChevronLeftIcon className="h-4 w-4" />,
|
IconLeft: () => <ChevronLeftIcon className="h-4 w-4" />,
|
||||||
IconRight: ({ ...props }) => <ChevronRightIcon className="h-4 w-4" />,
|
IconRight: () => <ChevronRightIcon className="h-4 w-4" />,
|
||||||
}}
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -18,12 +18,15 @@ import { Typography } from "./typography"
|
|||||||
export type UpdateRangeFunction = (newRange: DateRange) => void;
|
export type UpdateRangeFunction = (newRange: DateRange) => void;
|
||||||
|
|
||||||
export function DatePickerWithRange({
|
export function DatePickerWithRange({
|
||||||
className, updateDateRange
|
className, updateDateRange, startDate, endDate, allowPast = true
|
||||||
}: { className?: React.HTMLAttributes<HTMLDivElement> | undefined, updateDateRange: UpdateRangeFunction | undefined }) {
|
}: {
|
||||||
|
className?: React.HTMLAttributes<HTMLDivElement> | undefined, updateDateRange: UpdateRangeFunction | undefined,
|
||||||
|
startDate?: Date, endDate?: Date, allowPast?: boolean
|
||||||
|
}) {
|
||||||
// Date Range State.
|
// Date Range State.
|
||||||
const [dateRange, setDateRange] = React.useState<DateRange | undefined>({
|
const [dateRange, setDateRange] = React.useState<DateRange | undefined>({
|
||||||
from: undefined,
|
from: startDate,
|
||||||
to: undefined,
|
to: endDate,
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODOME: Si el día es mods.outside, navegar al mes correspondiente.
|
//TODOME: Si el día es mods.outside, navegar al mes correspondiente.
|
||||||
@@ -61,6 +64,11 @@ export function DatePickerWithRange({
|
|||||||
beforeAndSelected = [beforeMatcher, dateMatcher];
|
beforeAndSelected = [beforeMatcher, dateMatcher];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pastMatcher: DateBefore | undefined = undefined;
|
||||||
|
if (!allowPast) {
|
||||||
|
pastMatcher = { before: new Date() };
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("grid gap-x-2 grid-cols-2 grid-rows-2", className)}>
|
<div className={cn("grid gap-x-2 grid-cols-2 grid-rows-2", className)}>
|
||||||
<Typography variant={"largeText"} as="p">Desde</Typography>
|
<Typography variant={"largeText"} as="p">Desde</Typography>
|
||||||
@@ -91,6 +99,7 @@ export function DatePickerWithRange({
|
|||||||
selected={dateRange?.from}
|
selected={dateRange?.from}
|
||||||
onDayClick={handleDayClickFrom}
|
onDayClick={handleDayClickFrom}
|
||||||
numberOfMonths={1}
|
numberOfMonths={1}
|
||||||
|
disabled={pastMatcher}
|
||||||
/>
|
/>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import ErrorPage from './error-page';
|
|||||||
import Homepage from './routes/home-page';
|
import Homepage from './routes/home-page';
|
||||||
import SearchPage from './routes/search-page';
|
import SearchPage from './routes/search-page';
|
||||||
import BookPage from './routes/book-page';
|
import BookPage from './routes/book-page';
|
||||||
|
import SuccessPage from './routes/success-page';
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
@@ -29,6 +30,10 @@ const router = createBrowserRouter([
|
|||||||
{
|
{
|
||||||
path: "/book",
|
path: "/book",
|
||||||
element: <BookPage />
|
element: <BookPage />
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/success",
|
||||||
|
element: <SuccessPage />
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,4 +18,8 @@ export type NewBookingRoom = {
|
|||||||
guestNumber: number,
|
guestNumber: number,
|
||||||
amount: number,
|
amount: number,
|
||||||
price: number
|
price: number
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type NewBookingResponse = {
|
||||||
|
refNumber: number,
|
||||||
|
}
|
||||||
+97
-11
@@ -1,12 +1,86 @@
|
|||||||
|
import { APISendCreateBooking } from "@/api/api-booking"
|
||||||
import { BookingDetails } from "@/components/booking/booking-details"
|
import { BookingDetails } from "@/components/booking/booking-details"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { Label } from "@/components/ui/label"
|
import { Label } from "@/components/ui/label"
|
||||||
import { Separator } from "@/components/ui/separator"
|
import { Separator } from "@/components/ui/separator"
|
||||||
import { Typography } from "@/components/ui/typography"
|
import { Typography } from "@/components/ui/typography"
|
||||||
|
import { useToast } from "@/components/ui/use-toast"
|
||||||
|
import { useAppStore } from "@/store"
|
||||||
|
import { ChangeEvent, useState } from "react"
|
||||||
|
import { useNavigate } from "react-router-dom"
|
||||||
|
|
||||||
|
enum PageState {
|
||||||
|
noData, showForm, sending, created, error
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function BookPage() {
|
function BookPage() {
|
||||||
|
const [pageState, setPageState] = useState<PageState>(PageState.showForm);
|
||||||
|
const bookingData = useAppStore((state) => state.newBookingData)
|
||||||
|
const setCustomerData = useAppStore((state) => state.setBookingCustomer);
|
||||||
|
const { toast } = useToast();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
if (!bookingData || !bookingData.customerDetails) {
|
||||||
|
return (
|
||||||
|
<Typography variant={"h2"}>You must select some rooms...</Typography>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOnChange(e: ChangeEvent<HTMLInputElement>) {
|
||||||
|
if (bookingData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newCustomerData = bookingData.customerDetails;
|
||||||
|
|
||||||
|
switch (e.target.name) {
|
||||||
|
case "name":
|
||||||
|
newCustomerData.name = e.target.value;
|
||||||
|
break;
|
||||||
|
case "surname":
|
||||||
|
newCustomerData.surname = e.target.value;
|
||||||
|
break;
|
||||||
|
case "email":
|
||||||
|
newCustomerData.email = e.target.value;
|
||||||
|
break;
|
||||||
|
case "phoneNumber":
|
||||||
|
newCustomerData.phoneNumber = e.target.value;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCustomerData(newCustomerData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOnBookingSubmit() {
|
||||||
|
const customerDetails = bookingData?.customerDetails;
|
||||||
|
|
||||||
|
if (!customerDetails ||
|
||||||
|
customerDetails.name == "" || customerDetails.surname == "" || customerDetails.phoneNumber == "" || customerDetails.email == "") {
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Uh oh! You must fill all fields.",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setPageState(PageState.sending);
|
||||||
|
console.log(bookingData);
|
||||||
|
|
||||||
|
sendCreateRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
const sendCreateRequest = async () => {
|
||||||
|
const rs = await APISendCreateBooking(bookingData);
|
||||||
|
if (rs.isError) {
|
||||||
|
setPageState(PageState.error);
|
||||||
|
} else {
|
||||||
|
navigate("/success", { state: rs.bookingResponse })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -16,21 +90,33 @@ function BookPage() {
|
|||||||
<div>
|
<div>
|
||||||
<Typography variant={"h3"}>Personal Details</Typography>
|
<Typography variant={"h3"}>Personal Details</Typography>
|
||||||
<div>
|
<div>
|
||||||
<Label>Name</Label>
|
<div>
|
||||||
<Input></Input>
|
<Label htmlFor="name">Name</Label>
|
||||||
<Label>Surname</Label>
|
<Input type="text" name="name" id="name" placeholder="Name" value={bookingData.customerDetails.name ?? ""}
|
||||||
<Input></Input>
|
onChange={handleOnChange} />
|
||||||
<Label>Email</Label>
|
</div>
|
||||||
<Input></Input>
|
<div>
|
||||||
<Label>Phone Number</Label>
|
<Label htmlFor="surname">Surname</Label>
|
||||||
<Input></Input>
|
<Input type="text" name="surname" id="surname" placeholder="Surname" value={bookingData.customerDetails.surname ?? ""}
|
||||||
|
onChange={handleOnChange} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Label htmlFor="email">Email</Label>
|
||||||
|
<Input type="email" name="email" id="email" placeholder="Email" value={bookingData.customerDetails.email ?? ""}
|
||||||
|
onChange={handleOnChange} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Label htmlFor="phone">Phone Number</Label>
|
||||||
|
<Input type="tel" name="phoneNumber" id="phone" placeholder="Number" value={bookingData.customerDetails.phoneNumber ?? ""}
|
||||||
|
onChange={handleOnChange} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
<BookingDetails></BookingDetails>
|
<BookingDetails mode="View"></BookingDetails>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
<Button>
|
<Button onClick={handleOnBookingSubmit} disabled={pageState == PageState.sending}>
|
||||||
<Typography variant={"h3"} className="text-primary-foreground">Book it now!</Typography>
|
<Typography variant={"h3"} className="text-primary-foreground">Book it now!</Typography>
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ function Homepage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h1"}>Hostal del Val</Typography>
|
<Typography variant={"h1"}>Somnia Rooms</Typography>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
<SearchFilterCard onSearchClick={onBtSearchClick}/>
|
<SearchFilterCard onSearchClick={onBtSearchClick}/>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ function SearchPage() {
|
|||||||
{hasRooms ? roomList : (isSearched && noRoomsAvailable)}
|
{hasRooms ? roomList : (isSearched && noRoomsAvailable)}
|
||||||
</div>
|
</div>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
<BookingDetails onBookingConfirm={onBookingContinue}></BookingDetails>
|
<BookingDetails onBookingConfirm={onBookingContinue} mode={"Book"}></BookingDetails>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
<BackendConnectionStatus isLoading={isLoading} isError={isError} />
|
<BackendConnectionStatus isLoading={isLoading} isError={isError} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Card, CardContent, CardHeader } from "@/components/ui/card"
|
||||||
|
import { Typography } from "@/components/ui/typography"
|
||||||
|
import { NewBookingResponse } from "@/model/Bookings"
|
||||||
|
import { useAppStore } from "@/store"
|
||||||
|
import { addDays } from "date-fns"
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import { useLocation, useNavigate } from "react-router-dom"
|
||||||
|
|
||||||
|
function SuccessPage() {
|
||||||
|
|
||||||
|
const [pageState, setPageState] = useState<NewBookingResponse|null>(null)
|
||||||
|
const resetBookingState = useAppStore((state) => state.resetBookingState);
|
||||||
|
|
||||||
|
const location = useLocation();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if(location.state == null) {
|
||||||
|
navigate("/home");
|
||||||
|
}
|
||||||
|
setPageState(location.state);
|
||||||
|
|
||||||
|
}, [location, navigate])
|
||||||
|
|
||||||
|
const handleBtBackClick = () => {
|
||||||
|
resetBookingState(new Date(), addDays(new Date(), 2));
|
||||||
|
navigate("/home");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<Typography variant={"h2"}>Booking Completed</Typography>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Typography variant={"largeText"}>Booking ref: {pageState?.refNumber}</Typography>
|
||||||
|
<Button className="my-4" onClick={handleBtBackClick}>
|
||||||
|
<Typography variant={"largeText"} className="text-primary-foreground">Go Back</Typography>
|
||||||
|
</Button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SuccessPage
|
||||||
+17
-2
@@ -1,6 +1,6 @@
|
|||||||
import { create } from 'zustand'
|
import { create } from 'zustand'
|
||||||
import { SearchFilter } from './model/SearchFilter'
|
import { SearchFilter } from './model/SearchFilter'
|
||||||
import { NewBooking, NewBookingRoom } from './model/Bookings'
|
import { NewBooking, NewBookingCustomerDetails, NewBookingRoom } from './model/Bookings'
|
||||||
|
|
||||||
interface AppState {
|
interface AppState {
|
||||||
searchFilter: SearchFilter
|
searchFilter: SearchFilter
|
||||||
@@ -9,6 +9,7 @@ interface AppState {
|
|||||||
setNewBooking: (newBooking: NewBooking) => void
|
setNewBooking: (newBooking: NewBooking) => void
|
||||||
resetBookingState: (arrival: Date, departure: Date) => void
|
resetBookingState: (arrival: Date, departure: Date) => void
|
||||||
addNewBookingRoom: (newRoom: NewBookingRoom) => void
|
addNewBookingRoom: (newRoom: NewBookingRoom) => void
|
||||||
|
setBookingCustomer: (newCustomer: NewBookingCustomerDetails) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultSearchFilter: SearchFilter = {
|
const defaultSearchFilter: SearchFilter = {
|
||||||
@@ -68,6 +69,18 @@ function addNewBookingRoomToCurrentState(newRoom: NewBookingRoom, currentState:
|
|||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setBookingCustomer(newCustomer: NewBookingCustomerDetails, currentState: NewBooking | null) {
|
||||||
|
if(currentState == null) {
|
||||||
|
return currentState;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newState: NewBooking = {
|
||||||
|
...currentState,
|
||||||
|
customerDetails: newCustomer
|
||||||
|
};
|
||||||
|
return newState;
|
||||||
|
}
|
||||||
|
|
||||||
export const useAppStore = create<AppState>()((set) => ({
|
export const useAppStore = create<AppState>()((set) => ({
|
||||||
searchFilter: defaultSearchFilter,
|
searchFilter: defaultSearchFilter,
|
||||||
setSearchFilter: (newFilter) => set(() => ({ searchFilter: newFilter })),
|
setSearchFilter: (newFilter) => set(() => ({ searchFilter: newFilter })),
|
||||||
@@ -76,5 +89,7 @@ export const useAppStore = create<AppState>()((set) => ({
|
|||||||
resetBookingState: (arrival, departure) =>
|
resetBookingState: (arrival, departure) =>
|
||||||
set(() => ({ newBookingData: getDefaultBookingData(arrival, departure) })),
|
set(() => ({ newBookingData: getDefaultBookingData(arrival, departure) })),
|
||||||
addNewBookingRoom: (newRoom: NewBookingRoom) =>
|
addNewBookingRoom: (newRoom: NewBookingRoom) =>
|
||||||
set((state) => ({ newBookingData: addNewBookingRoomToCurrentState(newRoom, state.newBookingData) }))
|
set((state) => ({ newBookingData: addNewBookingRoomToCurrentState(newRoom, state.newBookingData) })),
|
||||||
|
setBookingCustomer: (newCustomer: NewBookingCustomerDetails) =>
|
||||||
|
set((state) => ({newBookingData: setBookingCustomer(newCustomer, state.newBookingData)}))
|
||||||
}))
|
}))
|
||||||
|
|||||||
Reference in New Issue
Block a user