Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
899d27f468 | ||
|
|
90fa82234d | ||
|
|
b8ec6f7bdd | ||
|
|
94312de6e2 | ||
|
|
d4094d09c6 | ||
|
|
42437881c4 | ||
|
|
5d2eb2e635 | ||
|
|
2b3d1eafd3 | ||
|
|
70e483bc45 | ||
|
|
99653371a8 | ||
|
|
3e77426d1d | ||
|
|
550beffba8 | ||
|
|
590d7f6fa1 | ||
|
|
4c21dc2764 | ||
|
|
4d01112006 | ||
|
|
984c386588 | ||
|
|
0efe5bfa9e | ||
|
|
7ba7c4b04b | ||
|
|
bb53ba6cb4 | ||
|
|
57dcbdec14 | ||
|
|
825dc4365f | ||
|
|
67f9e19eb8 | ||
|
|
06c1af92b3 | ||
|
|
532337a46a | ||
|
|
191379ed03 | ||
|
|
f476f4307a | ||
|
|
dedfc1cdd8 | ||
|
|
2d2992593a | ||
|
|
b034d2e9c9 | ||
|
|
d4458e8f00 |
@@ -1,18 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
root: true,
|
|
||||||
env: { browser: true, es2020: true, node: false },
|
|
||||||
extends: [
|
|
||||||
'eslint:recommended',
|
|
||||||
'plugin:@typescript-eslint/recommended',
|
|
||||||
'plugin:react-hooks/recommended',
|
|
||||||
],
|
|
||||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
|
||||||
parser: '@typescript-eslint/parser',
|
|
||||||
plugins: ['react-refresh'],
|
|
||||||
rules: {
|
|
||||||
'react-refresh/only-export-components': [
|
|
||||||
'warn',
|
|
||||||
{ allowConstantExport: true },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# EOL normalization
|
||||||
|
* text=auto
|
||||||
@@ -12,7 +12,6 @@ concurrency:
|
|||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
name: Docker Lint
|
name: Docker Lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@@ -41,5 +41,5 @@ jobs:
|
|||||||
tags: ${{vars.REGISTRY_INSTANCE}}/somnia/somniaroomsapp:devbuild
|
tags: ${{vars.REGISTRY_INSTANCE}}/somnia/somniaroomsapp:devbuild
|
||||||
target: final-prod
|
target: final-prod
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
secrets: |
|
secrets: |
|
||||||
GIT_AUTH_TOKEN=${{secrets.REGISTRY_TOKEN}}
|
GIT_AUTH_TOKEN=${{secrets.REGISTRY_TOKEN}}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Ignore artifacts:
|
||||||
|
**/dist
|
||||||
|
|
||||||
|
**/.git
|
||||||
|
**/.svn
|
||||||
|
**/.hg
|
||||||
|
**/node_modules
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"endOfLine": "auto",
|
||||||
|
"plugins": ["prettier-plugin-tailwindcss"],
|
||||||
|
"tailwindStylesheet": "./src/index.css"
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"ExpandedNodes": [
|
|
||||||
""
|
|
||||||
],
|
|
||||||
"PreviewInSolutionExplorer": false
|
|
||||||
}
|
|
||||||
Binary file not shown.
+5
-5
@@ -1,23 +1,23 @@
|
|||||||
# Base Node Environment.
|
# Base Node Environment.
|
||||||
FROM node:21.7-alpine3.19 as app-base
|
FROM node:22-alpine AS app-base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENV PATH /app/node_modules/.bin:$PATH
|
ENV PATH=/app/node_modules/.bin:$PATH
|
||||||
COPY package.json ./
|
COPY package.json ./
|
||||||
COPY package-lock.json ./
|
COPY package-lock.json ./
|
||||||
COPY . ./
|
COPY . ./
|
||||||
|
|
||||||
# Dev environment.
|
# Dev environment.
|
||||||
FROM app-base as final-dev
|
FROM app-base AS final-dev
|
||||||
RUN npm install
|
RUN npm install
|
||||||
ENV CHOKIDAR_USEPOLLING=true
|
ENV CHOKIDAR_USEPOLLING=true
|
||||||
CMD ["npm", "run", "dev"]
|
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 && npm run build
|
RUN npm ci && 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 /public /usr/share/nginx/html/public
|
||||||
COPY scripts/env.sh /docker-entrypoint.d/env.sh
|
COPY scripts/env.sh /docker-entrypoint.d/env.sh
|
||||||
|
|||||||
@@ -2,43 +2,50 @@
|
|||||||
|
|
||||||
User app for SomniaRooms.
|
User app for SomniaRooms.
|
||||||
|
|
||||||
|
## Podman Usage:
|
||||||
## Docker Usage:
|
|
||||||
|
|
||||||
### Dev
|
### Dev
|
||||||
|
|
||||||
**Build Image:**
|
**Build Image:**
|
||||||
|
|
||||||
```
|
```
|
||||||
docker build -t somniarooms-app:dev --target final-dev .
|
podman build -t somniarooms-app:dev --target final-dev .
|
||||||
```
|
```
|
||||||
|
|
||||||
**Docker Run Image:**
|
**Podman Run Image:**
|
||||||
|
|
||||||
```
|
```
|
||||||
docker run -d -it --rm -v ${PWD}:/app -v /app/node_modules -p 3000:3000 --name somniarooms-app somniarooms-app:dev
|
podman run -d -it --rm -v ${PWD}:/app -v /app/node_modules -p 3000:3000 --name somniarooms-app somniarooms-app:dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Notas:
|
Notas:
|
||||||
|
|
||||||
- Usar `-rm` para eliminar el contenedor y sus volúmenes en stop.
|
- Usar `-rm` para eliminar el contenedor y sus volúmenes en stop.
|
||||||
- Usar `-d` para modo detached.
|
- Usar `-d` para modo detached.
|
||||||
|
|
||||||
### Prod:
|
### Prod:
|
||||||
|
|
||||||
**Build Image**
|
**Build Image**
|
||||||
|
|
||||||
```
|
```
|
||||||
docker build -t somniarooms-app:prod --target final-prod .
|
podman build -t somniarooms-app:prod --target final-prod .
|
||||||
```
|
```
|
||||||
|
|
||||||
**Docker Run**
|
**Podman Run**
|
||||||
|
|
||||||
```
|
```
|
||||||
docker run -d -it -p 8080:80 --name somniarooms-app somniarooms-app:prod
|
podman run -d -it -p 8080:80 --name somniarooms-app somniarooms-app:prod
|
||||||
```
|
```
|
||||||
|
|
||||||
**Docker run with env vars:**
|
**Podman 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
|
podman 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.
|
## Env Vars.
|
||||||
As this is distributed as a docker image ready to use, you must set some env variables to configure the app:
|
|
||||||
|
As this is distributed as a image ready to use, you must set some env variables to configure the app:
|
||||||
|
|
||||||
| Var | Default Value | Description |
|
| Var | Default Value | Description |
|
||||||
| :------------------------: | :----------------------------: | :------------------------------------------------------------------------------------------: |
|
| :------------------------: | :----------------------------: | :------------------------------------------------------------------------------------------: |
|
||||||
@@ -49,12 +56,14 @@ As this is distributed as a docker image ready to use, you must set some env var
|
|||||||
|
|
||||||
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.
|
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
|
### .env
|
||||||
|
|
||||||
Contains default values. It is just an example configuration.
|
Contains default values. It is just an example configuration.
|
||||||
|
|
||||||
For development is recomended to create a `.env.local` file based on `.env`.
|
For development is recomended to create a `.env.local` file based on `.env`.
|
||||||
|
|
||||||
### .env.production
|
### .env.production
|
||||||
|
|
||||||
Set varibles to certains placeholder, that are replace on container startup.
|
Set varibles to certains placeholder, that are replace on container startup.
|
||||||
|
|
||||||
(We are using this solution: https://stackoverflow.com/a/77454537)
|
(We are using this solution: https://stackoverflow.com/a/77454537)
|
||||||
|
|||||||
+7
-4
@@ -4,7 +4,7 @@
|
|||||||
"rsc": false,
|
"rsc": false,
|
||||||
"tsx": true,
|
"tsx": true,
|
||||||
"tailwind": {
|
"tailwind": {
|
||||||
"config": "tailwind.config.js",
|
"config": "",
|
||||||
"css": "src/index.css",
|
"css": "src/index.css",
|
||||||
"baseColor": "stone",
|
"baseColor": "stone",
|
||||||
"cssVariables": true,
|
"cssVariables": true,
|
||||||
@@ -13,6 +13,9 @@
|
|||||||
"aliases": {
|
"aliases": {
|
||||||
"components": "@/components",
|
"components": "@/components",
|
||||||
"utils": "@/lib/utils",
|
"utils": "@/lib/utils",
|
||||||
"ui": "src/components/ui"
|
"ui": "@/components/ui",
|
||||||
}
|
"lib": "@/lib",
|
||||||
}
|
"hooks": "@/hooks"
|
||||||
|
},
|
||||||
|
"iconLibrary": "lucide"
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
const { defineConfig, globalIgnores } = require("eslint/config");
|
||||||
|
|
||||||
|
const globals = require("globals");
|
||||||
|
|
||||||
|
const { fixupConfigRules } = require("@eslint/compat");
|
||||||
|
|
||||||
|
const tsParser = require("@typescript-eslint/parser");
|
||||||
|
const reactRefresh = require("eslint-plugin-react-refresh");
|
||||||
|
const js = require("@eslint/js");
|
||||||
|
|
||||||
|
const { FlatCompat } = require("@eslint/eslintrc");
|
||||||
|
|
||||||
|
const compat = new FlatCompat({
|
||||||
|
baseDirectory: __dirname,
|
||||||
|
recommendedConfig: js.configs.recommended,
|
||||||
|
allConfig: js.configs.all,
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = defineConfig([
|
||||||
|
{
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
...globals.browser,
|
||||||
|
...Object.fromEntries(
|
||||||
|
Object.entries(globals.node).map(([key]) => [key, "off"]),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
parser: tsParser,
|
||||||
|
},
|
||||||
|
|
||||||
|
extends: fixupConfigRules(
|
||||||
|
compat.extends(
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"plugin:react-hooks/recommended",
|
||||||
|
"prettier",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
plugins: {
|
||||||
|
"react-refresh": reactRefresh,
|
||||||
|
},
|
||||||
|
|
||||||
|
rules: {
|
||||||
|
"react-refresh/only-export-components": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
allowConstantExport: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
globalIgnores(["**/dist", "eslint.config.cjs"]),
|
||||||
|
]);
|
||||||
Generated
+3782
-2498
File diff suppressed because it is too large
Load Diff
+37
-32
@@ -6,48 +6,53 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 && npx prettier . --check",
|
||||||
|
"pretty": "npx prettier . --write",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@radix-ui/react-checkbox": "^1.0.4",
|
"@hookform/resolvers": "^5.2.2",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
"@tailwindcss/vite": "^4.1.18",
|
||||||
"@radix-ui/react-icons": "^1.3.0",
|
"class-variance-authority": "^0.7.1",
|
||||||
"@radix-ui/react-label": "^2.0.2",
|
|
||||||
"@radix-ui/react-popover": "^1.0.7",
|
|
||||||
"@radix-ui/react-separator": "^1.0.3",
|
|
||||||
"@radix-ui/react-slot": "^1.0.2",
|
|
||||||
"@radix-ui/react-toast": "^1.1.5",
|
|
||||||
"@radix-ui/react-tooltip": "^1.0.7",
|
|
||||||
"class-variance-authority": "^0.7.0",
|
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"date-fns": "^3.6.0",
|
"date-fns": "^4.1.0",
|
||||||
"embla-carousel-react": "^8.0.2",
|
"embla-carousel-react": "^8.6.0",
|
||||||
"lucide-react": "^0.378.0",
|
"lucide-react": "^0.562.0",
|
||||||
|
"radix-ui": "^1.4.3",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-day-picker": "^8.10.1",
|
"react-day-picker": "^9.13.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-router-dom": "^6.23.0",
|
"react-hook-form": "^7.70.0",
|
||||||
"swr": "^2.2.5",
|
"react-router-dom": "^6.30.2",
|
||||||
"tailwind-merge": "^2.3.0",
|
"swr": "^2.3.8",
|
||||||
"zustand": "^4.5.2"
|
"tailwind-merge": "^3.4.0",
|
||||||
|
"zod": "^3.25.76",
|
||||||
|
"zustand": "^5.0.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.12.8",
|
"@eslint/compat": "^2.0.0",
|
||||||
|
"@eslint/eslintrc": "^3.3.3",
|
||||||
|
"@eslint/js": "^9.39.2",
|
||||||
|
"@iconify-icon/react": "^3.0.3",
|
||||||
|
"@tailwindcss/postcss": "^4.1.18",
|
||||||
|
"@types/node": "^22.15.30",
|
||||||
"@types/react": "^18.2.66",
|
"@types/react": "^18.2.66",
|
||||||
"@types/react-dom": "^18.2.22",
|
"@types/react-dom": "^18.2.22",
|
||||||
"@types/react-router-dom": "^5.3.3",
|
"@types/react-router-dom": "^5.3.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
||||||
"@typescript-eslint/parser": "^7.2.0",
|
"@typescript-eslint/parser": "^8.52.0",
|
||||||
"@vitejs/plugin-react-swc": "^3.5.0",
|
"@vitejs/plugin-react-swc": "^4.2.2",
|
||||||
"autoprefixer": "^10.4.19",
|
"eslint": "^9.39.2",
|
||||||
"eslint": "^8.57.0",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^7.0.1",
|
||||||
"eslint-plugin-react-refresh": "^0.4.6",
|
"eslint-plugin-react-refresh": "^0.4.26",
|
||||||
"postcss": "^8.4.38",
|
"globals": "^17.0.0",
|
||||||
"tailwindcss": "^3.4.3",
|
"postcss": "^8.5.6",
|
||||||
"tailwindcss-animate": "^1.0.7",
|
"prettier": "^3.7.4",
|
||||||
"typescript": "^5.2.2",
|
"prettier-plugin-tailwindcss": "^0.7.2",
|
||||||
"vite": "^5.2.0"
|
"tailwindcss": "^4.1.18",
|
||||||
|
"tw-animate-css": "^1.4.0",
|
||||||
|
"typescript": "^5.9.3",
|
||||||
|
"vite": "^6.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -1,6 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
plugins: {
|
plugins: {
|
||||||
tailwindcss: {},
|
"@tailwindcss/postcss": {},
|
||||||
autoprefixer: {},
|
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|||||||
+22
-12
@@ -2,18 +2,28 @@ import { NewBooking, NewBookingResponse } from "@/model/Bookings";
|
|||||||
import { fetcherWithFilter } from "./backend";
|
import { fetcherWithFilter } from "./backend";
|
||||||
|
|
||||||
export async function APISendCreateBooking(bookingData: NewBooking | null) {
|
export async function APISendCreateBooking(bookingData: NewBooking | null) {
|
||||||
|
if (!bookingData) {
|
||||||
|
return {
|
||||||
|
bookingResponse: null,
|
||||||
|
isError: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (!bookingData) {
|
try {
|
||||||
return {
|
const rs = await fetcherWithFilter<NewBookingResponse>(
|
||||||
bookingResponse: null,
|
"/api/booking/create",
|
||||||
isError: true
|
bookingData,
|
||||||
}
|
);
|
||||||
}
|
|
||||||
|
|
||||||
const rs = await fetcherWithFilter<NewBookingResponse>("/api/booking/create", bookingData);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bookingResponse: rs,
|
bookingResponse: rs,
|
||||||
isError: false
|
isError: false,
|
||||||
}
|
};
|
||||||
}
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
bookingResponse: null,
|
||||||
|
isError: true,
|
||||||
|
errorMessage: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { ConfigVar } from "@/model/ConfigVar";
|
||||||
|
import { fetcher, fetcherUnwraper } from "./backend";
|
||||||
|
import useSWR from "swr";
|
||||||
|
|
||||||
|
export function useAPIConfigVarList() {
|
||||||
|
const { data, error, isLoading } = useSWR<ConfigVar[]>(
|
||||||
|
"/api/config",
|
||||||
|
fetcherUnwraper,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
configVarList: data,
|
||||||
|
isLoading,
|
||||||
|
isError: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAPIConfigVar(key: string) {
|
||||||
|
const url = `/api/config/var/${key}`;
|
||||||
|
|
||||||
|
const { data, error, isLoading } = useSWR<ConfigVar>(url, fetcher);
|
||||||
|
|
||||||
|
return {
|
||||||
|
configVar: data,
|
||||||
|
isLoading,
|
||||||
|
isError: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,25 +1,28 @@
|
|||||||
import { RoomCategory } from "@/model/RoomCategory";
|
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[]>('/api/room/category', fetcherUnwraper)
|
const { data, error, isLoading } = useSWR<RoomCategory[]>(
|
||||||
|
"/api/room/category",
|
||||||
|
fetcherUnwraper,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
roomCategoryList: data,
|
roomCategoryList: data,
|
||||||
isLoading,
|
isLoading,
|
||||||
isError: error
|
isError: error,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
roomCategory: data,
|
roomCategory: data,
|
||||||
isLoading,
|
isLoading,
|
||||||
isError: error
|
isError: error,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-27
@@ -1,33 +1,35 @@
|
|||||||
import { fetcherUnwraperWithFilter } from "./backend";
|
import { fetcherUnwraperWithFilter } from "./backend";
|
||||||
import useSWR from 'swr';
|
import useSWR from "swr";
|
||||||
import { AvailabilityFilter, AvailabilityRequest, FareFilter, FareRequest, RoomAvailabity, RoomPrice } from "@/model/RoomSearch";
|
import {
|
||||||
|
SearchPeriodRequest,
|
||||||
|
RoomAvailabity,
|
||||||
|
RoomPriceSearchResponse,
|
||||||
|
} from "@/model/RoomSearch";
|
||||||
|
|
||||||
export function useAPIRoomAvailability(filter: AvailabilityFilter | null) {
|
export function useAPIRoomAvailability(filter: SearchPeriodRequest | null) {
|
||||||
|
const { data, isLoading, error } = useSWR(
|
||||||
|
filter ? ["/api/search/availability", filter] : null,
|
||||||
|
([url, request]) =>
|
||||||
|
fetcherUnwraperWithFilter<RoomAvailabity[]>(url, request),
|
||||||
|
);
|
||||||
|
|
||||||
const request: AvailabilityRequest | null = filter ? {
|
return {
|
||||||
filter: filter
|
roomAvailabilityList: data,
|
||||||
} : null;
|
isLoading,
|
||||||
|
isError: error,
|
||||||
const { data, isLoading, error } = useSWR(request ? ['/api/search/availability', request] : null, ([url, request]) => fetcherUnwraperWithFilter<RoomAvailabity[]>(url, request))
|
};
|
||||||
|
|
||||||
return {
|
|
||||||
roomAvailabilityList: data,
|
|
||||||
isLoading,
|
|
||||||
isError: error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAPIRoomPrices(filter: FareFilter | null) {
|
export function useAPIRoomPrices(filter: SearchPeriodRequest | null) {
|
||||||
|
const { data, isLoading, error } = useSWR(
|
||||||
|
filter ? ["/api/search/prices", filter] : null,
|
||||||
|
([url, request]) =>
|
||||||
|
fetcherUnwraperWithFilter<RoomPriceSearchResponse[]>(url, request),
|
||||||
|
);
|
||||||
|
|
||||||
const request: FareRequest | null = filter ? {
|
return {
|
||||||
filter: filter
|
roomPriceList: data,
|
||||||
} : null;
|
isLoading,
|
||||||
|
isError: error,
|
||||||
const { data, isLoading, error } = useSWR(request ? ['/api/search/fares', request] : null, ([url, request]) => fetcherUnwraperWithFilter<RoomPrice[]>(url, request))
|
};
|
||||||
|
}
|
||||||
return {
|
|
||||||
roomPriceList: data,
|
|
||||||
isLoading,
|
|
||||||
isError: error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+58
-53
@@ -1,66 +1,71 @@
|
|||||||
|
|
||||||
const BACKEND_HOST = import.meta.env.VITE_BACKEND_HOST;
|
const BACKEND_HOST = import.meta.env.VITE_BACKEND_HOST;
|
||||||
const BACKEND_PORT = import.meta.env.VITE_BACKEND_PORT;
|
const BACKEND_PORT = import.meta.env.VITE_BACKEND_PORT;
|
||||||
|
|
||||||
const url = BACKEND_HOST + (BACKEND_PORT == 443 || BACKEND_PORT == 80 ? "" : ":" + BACKEND_PORT)
|
const url =
|
||||||
|
BACKEND_HOST +
|
||||||
|
(BACKEND_PORT == 443 || BACKEND_PORT == 80 ? "" : ":" + BACKEND_PORT);
|
||||||
|
|
||||||
export function fetcher<T>(endpoint: string): Promise<T> {
|
export function fetcher<T>(endpoint: string): Promise<T> {
|
||||||
return fetch(url + endpoint, {
|
return fetch(url + endpoint, {
|
||||||
method: "GET"
|
method: "GET",
|
||||||
})
|
}).then((r) => {
|
||||||
.then(r => {
|
if (!r.ok) {
|
||||||
if (!r.ok) {
|
throw new Error(r.statusText);
|
||||||
throw new Error(r.statusText)
|
}
|
||||||
}
|
const data = r.json();
|
||||||
const data = r.json();
|
return data as Promise<T>;
|
||||||
return data as Promise<T>;
|
});
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetcherUnwraper<T>(endpoint: string): Promise<T> {
|
export function fetcherUnwraper<T>(endpoint: string): Promise<T> {
|
||||||
return fetch(url + endpoint)
|
return fetch(url + endpoint)
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(response.statusText)
|
throw new Error(response.statusText);
|
||||||
}
|
}
|
||||||
return response.json() as Promise<{ results: T }>
|
return response.json() as Promise<{ results: T }>;
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then((data) => {
|
||||||
return data.results
|
return data.results;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetcherWithFilter<T>(endpoint: string, body: NonNullable<unknown>): Promise<T> {
|
export function fetcherWithFilter<T>(
|
||||||
return fetch(url + endpoint, {
|
endpoint: string,
|
||||||
method: "POST",
|
body: NonNullable<unknown>,
|
||||||
body: JSON.stringify(body),
|
): Promise<T> {
|
||||||
headers: {
|
return fetch(url + endpoint, {
|
||||||
"Content-Type": "application/json",
|
method: "POST",
|
||||||
},
|
body: JSON.stringify(body),
|
||||||
})
|
headers: {
|
||||||
.then(response => {
|
"Content-Type": "application/json",
|
||||||
if (!response.ok) {
|
},
|
||||||
throw new Error(response.statusText)
|
}).then((response) => {
|
||||||
}
|
if (!response.ok) {
|
||||||
return response.json() as Promise<T>
|
throw new Error(response.statusText);
|
||||||
})
|
}
|
||||||
|
return response.json() as Promise<T>;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetcherUnwraperWithFilter<T>(endpoint: string, body: NonNullable<unknown>): Promise<T> {
|
export function fetcherUnwraperWithFilter<T>(
|
||||||
return fetch(url + endpoint, {
|
endpoint: string,
|
||||||
method: "POST",
|
body: NonNullable<unknown>,
|
||||||
body: JSON.stringify(body),
|
): Promise<T> {
|
||||||
headers: {
|
return fetch(url + endpoint, {
|
||||||
"Content-Type": "application/json",
|
method: "POST",
|
||||||
},
|
body: JSON.stringify(body),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(response.statusText);
|
||||||
|
}
|
||||||
|
return response.json() as Promise<{ results: T }>;
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((data) => {
|
||||||
if (!response.ok) {
|
return data.results;
|
||||||
throw new Error(response.statusText)
|
});
|
||||||
}
|
}
|
||||||
return response.json() as Promise<{ results: T }>
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
return data.results
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from "../ui/alert-dialog";
|
||||||
|
import { Button } from "../ui/button";
|
||||||
|
import { ConstsNav, ConstsTexts } from "@/utils/Consts";
|
||||||
|
|
||||||
|
type OnCancelClickFunction = () => void;
|
||||||
|
|
||||||
|
export function ContactUsDialog({
|
||||||
|
onCancelClick,
|
||||||
|
isOpen,
|
||||||
|
cancelButtonText = "Cancel",
|
||||||
|
}: {
|
||||||
|
cancelButtonText: string;
|
||||||
|
onCancelClick: OnCancelClickFunction;
|
||||||
|
isOpen: boolean;
|
||||||
|
}) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const navToContactPage = (text: string) => {
|
||||||
|
navigate(ConstsNav.page_Contact, {
|
||||||
|
state: text,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AlertDialog open={isOpen}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>
|
||||||
|
{ConstsTexts.contactUsAlertDialog_title}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{ConstsTexts.contactUsAlertDialog_text}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel asChild>
|
||||||
|
<Button variant={"secondary"} onClick={onCancelClick}>
|
||||||
|
{cancelButtonText}
|
||||||
|
</Button>
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction asChild>
|
||||||
|
<Button
|
||||||
|
variant={"link"}
|
||||||
|
onClick={() =>
|
||||||
|
navToContactPage("Contact us for a personalized quote!")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Go to contact page
|
||||||
|
</Button>
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,144 +1,184 @@
|
|||||||
import { useAPIRoomCategoryId } from "@/api/api-roomCategories"
|
import { Card, CardContent } from "../ui/card";
|
||||||
import { Card, CardContent, CardHeader } from "../ui/card"
|
|
||||||
import { useMemo, useState } from "react";
|
|
||||||
import { Typography } from "../ui/typography";
|
import { Typography } from "../ui/typography";
|
||||||
import { RoomCategoryPhoto } from "@/model/RoomCategory";
|
import {
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../ui/table";
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "../ui/table";
|
||||||
import { Skeleton } from "../ui/skeleton";
|
import { Skeleton } from "../ui/skeleton";
|
||||||
import { useAppStore } from "@/store";
|
import { useAppStore } from "@/store";
|
||||||
import { DateRange } from "react-day-picker";
|
|
||||||
import { FareFilter } from "@/model/RoomSearch";
|
|
||||||
import { useAPIRoomPrices } from "@/api/api-roomSearch";
|
|
||||||
import { NumberSelector } from "../ui/number-selector";
|
import { NumberSelector } from "../ui/number-selector";
|
||||||
import { NewBookingRoom } from "@/model/Bookings";
|
import { NewBooking, NewBookingRoom } from "@/model/Bookings";
|
||||||
|
import { RoomItemCard } from "./room-item-card";
|
||||||
|
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
||||||
|
import { UserIcon } from "lucide-react";
|
||||||
|
import { makeSearchPeriodRequestFromSearchFilter } from "@/utils/utils";
|
||||||
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
|
import { useRoomCategory, useRoomPrice } from "@/utils/apiHooks";
|
||||||
|
|
||||||
function RoomBooking({ roomCategoryId, availableAmount }: { roomCategoryId: number, availableAmount: number }) {
|
function RoomBooking({
|
||||||
|
roomCategoryId,
|
||||||
|
availableAmount,
|
||||||
|
}: {
|
||||||
|
roomCategoryId: number;
|
||||||
|
availableAmount: number;
|
||||||
|
}) {
|
||||||
|
const appSearchFilter: SearchFilter = useAppStore(
|
||||||
|
(state) => state.searchFilter,
|
||||||
|
);
|
||||||
|
const addNewRoom = useAppStore((state) => state.currentBookingAddRoom);
|
||||||
|
const bookingRooms: NewBooking | null = useAppStore(
|
||||||
|
(state) => state.currentBooking,
|
||||||
|
);
|
||||||
|
|
||||||
const [selectedAmount, setSelectedAmount] = useState<Map<number, number>>(new Map());
|
function onSelectedAmountUpdate(
|
||||||
|
guestNumber: number,
|
||||||
const currentDates: DateRange = useAppStore((state) => (state.searchFilter.dateRange));
|
newCount: number,
|
||||||
const addNewRoom = useAppStore((state) => (state.addNewBookingRoom));
|
price: number,
|
||||||
|
) {
|
||||||
function onSelectedAmountUpdate(guestNumber: number, newCount: number, price: number) {
|
console.log(
|
||||||
console.log("Room " + roomCategoryId + " Guestnumber: " + guestNumber + " Count: " + newCount);
|
"Room " +
|
||||||
|
roomCategoryId +
|
||||||
const newAmountMap = new Map(selectedAmount);
|
" Guestnumber: " +
|
||||||
newAmountMap.set(guestNumber, newCount);
|
guestNumber +
|
||||||
setSelectedAmount(newAmountMap)
|
" Count: " +
|
||||||
|
newCount,
|
||||||
|
);
|
||||||
|
|
||||||
const newRoom: NewBookingRoom = {
|
const newRoom: NewBookingRoom = {
|
||||||
roomCategory: roomCategoryId,
|
roomCategory: roomCategoryId,
|
||||||
guestNumber: guestNumber,
|
guestNumber: guestNumber,
|
||||||
amount: newCount,
|
amount: newCount,
|
||||||
price: price
|
price: price,
|
||||||
};
|
};
|
||||||
addNewRoom(newRoom);
|
addNewRoom(newRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalSelected = () => {
|
const getSelectedRoomAmount = (guestNumber: number | null) => {
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
selectedAmount.forEach((v) => sum += v)
|
if (bookingRooms) {
|
||||||
|
//Rooms with same category and, if guestNumber is set, rooms with same guestNumber.
|
||||||
|
bookingRooms.rooms
|
||||||
|
.filter((v) => {
|
||||||
|
const isSameCat = v.roomCategory == roomCategoryId;
|
||||||
|
const isSameGuestNum =
|
||||||
|
guestNumber != null ? v.guestNumber == guestNumber : true;
|
||||||
|
return isSameCat && isSameGuestNum;
|
||||||
|
})
|
||||||
|
.forEach((v) => (sum += v.amount));
|
||||||
|
}
|
||||||
return sum;
|
return sum;
|
||||||
};
|
};
|
||||||
const canAddMore: boolean = availableAmount > totalSelected();
|
const totalSelectAmount = getSelectedRoomAmount(null);
|
||||||
|
const canAddMoreRooms: boolean = availableAmount > totalSelectAmount;
|
||||||
|
|
||||||
//This seems a little bit overkill, but IDK.
|
//This seems a little bit overkill, but IDK.
|
||||||
const fareFilter: FareFilter | null = useMemo(
|
const fareFilter = makeSearchPeriodRequestFromSearchFilter(appSearchFilter);
|
||||||
() => {
|
|
||||||
if (currentDates && currentDates.from && currentDates.to) {
|
const { value: roomCategory, isLoading: isLoadingCategory } =
|
||||||
const filter: FareFilter = {
|
useRoomCategory(roomCategoryId);
|
||||||
startDate: currentDates.from?.toDateString(),
|
const { value: roomPriceList, isLoading: isLoadingPrices } = useRoomPrice(
|
||||||
endDate: currentDates.to?.toDateString(),
|
fareFilter,
|
||||||
roomCategory: roomCategoryId
|
roomCategoryId,
|
||||||
}
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
[currentDates, roomCategoryId]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const { roomCategory, isLoading: isLoadingCategory, isError: isErrorCategory } = useAPIRoomCategoryId(roomCategoryId);
|
|
||||||
const { roomPriceList, isLoading: isLoadingPrices, isError: isErrorPrices } = useAPIRoomPrices(fareFilter);
|
|
||||||
|
|
||||||
|
|
||||||
//TODOME: Gestionar también los estados al cargar los precios.
|
|
||||||
const isLoading = isLoadingCategory || isLoadingPrices;
|
const isLoading = isLoadingCategory || isLoadingPrices;
|
||||||
const isError = isErrorCategory || isErrorPrices;
|
const isError = roomCategory == null;
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return <Skeleton className="mx-auto h-[150px] w-[600px]" />;
|
||||||
<Skeleton className="w-[600px] h-[150px] mx-auto" />
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError) {
|
if (isError) {
|
||||||
return (
|
return (
|
||||||
<Typography variant={"h3"} as="h3">Sorry, there was an error loading data.</Typography>
|
<Typography variant={"h3"} as="h3">
|
||||||
|
Sorry, there was an error loading data.
|
||||||
|
</Typography>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const mainPhoto: RoomCategoryPhoto | undefined = roomCategory?.roomCategoryPhotos.filter((p) => p.kind == "main")[0];
|
|
||||||
const photoElement = mainPhoto && (
|
|
||||||
<img src={mainPhoto.path} alt={mainPhoto.altText} className="rounded-md mx-0 px-0"></img>
|
|
||||||
);
|
|
||||||
|
|
||||||
const hasPrices = roomPriceList != null && roomPriceList?.length > 0;
|
const hasPrices = roomPriceList != null && roomPriceList?.length > 0;
|
||||||
let priceTable = null;
|
let priceTable = null;
|
||||||
if (hasPrices) {
|
if (hasPrices) {
|
||||||
const tableRows = roomPriceList?.map((el) => {
|
//A row for each room guestNumber.
|
||||||
return (
|
let tableRows = null;
|
||||||
<TableRow key={el.guestNumber}>
|
if (!isLoadingPrices) {
|
||||||
<TableCell>{el.guestNumber}</TableCell>
|
tableRows = roomPriceList?.map((el) => {
|
||||||
<TableCell>{el.price / 100} €</TableCell>
|
const selectedRoomAmount =
|
||||||
<TableCell>
|
totalSelectAmount > 0 ? getSelectedRoomAmount(el.guestNumber) : 0;
|
||||||
<NumberSelector updateCount={(count) => onSelectedAmountUpdate(el.guestNumber, count, el.price)} addEnabled={canAddMore}></NumberSelector>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableRow key={roomCategoryId + "-" + el.guestNumber}>
|
||||||
|
<TableCell>
|
||||||
|
<IconWithTooltip
|
||||||
|
label={el.guestNumber?.toString()}
|
||||||
|
tooltipText={"Guest Number"}
|
||||||
|
labelPosition={"right"}
|
||||||
|
>
|
||||||
|
<UserIcon></UserIcon>
|
||||||
|
</IconWithTooltip>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{el.price / 100} €</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<NumberSelector
|
||||||
|
updateCount={(count) =>
|
||||||
|
onSelectedAmountUpdate(el.guestNumber, count, el.price)
|
||||||
|
}
|
||||||
|
addEnabled={canAddMoreRooms}
|
||||||
|
initialValue={selectedRoomAmount}
|
||||||
|
></NumberSelector>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//Element for
|
||||||
priceTable = (
|
priceTable = (
|
||||||
<>
|
<Table className="overflow-hidden">
|
||||||
<Table>
|
<TableHeader>
|
||||||
<TableHeader>
|
<TableRow>
|
||||||
<TableRow>
|
<TableHead>Guest number</TableHead>
|
||||||
<TableHead>Guest number</TableHead>
|
<TableHead>Price</TableHead>
|
||||||
<TableHead>Price</TableHead>
|
<TableHead>Amount</TableHead>
|
||||||
<TableHead>Amount</TableHead>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHeader>
|
||||||
</TableHeader>
|
<TableBody>
|
||||||
<TableBody>
|
{isLoadingPrices ? <Skeleton className="h-full w-full" /> : tableRows}
|
||||||
{isLoadingPrices ? <Skeleton className="w-[80%] h-[100%]" /> : tableRows}
|
</TableBody>
|
||||||
</TableBody>
|
</Table>
|
||||||
</Table>
|
|
||||||
<p>Rooms Available: {availableAmount}</p>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let roomCard = null;
|
||||||
|
if (roomCategory) {
|
||||||
|
roomCard = (
|
||||||
|
<RoomItemCard
|
||||||
|
room={roomCategory}
|
||||||
|
key={roomCategoryId}
|
||||||
|
className="z-20 border-4"
|
||||||
|
></RoomItemCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<div className="relative sm:grid sm:grid-cols-40/60">
|
||||||
<CardHeader>
|
{roomCard}
|
||||||
<div className="flex flex-row gap-5 w-full">
|
<Card className="relative mx-auto w-[95%] -translate-y-2 self-center rounded-none rounded-b-xl sm:mx-0 sm:h-4/5 sm:w-full sm:-translate-x-2 sm:translate-y-0 sm:rounded-e-xl">
|
||||||
<div className="w-[40%] flex-none">
|
<CardContent className="flex h-full w-full flex-col justify-center gap-4 p-5">
|
||||||
{photoElement}
|
{hasPrices ? (
|
||||||
</div>
|
priceTable
|
||||||
<div>
|
) : (
|
||||||
<Typography variant={"h3"} as="h3">{roomCategory?.name}</Typography>
|
<Typography variant={"largeText"}>No Prices available</Typography>
|
||||||
<Typography >{roomCategory?.description}</Typography>
|
)}
|
||||||
</div>
|
<p>Rooms Available: {availableAmount}</p>
|
||||||
</div>
|
</CardContent>
|
||||||
</CardHeader>
|
</Card>
|
||||||
<CardContent>
|
</div>
|
||||||
{hasPrices ? priceTable : <Typography variant={"largeText"}>No Prices available</Typography>}
|
|
||||||
<div>
|
|
||||||
</div>
|
|
||||||
<p>Selected: {totalSelected()}</p>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default RoomBooking
|
export default RoomBooking;
|
||||||
|
|||||||
@@ -1,65 +1,100 @@
|
|||||||
import { Separator } from "../ui/separator"
|
import { Separator } from "../ui/separator";
|
||||||
import { Card, CardContent, CardHeader } 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 { UserIcon } from "lucide-react";
|
||||||
import { RoomCategory, RoomCategoryPhoto } from "@/model/RoomCategory"
|
import { RoomCategory } from "@/model/RoomCategory";
|
||||||
import { IconWithTooltipNumber } from "../ui/icon-number-tooltip"
|
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
||||||
|
import defaultRoomImg from "@/res/SomniaRoomImage.svg";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Icon } from "@iconify-icon/react";
|
||||||
|
import { useConfigVariable } from "@/utils/apiHooks";
|
||||||
|
import { eConfigVarKeys } from "@/model/ConfigVar";
|
||||||
|
|
||||||
interface RoomItemCardProps {
|
interface RoomItemCardProps {
|
||||||
room: RoomCategory
|
room: RoomCategory;
|
||||||
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultRoom: RoomCategory = {
|
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({ room = defaultRoom }: RoomItemCardProps) {
|
export function RoomItemCard({
|
||||||
|
room = defaultRoom,
|
||||||
|
className,
|
||||||
|
}: RoomItemCardProps) {
|
||||||
|
const { value: varPhotoAspect } = useConfigVariable(
|
||||||
|
eConfigVarKeys.varPhotoAspectRatio,
|
||||||
|
"4/3",
|
||||||
|
);
|
||||||
|
|
||||||
const mainPhoto: RoomCategoryPhoto | undefined = room.roomCategoryPhotos.find((element) => {
|
//FIXME: Use PhotoOrder.
|
||||||
return element.kind = "main"
|
const getRoomMainPhoto = () => {
|
||||||
|
if (room.roomCategoryPhotos.length < 0) {
|
||||||
|
return defaultRoomImg;
|
||||||
|
}
|
||||||
|
return room.roomCategoryPhotos.at(0)?.path ?? defaultRoomImg;
|
||||||
|
};
|
||||||
|
|
||||||
|
const bedTypeIconList = room.roomCategoryBedTypes.map((e) => {
|
||||||
|
return (
|
||||||
|
<IconWithTooltip
|
||||||
|
key={room.id.toString() + e.bedTypeIcon}
|
||||||
|
tooltipText={e.bedTypeName}
|
||||||
|
label={e.amount.toString()}
|
||||||
|
>
|
||||||
|
<Icon icon={e.bedTypeIcon} height="auto" />
|
||||||
|
</IconWithTooltip>
|
||||||
|
);
|
||||||
});
|
});
|
||||||
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);
|
|
||||||
|
|
||||||
|
const photoAspectRationClassName = "aspect-" + varPhotoAspect;
|
||||||
return (
|
return (
|
||||||
<Card id={room.id.toString()}>
|
<Card key={room.id} className={cn(className, "relative", "py-0")}>
|
||||||
<CardHeader className="p-0 m-0 mb-5">
|
{/* <CardHeader className="p-0 m-0 mb-5">
|
||||||
<img src={mainPhoto?.path ?? "https://images.unsplash.com/photo-1618773928121-c32242e63f39"} className="rounded-md"></img>
|
</CardHeader> */}
|
||||||
<Typography variant={"h2"} as="h1" className="mx-5 py-2">{room.name}</Typography>
|
<CardContent className="flex h-full w-full flex-col p-0">
|
||||||
</CardHeader>
|
<div className="">
|
||||||
<CardContent>
|
<img
|
||||||
<Typography variant={"p"} as="p">
|
src={getRoomMainPhoto()}
|
||||||
{room.description}
|
className={
|
||||||
</Typography>
|
photoAspectRationClassName + " w-full rounded-t-md object-cover"
|
||||||
<Separator className="my-4" />
|
}
|
||||||
<div className="flex justify-around">
|
></img>
|
||||||
<div className="flex flex-row gap-2">
|
<Separator className="my-0 border-2" />
|
||||||
{hasSingleBed && (
|
</div>
|
||||||
<IconWithTooltipNumber altText="Single bed" amount={bedTypeList[0]}>
|
<div>
|
||||||
<BedSingleIcon />
|
<Typography variant={"h2"} as="h2" className="border-none px-4 pt-4">
|
||||||
</IconWithTooltipNumber>
|
{room.name}
|
||||||
)}
|
</Typography>
|
||||||
{hasDoubleBed && (
|
</div>
|
||||||
<>
|
<div>
|
||||||
<IconWithTooltipNumber altText="Double bed" amount={bedTypeList[1]}>
|
<Typography variant={"p"} as="h2" className="px-5">
|
||||||
<BedDoubleIcon />
|
{room.description}
|
||||||
</IconWithTooltipNumber>
|
</Typography>
|
||||||
</>
|
</div>
|
||||||
)}
|
<div className="mt-auto pb-4">
|
||||||
</div>
|
<Separator className="my-4" />
|
||||||
<div className="flex flex-row">
|
<div className="flex justify-around">
|
||||||
<UserIcon />
|
<div className="flex flex-row gap-2">{bedTypeIconList}</div>
|
||||||
<Typography variant={"p_inline"} className="ml-3">{room.maxGuestNum}</Typography>
|
<div className="flex flex-row">
|
||||||
|
<IconWithTooltip
|
||||||
|
tooltipText="Max. gests"
|
||||||
|
label={room.maxGuestNum?.toString()}
|
||||||
|
labelPosition={"right"}
|
||||||
|
>
|
||||||
|
<UserIcon />
|
||||||
|
</IconWithTooltip>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,101 +1,152 @@
|
|||||||
import { Separator } from "../ui/separator"
|
import { Separator } from "../ui/separator";
|
||||||
import { Card, CardContent, CardHeader } from "../ui/card"
|
import { Card, CardContent, CardHeader } from "../ui/card";
|
||||||
import { Typography } from "../ui/typography"
|
import { Typography } from "../ui/typography";
|
||||||
import 'react-day-picker/dist/style.css';
|
import "react-day-picker/dist/style.css";
|
||||||
import { DatePickerWithRange } from "../ui/dateRange-picker";
|
import { DatePickerWithRange } from "../ui/dateRange-picker";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { SearchIcon } from "lucide-react";
|
import { SearchIcon } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { SearchFilter } from "@/model/SearchFilter";
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
import { DateRange } from "react-day-picker";
|
import { DateRange } from "react-day-picker";
|
||||||
import { useToast } from "../ui/use-toast";
|
import { isValidSearchFilter } from "@/utils/utils";
|
||||||
import { useAppStore } from "@/store";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useLocation } from "react-router-dom";
|
import { ConstsNav, ConstsTexts } from "@/utils/Consts";
|
||||||
|
import { ContactUsDialog } from "../Dialogs/ContactUsDialog";
|
||||||
|
import { useCheckForNightCount } from "@/utils/hooks";
|
||||||
|
|
||||||
type funOnSearchClick = (newFilter: SearchFilter) => void;
|
type funOnSearchClick = (newFilter: SearchFilter) => void;
|
||||||
|
|
||||||
export function SearchFilterCard({ onSearchClick }: { onSearchClick?: funOnSearchClick }) {
|
export function SearchFilterCard({
|
||||||
|
onSearchClick,
|
||||||
//App filter. Updated on btSearchClick.
|
initialsearchFilter,
|
||||||
const appSearchFilter = useAppStore((state) => (state.searchFilter));
|
}: {
|
||||||
const setAppSearchFilter = useAppStore((state) => (state.setSearchFilter));
|
onSearchClick?: funOnSearchClick;
|
||||||
|
initialsearchFilter?: SearchFilter;
|
||||||
|
}) {
|
||||||
//Local Filter state.
|
//Local Filter state.
|
||||||
const [searchFilter, setSearchFilter] = useState<SearchFilter>(appSearchFilter)
|
const [searchFilter, setSearchFilter] = useState<SearchFilter | null>(
|
||||||
|
initialsearchFilter ?? null,
|
||||||
|
);
|
||||||
|
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
||||||
|
const [isContactDialogOpen, setIsContactDialogOpen] =
|
||||||
|
useState<boolean>(false);
|
||||||
|
|
||||||
//On location change, try to load searchFilter from state.
|
const {
|
||||||
//FIXME: Si llegamos sin state, hay que borrar el state global...
|
isLoading: isNightCountLoading,
|
||||||
const location = useLocation();
|
isOverApiMax: nightCountCheckIsOverApi,
|
||||||
useEffect(() => {
|
shouldShowContactDialog: nightCountShowDialog,
|
||||||
setSearchFilter(location.state);
|
} = useCheckForNightCount(searchFilter);
|
||||||
}, [location]);
|
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
const { toast } = useToast();
|
|
||||||
|
|
||||||
// Validate and call callback on btSearch click.
|
// Validate and call callback on btSearch click.
|
||||||
//TODOME: Add data validations and show messages.
|
|
||||||
const btSearchClick = () => {
|
const btSearchClick = () => {
|
||||||
if (!searchFilter || !searchFilter.dateRange) {
|
if (!isValidSearchFilter(searchFilter)) {
|
||||||
toast({
|
setErrorMsg("Select a valid 'from' and 'to' dates!");
|
||||||
variant: "destructive",
|
return;
|
||||||
title: "Uh oh! Invalid Search.",
|
}
|
||||||
|
|
||||||
|
//Check for max night count.
|
||||||
|
//API Config vars values must be loaded before this! Unexpected behaviours may happen otherwise.
|
||||||
|
if (nightCountCheckIsOverApi) {
|
||||||
|
//Navigate to contact page and show info.
|
||||||
|
navigate(ConstsNav.page_Contact, {
|
||||||
|
state: ConstsTexts.navToContact_maxAllowedNightCount,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (nightCountShowDialog) {
|
||||||
if (!searchFilter.dateRange.from || !searchFilter.dateRange.to) {
|
//Show Alert dialog.
|
||||||
toast({
|
setIsContactDialogOpen(true);
|
||||||
variant: "destructive",
|
//Page onSearch action will be executed based on the dialog result.
|
||||||
title: "Uh oh! Invalid Search.",
|
|
||||||
description: "You should select a 'from' and 'to' dates"
|
|
||||||
})
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Execute page onSearch action.
|
||||||
if (onSearchClick) {
|
if (onSearchClick) {
|
||||||
setAppSearchFilter(searchFilter);
|
|
||||||
onSearchClick(searchFilter);
|
onSearchClick(searchFilter);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Handle Element updates.
|
// Handle internal Searchfilter updates.
|
||||||
const updateDateRange = (newRange: DateRange) => {
|
const updateDateRange = (newRange: DateRange) => {
|
||||||
setSearchFilter({
|
const newSearchFilter = {
|
||||||
...searchFilter,
|
...searchFilter,
|
||||||
dateRange: newRange,
|
dateRange: newRange,
|
||||||
});
|
};
|
||||||
|
|
||||||
console.log("SearchFilterCard filter UPDATED");
|
setSearchFilter(newSearchFilter);
|
||||||
}
|
|
||||||
|
|
||||||
const datePickerElement = searchFilter == null ? (
|
if (isValidSearchFilter(newSearchFilter)) {
|
||||||
<DatePickerWithRange
|
setErrorMsg(null);
|
||||||
updateDateRange={updateDateRange}
|
}
|
||||||
allowPast={false}>
|
};
|
||||||
</DatePickerWithRange>
|
|
||||||
) : (
|
const onContactDialogClose = () => {
|
||||||
<DatePickerWithRange
|
setIsContactDialogOpen(false);
|
||||||
updateDateRange={updateDateRange}
|
|
||||||
allowPast={false}
|
if (!isValidSearchFilter(searchFilter)) {
|
||||||
startDate={searchFilter.dateRange.from}
|
return;
|
||||||
endDate={searchFilter.dateRange.to}>
|
}
|
||||||
</DatePickerWithRange>
|
if (onSearchClick) {
|
||||||
|
onSearchClick(searchFilter);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isSearchButtonDisabled = isNightCountLoading;
|
||||||
|
|
||||||
|
const datePickerElement =
|
||||||
|
searchFilter == null ? (
|
||||||
|
<DatePickerWithRange
|
||||||
|
updateDateRange={updateDateRange}
|
||||||
|
allowPast={false}
|
||||||
|
></DatePickerWithRange>
|
||||||
|
) : (
|
||||||
|
<DatePickerWithRange
|
||||||
|
updateDateRange={updateDateRange}
|
||||||
|
allowPast={false}
|
||||||
|
startDate={searchFilter.dateRange.from}
|
||||||
|
endDate={searchFilter.dateRange.to}
|
||||||
|
></DatePickerWithRange>
|
||||||
|
);
|
||||||
|
|
||||||
|
const errorMsgLabel = (
|
||||||
|
<Typography variant={"errorText"} className="mt-2 text-lg">
|
||||||
|
{errorMsg}
|
||||||
|
</Typography>
|
||||||
);
|
);
|
||||||
|
const searchHasErrors = errorMsg != null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<>
|
||||||
<CardHeader className="p-0 m-0 mb-5">
|
<ContactUsDialog
|
||||||
<Typography variant={"h2"} as="h1" className="mx-5 py-2">Reserva ahora</Typography>
|
isOpen={isContactDialogOpen}
|
||||||
</CardHeader>
|
onCancelClick={onContactDialogClose}
|
||||||
<CardContent>
|
cancelButtonText="Continue Search"
|
||||||
{datePickerElement}
|
/>
|
||||||
<Separator className="my-4" />
|
<Card>
|
||||||
<Button size={"lg"} onClick={btSearchClick}>
|
<CardHeader className="m-0 mb-5 p-0">
|
||||||
<SearchIcon className="text-primary-foreground me-2" />
|
<Typography variant={"h2"} as="h1" className="mx-5 py-2">
|
||||||
<Typography variant={"h3"} className="text-primary-foreground">Buscar</Typography>
|
Reserva ahora
|
||||||
</Button>
|
</Typography>
|
||||||
</CardContent>
|
</CardHeader>
|
||||||
</Card>
|
<CardContent>
|
||||||
)
|
{datePickerElement}
|
||||||
|
{searchHasErrors && errorMsgLabel}
|
||||||
|
<Separator className="my-4" />
|
||||||
|
<Button
|
||||||
|
size={"lg"}
|
||||||
|
onClick={btSearchClick}
|
||||||
|
disabled={isSearchButtonDisabled}
|
||||||
|
variant={searchHasErrors ? "destructive" : "default"}
|
||||||
|
>
|
||||||
|
<SearchIcon className="me-2 text-primary-foreground" />
|
||||||
|
<Typography variant={"h3"} className="text-primary-foreground">
|
||||||
|
Buscar
|
||||||
|
</Typography>
|
||||||
|
</Button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+122
-13
@@ -1,21 +1,130 @@
|
|||||||
|
import { Separator } from "./ui/separator";
|
||||||
|
import { Typography } from "./ui/typography";
|
||||||
|
import { eConfigVarKeys } from "@/model/ConfigVar";
|
||||||
|
import {
|
||||||
|
c_sominaRooms_webpage,
|
||||||
|
c_somniaRooms_notice_text,
|
||||||
|
} from "@/utils/Consts";
|
||||||
|
import { Skeleton } from "./ui/skeleton";
|
||||||
|
import { Mail, Phone } from "lucide-react";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
|
import { useConfigVariable } from "@/utils/apiHooks";
|
||||||
|
|
||||||
function AppFooter() {
|
function AppFooter() {
|
||||||
|
const { value: varCompanyLogo, isLoading: isLogoLoading } = useConfigVariable(
|
||||||
|
eConfigVarKeys.varCompanyLogo,
|
||||||
|
"public/SR2.svg",
|
||||||
|
);
|
||||||
|
const { value: varCompanyLogoSize, isLoading: isLogoSizeLoading } =
|
||||||
|
useConfigVariable(eConfigVarKeys.varCompanyLogoSize, "64px");
|
||||||
|
const { value: varCompanyName, isLoading: isNameLoading } = useConfigVariable(
|
||||||
|
eConfigVarKeys.varCompanyName,
|
||||||
|
"Somnia Rooms",
|
||||||
|
);
|
||||||
|
const { value: varCompanyAddress, isLoading: isAddressLoading } =
|
||||||
|
useConfigVariable(eConfigVarKeys.varCompanyAddress, "");
|
||||||
|
const { value: varCompanyPhone, isLoading: isPhoneLoading } =
|
||||||
|
useConfigVariable(eConfigVarKeys.varCompanyPhone, "");
|
||||||
|
const { value: varCompanyMail, isLoading: isMailLoading } = useConfigVariable(
|
||||||
|
eConfigVarKeys.varCompanyEmail,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
|
||||||
|
const logoSizeClass = "w-[" + varCompanyLogoSize + "]";
|
||||||
|
|
||||||
|
const isLoading =
|
||||||
|
isLogoLoading ||
|
||||||
|
isLogoSizeLoading ||
|
||||||
|
isNameLoading ||
|
||||||
|
isAddressLoading ||
|
||||||
|
isPhoneLoading ||
|
||||||
|
isMailLoading;
|
||||||
|
const getCompanyElement = () => {
|
||||||
|
if (isLoading) {
|
||||||
|
return <Skeleton className="h-16" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<img
|
||||||
|
src={varCompanyLogo}
|
||||||
|
alt="company-logo"
|
||||||
|
className={logoSizeClass}
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
<Typography variant={"p_inline"} className="text-nowrap">
|
||||||
|
{varCompanyName} - © {new Date().getUTCFullYear()}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant={"p_inline"}>{varCompanyAddress}</Typography>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getContactElement = () => {
|
||||||
|
if (isLoading) {
|
||||||
|
return <Skeleton className="w-16" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<li className="flex items-center gap-2">
|
||||||
|
<Phone size={"1.2em"} />
|
||||||
|
<Typography variant={"p_inline"}>{varCompanyPhone}</Typography>
|
||||||
|
</li>
|
||||||
|
<li className="flex items-center gap-2">
|
||||||
|
<Mail size={"1.2em"} />
|
||||||
|
<Typography variant={"p_inline"}>{varCompanyMail}</Typography>
|
||||||
|
</li>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-secondary flex-col hidden">
|
<footer className="w-full p-8 pt-0">
|
||||||
<div className="">
|
<Separator className="my-4" />
|
||||||
Created with Love by me :)
|
<div className="flex flex-row flex-wrap items-center justify-center gap-x-12 gap-y-6 text-center lg:justify-between">
|
||||||
|
<div className="flex flex-row items-center gap-2">
|
||||||
|
{getCompanyElement()}
|
||||||
</div>
|
</div>
|
||||||
<div className="">
|
<ul className="flex flex-wrap items-start gap-x-10 gap-y-2 px-4 py-4">
|
||||||
<p>Más información</p>
|
<li>
|
||||||
<ul className="list-outside">
|
<ul className="text-start">
|
||||||
<li>Info</li>
|
<li>
|
||||||
<li>Info2</li>
|
<Typography variant={"largeText"} className="text-start">
|
||||||
<li>Info3</li>
|
Legal
|
||||||
|
</Typography>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<Typography asChild className="hover:text-blue-500">
|
||||||
|
<Link to={"terms"}>Terms and conditions</Link>
|
||||||
|
</Typography>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<Typography asChild className="hover:text-blue-500">
|
||||||
|
<Link to={"privacy"}>Privacy policy</Link>
|
||||||
|
</Typography>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</li>
|
||||||
</div>
|
<li>
|
||||||
)
|
<ul>
|
||||||
|
<li>
|
||||||
|
<Typography variant={"largeText"} className="text-start">
|
||||||
|
Contact Us
|
||||||
|
</Typography>
|
||||||
|
</li>
|
||||||
|
{getContactElement()}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<Separator className="my-4" />
|
||||||
|
<Typography className="text-center" variant={"mutedText"}>
|
||||||
|
<a href={c_sominaRooms_webpage}>{c_somniaRooms_notice_text}</a>
|
||||||
|
</Typography>
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AppFooter
|
export default AppFooter;
|
||||||
|
|||||||
@@ -1,32 +1,81 @@
|
|||||||
import { ModeToggle } from "./mode-toggle"
|
import { ModeToggle } from "./mode-toggle";
|
||||||
import { Button } from "./ui/button"
|
import { Button } from "./ui/button";
|
||||||
import { Card, CardContent } from "./ui/card"
|
import { Card, CardContent } from "./ui/card";
|
||||||
import { Typography } from "./ui/typography"
|
import { Typography } from "./ui/typography";
|
||||||
import { Link } from "react-router-dom"
|
import { Link } from "react-router-dom";
|
||||||
import { BookAIcon, HomeIcon } from "lucide-react"
|
import { Bed, BookAIcon, HomeIcon } from "lucide-react";
|
||||||
|
import { eConfigVarKeys } from "@/model/ConfigVar";
|
||||||
|
import { Skeleton } from "./ui/skeleton";
|
||||||
|
import { useConfigVariable } from "@/utils/apiHooks";
|
||||||
|
|
||||||
function AppHeader() {
|
function AppHeader() {
|
||||||
|
const { value: varCompanyLogo, isLoading: isLogoLoading } = useConfigVariable(
|
||||||
|
eConfigVarKeys.varCompanyLogo,
|
||||||
|
"public/SR2.svg",
|
||||||
|
);
|
||||||
|
const { value: varCompanyLogoSize, isLoading: isLogoSizeLoading } =
|
||||||
|
useConfigVariable(eConfigVarKeys.varCompanyLogoSize, "64px");
|
||||||
|
const { value: varCompanyName, isLoading: isNameLoading } = useConfigVariable(
|
||||||
|
eConfigVarKeys.varCompanyName,
|
||||||
|
"Somnia Rooms",
|
||||||
|
);
|
||||||
|
const { value: varCompanyWeb, isLoading: isWebLoading } = useConfigVariable(
|
||||||
|
eConfigVarKeys.varCompanyWebsite,
|
||||||
|
"#",
|
||||||
|
);
|
||||||
|
|
||||||
|
const isLoading =
|
||||||
|
isLogoLoading || isNameLoading || isWebLoading || isLogoSizeLoading;
|
||||||
|
|
||||||
|
const getElementLogo = () => {
|
||||||
|
if (isLoading) {
|
||||||
|
return <Skeleton className="w-[64px]" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const logoSizeClass = "w-[" + varCompanyLogoSize + "]";
|
||||||
|
return (
|
||||||
|
<div className="relative flex flex-row items-center gap-2">
|
||||||
|
<img src={varCompanyLogo} className={logoSizeClass}></img>
|
||||||
|
<Typography variant={"largeText"} className="text-nowrap">
|
||||||
|
{varCompanyName}
|
||||||
|
</Typography>
|
||||||
|
<a href={varCompanyWeb} className="absolute h-full w-full"></a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="flex items-center mx-10 my-4">
|
<header>
|
||||||
<CardContent className="w-full py-2">
|
<Card className="mx-10 my-4 items-center py-0">
|
||||||
<div className="flex justify-around items-center">
|
<CardContent className="w-full py-2">
|
||||||
<div className="flex flex-row items-center gap-2 relative">
|
<div className="flex flex-col items-center justify-around gap-y-3 md:flex-row">
|
||||||
<img src="public/SR2.svg" className="w-[64px]"></img>
|
{getElementLogo()}
|
||||||
<Typography variant={"largeText"}>Somnia Rooms</Typography>
|
<div className="flex flex-row items-center">
|
||||||
<a href="https://duck.com" className="absolute w-[100%] h-[100%]"></a>
|
<Link to={`home`}>
|
||||||
|
<Button variant="ghost" className="h-15 hover:cursor-pointer">
|
||||||
|
<HomeIcon className="mx-auto" />
|
||||||
|
Home
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
<Link to={`search`}>
|
||||||
|
<Button variant="ghost" className="h-15 hover:cursor-pointer">
|
||||||
|
<BookAIcon className="mx-auto" />
|
||||||
|
Reservar
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
<Link to={`home`}>
|
||||||
|
<Button variant="ghost" className="h-15 hover:cursor-pointer">
|
||||||
|
<Bed className="mx-auto" />
|
||||||
|
Mi reserva
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<ModeToggle />
|
||||||
</div>
|
</div>
|
||||||
<Button variant="ghost" className="h-15">
|
</CardContent>
|
||||||
<Link to={`home`}><HomeIcon className="mx-auto" />Home</Link>
|
</Card>
|
||||||
</Button>
|
</header>
|
||||||
<Button variant="ghost" className="h-15">
|
);
|
||||||
<Link to={`search`}><BookAIcon className="mx-auto" />Reservar</Link>
|
|
||||||
</Button>
|
|
||||||
<ModeToggle />
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AppHeader
|
export default AppHeader;
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
function BackendConnectionStatus({
|
||||||
function BackendConnectionStatus({ isLoading, isError }: { isLoading?: boolean, isError?: boolean }) {
|
isLoading,
|
||||||
|
isError,
|
||||||
|
}: {
|
||||||
|
isLoading?: boolean;
|
||||||
|
isError?: boolean;
|
||||||
|
}) {
|
||||||
const BACKEND_HOST = import.meta.env.VITE_BACKEND_HOST;
|
const BACKEND_HOST = import.meta.env.VITE_BACKEND_HOST;
|
||||||
const BACKEND_PORT = import.meta.env.VITE_BACKEND_PORT;
|
const BACKEND_PORT = import.meta.env.VITE_BACKEND_PORT;
|
||||||
|
|
||||||
@@ -10,10 +14,10 @@ function BackendConnectionStatus({ isLoading, isError }: { isLoading?: boolean,
|
|||||||
Conected to Back-End at: {BACKEND_HOST} - {BACKEND_PORT}
|
Conected to Back-End at: {BACKEND_HOST} - {BACKEND_PORT}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Conection Status: {isError ? "ERROR" : (isLoading ? "LOADING" : "LOADED")}
|
Conection Status: {isError ? "ERROR" : isLoading ? "LOADING" : "LOADED"}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BackendConnectionStatus
|
export default BackendConnectionStatus;
|
||||||
|
|||||||
@@ -1,29 +1,76 @@
|
|||||||
import { useAppStore } from "@/store"
|
import { useAppStore } from "@/store";
|
||||||
import { Card, CardContent, CardHeader } from "../ui/card"
|
import { Card, CardContent, CardHeader } from "../ui/card";
|
||||||
import { Typography } from "../ui/typography"
|
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 { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../ui/table";
|
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
|
import { useAPIRoomCategoryList } from "@/api/api-roomCategories";
|
||||||
|
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
||||||
|
import { UserIcon } from "lucide-react";
|
||||||
|
import { useCheckForGuestNumber } from "@/utils/hooks";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { ConstsNav, ConstsTexts } from "@/utils/Consts";
|
||||||
|
import { ContactUsDialog } from "../Dialogs/ContactUsDialog";
|
||||||
|
|
||||||
type OnBookingClickFunction = () => void;
|
type OnBookingClickFunction = () => void;
|
||||||
type BookingDetailsModes = "Book" | "View"
|
type BookingDetailsModes = "Book" | "View";
|
||||||
|
|
||||||
export function BookingDetails({ onBookingConfirm, mode }: { onBookingConfirm?: OnBookingClickFunction, mode: BookingDetailsModes }) {
|
export function BookingDetails({
|
||||||
|
onBookingConfirm,
|
||||||
|
mode,
|
||||||
|
}: {
|
||||||
|
onBookingConfirm?: OnBookingClickFunction;
|
||||||
|
mode: BookingDetailsModes;
|
||||||
|
}) {
|
||||||
|
const [isContactDialogOpen, setIsContactDialogOpen] =
|
||||||
|
useState<boolean>(false);
|
||||||
|
|
||||||
const bookingData = useAppStore((state) => state.newBookingData);
|
const bookingData = useAppStore((state) => state.currentBooking);
|
||||||
|
const { roomCategoryList } = useAPIRoomCategoryList();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const {
|
||||||
|
isLoading: isGuestNumberCheckLoading,
|
||||||
|
isOverApiMax: guestNumberCheckIsOverApi,
|
||||||
|
shouldShowContactDialog: guestNumberShowDialog,
|
||||||
|
} = useCheckForGuestNumber(bookingData);
|
||||||
|
|
||||||
const onBtBookingClick = () => {
|
const onBtBookingClick = () => {
|
||||||
|
//Check for Guest Number limits.
|
||||||
|
//API Config vars values must be loaded before this! Unexpected behaviours may happen otherwise.
|
||||||
|
if (guestNumberCheckIsOverApi) {
|
||||||
|
//Navigate to contact page and show info.
|
||||||
|
navigate(ConstsNav.page_Contact, {
|
||||||
|
state: ConstsTexts.navToContact_maxAllowedGuestNumber,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (guestNumberShowDialog) {
|
||||||
|
//Show Alert dialog.
|
||||||
|
setIsContactDialogOpen(true);
|
||||||
|
//Page onSearch action will be executed based on the dialog result.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (onBookingConfirm) {
|
if (onBookingConfirm) {
|
||||||
onBookingConfirm();
|
onBookingConfirm();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const onContactDialogClose = () => {
|
||||||
|
if (onBookingConfirm) {
|
||||||
|
onBookingConfirm();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!bookingData || bookingData.rooms.length <= 0) {
|
if (!bookingData || bookingData.rooms.length <= 0) {
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<Typography variant={"h2"} as="h2">Your Booking</Typography>
|
<Typography variant={"h2"} as="h2">
|
||||||
|
Your Booking
|
||||||
|
</Typography>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography variant={"h3"}>No rooms added yet</Typography>
|
<Typography variant={"h3"}>No rooms added yet</Typography>
|
||||||
@@ -33,63 +80,95 @@ export function BookingDetails({ onBookingConfirm, mode }: { onBookingConfirm?:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const roomList = bookingData.rooms.map((room) => {
|
const roomList = bookingData.rooms.map((room) => {
|
||||||
|
const category = roomCategoryList?.find((c) => c.id == room.roomCategory);
|
||||||
|
const photo = category?.roomCategoryPhotos.at(0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow key={room.roomCategory + "_" + room.guestNumber}>
|
<Card
|
||||||
<TableCell>{room.roomCategory}</TableCell>
|
key={room.roomCategory.toString() + room.guestNumber.toString()}
|
||||||
<TableCell>{room.guestNumber}</TableCell>
|
className="my-3 flex flex-row bg-accent py-0"
|
||||||
<TableCell>{room.amount}</TableCell>
|
>
|
||||||
<TableCell>{room.price / 100} €</TableCell>
|
{photo && (
|
||||||
<TableCell>{(room.price * room.amount) / 100} €</TableCell>
|
<img
|
||||||
</TableRow>
|
src={photo.path}
|
||||||
|
className="max-w-[30%] rounded-s-xl object-cover"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<div className="w-full p-3">
|
||||||
|
<Typography variant={"h3"} as="h3" className="m-2 text-center">
|
||||||
|
{category?.name}
|
||||||
|
</Typography>
|
||||||
|
<div className="flex w-full flex-row justify-around">
|
||||||
|
<IconWithTooltip
|
||||||
|
label={room.guestNumber.toString()}
|
||||||
|
labelPosition={"right"}
|
||||||
|
tooltipText={"Guest Number"}
|
||||||
|
>
|
||||||
|
<UserIcon />
|
||||||
|
</IconWithTooltip>
|
||||||
|
<Typography variant={"largeText"}>
|
||||||
|
{room.amount} x {room.price / 100}€
|
||||||
|
</Typography>
|
||||||
|
<Typography variant={"largeText"}>
|
||||||
|
{(room.amount * room.price) / 100}€
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
);
|
);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
const totalPrice = bookingData.rooms.reduce(
|
||||||
const roomTable = (
|
(acc, room) => acc + room.price * room.amount,
|
||||||
<Table>
|
0,
|
||||||
<TableHeader>
|
|
||||||
<TableRow>
|
|
||||||
<TableHead>Room</TableHead>
|
|
||||||
<TableHead>Guests</TableHead>
|
|
||||||
<TableHead>Quantity</TableHead>
|
|
||||||
<TableHead>Unit price</TableHead>
|
|
||||||
<TableHead>Total price</TableHead>
|
|
||||||
</TableRow>
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{roomList}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const totalPrice = bookingData.rooms.reduce((acc, room) => (acc + (room.price * room.amount)), 0);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<>
|
||||||
<CardHeader>
|
<ContactUsDialog
|
||||||
<Typography variant={"h2"} as="h2">Your Booking</Typography>
|
isOpen={isContactDialogOpen}
|
||||||
</CardHeader>
|
cancelButtonText="Continue booking"
|
||||||
<CardContent>
|
onCancelClick={onContactDialogClose}
|
||||||
<Typography variant={"h3"}>Your Dates</Typography>
|
/>
|
||||||
<Typography variant={"largeText"}>
|
<Card>
|
||||||
Arrival: {bookingData.arrivalDate.toLocaleDateString()} -
|
<CardHeader>
|
||||||
Departure: {bookingData.departureDate.toLocaleDateString()} <br></br>
|
<Typography variant={"h2"} as="h2">
|
||||||
Number of nights: {differenceInDays(bookingData.departureDate, bookingData.arrivalDate)}
|
Your Booking
|
||||||
</Typography>
|
</Typography>
|
||||||
<Separator className="my-2"></Separator>
|
</CardHeader>
|
||||||
<Typography variant={"h3"}>Your Rooms</Typography>
|
<CardContent>
|
||||||
{roomTable}
|
<Typography variant={"h3"}>Your Dates</Typography>
|
||||||
<Separator className="my-2"></Separator>
|
<Typography variant={"largeText"}>
|
||||||
<Typography variant={"h3"}>Total Price</Typography>
|
Arrival: {bookingData.arrivalDate.toLocaleDateString()} - Departure:{" "}
|
||||||
<Typography variant={"h3"}>{totalPrice / 100} €</Typography>
|
{bookingData.departureDate.toLocaleDateString()} <br></br>
|
||||||
{
|
Number of nights:{" "}
|
||||||
mode == "Book" &&
|
{differenceInDays(
|
||||||
<Button className="my-2" onClick={onBtBookingClick}>
|
bookingData.departureDate,
|
||||||
<Typography variant={"largeText"} className="text-primary-foreground">Book it!</Typography>
|
bookingData.arrivalDate,
|
||||||
</Button>
|
)}
|
||||||
}
|
</Typography>
|
||||||
</CardContent>
|
<Separator className="my-2"></Separator>
|
||||||
</Card>
|
<Typography variant={"h3"}>Your Rooms</Typography>
|
||||||
)
|
<div className="">{roomList}</div>
|
||||||
|
<Separator className="my-2"></Separator>
|
||||||
|
<Typography variant={"h3"}>Total Price</Typography>
|
||||||
|
<Typography variant={"h3"}>{totalPrice / 100} €</Typography>
|
||||||
|
{mode == "Book" && (
|
||||||
|
<Button
|
||||||
|
className="my-2"
|
||||||
|
onClick={onBtBookingClick}
|
||||||
|
disabled={isGuestNumberCheckLoading}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant={"largeText"}
|
||||||
|
className="text-primary-foreground"
|
||||||
|
>
|
||||||
|
Book it!
|
||||||
|
</Typography>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,40 @@
|
|||||||
import { MoonIcon, SunIcon } from "@radix-ui/react-icons"
|
import { MonitorIcon, MoonIcon, SunIcon } from "lucide-react";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu"
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { useTheme } from "@/components/theme-provider"
|
import { useTheme } from "@/components/theme-provider";
|
||||||
|
|
||||||
export function ModeToggle() {
|
export function ModeToggle() {
|
||||||
const { setTheme } = useTheme()
|
const { setTheme } = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger>
|
||||||
<Button variant="outline" size="icon">
|
<Button variant="outline" size="icon">
|
||||||
<SunIcon className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
<SunIcon className="h-[1.2rem] w-[1.2rem] scale-100 rotate-0 transition-all dark:scale-0 dark:-rotate-90" />
|
||||||
<MoonIcon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
<MoonIcon className="absolute h-[1.2rem] w-[1.2rem] scale-0 rotate-90 transition-all dark:scale-100 dark:rotate-0" />
|
||||||
<span className="sr-only">Toggle theme</span>
|
<span className="sr-only">Toggle theme</span>
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuItem onClick={() => setTheme("light")}>
|
<DropdownMenuItem onClick={() => setTheme("light")}>
|
||||||
|
<SunIcon className="h-[1.2rem] w-[1.2rem] scale-100" />
|
||||||
Light
|
Light
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={() => setTheme("dark")}>
|
<DropdownMenuItem onClick={() => setTheme("dark")}>
|
||||||
|
<MoonIcon className="h-[1.2rem] w-[1.2rem] scale-100" />
|
||||||
Dark
|
Dark
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={() => setTheme("system")}>
|
<DropdownMenuItem onClick={() => setTheme("system")}>
|
||||||
|
<MonitorIcon className="h-[1.2rem] w-[1.2rem] scale-100" />
|
||||||
System
|
System
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +1,74 @@
|
|||||||
import { createContext, useContext, useEffect, useState } from "react"
|
import { createContext, useContext, useEffect, useState } from "react";
|
||||||
|
|
||||||
type Theme = "dark" | "light" | "system"
|
type Theme = "dark" | "light" | "system";
|
||||||
|
|
||||||
type ThemeProviderProps = {
|
type ThemeProviderProps = {
|
||||||
children: React.ReactNode
|
children: React.ReactNode;
|
||||||
defaultTheme?: Theme
|
defaultTheme?: Theme;
|
||||||
storageKey?: string
|
storageKey?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
type ThemeProviderState = {
|
type ThemeProviderState = {
|
||||||
theme: Theme
|
theme: Theme;
|
||||||
setTheme: (theme: Theme) => void
|
setTheme: (theme: Theme) => void;
|
||||||
}
|
};
|
||||||
|
|
||||||
const initialState: ThemeProviderState = {
|
const initialState: ThemeProviderState = {
|
||||||
theme: "system",
|
theme: "system",
|
||||||
setTheme: () => null,
|
setTheme: () => null,
|
||||||
}
|
};
|
||||||
|
|
||||||
const ThemeProviderContext = createContext<ThemeProviderState>(initialState)
|
const ThemeProviderContext = createContext<ThemeProviderState>(initialState);
|
||||||
|
|
||||||
export function ThemeProvider({
|
export function ThemeProvider({
|
||||||
children,
|
children,
|
||||||
defaultTheme = "system",
|
defaultTheme = "system",
|
||||||
storageKey = "vite-ui-theme",
|
storageKey = "vite-ui-theme",
|
||||||
...props
|
...props
|
||||||
}: ThemeProviderProps) {
|
}: ThemeProviderProps) {
|
||||||
const [theme, setTheme] = useState<Theme>(
|
const [theme, setTheme] = useState<Theme>(
|
||||||
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme
|
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme,
|
||||||
)
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const root = window.document.documentElement
|
const root = window.document.documentElement;
|
||||||
|
|
||||||
root.classList.remove("light", "dark")
|
root.classList.remove("light", "dark");
|
||||||
|
|
||||||
if (theme === "system") {
|
if (theme === "system") {
|
||||||
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
|
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
|
||||||
.matches
|
.matches
|
||||||
? "dark"
|
? "dark"
|
||||||
: "light"
|
: "light";
|
||||||
|
|
||||||
root.classList.add(systemTheme)
|
root.classList.add(systemTheme);
|
||||||
return
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
root.classList.add(theme)
|
|
||||||
}, [theme])
|
|
||||||
|
|
||||||
const value = {
|
|
||||||
theme,
|
|
||||||
setTheme: (theme: Theme) => {
|
|
||||||
localStorage.setItem(storageKey, theme)
|
|
||||||
setTheme(theme)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
root.classList.add(theme);
|
||||||
<ThemeProviderContext.Provider {...props} value={value}>
|
}, [theme]);
|
||||||
{children}
|
|
||||||
</ThemeProviderContext.Provider>
|
const value = {
|
||||||
)
|
theme,
|
||||||
|
setTheme: (theme: Theme) => {
|
||||||
|
localStorage.setItem(storageKey, theme);
|
||||||
|
setTheme(theme);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThemeProviderContext.Provider {...props} value={value}>
|
||||||
|
{children}
|
||||||
|
</ThemeProviderContext.Provider>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line react-refresh/only-export-components
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
export const useTheme = () => {
|
export const useTheme = () => {
|
||||||
const context = useContext(ThemeProviderContext)
|
const context = useContext(ThemeProviderContext);
|
||||||
|
|
||||||
if (context === undefined)
|
if (context === undefined)
|
||||||
throw new Error("useTheme must be used within a ThemeProvider")
|
throw new Error("useTheme must be used within a ThemeProvider");
|
||||||
|
|
||||||
return context
|
return context;
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -0,0 +1,155 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { AlertDialog as AlertDialogPrimitive } from "radix-ui";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { buttonVariants } from "@/components/ui/button";
|
||||||
|
|
||||||
|
function AlertDialog({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
|
||||||
|
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
|
||||||
|
return (
|
||||||
|
<AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogPortal({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
|
||||||
|
return (
|
||||||
|
<AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogOverlay({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
|
||||||
|
return (
|
||||||
|
<AlertDialogPrimitive.Overlay
|
||||||
|
data-slot="alert-dialog-overlay"
|
||||||
|
className={cn(
|
||||||
|
"fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogContent({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<AlertDialogPortal>
|
||||||
|
<AlertDialogOverlay />
|
||||||
|
<AlertDialogPrimitive.Content
|
||||||
|
data-slot="alert-dialog-content"
|
||||||
|
className={cn(
|
||||||
|
"fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</AlertDialogPortal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogHeader({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="alert-dialog-header"
|
||||||
|
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogFooter({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="alert-dialog-footer"
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogTitle({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
|
||||||
|
return (
|
||||||
|
<AlertDialogPrimitive.Title
|
||||||
|
data-slot="alert-dialog-title"
|
||||||
|
className={cn("text-lg font-semibold", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogDescription({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
|
||||||
|
return (
|
||||||
|
<AlertDialogPrimitive.Description
|
||||||
|
data-slot="alert-dialog-description"
|
||||||
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogAction({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AlertDialogPrimitive.Action>) {
|
||||||
|
return (
|
||||||
|
<AlertDialogPrimitive.Action
|
||||||
|
className={cn(buttonVariants(), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDialogCancel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) {
|
||||||
|
return (
|
||||||
|
<AlertDialogPrimitive.Cancel
|
||||||
|
className={cn(buttonVariants({ variant: "outline" }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogPortal,
|
||||||
|
AlertDialogOverlay,
|
||||||
|
AlertDialogTrigger,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogTitle,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
};
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import * as React from "react"
|
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
|
|
||||||
const badgeVariants = cva(
|
|
||||||
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
||||||
{
|
|
||||||
variants: {
|
|
||||||
variant: {
|
|
||||||
default:
|
|
||||||
"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
|
|
||||||
secondary:
|
|
||||||
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
||||||
destructive:
|
|
||||||
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
|
|
||||||
outline: "text-foreground",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
defaultVariants: {
|
|
||||||
variant: "default",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
export interface BadgeProps
|
|
||||||
extends React.HTMLAttributes<HTMLDivElement>,
|
|
||||||
VariantProps<typeof badgeVariants> {}
|
|
||||||
|
|
||||||
function Badge({ className, variant, ...props }: BadgeProps) {
|
|
||||||
return (
|
|
||||||
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export { Badge, badgeVariants }
|
|
||||||
@@ -1,57 +1,63 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import { Slot } from "@radix-ui/react-slot"
|
import { Slot as SlotPrimitive } from "radix-ui";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default:
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||||
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
||||||
destructive:
|
destructive:
|
||||||
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||||
outline:
|
outline:
|
||||||
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||||
secondary:
|
secondary:
|
||||||
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
ghost:
|
||||||
|
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||||
link: "text-primary underline-offset-4 hover:underline",
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
default: "h-9 px-4 py-2",
|
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||||
sm: "h-8 rounded-md px-3 text-xs",
|
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||||
lg: "h-10 rounded-md px-8",
|
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||||
icon: "h-9 w-9",
|
icon: "size-9",
|
||||||
|
"icon-sm": "size-8",
|
||||||
|
"icon-lg": "size-10",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
variant: "default",
|
variant: "default",
|
||||||
size: "default",
|
size: "default",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
);
|
||||||
|
|
||||||
export interface ButtonProps
|
function Button({
|
||||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
className,
|
||||||
VariantProps<typeof buttonVariants> {
|
variant = "default",
|
||||||
asChild?: boolean
|
size = "default",
|
||||||
|
asChild = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"button"> &
|
||||||
|
VariantProps<typeof buttonVariants> & {
|
||||||
|
asChild?: boolean;
|
||||||
|
}) {
|
||||||
|
const Comp = asChild ? SlotPrimitive.Slot : "button";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
data-slot="button"
|
||||||
|
data-variant={variant}
|
||||||
|
data-size={size}
|
||||||
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
export { Button, buttonVariants };
|
||||||
const Comp = asChild ? Slot : "button"
|
|
||||||
return (
|
|
||||||
<Comp
|
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
|
||||||
ref={ref}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Button.displayName = "Button"
|
|
||||||
|
|
||||||
export { Button, buttonVariants }
|
|
||||||
|
|||||||
+195
-47
@@ -1,70 +1,218 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons"
|
import {
|
||||||
import { DayPicker } from "react-day-picker"
|
ChevronDownIcon,
|
||||||
|
ChevronLeftIcon,
|
||||||
|
ChevronRightIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
import {
|
||||||
|
DayPicker,
|
||||||
|
getDefaultClassNames,
|
||||||
|
type DayButton,
|
||||||
|
} from "react-day-picker";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
import { buttonVariants } from "@/components/ui/button"
|
import { Button, buttonVariants } from "@/components/ui/button";
|
||||||
|
|
||||||
export type CalendarProps = React.ComponentProps<typeof DayPicker>
|
|
||||||
|
|
||||||
function Calendar({
|
function Calendar({
|
||||||
className,
|
className,
|
||||||
classNames,
|
classNames,
|
||||||
showOutsideDays = true,
|
showOutsideDays = true,
|
||||||
|
captionLayout = "label",
|
||||||
|
buttonVariant = "ghost",
|
||||||
|
formatters,
|
||||||
|
components,
|
||||||
...props
|
...props
|
||||||
}: CalendarProps) {
|
}: React.ComponentProps<typeof DayPicker> & {
|
||||||
|
buttonVariant?: React.ComponentProps<typeof Button>["variant"];
|
||||||
|
}) {
|
||||||
|
const defaultClassNames = getDefaultClassNames();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DayPicker
|
<DayPicker
|
||||||
showOutsideDays={showOutsideDays}
|
showOutsideDays={showOutsideDays}
|
||||||
className={cn("p-3", className)}
|
className={cn(
|
||||||
|
"group/calendar bg-background p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
|
||||||
|
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
|
||||||
|
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
captionLayout={captionLayout}
|
||||||
|
formatters={{
|
||||||
|
formatMonthDropdown: (date) =>
|
||||||
|
date.toLocaleString("default", { month: "short" }),
|
||||||
|
...formatters,
|
||||||
|
}}
|
||||||
classNames={{
|
classNames={{
|
||||||
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
|
root: cn("w-fit", defaultClassNames.root),
|
||||||
month: "space-y-4",
|
months: cn(
|
||||||
caption: "flex justify-center pt-1 relative items-center",
|
"flex gap-4 flex-col md:flex-row relative",
|
||||||
caption_label: "text-sm font-medium",
|
defaultClassNames.months,
|
||||||
nav: "space-x-1 flex items-center",
|
|
||||||
nav_button: cn(
|
|
||||||
buttonVariants({ variant: "outline" }),
|
|
||||||
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
|
|
||||||
),
|
),
|
||||||
nav_button_previous: "absolute left-1",
|
month: cn("flex flex-col w-full gap-4", defaultClassNames.month),
|
||||||
nav_button_next: "absolute right-1",
|
nav: cn(
|
||||||
table: "w-full border-collapse space-y-1",
|
"flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between",
|
||||||
head_row: "flex",
|
defaultClassNames.nav,
|
||||||
head_cell:
|
),
|
||||||
"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",
|
button_previous: cn(
|
||||||
row: "flex w-full mt-2",
|
buttonVariants({ variant: buttonVariant }),
|
||||||
cell: cn(
|
"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
|
||||||
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md",
|
defaultClassNames.button_previous,
|
||||||
props.mode === "range"
|
),
|
||||||
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
|
button_next: cn(
|
||||||
: "[&:has([aria-selected])]:rounded-md"
|
buttonVariants({ variant: buttonVariant }),
|
||||||
|
"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
|
||||||
|
defaultClassNames.button_next,
|
||||||
|
),
|
||||||
|
month_caption: cn(
|
||||||
|
"flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)",
|
||||||
|
defaultClassNames.month_caption,
|
||||||
|
),
|
||||||
|
dropdowns: cn(
|
||||||
|
"w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5",
|
||||||
|
defaultClassNames.dropdowns,
|
||||||
|
),
|
||||||
|
dropdown_root: cn(
|
||||||
|
"relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md",
|
||||||
|
defaultClassNames.dropdown_root,
|
||||||
|
),
|
||||||
|
dropdown: cn(
|
||||||
|
"absolute bg-popover inset-0 opacity-0",
|
||||||
|
defaultClassNames.dropdown,
|
||||||
|
),
|
||||||
|
caption_label: cn(
|
||||||
|
"select-none font-medium",
|
||||||
|
captionLayout === "label"
|
||||||
|
? "text-sm"
|
||||||
|
: "rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5",
|
||||||
|
defaultClassNames.caption_label,
|
||||||
|
),
|
||||||
|
table: "w-full border-collapse",
|
||||||
|
weekdays: cn("flex", defaultClassNames.weekdays),
|
||||||
|
weekday: cn(
|
||||||
|
"text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none",
|
||||||
|
defaultClassNames.weekday,
|
||||||
|
),
|
||||||
|
week: cn("flex w-full mt-2", defaultClassNames.week),
|
||||||
|
week_number_header: cn(
|
||||||
|
"select-none w-(--cell-size)",
|
||||||
|
defaultClassNames.week_number_header,
|
||||||
|
),
|
||||||
|
week_number: cn(
|
||||||
|
"text-[0.8rem] select-none text-muted-foreground",
|
||||||
|
defaultClassNames.week_number,
|
||||||
),
|
),
|
||||||
day: cn(
|
day: cn(
|
||||||
buttonVariants({ variant: "ghost" }),
|
"relative w-full h-full p-0 text-center [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",
|
||||||
"h-8 w-8 p-0 font-normal aria-selected:opacity-100"
|
props.showWeekNumber
|
||||||
|
? "[&:nth-child(2)[data-selected=true]_button]:rounded-l-md"
|
||||||
|
: "[&:first-child[data-selected=true]_button]:rounded-l-md",
|
||||||
|
defaultClassNames.day,
|
||||||
),
|
),
|
||||||
day_range_start: "day-range-start",
|
range_start: cn(
|
||||||
day_range_end: "day-range-end",
|
"rounded-l-md bg-accent",
|
||||||
day_selected:
|
defaultClassNames.range_start,
|
||||||
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
|
),
|
||||||
day_today: "bg-accent text-accent-foreground",
|
range_middle: cn("rounded-none", defaultClassNames.range_middle),
|
||||||
day_outside:
|
range_end: cn("rounded-r-md bg-accent", defaultClassNames.range_end),
|
||||||
"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",
|
today: cn(
|
||||||
day_disabled: "text-muted-foreground opacity-50",
|
"bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",
|
||||||
day_range_middle:
|
defaultClassNames.today,
|
||||||
"aria-selected:bg-accent aria-selected:text-accent-foreground",
|
),
|
||||||
day_hidden: "invisible",
|
outside: cn(
|
||||||
|
"text-muted-foreground aria-selected:text-muted-foreground",
|
||||||
|
defaultClassNames.outside,
|
||||||
|
),
|
||||||
|
disabled: cn(
|
||||||
|
"text-muted-foreground opacity-50",
|
||||||
|
defaultClassNames.disabled,
|
||||||
|
),
|
||||||
|
hidden: cn("invisible", defaultClassNames.hidden),
|
||||||
...classNames,
|
...classNames,
|
||||||
}}
|
}}
|
||||||
components={{
|
components={{
|
||||||
IconLeft: () => <ChevronLeftIcon className="h-4 w-4" />,
|
Root: ({ className, rootRef, ...props }) => {
|
||||||
IconRight: () => <ChevronRightIcon className="h-4 w-4" />,
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="calendar"
|
||||||
|
ref={rootRef}
|
||||||
|
className={cn(className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
Chevron: ({ className, orientation, ...props }) => {
|
||||||
|
if (orientation === "left") {
|
||||||
|
return (
|
||||||
|
<ChevronLeftIcon className={cn("size-4", className)} {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orientation === "right") {
|
||||||
|
return (
|
||||||
|
<ChevronRightIcon
|
||||||
|
className={cn("size-4", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChevronDownIcon className={cn("size-4", className)} {...props} />
|
||||||
|
);
|
||||||
|
},
|
||||||
|
DayButton: CalendarDayButton,
|
||||||
|
WeekNumber: ({ children, ...props }) => {
|
||||||
|
return (
|
||||||
|
<td {...props}>
|
||||||
|
<div className="flex size-(--cell-size) items-center justify-center text-center">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...components,
|
||||||
}}
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
Calendar.displayName = "Calendar"
|
|
||||||
|
|
||||||
export { Calendar }
|
function CalendarDayButton({
|
||||||
|
className,
|
||||||
|
day,
|
||||||
|
modifiers,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DayButton>) {
|
||||||
|
const defaultClassNames = getDefaultClassNames();
|
||||||
|
|
||||||
|
const ref = React.useRef<HTMLButtonElement>(null);
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (modifiers.focused) ref.current?.focus();
|
||||||
|
}, [modifiers.focused]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
ref={ref}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
data-day={day.date.toLocaleDateString()}
|
||||||
|
data-selected-single={
|
||||||
|
modifiers.selected &&
|
||||||
|
!modifiers.range_start &&
|
||||||
|
!modifiers.range_end &&
|
||||||
|
!modifiers.range_middle
|
||||||
|
}
|
||||||
|
data-range-start={modifiers.range_start}
|
||||||
|
data-range-end={modifiers.range_end}
|
||||||
|
data-range-middle={modifiers.range_middle}
|
||||||
|
className={cn(
|
||||||
|
"flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground dark:hover:text-accent-foreground [&>span]:text-xs [&>span]:opacity-70",
|
||||||
|
defaultClassNames.day,
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Calendar, CalendarDayButton };
|
||||||
|
|||||||
+84
-68
@@ -1,76 +1,92 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Card = React.forwardRef<
|
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card"
|
||||||
<div
|
className={cn(
|
||||||
ref={ref}
|
"flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm",
|
||||||
className={cn(
|
className,
|
||||||
"rounded-xl border bg-card text-card-foreground shadow",
|
)}
|
||||||
className
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
))
|
|
||||||
Card.displayName = "Card"
|
|
||||||
|
|
||||||
const CardHeader = React.forwardRef<
|
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-header"
|
||||||
<div
|
className={cn(
|
||||||
ref={ref}
|
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||||
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
className,
|
||||||
{...props}
|
)}
|
||||||
/>
|
{...props}
|
||||||
))
|
/>
|
||||||
CardHeader.displayName = "CardHeader"
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const CardTitle = React.forwardRef<
|
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLParagraphElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLHeadingElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-title"
|
||||||
<h3
|
className={cn("leading-none font-semibold", className)}
|
||||||
ref={ref}
|
{...props}
|
||||||
className={cn("font-semibold leading-none tracking-tight", className)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
))
|
|
||||||
CardTitle.displayName = "CardTitle"
|
|
||||||
|
|
||||||
const CardDescription = React.forwardRef<
|
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLParagraphElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLParagraphElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-description"
|
||||||
<p
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
ref={ref}
|
{...props}
|
||||||
className={cn("text-sm text-muted-foreground", className)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
))
|
|
||||||
CardDescription.displayName = "CardDescription"
|
|
||||||
|
|
||||||
const CardContent = React.forwardRef<
|
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-action"
|
||||||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
className={cn(
|
||||||
))
|
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||||
CardContent.displayName = "CardContent"
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const CardFooter = React.forwardRef<
|
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-content"
|
||||||
<div
|
className={cn("px-6", className)}
|
||||||
ref={ref}
|
{...props}
|
||||||
className={cn("flex items-center p-6 pt-0", className)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
))
|
|
||||||
CardFooter.displayName = "CardFooter"
|
|
||||||
|
|
||||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
|
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-footer"
|
||||||
|
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Card,
|
||||||
|
CardHeader,
|
||||||
|
CardFooter,
|
||||||
|
CardTitle,
|
||||||
|
CardAction,
|
||||||
|
CardDescription,
|
||||||
|
CardContent,
|
||||||
|
};
|
||||||
|
|||||||
+153
-174
@@ -1,254 +1,233 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import { ArrowLeftIcon, ArrowRightIcon } from "@radix-ui/react-icons"
|
|
||||||
import useEmblaCarousel, {
|
import useEmblaCarousel, {
|
||||||
type UseEmblaCarouselType,
|
type UseEmblaCarouselType,
|
||||||
} from "embla-carousel-react"
|
} from "embla-carousel-react";
|
||||||
|
import { ArrowLeft, ArrowRight } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
type CarouselApi = UseEmblaCarouselType[1]
|
type CarouselApi = UseEmblaCarouselType[1];
|
||||||
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
|
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
|
||||||
type CarouselOptions = UseCarouselParameters[0]
|
type CarouselOptions = UseCarouselParameters[0];
|
||||||
type CarouselPlugin = UseCarouselParameters[1]
|
type CarouselPlugin = UseCarouselParameters[1];
|
||||||
|
|
||||||
type CarouselProps = {
|
type CarouselProps = {
|
||||||
opts?: CarouselOptions
|
opts?: CarouselOptions;
|
||||||
plugins?: CarouselPlugin
|
plugins?: CarouselPlugin;
|
||||||
orientation?: "horizontal" | "vertical"
|
orientation?: "horizontal" | "vertical";
|
||||||
setApi?: (api: CarouselApi) => void
|
setApi?: (api: CarouselApi) => void;
|
||||||
}
|
};
|
||||||
|
|
||||||
type CarouselContextProps = {
|
type CarouselContextProps = {
|
||||||
carouselRef: ReturnType<typeof useEmblaCarousel>[0]
|
carouselRef: ReturnType<typeof useEmblaCarousel>[0];
|
||||||
api: ReturnType<typeof useEmblaCarousel>[1]
|
api: ReturnType<typeof useEmblaCarousel>[1];
|
||||||
scrollPrev: () => void
|
scrollPrev: () => void;
|
||||||
scrollNext: () => void
|
scrollNext: () => void;
|
||||||
canScrollPrev: boolean
|
canScrollPrev: boolean;
|
||||||
canScrollNext: boolean
|
canScrollNext: boolean;
|
||||||
} & CarouselProps
|
} & CarouselProps;
|
||||||
|
|
||||||
const CarouselContext = React.createContext<CarouselContextProps | null>(null)
|
const CarouselContext = React.createContext<CarouselContextProps | null>(null);
|
||||||
|
|
||||||
function useCarousel() {
|
function useCarousel() {
|
||||||
const context = React.useContext(CarouselContext)
|
const context = React.useContext(CarouselContext);
|
||||||
|
|
||||||
if (!context) {
|
if (!context) {
|
||||||
throw new Error("useCarousel must be used within a <Carousel />")
|
throw new Error("useCarousel must be used within a <Carousel />");
|
||||||
}
|
}
|
||||||
|
|
||||||
return context
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Carousel = React.forwardRef<
|
function Carousel({
|
||||||
HTMLDivElement,
|
orientation = "horizontal",
|
||||||
React.HTMLAttributes<HTMLDivElement> & CarouselProps
|
opts,
|
||||||
>(
|
setApi,
|
||||||
(
|
plugins,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & CarouselProps) {
|
||||||
|
const [carouselRef, api] = useEmblaCarousel(
|
||||||
{
|
{
|
||||||
orientation = "horizontal",
|
...opts,
|
||||||
opts,
|
axis: orientation === "horizontal" ? "x" : "y",
|
||||||
setApi,
|
|
||||||
plugins,
|
|
||||||
className,
|
|
||||||
children,
|
|
||||||
...props
|
|
||||||
},
|
},
|
||||||
ref
|
plugins,
|
||||||
) => {
|
);
|
||||||
const [carouselRef, api] = useEmblaCarousel(
|
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
||||||
{
|
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
||||||
...opts,
|
|
||||||
axis: orientation === "horizontal" ? "x" : "y",
|
|
||||||
},
|
|
||||||
plugins
|
|
||||||
)
|
|
||||||
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
|
|
||||||
const [canScrollNext, setCanScrollNext] = React.useState(false)
|
|
||||||
|
|
||||||
const onSelect = React.useCallback((api: CarouselApi) => {
|
const onSelect = React.useCallback((api: CarouselApi) => {
|
||||||
if (!api) {
|
if (!api) return;
|
||||||
return
|
setCanScrollPrev(api.canScrollPrev());
|
||||||
|
setCanScrollNext(api.canScrollNext());
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const scrollPrev = React.useCallback(() => {
|
||||||
|
api?.scrollPrev();
|
||||||
|
}, [api]);
|
||||||
|
|
||||||
|
const scrollNext = React.useCallback(() => {
|
||||||
|
api?.scrollNext();
|
||||||
|
}, [api]);
|
||||||
|
|
||||||
|
const handleKeyDown = React.useCallback(
|
||||||
|
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||||
|
if (event.key === "ArrowLeft") {
|
||||||
|
event.preventDefault();
|
||||||
|
scrollPrev();
|
||||||
|
} else if (event.key === "ArrowRight") {
|
||||||
|
event.preventDefault();
|
||||||
|
scrollNext();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
[scrollPrev, scrollNext],
|
||||||
|
);
|
||||||
|
|
||||||
setCanScrollPrev(api.canScrollPrev())
|
React.useEffect(() => {
|
||||||
setCanScrollNext(api.canScrollNext())
|
if (!api || !setApi) return;
|
||||||
}, [])
|
setApi(api);
|
||||||
|
}, [api, setApi]);
|
||||||
|
|
||||||
const scrollPrev = React.useCallback(() => {
|
React.useEffect(() => {
|
||||||
api?.scrollPrev()
|
if (!api) return;
|
||||||
}, [api])
|
onSelect(api);
|
||||||
|
api.on("reInit", onSelect);
|
||||||
|
api.on("select", onSelect);
|
||||||
|
|
||||||
const scrollNext = React.useCallback(() => {
|
return () => {
|
||||||
api?.scrollNext()
|
api?.off("select", onSelect);
|
||||||
}, [api])
|
};
|
||||||
|
}, [api, onSelect]);
|
||||||
const handleKeyDown = React.useCallback(
|
|
||||||
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
||||||
if (event.key === "ArrowLeft") {
|
|
||||||
event.preventDefault()
|
|
||||||
scrollPrev()
|
|
||||||
} else if (event.key === "ArrowRight") {
|
|
||||||
event.preventDefault()
|
|
||||||
scrollNext()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[scrollPrev, scrollNext]
|
|
||||||
)
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (!api || !setApi) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
setApi(api)
|
|
||||||
}, [api, setApi])
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (!api) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
onSelect(api)
|
|
||||||
api.on("reInit", onSelect)
|
|
||||||
api.on("select", onSelect)
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
api?.off("select", onSelect)
|
|
||||||
}
|
|
||||||
}, [api, onSelect])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<CarouselContext.Provider
|
|
||||||
value={{
|
|
||||||
carouselRef,
|
|
||||||
api: api,
|
|
||||||
opts,
|
|
||||||
orientation:
|
|
||||||
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
||||||
scrollPrev,
|
|
||||||
scrollNext,
|
|
||||||
canScrollPrev,
|
|
||||||
canScrollNext,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
ref={ref}
|
|
||||||
onKeyDownCapture={handleKeyDown}
|
|
||||||
className={cn("relative", className)}
|
|
||||||
role="region"
|
|
||||||
aria-roledescription="carousel"
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</CarouselContext.Provider>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Carousel.displayName = "Carousel"
|
|
||||||
|
|
||||||
const CarouselContent = React.forwardRef<
|
|
||||||
HTMLDivElement,
|
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
|
||||||
>(({ className, ...props }, ref) => {
|
|
||||||
const { carouselRef, orientation } = useCarousel()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={carouselRef} className="overflow-hidden">
|
<CarouselContext.Provider
|
||||||
|
value={{
|
||||||
|
carouselRef,
|
||||||
|
api: api,
|
||||||
|
opts,
|
||||||
|
orientation:
|
||||||
|
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
||||||
|
scrollPrev,
|
||||||
|
scrollNext,
|
||||||
|
canScrollPrev,
|
||||||
|
canScrollNext,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
onKeyDownCapture={handleKeyDown}
|
||||||
|
className={cn("relative", className)}
|
||||||
|
role="region"
|
||||||
|
aria-roledescription="carousel"
|
||||||
|
data-slot="carousel"
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</CarouselContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
const { carouselRef, orientation } = useCarousel();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={carouselRef}
|
||||||
|
className="overflow-hidden"
|
||||||
|
data-slot="carousel-content"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex",
|
"flex",
|
||||||
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
})
|
}
|
||||||
CarouselContent.displayName = "CarouselContent"
|
|
||||||
|
|
||||||
const CarouselItem = React.forwardRef<
|
function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
const { orientation } = useCarousel();
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
|
||||||
>(({ className, ...props }, ref) => {
|
|
||||||
const { orientation } = useCarousel()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
|
||||||
role="group"
|
role="group"
|
||||||
aria-roledescription="slide"
|
aria-roledescription="slide"
|
||||||
|
data-slot="carousel-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
"min-w-0 shrink-0 grow-0 basis-full",
|
"min-w-0 shrink-0 grow-0 basis-full",
|
||||||
orientation === "horizontal" ? "pl-4" : "pt-4",
|
orientation === "horizontal" ? "pl-4" : "pt-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
})
|
}
|
||||||
CarouselItem.displayName = "CarouselItem"
|
|
||||||
|
|
||||||
const CarouselPrevious = React.forwardRef<
|
function CarouselPrevious({
|
||||||
HTMLButtonElement,
|
className,
|
||||||
React.ComponentProps<typeof Button>
|
variant = "outline",
|
||||||
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
size = "icon",
|
||||||
const { orientation, scrollPrev, canScrollPrev } = useCarousel()
|
...props
|
||||||
|
}: React.ComponentProps<typeof Button>) {
|
||||||
|
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
ref={ref}
|
data-slot="carousel-previous"
|
||||||
variant={variant}
|
variant={variant}
|
||||||
size={size}
|
size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute h-8 w-8 rounded-full",
|
"absolute size-8 rounded-full",
|
||||||
orientation === "horizontal"
|
orientation === "horizontal"
|
||||||
? "-left-12 top-1/2 -translate-y-1/2"
|
? "top-1/2 -left-12 -translate-y-1/2"
|
||||||
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
disabled={!canScrollPrev}
|
disabled={!canScrollPrev}
|
||||||
onClick={scrollPrev}
|
onClick={scrollPrev}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<ArrowLeftIcon className="h-4 w-4" />
|
<ArrowLeft />
|
||||||
<span className="sr-only">Previous slide</span>
|
<span className="sr-only">Previous slide</span>
|
||||||
</Button>
|
</Button>
|
||||||
)
|
);
|
||||||
})
|
}
|
||||||
CarouselPrevious.displayName = "CarouselPrevious"
|
|
||||||
|
|
||||||
const CarouselNext = React.forwardRef<
|
function CarouselNext({
|
||||||
HTMLButtonElement,
|
className,
|
||||||
React.ComponentProps<typeof Button>
|
variant = "outline",
|
||||||
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
size = "icon",
|
||||||
const { orientation, scrollNext, canScrollNext } = useCarousel()
|
...props
|
||||||
|
}: React.ComponentProps<typeof Button>) {
|
||||||
|
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
ref={ref}
|
data-slot="carousel-next"
|
||||||
variant={variant}
|
variant={variant}
|
||||||
size={size}
|
size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute h-8 w-8 rounded-full",
|
"absolute size-8 rounded-full",
|
||||||
orientation === "horizontal"
|
orientation === "horizontal"
|
||||||
? "-right-12 top-1/2 -translate-y-1/2"
|
? "top-1/2 -right-12 -translate-y-1/2"
|
||||||
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
disabled={!canScrollNext}
|
disabled={!canScrollNext}
|
||||||
onClick={scrollNext}
|
onClick={scrollNext}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<ArrowRightIcon className="h-4 w-4" />
|
<ArrowRight />
|
||||||
<span className="sr-only">Next slide</span>
|
<span className="sr-only">Next slide</span>
|
||||||
</Button>
|
</Button>
|
||||||
)
|
);
|
||||||
})
|
}
|
||||||
CarouselNext.displayName = "CarouselNext"
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
type CarouselApi,
|
type CarouselApi,
|
||||||
@@ -257,4 +236,4 @@ export {
|
|||||||
CarouselItem,
|
CarouselItem,
|
||||||
CarouselPrevious,
|
CarouselPrevious,
|
||||||
CarouselNext,
|
CarouselNext,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,28 +1,30 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
import { Checkbox as CheckboxPrimitive } from "radix-ui";
|
||||||
import { CheckIcon } from "@radix-ui/react-icons"
|
import { CheckIcon } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Checkbox = React.forwardRef<
|
function Checkbox({
|
||||||
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
className,
|
||||||
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
...props
|
||||||
>(({ className, ...props }, ref) => (
|
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
||||||
<CheckboxPrimitive.Root
|
return (
|
||||||
ref={ref}
|
<CheckboxPrimitive.Root
|
||||||
className={cn(
|
data-slot="checkbox"
|
||||||
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
className={cn(
|
||||||
className
|
"peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",
|
||||||
)}
|
className,
|
||||||
{...props}
|
)}
|
||||||
>
|
{...props}
|
||||||
<CheckboxPrimitive.Indicator
|
|
||||||
className={cn("flex items-center justify-center text-current")}
|
|
||||||
>
|
>
|
||||||
<CheckIcon className="h-4 w-4" />
|
<CheckboxPrimitive.Indicator
|
||||||
</CheckboxPrimitive.Indicator>
|
data-slot="checkbox-indicator"
|
||||||
</CheckboxPrimitive.Root>
|
className="grid place-content-center text-current transition-none"
|
||||||
))
|
>
|
||||||
Checkbox.displayName = CheckboxPrimitive.Root.displayName
|
<CheckIcon className="size-3.5" />
|
||||||
|
</CheckboxPrimitive.Indicator>
|
||||||
|
</CheckboxPrimitive.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export { Checkbox }
|
export { Checkbox };
|
||||||
|
|||||||
@@ -1,27 +1,34 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import { CalendarIcon } from "@radix-ui/react-icons"
|
import { format } from "date-fns";
|
||||||
import { format } from "date-fns"
|
import { DateBefore, DateRange, Matcher, Modifiers } from "react-day-picker";
|
||||||
import { ActiveModifiers, DateBefore, DateRange, Matcher } from "react-day-picker"
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button";
|
||||||
import { Calendar } from "@/components/ui/calendar"
|
import { Calendar } from "@/components/ui/calendar";
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
} from "@/components/ui/popover"
|
} from "@/components/ui/popover";
|
||||||
import { Typography } from "./typography"
|
import { Typography } from "./typography";
|
||||||
|
import { CalendarIcon } from "lucide-react";
|
||||||
|
|
||||||
export type UpdateRangeFunction = (newRange: DateRange) => void;
|
export type UpdateRangeFunction = (newRange: DateRange) => void;
|
||||||
|
|
||||||
export function DatePickerWithRange({
|
export function DatePickerWithRange({
|
||||||
className, updateDateRange, startDate, endDate, allowPast = true
|
className,
|
||||||
|
updateDateRange,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
allowPast = true,
|
||||||
}: {
|
}: {
|
||||||
className?: React.HTMLAttributes<HTMLDivElement> | undefined, updateDateRange: UpdateRangeFunction | undefined,
|
className?: React.HTMLAttributes<HTMLDivElement> | undefined;
|
||||||
startDate?: Date, endDate?: Date, allowPast?: boolean
|
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>({
|
||||||
@@ -31,30 +38,30 @@ export function DatePickerWithRange({
|
|||||||
|
|
||||||
//TODOME: Si el día es mods.outside, navegar al mes correspondiente.
|
//TODOME: Si el día es mods.outside, navegar al mes correspondiente.
|
||||||
// Handle Day change events.
|
// Handle Day change events.
|
||||||
const handleDayClickFrom = (day: Date, mods: ActiveModifiers) => {
|
const handleDayClickFrom = (day: Date, mods: Modifiers) => {
|
||||||
const newDateRange: DateRange = {
|
const newDateRange: DateRange = {
|
||||||
from: mods.selected ? undefined : day,
|
from: mods.selected ? undefined : day,
|
||||||
to: dateRange?.to
|
to: undefined,
|
||||||
}
|
};
|
||||||
|
|
||||||
setDateRange(newDateRange)
|
fnUpdateRange(newDateRange);
|
||||||
if (updateDateRange !== undefined) {
|
};
|
||||||
updateDateRange(newDateRange)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleDayClickTo = (day: Date, mods: ActiveModifiers) => {
|
const handleDayClickTo = (day: Date, mods: Modifiers) => {
|
||||||
const newDateRange: DateRange = {
|
const newDateRange: DateRange = {
|
||||||
from: dateRange?.from,
|
from: dateRange?.from,
|
||||||
to: mods.selected ? undefined : day
|
to: mods.selected ? undefined : day,
|
||||||
}
|
};
|
||||||
|
|
||||||
setDateRange(newDateRange)
|
fnUpdateRange(newDateRange);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fnUpdateRange = (range: DateRange) => {
|
||||||
|
setDateRange(range);
|
||||||
if (updateDateRange !== undefined) {
|
if (updateDateRange !== undefined) {
|
||||||
updateDateRange(newDateRange)
|
updateDateRange(range);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Disable days from "To" before "From"
|
// Disable days from "To" before "From"
|
||||||
let beforeAndSelected: Matcher[] = [];
|
let beforeAndSelected: Matcher[] = [];
|
||||||
@@ -70,30 +77,31 @@ export function DatePickerWithRange({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("grid gap-x-2 grid-cols-2 grid-rows-2", className)}>
|
<div className={cn("grid grid-cols-2 grid-rows-2 gap-x-2", className)}>
|
||||||
<Typography variant={"largeText"} as="p">Desde</Typography>
|
<Typography variant={"largeText"} as="p">
|
||||||
<Typography variant={"largeText"} as="p">Hasta</Typography>
|
Desde
|
||||||
|
</Typography>
|
||||||
|
<Typography variant={"largeText"} as="p">
|
||||||
|
Hasta
|
||||||
|
</Typography>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger>
|
||||||
<Button
|
<Button
|
||||||
id="dateFrom"
|
id="dateFrom"
|
||||||
variant={"outline"}
|
variant="outline"
|
||||||
className={cn(
|
data-empty={!dateRange}
|
||||||
"justify-start text-left font-normal",
|
className="w-full justify-start text-left font-normal data-[empty=true]:text-muted-foreground"
|
||||||
!dateRange && "text-muted-foreground"
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
<CalendarIcon className="mr-2 h-4 w-4" />
|
<CalendarIcon />
|
||||||
{dateRange?.from ? (
|
{dateRange?.from ? (
|
||||||
format(dateRange.from, "LLL dd, y")
|
format(dateRange.from, "PPP")
|
||||||
) : (
|
) : (
|
||||||
<span>Pick a date</span>
|
<span>Pick a date</span>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-auto p-0" align="start">
|
<PopoverContent className="w-auto p-0" align="center">
|
||||||
<Calendar
|
<Calendar
|
||||||
initialFocus
|
|
||||||
mode="single"
|
mode="single"
|
||||||
defaultMonth={dateRange?.from}
|
defaultMonth={dateRange?.from}
|
||||||
selected={dateRange?.from}
|
selected={dateRange?.from}
|
||||||
@@ -104,28 +112,26 @@ export function DatePickerWithRange({
|
|||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger>
|
||||||
<Button
|
<Button
|
||||||
id="dateTo"
|
id="dateTo"
|
||||||
variant={"outline"}
|
variant={"outline"}
|
||||||
className={cn(
|
data-empty={!dateRange}
|
||||||
"justify-start text-left font-normal",
|
className="w-full justify-start text-left font-normal data-[empty=true]:text-muted-foreground"
|
||||||
!dateRange && "text-muted-foreground"
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
<CalendarIcon className="mr-2 h-4 w-4" />
|
<CalendarIcon className="mr-2 h-4 w-4" />
|
||||||
{dateRange?.to ? (
|
{dateRange?.to ? (
|
||||||
format(dateRange.to, "LLL dd, y")
|
format(dateRange.to, "PPP")
|
||||||
) : (
|
) : (
|
||||||
<span>Pick a date</span>
|
<span>Pick a date</span>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-auto p-0" align="start">
|
<PopoverContent className="w-auto p-0" align="center">
|
||||||
<Calendar
|
<Calendar
|
||||||
initialFocus
|
autoFocus
|
||||||
mode="single"
|
mode="single"
|
||||||
defaultMonth={dateRange?.to}
|
defaultMonth={dateRange?.to ?? dateRange?.from}
|
||||||
selected={dateRange?.to}
|
selected={dateRange?.to}
|
||||||
onDayClick={handleDayClickTo}
|
onDayClick={handleDayClickTo}
|
||||||
numberOfMonths={1}
|
numberOfMonths={1}
|
||||||
@@ -134,5 +140,5 @@ export function DatePickerWithRange({
|
|||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+225
-173
@@ -1,203 +1,255 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||||
import {
|
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react";
|
||||||
CheckIcon,
|
|
||||||
ChevronRightIcon,
|
|
||||||
DotFilledIcon,
|
|
||||||
} from "@radix-ui/react-icons"
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const DropdownMenu = DropdownMenuPrimitive.Root
|
function DropdownMenu({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||||
|
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
|
function DropdownMenuPortal({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuGroup = DropdownMenuPrimitive.Group
|
function DropdownMenuTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Trigger
|
||||||
|
data-slot="dropdown-menu-trigger"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuPortal = DropdownMenuPrimitive.Portal
|
function DropdownMenuContent({
|
||||||
|
className,
|
||||||
|
sideOffset = 4,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal>
|
||||||
|
<DropdownMenuPrimitive.Content
|
||||||
|
data-slot="dropdown-menu-content"
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</DropdownMenuPrimitive.Portal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuSub = DropdownMenuPrimitive.Sub
|
function DropdownMenuGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup
|
function DropdownMenuItem({
|
||||||
|
className,
|
||||||
const DropdownMenuSubTrigger = React.forwardRef<
|
inset,
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
variant = "default",
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
...props
|
||||||
inset?: boolean
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||||
}
|
inset?: boolean;
|
||||||
>(({ className, inset, children, ...props }, ref) => (
|
variant?: "default" | "destructive";
|
||||||
<DropdownMenuPrimitive.SubTrigger
|
}) {
|
||||||
ref={ref}
|
return (
|
||||||
className={cn(
|
<DropdownMenuPrimitive.Item
|
||||||
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",
|
data-slot="dropdown-menu-item"
|
||||||
inset && "pl-8",
|
data-inset={inset}
|
||||||
className
|
data-variant={variant}
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
<ChevronRightIcon className="ml-auto h-4 w-4" />
|
|
||||||
</DropdownMenuPrimitive.SubTrigger>
|
|
||||||
))
|
|
||||||
DropdownMenuSubTrigger.displayName =
|
|
||||||
DropdownMenuPrimitive.SubTrigger.displayName
|
|
||||||
|
|
||||||
const DropdownMenuSubContent = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.SubContent
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
DropdownMenuSubContent.displayName =
|
|
||||||
DropdownMenuPrimitive.SubContent.displayName
|
|
||||||
|
|
||||||
const DropdownMenuContent = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
|
||||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.Portal>
|
|
||||||
<DropdownMenuPrimitive.Content
|
|
||||||
ref={ref}
|
|
||||||
sideOffset={sideOffset}
|
|
||||||
className={cn(
|
className={cn(
|
||||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
|
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:!text-destructive",
|
||||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
className,
|
||||||
className
|
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</DropdownMenuPrimitive.Portal>
|
);
|
||||||
))
|
}
|
||||||
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
|
|
||||||
|
|
||||||
const DropdownMenuItem = React.forwardRef<
|
function DropdownMenuCheckboxItem({
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
|
||||||
inset?: boolean
|
|
||||||
}
|
|
||||||
>(({ className, inset, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.Item
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
||||||
inset && "pl-8",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
|
|
||||||
|
|
||||||
const DropdownMenuCheckboxItem = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
|
||||||
>(({ className, children, checked, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.CheckboxItem
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
checked={checked}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
||||||
<DropdownMenuPrimitive.ItemIndicator>
|
|
||||||
<CheckIcon className="h-4 w-4" />
|
|
||||||
</DropdownMenuPrimitive.ItemIndicator>
|
|
||||||
</span>
|
|
||||||
{children}
|
|
||||||
</DropdownMenuPrimitive.CheckboxItem>
|
|
||||||
))
|
|
||||||
DropdownMenuCheckboxItem.displayName =
|
|
||||||
DropdownMenuPrimitive.CheckboxItem.displayName
|
|
||||||
|
|
||||||
const DropdownMenuRadioItem = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
|
||||||
>(({ className, children, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.RadioItem
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
||||||
<DropdownMenuPrimitive.ItemIndicator>
|
|
||||||
<DotFilledIcon className="h-4 w-4 fill-current" />
|
|
||||||
</DropdownMenuPrimitive.ItemIndicator>
|
|
||||||
</span>
|
|
||||||
{children}
|
|
||||||
</DropdownMenuPrimitive.RadioItem>
|
|
||||||
))
|
|
||||||
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName
|
|
||||||
|
|
||||||
const DropdownMenuLabel = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
|
|
||||||
inset?: boolean
|
|
||||||
}
|
|
||||||
>(({ className, inset, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.Label
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"px-2 py-1.5 text-sm font-semibold",
|
|
||||||
inset && "pl-8",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName
|
|
||||||
|
|
||||||
const DropdownMenuSeparator = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.Separator
|
|
||||||
ref={ref}
|
|
||||||
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
|
|
||||||
|
|
||||||
const DropdownMenuShortcut = ({
|
|
||||||
className,
|
className,
|
||||||
|
children,
|
||||||
|
checked,
|
||||||
...props
|
...props
|
||||||
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
||||||
return (
|
return (
|
||||||
<span
|
<DropdownMenuPrimitive.CheckboxItem
|
||||||
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
|
data-slot="dropdown-menu-checkbox-item"
|
||||||
|
className={cn(
|
||||||
|
"relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
checked={checked}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="size-4" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.CheckboxItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuRadioGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioGroup
|
||||||
|
data-slot="dropdown-menu-radio-group"
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuRadioItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioItem
|
||||||
|
data-slot="dropdown-menu-radio-item"
|
||||||
|
className={cn(
|
||||||
|
"relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CircleIcon className="size-2 fill-current" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.RadioItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuLabel({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||||
|
inset?: boolean;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Label
|
||||||
|
data-slot="dropdown-menu-label"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn(
|
||||||
|
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Separator
|
||||||
|
data-slot="dropdown-menu-separator"
|
||||||
|
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuShortcut({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span">) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
data-slot="dropdown-menu-shortcut"
|
||||||
|
className={cn(
|
||||||
|
"ml-auto text-xs tracking-widest text-muted-foreground",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSub({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||||
|
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubTrigger({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||||
|
inset?: boolean;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubTrigger
|
||||||
|
data-slot="dropdown-menu-sub-trigger"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<ChevronRightIcon className="ml-auto size-4" />
|
||||||
|
</DropdownMenuPrimitive.SubTrigger>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubContent({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubContent
|
||||||
|
data-slot="dropdown-menu-sub-content"
|
||||||
|
className={cn(
|
||||||
|
"z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
DropdownMenuShortcut.displayName = "DropdownMenuShortcut"
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
|
DropdownMenuPortal,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
DropdownMenuGroup,
|
||||||
|
DropdownMenuLabel,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuCheckboxItem,
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuRadioGroup,
|
||||||
DropdownMenuRadioItem,
|
DropdownMenuRadioItem,
|
||||||
DropdownMenuLabel,
|
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuShortcut,
|
DropdownMenuShortcut,
|
||||||
DropdownMenuGroup,
|
|
||||||
DropdownMenuPortal,
|
|
||||||
DropdownMenuSub,
|
DropdownMenuSub,
|
||||||
DropdownMenuSubContent,
|
|
||||||
DropdownMenuSubTrigger,
|
DropdownMenuSubTrigger,
|
||||||
DropdownMenuRadioGroup,
|
DropdownMenuSubContent,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { Label as LabelPrimitive, Slot as SlotPrimitive } from "radix-ui";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
FormProvider,
|
||||||
|
useFormContext,
|
||||||
|
useFormState,
|
||||||
|
type ControllerProps,
|
||||||
|
type FieldPath,
|
||||||
|
type FieldValues,
|
||||||
|
} from "react-hook-form";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
||||||
|
const Form = FormProvider;
|
||||||
|
|
||||||
|
type FormFieldContextValue<
|
||||||
|
TFieldValues extends FieldValues = FieldValues,
|
||||||
|
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||||
|
> = {
|
||||||
|
name: TName;
|
||||||
|
};
|
||||||
|
|
||||||
|
const FormFieldContext = React.createContext<FormFieldContextValue>(
|
||||||
|
{} as FormFieldContextValue,
|
||||||
|
);
|
||||||
|
|
||||||
|
const FormField = <
|
||||||
|
TFieldValues extends FieldValues = FieldValues,
|
||||||
|
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||||
|
>({
|
||||||
|
...props
|
||||||
|
}: ControllerProps<TFieldValues, TName>) => {
|
||||||
|
return (
|
||||||
|
<FormFieldContext.Provider value={{ name: props.name }}>
|
||||||
|
<Controller {...props} />
|
||||||
|
</FormFieldContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const useFormField = () => {
|
||||||
|
const fieldContext = React.useContext(FormFieldContext);
|
||||||
|
const itemContext = React.useContext(FormItemContext);
|
||||||
|
const { getFieldState } = useFormContext();
|
||||||
|
const formState = useFormState({ name: fieldContext.name });
|
||||||
|
const fieldState = getFieldState(fieldContext.name, formState);
|
||||||
|
|
||||||
|
if (!fieldContext) {
|
||||||
|
throw new Error("useFormField should be used within <FormField>");
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = itemContext;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name: fieldContext.name,
|
||||||
|
formItemId: `${id}-form-item`,
|
||||||
|
formDescriptionId: `${id}-form-item-description`,
|
||||||
|
formMessageId: `${id}-form-item-message`,
|
||||||
|
...fieldState,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
type FormItemContextValue = {
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const FormItemContext = React.createContext<FormItemContextValue>(
|
||||||
|
{} as FormItemContextValue,
|
||||||
|
);
|
||||||
|
|
||||||
|
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
const id = React.useId();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormItemContext.Provider value={{ id }}>
|
||||||
|
<div
|
||||||
|
data-slot="form-item"
|
||||||
|
className={cn("grid gap-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</FormItemContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FormLabel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||||
|
const { error, formItemId } = useFormField();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Label
|
||||||
|
data-slot="form-label"
|
||||||
|
data-error={!!error}
|
||||||
|
className={cn("data-[error=true]:text-destructive", className)}
|
||||||
|
htmlFor={formItemId}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FormControl({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SlotPrimitive.Slot>) {
|
||||||
|
const { error, formItemId, formDescriptionId, formMessageId } =
|
||||||
|
useFormField();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SlotPrimitive.Slot
|
||||||
|
data-slot="form-control"
|
||||||
|
id={formItemId}
|
||||||
|
aria-describedby={
|
||||||
|
!error
|
||||||
|
? `${formDescriptionId}`
|
||||||
|
: `${formDescriptionId} ${formMessageId}`
|
||||||
|
}
|
||||||
|
aria-invalid={!!error}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||||
|
const { formDescriptionId } = useFormField();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<p
|
||||||
|
data-slot="form-description"
|
||||||
|
id={formDescriptionId}
|
||||||
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
|
||||||
|
const { error, formMessageId } = useFormField();
|
||||||
|
const body = error ? String(error?.message ?? "") : props.children;
|
||||||
|
|
||||||
|
if (!body) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<p
|
||||||
|
data-slot="form-message"
|
||||||
|
id={formMessageId}
|
||||||
|
className={cn("text-sm text-destructive", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{body}
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
|
useFormField,
|
||||||
|
Form,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormControl,
|
||||||
|
FormDescription,
|
||||||
|
FormMessage,
|
||||||
|
FormField,
|
||||||
|
};
|
||||||
@@ -1,35 +1,47 @@
|
|||||||
import { Typography } from "./typography";
|
import { Typography } from "./typography";
|
||||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip";
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "./tooltip";
|
||||||
import { PropsWithChildren } from "react";
|
import { PropsWithChildren } from "react";
|
||||||
|
|
||||||
interface IconWithTooltipNumberProps {
|
interface IconWithTooltipNumberProps {
|
||||||
amount?: number | null |undefined,
|
label?: string | null | undefined;
|
||||||
altText?: string | null | undefined
|
labelPosition?: "left" | "right" | null | undefined;
|
||||||
|
tooltipText?: string | null | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function IconWithTooltipNumber({ amount = undefined, altText = undefined, children }: PropsWithChildren<IconWithTooltipNumberProps>) {
|
export function IconWithTooltip({
|
||||||
|
label = undefined,
|
||||||
const iconElement = altText ? (
|
labelPosition = "left",
|
||||||
|
tooltipText = undefined,
|
||||||
|
children,
|
||||||
|
}: PropsWithChildren<IconWithTooltipNumberProps>) {
|
||||||
|
const iconElement = tooltipText ? (
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>{children}</TooltipTrigger>
|
||||||
{children}
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>
|
<TooltipContent>
|
||||||
<p>{altText}</p>
|
<p className="inline">{tooltipText}</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>{children}</>
|
||||||
{children}
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const labelElement = (
|
||||||
|
<Typography variant={"p_inline"} className="px-1">
|
||||||
|
{label}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="flex flex-row items-center gap-1">
|
||||||
{amount && <Typography variant={"p_inline"}>{amount}</Typography>}
|
{label && labelPosition == "left" && labelElement}
|
||||||
{iconElement}
|
{iconElement}
|
||||||
</>
|
{label && labelPosition == "right" && labelElement}
|
||||||
)
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-22
@@ -1,25 +1,21 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
export interface InputProps
|
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
return (
|
||||||
|
<input
|
||||||
|
type={type}
|
||||||
|
data-slot="input"
|
||||||
|
className={cn(
|
||||||
|
"h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30",
|
||||||
|
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
||||||
|
"aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
export { Input };
|
||||||
({ className, type, ...props }, ref) => {
|
|
||||||
return (
|
|
||||||
<input
|
|
||||||
type={type}
|
|
||||||
className={cn(
|
|
||||||
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
ref={ref}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Input.displayName = "Input"
|
|
||||||
|
|
||||||
export { Input }
|
|
||||||
|
|||||||
+19
-21
@@ -1,24 +1,22 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
import { Label as LabelPrimitive } from "radix-ui";
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const labelVariants = cva(
|
function Label({
|
||||||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
className,
|
||||||
)
|
...props
|
||||||
|
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||||
|
return (
|
||||||
|
<LabelPrimitive.Root
|
||||||
|
data-slot="label"
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const Label = React.forwardRef<
|
export { Label };
|
||||||
React.ElementRef<typeof LabelPrimitive.Root>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
|
|
||||||
VariantProps<typeof labelVariants>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<LabelPrimitive.Root
|
|
||||||
ref={ref}
|
|
||||||
className={cn(labelVariants(), className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
Label.displayName = LabelPrimitive.Root.displayName
|
|
||||||
|
|
||||||
export { Label }
|
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
import { useState } from "react"
|
import { useState } from "react";
|
||||||
import { Button } from "./button";
|
import { Button } from "./button";
|
||||||
import { Typography } from "./typography";
|
import { Typography } from "./typography";
|
||||||
|
|
||||||
|
|
||||||
export type UpdateSelectedNumberFunction = (newCount: number) => void;
|
export type UpdateSelectedNumberFunction = (newCount: number) => void;
|
||||||
|
|
||||||
export function NumberSelector(
|
export function NumberSelector({
|
||||||
{ updateCount, addEnabled = true, allowNegative = false }:
|
updateCount,
|
||||||
{ updateCount: UpdateSelectedNumberFunction, addEnabled?: boolean, allowNegative?: boolean }) {
|
addEnabled = true,
|
||||||
|
allowNegative = false,
|
||||||
const [count, setCount] = useState<number>(0);
|
initialValue = 0,
|
||||||
|
}: {
|
||||||
|
updateCount: UpdateSelectedNumberFunction;
|
||||||
|
addEnabled?: boolean;
|
||||||
|
allowNegative?: boolean;
|
||||||
|
initialValue?: number;
|
||||||
|
}) {
|
||||||
|
const [count, setCount] = useState<number>(initialValue);
|
||||||
|
|
||||||
const counterUpdated = (newAmount: number) => {
|
const counterUpdated = (newAmount: number) => {
|
||||||
setCount(newAmount);
|
setCount(newAmount);
|
||||||
@@ -17,17 +23,24 @@ export function NumberSelector(
|
|||||||
if (updateCount != undefined) {
|
if (updateCount != undefined) {
|
||||||
updateCount(newAmount);
|
updateCount(newAmount);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const minusDisabled = (!allowNegative && count <= 0)
|
const minusDisabled = !allowNegative && count <= 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-row items-center gap-2">
|
<div className="flex flex-row items-center gap-2">
|
||||||
<Button disabled={minusDisabled}
|
<Button
|
||||||
onClick={() => counterUpdated(count - 1)}>-</Button>
|
disabled={minusDisabled}
|
||||||
<Typography variant={"largeText"} className="mx-2">{count}</Typography>
|
onClick={() => counterUpdated(count - 1)}
|
||||||
<Button disabled={!addEnabled}
|
>
|
||||||
onClick={() => counterUpdated(count + 1)}>+</Button>
|
-
|
||||||
|
</Button>
|
||||||
|
<Typography variant={"largeText"} className="mx-2">
|
||||||
|
{count}
|
||||||
|
</Typography>
|
||||||
|
<Button disabled={!addEnabled} onClick={() => counterUpdated(count + 1)}>
|
||||||
|
+
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,46 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as PopoverPrimitive from "@radix-ui/react-popover"
|
import { Popover as PopoverPrimitive } from "radix-ui";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Popover = PopoverPrimitive.Root
|
function Popover({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof PopoverPrimitive.Root>) {
|
||||||
|
return <PopoverPrimitive.Root data-slot="popover" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
const PopoverTrigger = PopoverPrimitive.Trigger
|
function PopoverTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
|
||||||
|
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
const PopoverAnchor = PopoverPrimitive.Anchor
|
function PopoverContent({
|
||||||
|
className,
|
||||||
|
align = "center",
|
||||||
|
sideOffset = 4,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof PopoverPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<PopoverPrimitive.Portal>
|
||||||
|
<PopoverPrimitive.Content
|
||||||
|
data-slot="popover-content"
|
||||||
|
align={align}
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</PopoverPrimitive.Portal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const PopoverContent = React.forwardRef<
|
function PopoverAnchor({
|
||||||
React.ElementRef<typeof PopoverPrimitive.Content>,
|
...props
|
||||||
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
|
||||||
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
|
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />;
|
||||||
<PopoverPrimitive.Portal>
|
}
|
||||||
<PopoverPrimitive.Content
|
|
||||||
ref={ref}
|
|
||||||
align={align}
|
|
||||||
sideOffset={sideOffset}
|
|
||||||
className={cn(
|
|
||||||
"z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
</PopoverPrimitive.Portal>
|
|
||||||
))
|
|
||||||
PopoverContent.displayName = PopoverPrimitive.Content.displayName
|
|
||||||
|
|
||||||
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }
|
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
|
||||||
|
|||||||
@@ -1,29 +1,40 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
import { Separator as SeparatorPrimitive } from "radix-ui";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
import { cva, VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
const Separator = React.forwardRef<
|
const separatorVariants = cva(
|
||||||
React.ElementRef<typeof SeparatorPrimitive.Root>,
|
"shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
||||||
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
|
{
|
||||||
>(
|
variants: {
|
||||||
(
|
variant: {
|
||||||
{ className, orientation = "horizontal", decorative = true, ...props },
|
default: "my-10",
|
||||||
ref
|
},
|
||||||
) => (
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
function Separator({
|
||||||
|
className,
|
||||||
|
variant,
|
||||||
|
orientation = "horizontal",
|
||||||
|
decorative = true,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SeparatorPrimitive.Root> &
|
||||||
|
VariantProps<typeof separatorVariants>) {
|
||||||
|
return (
|
||||||
<SeparatorPrimitive.Root
|
<SeparatorPrimitive.Root
|
||||||
ref={ref}
|
data-slot="separator"
|
||||||
decorative={decorative}
|
decorative={decorative}
|
||||||
orientation={orientation}
|
orientation={orientation}
|
||||||
className={cn(
|
className={cn(separatorVariants({ variant, className }))}
|
||||||
"shrink-0 bg-border",
|
|
||||||
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
)
|
}
|
||||||
Separator.displayName = SeparatorPrimitive.Root.displayName
|
|
||||||
|
|
||||||
export { Separator }
|
export { Separator };
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function Skeleton({
|
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
className,
|
|
||||||
...props
|
|
||||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn("animate-pulse rounded-md bg-primary/10", className)}
|
data-slot="skeleton"
|
||||||
|
className={cn("animate-pulse rounded-md bg-accent", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Skeleton }
|
export { Skeleton };
|
||||||
|
|||||||
+94
-100
@@ -1,112 +1,106 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Table = React.forwardRef<
|
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
||||||
HTMLTableElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-container"
|
||||||
<div className="relative w-full overflow-auto">
|
className="relative w-full overflow-x-auto"
|
||||||
<table
|
>
|
||||||
ref={ref}
|
<table
|
||||||
className={cn("w-full caption-bottom text-sm", className)}
|
data-slot="table"
|
||||||
|
className={cn("w-full caption-bottom text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
||||||
|
return (
|
||||||
|
<thead
|
||||||
|
data-slot="table-header"
|
||||||
|
className={cn("[&_tr]:border-b", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</div>
|
);
|
||||||
))
|
}
|
||||||
Table.displayName = "Table"
|
|
||||||
|
|
||||||
const TableHeader = React.forwardRef<
|
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
||||||
HTMLTableSectionElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableSectionElement>
|
<tbody
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-body"
|
||||||
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
|
className={cn("[&_tr:last-child]:border-0", className)}
|
||||||
))
|
{...props}
|
||||||
TableHeader.displayName = "TableHeader"
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const TableBody = React.forwardRef<
|
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
||||||
HTMLTableSectionElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableSectionElement>
|
<tfoot
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-footer"
|
||||||
<tbody
|
className={cn(
|
||||||
ref={ref}
|
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
||||||
className={cn("[&_tr:last-child]:border-0", className)}
|
className,
|
||||||
{...props}
|
)}
|
||||||
/>
|
{...props}
|
||||||
))
|
/>
|
||||||
TableBody.displayName = "TableBody"
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const TableFooter = React.forwardRef<
|
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
||||||
HTMLTableSectionElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableSectionElement>
|
<tr
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-row"
|
||||||
<tfoot
|
className={cn(
|
||||||
ref={ref}
|
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
||||||
className={cn(
|
className,
|
||||||
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
)}
|
||||||
className
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
))
|
|
||||||
TableFooter.displayName = "TableFooter"
|
|
||||||
|
|
||||||
const TableRow = React.forwardRef<
|
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
||||||
HTMLTableRowElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableRowElement>
|
<th
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-head"
|
||||||
<tr
|
className={cn(
|
||||||
ref={ref}
|
"h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
className={cn(
|
className,
|
||||||
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
)}
|
||||||
className
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
))
|
|
||||||
TableRow.displayName = "TableRow"
|
|
||||||
|
|
||||||
const TableHead = React.forwardRef<
|
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||||
HTMLTableCellElement,
|
return (
|
||||||
React.ThHTMLAttributes<HTMLTableCellElement>
|
<td
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-cell"
|
||||||
<th
|
className={cn(
|
||||||
ref={ref}
|
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
className={cn(
|
className,
|
||||||
"h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
)}
|
||||||
className
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
))
|
|
||||||
TableHead.displayName = "TableHead"
|
|
||||||
|
|
||||||
const TableCell = React.forwardRef<
|
function TableCaption({
|
||||||
HTMLTableCellElement,
|
className,
|
||||||
React.TdHTMLAttributes<HTMLTableCellElement>
|
...props
|
||||||
>(({ className, ...props }, ref) => (
|
}: React.ComponentProps<"caption">) {
|
||||||
<td
|
return (
|
||||||
ref={ref}
|
<caption
|
||||||
className={cn(
|
data-slot="table-caption"
|
||||||
"p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
||||||
className
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
))
|
|
||||||
TableCell.displayName = "TableCell"
|
|
||||||
|
|
||||||
const TableCaption = React.forwardRef<
|
|
||||||
HTMLTableCaptionElement,
|
|
||||||
React.HTMLAttributes<HTMLTableCaptionElement>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<caption
|
|
||||||
ref={ref}
|
|
||||||
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
TableCaption.displayName = "TableCaption"
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Table,
|
Table,
|
||||||
@@ -117,4 +111,4 @@ export {
|
|||||||
TableRow,
|
TableRow,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableCaption,
|
TableCaption,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,127 +0,0 @@
|
|||||||
import * as React from "react"
|
|
||||||
import { Cross2Icon } from "@radix-ui/react-icons"
|
|
||||||
import * as ToastPrimitives from "@radix-ui/react-toast"
|
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
|
|
||||||
const ToastProvider = ToastPrimitives.Provider
|
|
||||||
|
|
||||||
const ToastViewport = React.forwardRef<
|
|
||||||
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<ToastPrimitives.Viewport
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
|
|
||||||
|
|
||||||
const toastVariants = cva(
|
|
||||||
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
|
||||||
{
|
|
||||||
variants: {
|
|
||||||
variant: {
|
|
||||||
default: "border bg-background text-foreground",
|
|
||||||
destructive:
|
|
||||||
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
defaultVariants: {
|
|
||||||
variant: "default",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const Toast = React.forwardRef<
|
|
||||||
React.ElementRef<typeof ToastPrimitives.Root>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
|
||||||
VariantProps<typeof toastVariants>
|
|
||||||
>(({ className, variant, ...props }, ref) => {
|
|
||||||
return (
|
|
||||||
<ToastPrimitives.Root
|
|
||||||
ref={ref}
|
|
||||||
className={cn(toastVariants({ variant }), className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
Toast.displayName = ToastPrimitives.Root.displayName
|
|
||||||
|
|
||||||
const ToastAction = React.forwardRef<
|
|
||||||
React.ElementRef<typeof ToastPrimitives.Action>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<ToastPrimitives.Action
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
ToastAction.displayName = ToastPrimitives.Action.displayName
|
|
||||||
|
|
||||||
const ToastClose = React.forwardRef<
|
|
||||||
React.ElementRef<typeof ToastPrimitives.Close>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<ToastPrimitives.Close
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
toast-close=""
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<Cross2Icon className="h-4 w-4" />
|
|
||||||
</ToastPrimitives.Close>
|
|
||||||
))
|
|
||||||
ToastClose.displayName = ToastPrimitives.Close.displayName
|
|
||||||
|
|
||||||
const ToastTitle = React.forwardRef<
|
|
||||||
React.ElementRef<typeof ToastPrimitives.Title>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<ToastPrimitives.Title
|
|
||||||
ref={ref}
|
|
||||||
className={cn("text-sm font-semibold [&+div]:text-xs", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
ToastTitle.displayName = ToastPrimitives.Title.displayName
|
|
||||||
|
|
||||||
const ToastDescription = React.forwardRef<
|
|
||||||
React.ElementRef<typeof ToastPrimitives.Description>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<ToastPrimitives.Description
|
|
||||||
ref={ref}
|
|
||||||
className={cn("text-sm opacity-90", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
ToastDescription.displayName = ToastPrimitives.Description.displayName
|
|
||||||
|
|
||||||
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
|
|
||||||
|
|
||||||
type ToastActionElement = React.ReactElement<typeof ToastAction>
|
|
||||||
|
|
||||||
export {
|
|
||||||
type ToastProps,
|
|
||||||
type ToastActionElement,
|
|
||||||
ToastProvider,
|
|
||||||
ToastViewport,
|
|
||||||
Toast,
|
|
||||||
ToastTitle,
|
|
||||||
ToastDescription,
|
|
||||||
ToastClose,
|
|
||||||
ToastAction,
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import {
|
|
||||||
Toast,
|
|
||||||
ToastClose,
|
|
||||||
ToastDescription,
|
|
||||||
ToastProvider,
|
|
||||||
ToastTitle,
|
|
||||||
ToastViewport,
|
|
||||||
} from "@/components/ui/toast"
|
|
||||||
import { useToast } from "@/components/ui/use-toast"
|
|
||||||
|
|
||||||
export function Toaster() {
|
|
||||||
const { toasts } = useToast()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ToastProvider>
|
|
||||||
{toasts.map(function ({ id, title, description, action, ...props }) {
|
|
||||||
return (
|
|
||||||
<Toast key={id} {...props}>
|
|
||||||
<div className="grid gap-1">
|
|
||||||
{title && <ToastTitle>{title}</ToastTitle>}
|
|
||||||
{description && (
|
|
||||||
<ToastDescription>{description}</ToastDescription>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{action}
|
|
||||||
<ToastClose />
|
|
||||||
</Toast>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
<ToastViewport />
|
|
||||||
</ToastProvider>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,28 +1,59 @@
|
|||||||
import * as React from "react"
|
import * as React from "react";
|
||||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
import { Tooltip as TooltipPrimitive } from "radix-ui";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const TooltipProvider = TooltipPrimitive.Provider
|
function TooltipProvider({
|
||||||
|
delayDuration = 0,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
||||||
|
return (
|
||||||
|
<TooltipPrimitive.Provider
|
||||||
|
data-slot="tooltip-provider"
|
||||||
|
delayDuration={delayDuration}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const Tooltip = TooltipPrimitive.Root
|
function Tooltip({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
||||||
|
return (
|
||||||
|
<TooltipProvider>
|
||||||
|
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
||||||
|
</TooltipProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const TooltipTrigger = TooltipPrimitive.Trigger
|
function TooltipTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
||||||
|
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
const TooltipContent = React.forwardRef<
|
function TooltipContent({
|
||||||
React.ElementRef<typeof TooltipPrimitive.Content>,
|
className,
|
||||||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
sideOffset = 0,
|
||||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
children,
|
||||||
<TooltipPrimitive.Content
|
...props
|
||||||
ref={ref}
|
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
||||||
sideOffset={sideOffset}
|
return (
|
||||||
className={cn(
|
<TooltipPrimitive.Portal>
|
||||||
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
<TooltipPrimitive.Content
|
||||||
className
|
data-slot="tooltip-content"
|
||||||
)}
|
sideOffset={sideOffset}
|
||||||
{...props}
|
className={cn(
|
||||||
/>
|
"z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
|
||||||
))
|
className,
|
||||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<TooltipPrimitive.Arrow className="z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground" />
|
||||||
|
</TooltipPrimitive.Content>
|
||||||
|
</TooltipPrimitive.Portal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
||||||
|
|||||||
@@ -1,82 +1,85 @@
|
|||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from "react";
|
||||||
import { VariantProps, cva } from 'class-variance-authority';
|
import { VariantProps, cva } from "class-variance-authority";
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from "@/lib/utils";
|
||||||
import { Slot } from '@radix-ui/react-slot';
|
import { Slot as SlotPrimitive } from "radix-ui";
|
||||||
|
|
||||||
const typographyVariants = cva('text-foreground', {
|
const typographyVariants = cva("text-foreground", {
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
h1: 'scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl',
|
h1: "scroll-m-20 text-center text-4xl font-extrabold tracking-tight text-balance",
|
||||||
h2: 'scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight first:mt-0',
|
h2: "scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight first:mt-0",
|
||||||
h3: 'scroll-m-20 text-2xl font-semibold tracking-tight',
|
h3: "scroll-m-20 text-2xl font-semibold tracking-tight",
|
||||||
h4: 'scroll-m-20 text-xl font-semibold tracking-tight',
|
h4: "scroll-m-20 text-xl font-semibold tracking-tight",
|
||||||
h5: 'scroll-m-20 text-lg font-semibold tracking-tight',
|
h5: "scroll-m-20 text-lg font-semibold tracking-tight",
|
||||||
h6: 'scroll-m-20 text-base font-semibold tracking-tight',
|
h6: "scroll-m-20 text-base font-semibold tracking-tight",
|
||||||
p: 'leading-7 [&:not(:first-child)]:mt-6',
|
p: "leading-7 [&:not(:first-child)]:mt-6",
|
||||||
p_inline: 'leading-7',
|
p_inline: "leading-7",
|
||||||
blockquote: 'mt-6 border-l-2 pl-6 italic',
|
blockquote: "mt-6 border-l-2 pl-6 italic",
|
||||||
ul: 'my-6 ml-6 list-disc [&>li]:mt-2',
|
ul: "my-6 ml-6 list-disc [&>li]:mt-2",
|
||||||
inlineCode:
|
inlineCode:
|
||||||
'relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold',
|
"bg-muted relative rounded px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold",
|
||||||
lead: 'text-xl text-muted-foreground',
|
lead: "text-muted-foreground text-xl",
|
||||||
largeText: 'text-lg font-semibold',
|
largeText: "text-lg font-semibold",
|
||||||
smallText: 'text-sm font-medium leading-none',
|
smallText: "text-sm leading-none font-medium",
|
||||||
mutedText: 'text-sm text-muted-foreground',
|
mutedText: "text-muted-foreground text-sm",
|
||||||
},
|
errorText: "text-destructive text-sm font-normal",
|
||||||
},
|
|
||||||
defaultVariants: {
|
|
||||||
variant: "p",
|
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "p",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
type VariantPropType = VariantProps<typeof typographyVariants>;
|
type VariantPropType = VariantProps<typeof typographyVariants>;
|
||||||
|
|
||||||
const variantElementMap: Record<
|
const variantElementMap: Record<
|
||||||
NonNullable<VariantPropType['variant']>,
|
NonNullable<VariantPropType["variant"]>,
|
||||||
string
|
string
|
||||||
> = {
|
> = {
|
||||||
h1: 'h1',
|
h1: "h1",
|
||||||
h2: 'h2',
|
h2: "h2",
|
||||||
h3: 'h3',
|
h3: "h3",
|
||||||
h4: 'h4',
|
h4: "h4",
|
||||||
h5: 'h5',
|
h5: "h5",
|
||||||
h6: 'h6',
|
h6: "h6",
|
||||||
p: 'p',
|
p: "p",
|
||||||
p_inline: 'p',
|
p_inline: "p",
|
||||||
blockquote: 'blockquote',
|
blockquote: "blockquote",
|
||||||
inlineCode: 'code',
|
inlineCode: "code",
|
||||||
largeText: 'div',
|
largeText: "div",
|
||||||
smallText: 'small',
|
smallText: "small",
|
||||||
lead: 'p',
|
lead: "p",
|
||||||
mutedText: 'p',
|
mutedText: "p",
|
||||||
ul: 'ul',
|
errorText: "p",
|
||||||
|
ul: "ul",
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface TypographyProps
|
export interface TypographyProps
|
||||||
extends React.HTMLAttributes<HTMLElement>,
|
extends
|
||||||
VariantProps<typeof typographyVariants> {
|
React.HTMLAttributes<HTMLElement>,
|
||||||
asChild?: boolean;
|
VariantProps<typeof typographyVariants> {
|
||||||
as?: string;
|
asChild?: boolean;
|
||||||
|
as?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Typography = React.forwardRef<HTMLElement, TypographyProps>(
|
const Typography = React.forwardRef<HTMLElement, TypographyProps>(
|
||||||
({ className, variant, as, asChild, ...props }, ref) => {
|
({ className, variant, as, asChild, ...props }, ref) => {
|
||||||
const Comp = asChild
|
const Comp = asChild
|
||||||
? Slot
|
? SlotPrimitive.Slot
|
||||||
: as ?? (variant ? variantElementMap[variant] : undefined) ?? 'div';
|
: (as ?? (variant ? variantElementMap[variant] : undefined) ?? "div");
|
||||||
return (
|
return (
|
||||||
<Comp
|
<Comp
|
||||||
className={cn(typographyVariants({ variant, className }))}
|
className={cn(typographyVariants({ variant, className }))}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
Typography.displayName = 'Typography';
|
Typography.displayName = "Typography";
|
||||||
|
|
||||||
// eslint-disable-next-line react-refresh/only-export-components
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
export { Typography, typographyVariants };
|
export { Typography, typographyVariants };
|
||||||
|
|||||||
@@ -1,192 +0,0 @@
|
|||||||
// Inspired by react-hot-toast library
|
|
||||||
import * as React from "react"
|
|
||||||
|
|
||||||
import type {
|
|
||||||
ToastActionElement,
|
|
||||||
ToastProps,
|
|
||||||
} from "src/components/ui/toast"
|
|
||||||
|
|
||||||
const TOAST_LIMIT = 1
|
|
||||||
const TOAST_REMOVE_DELAY = 1000000
|
|
||||||
|
|
||||||
type ToasterToast = ToastProps & {
|
|
||||||
id: string
|
|
||||||
title?: React.ReactNode
|
|
||||||
description?: React.ReactNode
|
|
||||||
action?: ToastActionElement
|
|
||||||
}
|
|
||||||
|
|
||||||
const actionTypes = {
|
|
||||||
ADD_TOAST: "ADD_TOAST",
|
|
||||||
UPDATE_TOAST: "UPDATE_TOAST",
|
|
||||||
DISMISS_TOAST: "DISMISS_TOAST",
|
|
||||||
REMOVE_TOAST: "REMOVE_TOAST",
|
|
||||||
} as const
|
|
||||||
|
|
||||||
let count = 0
|
|
||||||
|
|
||||||
function genId() {
|
|
||||||
count = (count + 1) % Number.MAX_SAFE_INTEGER
|
|
||||||
return count.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
type ActionType = typeof actionTypes
|
|
||||||
|
|
||||||
type Action =
|
|
||||||
| {
|
|
||||||
type: ActionType["ADD_TOAST"]
|
|
||||||
toast: ToasterToast
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: ActionType["UPDATE_TOAST"]
|
|
||||||
toast: Partial<ToasterToast>
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: ActionType["DISMISS_TOAST"]
|
|
||||||
toastId?: ToasterToast["id"]
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: ActionType["REMOVE_TOAST"]
|
|
||||||
toastId?: ToasterToast["id"]
|
|
||||||
}
|
|
||||||
|
|
||||||
interface State {
|
|
||||||
toasts: ToasterToast[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
|
|
||||||
|
|
||||||
const addToRemoveQueue = (toastId: string) => {
|
|
||||||
if (toastTimeouts.has(toastId)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
toastTimeouts.delete(toastId)
|
|
||||||
dispatch({
|
|
||||||
type: "REMOVE_TOAST",
|
|
||||||
toastId: toastId,
|
|
||||||
})
|
|
||||||
}, TOAST_REMOVE_DELAY)
|
|
||||||
|
|
||||||
toastTimeouts.set(toastId, timeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const reducer = (state: State, action: Action): State => {
|
|
||||||
switch (action.type) {
|
|
||||||
case "ADD_TOAST":
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
|
||||||
}
|
|
||||||
|
|
||||||
case "UPDATE_TOAST":
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
toasts: state.toasts.map((t) =>
|
|
||||||
t.id === action.toast.id ? { ...t, ...action.toast } : t
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
case "DISMISS_TOAST": {
|
|
||||||
const { toastId } = action
|
|
||||||
|
|
||||||
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
|
||||||
// but I'll keep it here for simplicity
|
|
||||||
if (toastId) {
|
|
||||||
addToRemoveQueue(toastId)
|
|
||||||
} else {
|
|
||||||
state.toasts.forEach((toast) => {
|
|
||||||
addToRemoveQueue(toast.id)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
toasts: state.toasts.map((t) =>
|
|
||||||
t.id === toastId || toastId === undefined
|
|
||||||
? {
|
|
||||||
...t,
|
|
||||||
open: false,
|
|
||||||
}
|
|
||||||
: t
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "REMOVE_TOAST":
|
|
||||||
if (action.toastId === undefined) {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
toasts: [],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const listeners: Array<(state: State) => void> = []
|
|
||||||
|
|
||||||
let memoryState: State = { toasts: [] }
|
|
||||||
|
|
||||||
function dispatch(action: Action) {
|
|
||||||
memoryState = reducer(memoryState, action)
|
|
||||||
listeners.forEach((listener) => {
|
|
||||||
listener(memoryState)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type Toast = Omit<ToasterToast, "id">
|
|
||||||
|
|
||||||
function toast({ ...props }: Toast) {
|
|
||||||
const id = genId()
|
|
||||||
|
|
||||||
const update = (props: ToasterToast) =>
|
|
||||||
dispatch({
|
|
||||||
type: "UPDATE_TOAST",
|
|
||||||
toast: { ...props, id },
|
|
||||||
})
|
|
||||||
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
|
|
||||||
|
|
||||||
dispatch({
|
|
||||||
type: "ADD_TOAST",
|
|
||||||
toast: {
|
|
||||||
...props,
|
|
||||||
id,
|
|
||||||
open: true,
|
|
||||||
onOpenChange: (open) => {
|
|
||||||
if (!open) dismiss()
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: id,
|
|
||||||
dismiss,
|
|
||||||
update,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function useToast() {
|
|
||||||
const [state, setState] = React.useState<State>(memoryState)
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
listeners.push(setState)
|
|
||||||
return () => {
|
|
||||||
const index = listeners.indexOf(setState)
|
|
||||||
if (index > -1) {
|
|
||||||
listeners.splice(index, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [state])
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
toast,
|
|
||||||
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { useToast, toast }
|
|
||||||
+213
-50
@@ -1,61 +1,224 @@
|
|||||||
@tailwind base;
|
@import "tailwindcss";
|
||||||
@tailwind components;
|
@import "tw-animate-css";
|
||||||
@tailwind utilities;
|
|
||||||
|
|
||||||
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
@layer base {
|
@theme inline {
|
||||||
:root {
|
--radius-sm: calc(var(--radius) - 4px);
|
||||||
--background: 0 0% 100%;
|
|
||||||
--foreground: 240 10% 3.9%;
|
|
||||||
--card: 0 0% 100%;
|
|
||||||
--card-foreground: 240 10% 3.9%;
|
|
||||||
--popover: 0 0% 100%;
|
|
||||||
--popover-foreground: 240 10% 3.9%;
|
|
||||||
--primary: 142.1 76.2% 36.3%;
|
|
||||||
--primary-foreground: 355.7 100% 97.3%;
|
|
||||||
--secondary: 240 4.8% 95.9%;
|
|
||||||
--secondary-foreground: 240 5.9% 10%;
|
|
||||||
--muted: 240 4.8% 95.9%;
|
|
||||||
--muted-foreground: 240 3.8% 46.1%;
|
|
||||||
--accent: 240 4.8% 95.9%;
|
|
||||||
--accent-foreground: 240 5.9% 10%;
|
|
||||||
--destructive: 0 84.2% 60.2%;
|
|
||||||
--destructive-foreground: 0 0% 98%;
|
|
||||||
--border: 240 5.9% 90%;
|
|
||||||
--input: 240 5.9% 90%;
|
|
||||||
--ring: 142.1 76.2% 36.3%;
|
|
||||||
--radius: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dark {
|
--radius-md: calc(var(--radius) - 2px);
|
||||||
--background: 20 14.3% 4.1%;
|
|
||||||
--foreground: 0 0% 95%;
|
--radius-lg: var(--radius);
|
||||||
--card: 24 9.8% 10%;
|
|
||||||
--card-foreground: 0 0% 95%;
|
--radius-xl: calc(var(--radius) + 4px);
|
||||||
--popover: 0 0% 9%;
|
|
||||||
--popover-foreground: 0 0% 95%;
|
--color-background: var(--background);
|
||||||
--primary: 142.1 70.6% 45.3%;
|
|
||||||
--primary-foreground: 144.9 80.4% 10%;
|
--color-foreground: var(--foreground);
|
||||||
--secondary: 240 3.7% 15.9%;
|
|
||||||
--secondary-foreground: 0 0% 98%;
|
--color-card: var(--card);
|
||||||
--muted: 0 0% 15%;
|
|
||||||
--muted-foreground: 240 5% 64.9%;
|
--color-card-foreground: var(--card-foreground);
|
||||||
--accent: 12 6.5% 15.1%;
|
|
||||||
--accent-foreground: 0 0% 98%;
|
--color-popover: var(--popover);
|
||||||
--destructive: 0 62.8% 30.6%;
|
|
||||||
--destructive-foreground: 0 85.7% 97.3%;
|
--color-popover-foreground: var(--popover-foreground);
|
||||||
--border: 240 3.7% 15.9%;
|
|
||||||
--input: 240 3.7% 15.9%;
|
--color-primary: var(--primary);
|
||||||
--ring: 142.4 71.8% 29.2%;
|
|
||||||
}
|
--color-primary-foreground: var(--primary-foreground);
|
||||||
|
|
||||||
|
--color-secondary: var(--secondary);
|
||||||
|
|
||||||
|
--color-secondary-foreground: var(--secondary-foreground);
|
||||||
|
|
||||||
|
--color-muted: var(--muted);
|
||||||
|
|
||||||
|
--color-muted-foreground: var(--muted-foreground);
|
||||||
|
|
||||||
|
--color-accent: var(--accent);
|
||||||
|
|
||||||
|
--color-accent-foreground: var(--accent-foreground);
|
||||||
|
|
||||||
|
--color-destructive: var(--destructive);
|
||||||
|
|
||||||
|
--color-border: var(--border);
|
||||||
|
|
||||||
|
--color-input: var(--input);
|
||||||
|
|
||||||
|
--color-ring: var(--ring);
|
||||||
|
|
||||||
|
--color-chart-1: var(--chart-1);
|
||||||
|
|
||||||
|
--color-chart-2: var(--chart-2);
|
||||||
|
|
||||||
|
--color-chart-3: var(--chart-3);
|
||||||
|
|
||||||
|
--color-chart-4: var(--chart-4);
|
||||||
|
|
||||||
|
--color-chart-5: var(--chart-5);
|
||||||
|
|
||||||
|
--color-sidebar: var(--sidebar);
|
||||||
|
|
||||||
|
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||||
|
|
||||||
|
--color-sidebar-primary: var(--sidebar-primary);
|
||||||
|
|
||||||
|
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||||
|
|
||||||
|
--color-sidebar-accent: var(--sidebar-accent);
|
||||||
|
|
||||||
|
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||||
|
|
||||||
|
--color-sidebar-border: var(--sidebar-border);
|
||||||
|
|
||||||
|
--color-sidebar-ring: var(--sidebar-ring);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--radius: 0.625rem;
|
||||||
|
|
||||||
|
--background: oklch(1 0 0);
|
||||||
|
|
||||||
|
--foreground: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--card: oklch(1 0 0);
|
||||||
|
|
||||||
|
--card-foreground: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--popover: oklch(1 0 0);
|
||||||
|
|
||||||
|
--popover-foreground: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--primary: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--primary-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--secondary: oklch(0.97 0.001 106.424);
|
||||||
|
|
||||||
|
--secondary-foreground: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--muted: oklch(0.97 0.001 106.424);
|
||||||
|
|
||||||
|
--muted-foreground: oklch(0.553 0.013 58.071);
|
||||||
|
|
||||||
|
--accent: oklch(0.97 0.001 106.424);
|
||||||
|
|
||||||
|
--accent-foreground: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--destructive: oklch(0.577 0.245 27.325);
|
||||||
|
|
||||||
|
--border: oklch(0.923 0.003 48.717);
|
||||||
|
|
||||||
|
--input: oklch(0.923 0.003 48.717);
|
||||||
|
|
||||||
|
--ring: oklch(0.709 0.01 56.259);
|
||||||
|
|
||||||
|
--chart-1: oklch(0.646 0.222 41.116);
|
||||||
|
|
||||||
|
--chart-2: oklch(0.6 0.118 184.704);
|
||||||
|
|
||||||
|
--chart-3: oklch(0.398 0.07 227.392);
|
||||||
|
|
||||||
|
--chart-4: oklch(0.828 0.189 84.429);
|
||||||
|
|
||||||
|
--chart-5: oklch(0.769 0.188 70.08);
|
||||||
|
|
||||||
|
--sidebar: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-foreground: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--sidebar-primary: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--sidebar-primary-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-accent: oklch(0.97 0.001 106.424);
|
||||||
|
|
||||||
|
--sidebar-accent-foreground: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--sidebar-border: oklch(0.923 0.003 48.717);
|
||||||
|
|
||||||
|
--sidebar-ring: oklch(0.709 0.01 56.259);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
--background: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--card: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--card-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--popover: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--popover-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--primary: oklch(0.923 0.003 48.717);
|
||||||
|
|
||||||
|
--primary-foreground: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--secondary: oklch(0.268 0.007 34.298);
|
||||||
|
|
||||||
|
--secondary-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--muted: oklch(0.268 0.007 34.298);
|
||||||
|
|
||||||
|
--muted-foreground: oklch(0.709 0.01 56.259);
|
||||||
|
|
||||||
|
--accent: oklch(0.268 0.007 34.298);
|
||||||
|
|
||||||
|
--accent-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--destructive: oklch(0.704 0.191 22.216);
|
||||||
|
|
||||||
|
--border: oklch(1 0 0 / 10%);
|
||||||
|
|
||||||
|
--input: oklch(1 0 0 / 15%);
|
||||||
|
|
||||||
|
--ring: oklch(0.553 0.013 58.071);
|
||||||
|
|
||||||
|
--chart-1: oklch(0.488 0.243 264.376);
|
||||||
|
|
||||||
|
--chart-2: oklch(0.696 0.17 162.48);
|
||||||
|
|
||||||
|
--chart-3: oklch(0.769 0.188 70.08);
|
||||||
|
|
||||||
|
--chart-4: oklch(0.627 0.265 303.9);
|
||||||
|
|
||||||
|
--chart-5: oklch(0.645 0.246 16.439);
|
||||||
|
|
||||||
|
--sidebar: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--sidebar-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||||
|
|
||||||
|
--sidebar-primary-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-accent: oklch(0.268 0.007 34.298);
|
||||||
|
|
||||||
|
--sidebar-accent-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-border: oklch(1 0 0 / 10%);
|
||||||
|
|
||||||
|
--sidebar-ring: oklch(0.553 0.013 58.071);
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
* {
|
* {
|
||||||
@apply border-border;
|
@apply border-border outline-ring/50;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* SomniaRooms Extended CSS */
|
||||||
|
|
||||||
|
@utility grid-cols-40/60 {
|
||||||
|
grid-template-columns: 40% 60%;
|
||||||
|
}
|
||||||
|
@utility grid-cols-60/40 {
|
||||||
|
grid-template-columns: 60% 40%;
|
||||||
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
import { type ClassValue, clsx } from "clsx"
|
import { clsx, type ClassValue } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge"
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
return twMerge(clsx(inputs));
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-21
@@ -1,13 +1,14 @@
|
|||||||
import React from 'react'
|
import React from "react";
|
||||||
import ReactDOM from 'react-dom/client'
|
import ReactDOM from "react-dom/client";
|
||||||
import './index.css'
|
import "./index.css";
|
||||||
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
|
import { RouterProvider, createBrowserRouter } from "react-router-dom";
|
||||||
import Root from './routes/Root';
|
import Root from "./routes/Root";
|
||||||
import ErrorPage from './error-page';
|
import ErrorPage from "./routes/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';
|
import SuccessPage from "./routes/success-page";
|
||||||
|
import ContactPage from "./routes/contact-page";
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
@@ -17,32 +18,34 @@ const router = createBrowserRouter([
|
|||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
element: <Homepage />
|
element: <Homepage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/home",
|
path: "/home",
|
||||||
element: <Homepage />
|
element: <Homepage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/search",
|
path: "/search",
|
||||||
element: <SearchPage />
|
element: <SearchPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/book",
|
path: "/book",
|
||||||
element: <BookPage />
|
element: <BookPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/success",
|
path: "/success",
|
||||||
element: <SuccessPage />
|
element: <SuccessPage />,
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
|
path: "/contact",
|
||||||
|
element: <ContactPage />,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<RouterProvider router={router} />
|
<RouterProvider router={router} />
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
)
|
);
|
||||||
|
|||||||
+14
-15
@@ -1,25 +1,24 @@
|
|||||||
|
|
||||||
export type NewBooking = {
|
export type NewBooking = {
|
||||||
arrivalDate: Date,
|
arrivalDate: Date;
|
||||||
departureDate: Date,
|
departureDate: Date;
|
||||||
customerDetails: NewBookingCustomerDetails,
|
customerDetails: NewBookingCustomerDetails;
|
||||||
rooms: NewBookingRoom[]
|
rooms: NewBookingRoom[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NewBookingCustomerDetails = {
|
export type NewBookingCustomerDetails = {
|
||||||
name: string | null,
|
name: string | null;
|
||||||
surname: string | null,
|
surname: string | null;
|
||||||
email: string | null,
|
email: string | null;
|
||||||
phoneNumber: string | null
|
phoneNumber: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NewBookingRoom = {
|
export type NewBookingRoom = {
|
||||||
roomCategory: number,
|
roomCategory: number;
|
||||||
guestNumber: number,
|
guestNumber: number;
|
||||||
amount: number,
|
amount: number;
|
||||||
price: number
|
price: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NewBookingResponse = {
|
export type NewBookingResponse = {
|
||||||
refNumber: number,
|
refNumber: number;
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
export type ConfigVar = {
|
||||||
|
key: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export enum eConfigVarKeys {
|
||||||
|
varCompanyName = "CompanyName",
|
||||||
|
varCompanyWebsite = "CompanyWebsite",
|
||||||
|
varCompanyContactFormUrl = "CompanyContactFormUrl",
|
||||||
|
varCompanyLogo = "CompanyLogo",
|
||||||
|
varCompanyLogoSize = "CompanyLogoSize",
|
||||||
|
varCompanyEmail = "CompanyEmail",
|
||||||
|
varCompanyPhone = "CompanyPhone",
|
||||||
|
varCompanyAddress = "CompanyAddress",
|
||||||
|
varNightCountForContactDialog = "NightCountForContactDialog",
|
||||||
|
varGuestNumberForContactDialog = "GuestNumberForContactDialog",
|
||||||
|
varShowNonAvailableRooms = "ShowNonAvailableRooms",
|
||||||
|
varSomniaAttributionNotice = "SomniaAttributionNotice",
|
||||||
|
varPhotoAspectRatio = "PhotoAspectRatio",
|
||||||
|
varAPIMaxAllowedNightAmount = "MaxAllowedNightAmount",
|
||||||
|
varAPIMaxAllowedGuestNumber = "MaxAllowedGuestNumber",
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { z } from "zod/v4";
|
||||||
|
|
||||||
|
export const BookingFormSchema = z.object({
|
||||||
|
name: z.string().min(2).max(50),
|
||||||
|
surname: z.string().min(2).max(50),
|
||||||
|
email: z.email(),
|
||||||
|
phone: z.string().min(8),
|
||||||
|
});
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { DateRange } from "react-day-picker";
|
||||||
|
|
||||||
|
export type SearchFilter = {
|
||||||
|
dateRange: DateRange;
|
||||||
|
};
|
||||||
+18
-21
@@ -1,24 +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,
|
photoOrder: string | undefined;
|
||||||
kind: string,
|
};
|
||||||
}
|
|
||||||
|
export type RoomCategoryBedType = {
|
||||||
|
amount: number;
|
||||||
|
bedTypeName: string;
|
||||||
|
bedTypeIcon: string;
|
||||||
|
};
|
||||||
|
|||||||
+14
-25
@@ -1,30 +1,19 @@
|
|||||||
|
|
||||||
|
|
||||||
export type RoomAvailabity = {
|
export type RoomAvailabity = {
|
||||||
roomCategory: number,
|
roomCategory: number;
|
||||||
availability: number
|
availability: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type RoomPrice = {
|
export type RoomPrice = {
|
||||||
guestNumber: number,
|
guestNumber: number;
|
||||||
price: number
|
price: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type AvailabilityRequest = {
|
export type SearchPeriodRequest = {
|
||||||
filter: AvailabilityFilter
|
startDate: string;
|
||||||
}
|
endDate: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type AvailabilityFilter = {
|
export type RoomPriceSearchResponse = {
|
||||||
startDate: string,
|
roomCategoryId: number;
|
||||||
endDate: string
|
prices: RoomPrice[];
|
||||||
}
|
};
|
||||||
|
|
||||||
export type FareRequest = {
|
|
||||||
filter: FareFilter
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FareFilter = {
|
|
||||||
roomCategory: number,
|
|
||||||
startDate: string,
|
|
||||||
endDate: string
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
import { DateRange } from "react-day-picker"
|
|
||||||
|
|
||||||
export type SearchFilter = {
|
|
||||||
dateRange: DateRange
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 133 KiB |
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 96 KiB |
+7
-2
@@ -8,10 +8,15 @@ html {
|
|||||||
box-sizing: inherit;
|
box-sizing: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.appPage {
|
.appPage {
|
||||||
width: 80%;
|
width: 80%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iconify-icon {
|
||||||
|
display: inline-block;
|
||||||
|
min-width: 1em;
|
||||||
|
min-height: 1em;
|
||||||
|
}
|
||||||
|
|||||||
+8
-11
@@ -1,24 +1,21 @@
|
|||||||
import { Outlet } from 'react-router-dom'
|
import { Outlet } from "react-router-dom";
|
||||||
import './Root.css'
|
import "./Root.css";
|
||||||
import AppHeader from '../components/app-header'
|
import AppHeader from "../components/app-header";
|
||||||
import AppFooter from '../components/app-footer'
|
import AppFooter from "../components/app-footer";
|
||||||
import { ThemeProvider } from '@/components/theme-provider'
|
import { ThemeProvider } from "@/components/theme-provider";
|
||||||
import { Toaster } from '@/components/ui/toaster'
|
|
||||||
|
|
||||||
function Root() {
|
function Root() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
|
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
|
||||||
<AppHeader />
|
<AppHeader />
|
||||||
<div className='appPage bg-background text-foreground'>
|
<div className="mx-auto min-h-screen w-full bg-background p-8 text-center text-foreground sm:w-[90%] md:w-[80%]">
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</div>
|
</div>
|
||||||
<Toaster />
|
|
||||||
<AppFooter />
|
<AppFooter />
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Root
|
export default Root;
|
||||||
|
|||||||
+143
-86
@@ -1,71 +1,67 @@
|
|||||||
import { APISendCreateBooking } from "@/api/api-booking"
|
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 {
|
||||||
import { Label } from "@/components/ui/label"
|
Form,
|
||||||
import { Separator } from "@/components/ui/separator"
|
FormControl,
|
||||||
import { Typography } from "@/components/ui/typography"
|
FormField,
|
||||||
import { useToast } from "@/components/ui/use-toast"
|
FormItem,
|
||||||
import { useAppStore } from "@/store"
|
FormLabel,
|
||||||
import { ChangeEvent, useState } from "react"
|
FormMessage,
|
||||||
import { useNavigate } from "react-router-dom"
|
} from "@/components/ui/form";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import { Typography } from "@/components/ui/typography";
|
||||||
|
import { BookingFormSchema } from "@/model/FormSchema";
|
||||||
|
import { useAppStore } from "@/store";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { z } from "zod/v4";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { eBookingState } from "@/utils/AppStateManager";
|
||||||
|
import { useBookingStateDispacher } from "@/utils/hooks";
|
||||||
|
import { ConstsNav } from "@/utils/Consts";
|
||||||
|
import { NewBookingCustomerDetails } from "@/model/Bookings";
|
||||||
|
|
||||||
enum PageState {
|
enum PageState {
|
||||||
noData, showForm, sending, created, error
|
showForm,
|
||||||
|
sending,
|
||||||
|
error,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function BookPage() {
|
function BookPage() {
|
||||||
const [pageState, setPageState] = useState<PageState>(PageState.showForm);
|
const [pageState, setPageState] = useState<PageState>(PageState.showForm);
|
||||||
const bookingData = useAppStore((state) => state.newBookingData)
|
const bookingData = useAppStore((state) => state.currentBooking);
|
||||||
const setCustomerData = useAppStore((state) => state.setBookingCustomer);
|
const appBookingState = useAppStore((state) => state.bookingState);
|
||||||
const { toast } = useToast();
|
const setCustomerData = useAppStore(
|
||||||
|
(state) => state.currentBookingSetCustomer,
|
||||||
|
);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { setBookingStateBooked } = useBookingStateDispacher();
|
||||||
|
|
||||||
if (!bookingData || !bookingData.customerDetails) {
|
const bookingForm = useForm<z.infer<typeof BookingFormSchema>>({
|
||||||
return (
|
resolver: zodResolver(BookingFormSchema),
|
||||||
<Typography variant={"h2"}>You must select some rooms...</Typography>
|
defaultValues: {
|
||||||
)
|
email: "",
|
||||||
}
|
name: "",
|
||||||
|
surname: "",
|
||||||
|
phone: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
function handleOnChange(e: ChangeEvent<HTMLInputElement>) {
|
function onSubmit(values: z.infer<typeof BookingFormSchema>) {
|
||||||
if (bookingData == null) {
|
if (bookingData == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const newCustomerData: NewBookingCustomerDetails = {
|
||||||
const newCustomerData = bookingData.customerDetails;
|
...bookingData.customerDetails,
|
||||||
|
name: values.name,
|
||||||
switch (e.target.name) {
|
surname: values.surname,
|
||||||
case "name":
|
email: values.email,
|
||||||
newCustomerData.name = e.target.value;
|
phoneNumber: values.phone,
|
||||||
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);
|
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);
|
setPageState(PageState.sending);
|
||||||
console.log(bookingData);
|
console.log(bookingData);
|
||||||
@@ -78,48 +74,109 @@ function BookPage() {
|
|||||||
if (rs.isError) {
|
if (rs.isError) {
|
||||||
setPageState(PageState.error);
|
setPageState(PageState.error);
|
||||||
} else {
|
} else {
|
||||||
navigate("/success", { state: rs.bookingResponse })
|
setBookingStateBooked();
|
||||||
|
navigate(ConstsNav.page_Success, { state: rs.bookingResponse });
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//Redirect to home if no booking is active.
|
||||||
|
if (
|
||||||
|
!appBookingState ||
|
||||||
|
!bookingData ||
|
||||||
|
(appBookingState.state != eBookingState.Booking &&
|
||||||
|
appBookingState.state != eBookingState.Booked)
|
||||||
|
) {
|
||||||
|
navigate(ConstsNav.page_Home);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const errorMsg = (
|
||||||
|
<div>
|
||||||
|
<Typography variant={"inlineCode"}>
|
||||||
|
Server error. Try again later!
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h1"}>Booking Details</Typography>
|
<Typography variant={"h1"}>Booking Details</Typography>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
<div>
|
<div className="lg:grid lg:grid-cols-40/60 lg:gap-x-10">
|
||||||
<Typography variant={"h3"}>Personal Details</Typography>
|
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<Typography variant={"h3"} className="my-4">
|
||||||
<Label htmlFor="name">Name</Label>
|
Personal Details
|
||||||
<Input type="text" name="name" id="name" placeholder="Name" value={bookingData.customerDetails.name ?? ""}
|
</Typography>
|
||||||
onChange={handleOnChange} />
|
<Form {...bookingForm}>
|
||||||
</div>
|
<form
|
||||||
<div>
|
onSubmit={bookingForm.handleSubmit(onSubmit)}
|
||||||
<Label htmlFor="surname">Surname</Label>
|
className="space-y-8"
|
||||||
<Input type="text" name="surname" id="surname" placeholder="Surname" value={bookingData.customerDetails.surname ?? ""}
|
>
|
||||||
onChange={handleOnChange} />
|
<div className="flex w-full flex-row gap-x-3">
|
||||||
</div>
|
<FormField
|
||||||
<div>
|
control={bookingForm.control}
|
||||||
<Label htmlFor="email">Email</Label>
|
name="name"
|
||||||
<Input type="email" name="email" id="email" placeholder="Email" value={bookingData.customerDetails.email ?? ""}
|
render={({ field }) => (
|
||||||
onChange={handleOnChange} />
|
<FormItem className="flex-1">
|
||||||
</div>
|
<FormLabel>Name</FormLabel>
|
||||||
<div>
|
<FormControl>
|
||||||
<Label htmlFor="phone">Phone Number</Label>
|
<Input {...field} />
|
||||||
<Input type="tel" name="phoneNumber" id="phone" placeholder="Number" value={bookingData.customerDetails.phoneNumber ?? ""}
|
</FormControl>
|
||||||
onChange={handleOnChange} />
|
<FormMessage />
|
||||||
</div>
|
</FormItem>
|
||||||
|
)}
|
||||||
|
></FormField>
|
||||||
|
<FormField
|
||||||
|
control={bookingForm.control}
|
||||||
|
name="surname"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex-1">
|
||||||
|
<FormLabel>Surname</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
></FormField>
|
||||||
|
</div>
|
||||||
|
<FormField
|
||||||
|
control={bookingForm.control}
|
||||||
|
name="email"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Email</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
></FormField>
|
||||||
|
<FormField
|
||||||
|
control={bookingForm.control}
|
||||||
|
name="phone"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Phone</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
></FormField>
|
||||||
|
<Button type="submit" disabled={pageState == PageState.sending}>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
{pageState == PageState.error ? errorMsg : null}
|
||||||
</div>
|
</div>
|
||||||
|
<Separator className="my-10 lg:hidden" />
|
||||||
|
<BookingDetails mode="View"></BookingDetails>
|
||||||
</div>
|
</div>
|
||||||
<Separator className="my-10" />
|
|
||||||
<BookingDetails mode="View"></BookingDetails>
|
|
||||||
<Separator className="my-10" />
|
|
||||||
<Button onClick={handleOnBookingSubmit} disabled={pageState == PageState.sending}>
|
|
||||||
<Typography variant={"h3"} className="text-primary-foreground">Book it now!</Typography>
|
|
||||||
</Button>
|
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BookPage
|
export default BookPage;
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import { Typography } from "@/components/ui/typography";
|
||||||
|
import { eConfigVarKeys } from "@/model/ConfigVar";
|
||||||
|
import { useConfigVariable } from "@/utils/apiHooks";
|
||||||
|
import { Mail, Phone } from "lucide-react";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
|
function ContactPage() {
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
const { value: varCompanyPhone, isLoading: isPhoneLoading } =
|
||||||
|
useConfigVariable(eConfigVarKeys.varCompanyPhone, "");
|
||||||
|
const { value: varCompanyMail, isLoading: isMailLoading } = useConfigVariable(
|
||||||
|
eConfigVarKeys.varCompanyEmail,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
const { value: varCompanyContactPage, isLoading: isContactPageLoading } =
|
||||||
|
useConfigVariable(eConfigVarKeys.varCompanyContactFormUrl, "");
|
||||||
|
|
||||||
|
const isDataLoading = isPhoneLoading || isMailLoading || isContactPageLoading;
|
||||||
|
|
||||||
|
const mainText = location.state ?? "Contact us for a personalized quote!";
|
||||||
|
|
||||||
|
const LoadingContent = <Skeleton className="h-[100px] w-full" />;
|
||||||
|
|
||||||
|
const MainContent = (
|
||||||
|
<div className="mx-auto">
|
||||||
|
<div className="mx-auto">
|
||||||
|
<Typography variant={"largeText"}>{mainText}</Typography>
|
||||||
|
<div className="my-4 flex justify-center gap-4">
|
||||||
|
<Card className="flex flex-col items-center gap-2 px-5 hover:bg-secondary">
|
||||||
|
<Phone size={"1.2em"} />
|
||||||
|
<Typography variant={"p_inline"}>{varCompanyPhone}</Typography>
|
||||||
|
</Card>
|
||||||
|
<Card className="flex flex-col items-center gap-2 px-5 hover:bg-secondary">
|
||||||
|
<Mail size={"1.2em"} />
|
||||||
|
<Typography variant={"p_inline"}>{varCompanyMail}</Typography>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{varCompanyContactPage !== "" && (
|
||||||
|
<Button className="my-4" variant={"link"}>
|
||||||
|
<a href={varCompanyContactPage}>
|
||||||
|
<Typography variant={"largeText"}>Go to contact form</Typography>
|
||||||
|
</a>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<Typography variant={"h2"}>Contact us!</Typography>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>{isDataLoading ? LoadingContent : MainContent}</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ContactPage;
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
import { useRouteError } from "react-router-dom";
|
import { useRouteError } from "react-router-dom";
|
||||||
|
|
||||||
export default function ErrorPage() {
|
export default function ErrorPage() {
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const error : any = useRouteError();
|
const error: any = useRouteError();
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -15,4 +14,4 @@ export default function ErrorPage() {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.homePageRoomGrid {
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(300px, 3fr));
|
||||||
|
}
|
||||||
+56
-32
@@ -1,48 +1,72 @@
|
|||||||
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";
|
||||||
import { Separator } from "@/components/ui/separator"
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { Skeleton } from "@/components/ui/skeleton"
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { Typography } from "@/components/ui/typography"
|
import { Typography } from "@/components/ui/typography";
|
||||||
import { RoomCategory } from "@/model/RoomCategory"
|
import { RoomCategory } from "@/model/RoomCategory";
|
||||||
import { SearchFilter } from "@/model/SearchFilter"
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { LoaderIcon } from "lucide-react";
|
||||||
|
import "./home-page.css";
|
||||||
|
import { useAppStore } from "@/store";
|
||||||
|
import { useBookingStateDispacher } from "@/utils/hooks";
|
||||||
|
import { eConfigVarKeys } from "@/model/ConfigVar";
|
||||||
|
import { useConfigVariable } from "@/utils/apiHooks";
|
||||||
|
import { ConstsNav } from "@/utils/Consts";
|
||||||
|
|
||||||
function Homepage() {
|
function Homepage() {
|
||||||
|
const appSearchFilter = useAppStore((state) => state.searchFilter);
|
||||||
const { roomCategoryList, isLoading, isError } = useAPIRoomCategories();
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { setBookingStateSearched } = useBookingStateDispacher();
|
||||||
|
|
||||||
|
const { value: varCompanyName } = useConfigVariable(
|
||||||
|
eConfigVarKeys.varCompanyName,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
const {
|
||||||
|
roomCategoryList,
|
||||||
|
isLoading: isLoadingCategories,
|
||||||
|
isError,
|
||||||
|
} = useAPIRoomCategoryList();
|
||||||
|
|
||||||
const onBtSearchClick = (filter: SearchFilter) => {
|
const onBtSearchClick = (filter: SearchFilter) => {
|
||||||
navigate("/search", {state: filter})
|
setBookingStateSearched(filter);
|
||||||
}
|
|
||||||
|
navigate(ConstsNav.page_Search, { state: filter });
|
||||||
|
};
|
||||||
|
|
||||||
const roomList = roomCategoryList?.map((element: RoomCategory) => {
|
const roomList = roomCategoryList?.map((element: RoomCategory) => {
|
||||||
return (
|
return <RoomItemCard key={element.id} room={element} />;
|
||||||
<RoomItemCard key={element.id} room={element} />
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h1"}>Somnia Rooms</Typography>
|
<Typography variant={"h1"}>{varCompanyName}</Typography>
|
||||||
<Separator className="my-10" />
|
<Separator />
|
||||||
<SearchFilterCard onSearchClick={onBtSearchClick}/>
|
<SearchFilterCard
|
||||||
<Separator className="my-10" />
|
onSearchClick={onBtSearchClick}
|
||||||
<div className="grid grid-cols-2 gap-4">
|
initialsearchFilter={appSearchFilter}
|
||||||
{roomList}
|
/>
|
||||||
</div>
|
<Separator />
|
||||||
{isLoading && (
|
<div className="homePageRoomGrid grid gap-4">{roomList}</div>
|
||||||
|
{isLoadingCategories && (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h3"} as="h2">Loading...</Typography>
|
<Skeleton className="mx-auto flex h-[200px] w-full flex-col items-center justify-center">
|
||||||
<Skeleton className="w-[400px] h-[200px] mx-auto" />
|
<LoaderIcon />
|
||||||
|
<Typography variant={"h3"} as="h2">
|
||||||
|
Loading...
|
||||||
|
</Typography>
|
||||||
|
</Skeleton>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<Separator className="my-10" />
|
<Separator />
|
||||||
<BackendConnectionStatus isLoading={isLoading} isError={isError} />
|
<BackendConnectionStatus
|
||||||
|
isLoading={isLoadingCategories}
|
||||||
|
isError={isError}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Homepage
|
export default Homepage;
|
||||||
|
|||||||
+102
-75
@@ -1,95 +1,122 @@
|
|||||||
import { useAPIRoomAvailability } from "@/api/api-roomSearch"
|
import { useAPIRoomAvailability } from "@/api/api-roomSearch";
|
||||||
import RoomBooking from "@/components/Rooms/room-booking"
|
import RoomBooking from "@/components/Rooms/room-booking";
|
||||||
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";
|
||||||
import { BookingDetails } from "@/components/booking/booking-details"
|
import { BookingDetails } from "@/components/booking/booking-details";
|
||||||
import { Separator } from "@/components/ui/separator"
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { Skeleton } from "@/components/ui/skeleton"
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { Typography } from "@/components/ui/typography"
|
import { Typography } from "@/components/ui/typography";
|
||||||
import { AvailabilityFilter } from "@/model/RoomSearch"
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
import { SearchFilter } from "@/model/SearchFilter"
|
import { eBookingState } from "@/utils/AppStateManager";
|
||||||
import { useAppStore } from "@/store"
|
import { useAppStore } from "@/store";
|
||||||
import { useMemo, useState } from "react"
|
import { makeSearchPeriodRequestFromSearchFilter } from "@/utils/utils";
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useBookingStateDispacher } from "@/utils/hooks";
|
||||||
|
import { ConstsNav } from "@/utils/Consts";
|
||||||
|
|
||||||
//TODOME: Igual podemos crear un StateMachine conjunta para los siguiente estados de la página: Sin Buscar, Sin disponibilidad, error, cargando.
|
//TODOME: Al pulsar el botón "buscar", si ya existen datos en la reserva (se han añadido habitaciones) mostrar un cuadro de aviso de que si se busca se borrará la selección actual.
|
||||||
|
//TODOME: Mediante los estados globales de la reserva, si ya está en estado "booking" añadiendo los datos, mostrar un mensaje y permitir redirigir directamente para que continue donde lo dejó.
|
||||||
function SearchPage() {
|
function SearchPage() {
|
||||||
|
const appBookingState = useAppStore((state) => state.bookingState);
|
||||||
//const [availabilityFilter, setAvailabilityFilter] = useState<AvailabilityFilter>();
|
const appSearchFilter = useAppStore((state) => state.searchFilter);
|
||||||
const searchFilter = useAppStore((state) => (state.searchFilter));
|
|
||||||
const resetBooking = useAppStore((state) => (state.resetBookingState));
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [isSearched, setIsSearched] = useState<boolean>(false);
|
const { setBookingStateSearched, setBookingStateBooking } =
|
||||||
|
useBookingStateDispacher();
|
||||||
|
|
||||||
const onBtSearchClick = (newFilter: SearchFilter) => {
|
const {
|
||||||
console.log("onBtSearchClick: ");
|
roomAvailabilityList,
|
||||||
console.log(newFilter);
|
isLoading: isLoadingAvailability,
|
||||||
|
isError: isErrorAvailability,
|
||||||
if (newFilter.dateRange && newFilter.dateRange.from && newFilter.dateRange.to) {
|
} = useAPIRoomAvailability(
|
||||||
setIsSearched(true);
|
makeSearchPeriodRequestFromSearchFilter(appSearchFilter) ?? null,
|
||||||
|
|
||||||
resetBooking(newFilter.dateRange.from, newFilter.dateRange.to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const onBookingContinue = () => {
|
|
||||||
navigate("/book");
|
|
||||||
}
|
|
||||||
|
|
||||||
//This seems a little bit overkill, but IDK.
|
|
||||||
const availabilityFilter: AvailabilityFilter | null = useMemo(
|
|
||||||
() => {
|
|
||||||
if (searchFilter && searchFilter.dateRange && searchFilter.dateRange.from && searchFilter.dateRange.to) {
|
|
||||||
const newAvailabilityFilter: AvailabilityFilter = {
|
|
||||||
startDate: searchFilter.dateRange.from.toDateString(),
|
|
||||||
endDate: searchFilter.dateRange.to.toDateString()
|
|
||||||
};
|
|
||||||
return newAvailabilityFilter;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
[searchFilter]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const { roomAvailabilityList, isLoading: isLoadingAvailability, isError: isErrorAvailability } = useAPIRoomAvailability(availabilityFilter ?? null);
|
|
||||||
|
|
||||||
const isLoading = isLoadingAvailability;
|
const isLoading = isLoadingAvailability;
|
||||||
const isError = isErrorAvailability;
|
const isError = isErrorAvailability;
|
||||||
|
|
||||||
const roomList = roomAvailabilityList?.map((element) => {
|
const hasRooms =
|
||||||
return (
|
roomAvailabilityList?.length && roomAvailabilityList?.length > 0;
|
||||||
<RoomBooking key={element.roomCategory} availableAmount={element.availability} roomCategoryId={element.roomCategory} />
|
|
||||||
);
|
const onBtSearchClick = (newFilter: SearchFilter) => {
|
||||||
});
|
setBookingStateSearched(newFilter);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onBookingContinue = () => {
|
||||||
|
setBookingStateBooking();
|
||||||
|
navigate(ConstsNav.page_Book);
|
||||||
|
};
|
||||||
|
|
||||||
|
const roomList =
|
||||||
|
roomAvailabilityList?.map((element) => {
|
||||||
|
return (
|
||||||
|
<RoomBooking
|
||||||
|
key={element.roomCategory + "-" + appBookingState.lastSearchDate}
|
||||||
|
availableAmount={element.availability}
|
||||||
|
roomCategoryId={element.roomCategory}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}) ?? null;
|
||||||
const noRoomsAvailable = (
|
const noRoomsAvailable = (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h3"} as="h3">Sorry 😔, there aren't rooms available for selected period.
|
<Typography variant={"h3"} as="h3">
|
||||||
You can contact us for more info.</Typography>
|
Sorry 😔, there aren't rooms available for selected period. You can
|
||||||
|
contact us for more info.
|
||||||
|
</Typography>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
const hasRooms = (roomAvailabilityList?.length && roomAvailabilityList?.length > 0);
|
|
||||||
console.log(hasRooms);
|
const pageContentSearch = (
|
||||||
|
<Typography>
|
||||||
|
Realiza una búsqueda para ver la disponibilidad y los precios.
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
const pageContentLoading = (
|
||||||
|
<>
|
||||||
|
<Typography variant={"h3"} as="h2">
|
||||||
|
Loading...
|
||||||
|
</Typography>
|
||||||
|
<Skeleton className="mx-auto h-[200px] w-full" />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
const pageContentLoaded = (
|
||||||
|
<div className="2xl:grid 2xl:grid-cols-60/40 2xl:gap-6">
|
||||||
|
<div className="flex flex-col gap-5">{roomList}</div>
|
||||||
|
<Separator className="2xl:hidden" />
|
||||||
|
<BookingDetails
|
||||||
|
onBookingConfirm={onBookingContinue}
|
||||||
|
mode={"Book"}
|
||||||
|
></BookingDetails>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const getPageContent = () => {
|
||||||
|
const isSearched =
|
||||||
|
appBookingState.state == eBookingState.Searched ||
|
||||||
|
appBookingState.state == eBookingState.Booking;
|
||||||
|
if (!isSearched) {
|
||||||
|
return pageContentSearch;
|
||||||
|
}
|
||||||
|
if (isLoading) {
|
||||||
|
return pageContentLoading;
|
||||||
|
}
|
||||||
|
if (!hasRooms) {
|
||||||
|
return noRoomsAvailable;
|
||||||
|
}
|
||||||
|
return pageContentLoaded;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-background text-foreground">
|
<div className="bg-background text-foreground">
|
||||||
<SearchFilterCard onSearchClick={onBtSearchClick} />
|
<SearchFilterCard
|
||||||
<Separator className="my-10" />
|
onSearchClick={onBtSearchClick}
|
||||||
{isLoading && (
|
initialsearchFilter={appSearchFilter}
|
||||||
<>
|
/>
|
||||||
<Typography variant={"h3"} as="h2">Loading...</Typography>
|
<Separator />
|
||||||
<Skeleton className="w-[400px] h-[200px] mx-auto" />
|
{getPageContent()}
|
||||||
</>
|
<Separator />
|
||||||
)}
|
|
||||||
<div className="flex flex-col gap-5">
|
|
||||||
{hasRooms ? roomList : (isSearched && noRoomsAvailable)}
|
|
||||||
</div>
|
|
||||||
<Separator className="my-10" />
|
|
||||||
<BookingDetails onBookingConfirm={onBookingContinue} mode={"Book"}></BookingDetails>
|
|
||||||
<Separator className="my-10" />
|
|
||||||
<BackendConnectionStatus isLoading={isLoading} isError={isError} />
|
<BackendConnectionStatus isLoading={isLoading} isError={isError} />
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SearchPage
|
export default SearchPage;
|
||||||
|
|||||||
+38
-34
@@ -1,47 +1,51 @@
|
|||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button";
|
||||||
import { Card, CardContent, CardHeader } from "@/components/ui/card"
|
import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
||||||
import { Typography } from "@/components/ui/typography"
|
import { Typography } from "@/components/ui/typography";
|
||||||
import { NewBookingResponse } from "@/model/Bookings"
|
import { NewBookingResponse } from "@/model/Bookings";
|
||||||
import { useAppStore } from "@/store"
|
import { useAppStore } from "@/store";
|
||||||
import { addDays } from "date-fns"
|
import { ConstsNav } from "@/utils/Consts";
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react";
|
||||||
import { useLocation, useNavigate } from "react-router-dom"
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
function SuccessPage() {
|
function SuccessPage() {
|
||||||
|
const [pageState, setPageState] = useState<NewBookingResponse | null>(null);
|
||||||
|
const resetBookingState = useAppStore((state) => state.resetCurrentBooking);
|
||||||
|
|
||||||
const [pageState, setPageState] = useState<NewBookingResponse|null>(null)
|
const location = useLocation();
|
||||||
const resetBookingState = useAppStore((state) => state.resetBookingState);
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const location = useLocation();
|
if (pageState == null && location.state != null) {
|
||||||
const navigate = useNavigate();
|
setPageState(location.state);
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(location.state == null) {
|
if (location.state == null) {
|
||||||
navigate("/home");
|
navigate(ConstsNav.page_Home);
|
||||||
}
|
|
||||||
setPageState(location.state);
|
|
||||||
|
|
||||||
}, [location, navigate])
|
|
||||||
|
|
||||||
const handleBtBackClick = () => {
|
|
||||||
resetBookingState(new Date(), addDays(new Date(), 2));
|
|
||||||
navigate("/home");
|
|
||||||
}
|
}
|
||||||
|
}, [location, navigate]);
|
||||||
|
|
||||||
|
const handleBtBackClick = () => {
|
||||||
|
resetBookingState();
|
||||||
|
navigate(ConstsNav.page_Home);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<Typography variant={"h2"}>Booking Completed</Typography>
|
<Typography variant={"h2"}>Booking Completed</Typography>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography variant={"largeText"}>Booking ref: {pageState?.refNumber}</Typography>
|
<Typography variant={"largeText"}>
|
||||||
<Button className="my-4" onClick={handleBtBackClick}>
|
Booking ref: {pageState?.refNumber}
|
||||||
<Typography variant={"largeText"} className="text-primary-foreground">Go Back</Typography>
|
</Typography>
|
||||||
</Button>
|
<Button className="my-4" onClick={handleBtBackClick}>
|
||||||
</CardContent>
|
<Typography variant={"largeText"} className="text-primary-foreground">
|
||||||
|
Go Back
|
||||||
|
</Typography>
|
||||||
|
</Button>
|
||||||
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SuccessPage
|
export default SuccessPage;
|
||||||
|
|||||||
+119
-79
@@ -1,95 +1,135 @@
|
|||||||
import { create } from 'zustand'
|
import { create } from "zustand";
|
||||||
import { SearchFilter } from './model/SearchFilter'
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
import { NewBooking, NewBookingCustomerDetails, NewBookingRoom } from './model/Bookings'
|
import {
|
||||||
|
BookingState,
|
||||||
|
eBookingState,
|
||||||
|
SetBookingState,
|
||||||
|
} from "./utils/AppStateManager";
|
||||||
|
import {
|
||||||
|
NewBooking,
|
||||||
|
NewBookingCustomerDetails,
|
||||||
|
NewBookingRoom,
|
||||||
|
} from "./model/Bookings";
|
||||||
|
|
||||||
interface AppState {
|
interface State {
|
||||||
searchFilter: SearchFilter
|
searchFilter: SearchFilter;
|
||||||
setSearchFilter: (newFilter: SearchFilter) => void
|
currentBooking: NewBooking | null;
|
||||||
newBookingData: NewBooking | null
|
bookingState: BookingState;
|
||||||
setNewBooking: (newBooking: NewBooking) => void
|
}
|
||||||
resetBookingState: (arrival: Date, departure: Date) => void
|
|
||||||
addNewBookingRoom: (newRoom: NewBookingRoom) => void
|
interface Actions {
|
||||||
setBookingCustomer: (newCustomer: NewBookingCustomerDetails) => void
|
setSearchFilter: (newFilter: SearchFilter) => void;
|
||||||
|
resetSearchFilter: () => void;
|
||||||
|
setCurrentBooking: (newBooking: NewBooking) => void;
|
||||||
|
resetCurrentBooking: () => void;
|
||||||
|
initCurrentBooking: (arrival: Date, departure: Date) => void;
|
||||||
|
currentBookingAddRoom: (newRoom: NewBookingRoom) => void;
|
||||||
|
currentBookingSetCustomer: (newCustomer: NewBookingCustomerDetails) => void;
|
||||||
|
setBookingState: (newState: eBookingState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultSearchFilter: SearchFilter = {
|
const defaultSearchFilter: SearchFilter = {
|
||||||
dateRange: { from: new Date() }
|
dateRange: { from: new Date() },
|
||||||
}
|
};
|
||||||
|
|
||||||
const defaultNewBooking: NewBooking = {
|
const defaultNewBooking: NewBooking = {
|
||||||
arrivalDate: new Date(),
|
arrivalDate: new Date(),
|
||||||
departureDate: new Date(),
|
departureDate: new Date(),
|
||||||
customerDetails: {
|
customerDetails: {
|
||||||
name: null,
|
name: null,
|
||||||
surname: null,
|
surname: null,
|
||||||
email: null,
|
email: null,
|
||||||
phoneNumber: null
|
phoneNumber: null,
|
||||||
},
|
},
|
||||||
rooms: []
|
rooms: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultBookingState: BookingState = {
|
||||||
|
state: eBookingState.None,
|
||||||
|
lastSearchDate: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
function getDefaultBooking(arrivalDate: Date, departureDate: Date) {
|
||||||
|
return {
|
||||||
|
...defaultNewBooking,
|
||||||
|
arrivalDate: arrivalDate,
|
||||||
|
departureDate: departureDate,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultBookingData(arrivalDate: Date, departureDate: Date) {
|
function addNewBookingRoom(
|
||||||
return {
|
newRoom: NewBookingRoom,
|
||||||
...defaultNewBooking,
|
currentBookingState: NewBooking | null,
|
||||||
arrivalDate: arrivalDate,
|
): NewBooking | null {
|
||||||
departureDate: departureDate
|
if (currentBookingState == null) {
|
||||||
|
return currentBookingState;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Remove rooms with "same key".
|
||||||
|
const filteredRooms = currentBookingState.rooms.filter((room) => {
|
||||||
|
const isDiffRoom = room.roomCategory != newRoom.roomCategory;
|
||||||
|
const isDiffAmount = room.guestNumber != newRoom.guestNumber;
|
||||||
|
if (isDiffRoom || (!isDiffRoom && isDiffAmount)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
console.log(filteredRooms);
|
||||||
|
|
||||||
|
if (newRoom.amount > 0) {
|
||||||
|
filteredRooms.push(newRoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
const newState: NewBooking = {
|
||||||
|
...currentBookingState,
|
||||||
|
rooms: filteredRooms ?? [],
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Updated 'currentBooking' state:");
|
||||||
|
console.log(newState);
|
||||||
|
|
||||||
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addNewBookingRoomToCurrentState(newRoom: NewBookingRoom, currentState: NewBooking | null): NewBooking | null {
|
function setBookingCustomer(
|
||||||
|
newCustomer: NewBookingCustomerDetails,
|
||||||
|
currentBookingState: NewBooking | null,
|
||||||
|
) {
|
||||||
|
if (currentBookingState == null) {
|
||||||
|
return currentBookingState;
|
||||||
|
}
|
||||||
|
|
||||||
if (currentState == null) {
|
const newState: NewBooking = {
|
||||||
return currentState;
|
...currentBookingState,
|
||||||
}
|
customerDetails: newCustomer,
|
||||||
|
};
|
||||||
//Remove rooms with "same key".
|
return newState;
|
||||||
const filteredRooms = currentState.rooms.filter((room) => {
|
|
||||||
const diffRoom = room.roomCategory != newRoom.roomCategory;
|
|
||||||
const diffAmount = room.guestNumber != newRoom.guestNumber;
|
|
||||||
if(diffRoom || (!diffRoom && diffAmount)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
})
|
|
||||||
console.log(filteredRooms);
|
|
||||||
|
|
||||||
if (newRoom.amount > 0) {
|
|
||||||
filteredRooms.push(newRoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const newState: NewBooking = {
|
|
||||||
...currentState,
|
|
||||||
rooms: filteredRooms ?? []
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("AddRoomNewState:");
|
|
||||||
console.log(newState);
|
|
||||||
|
|
||||||
return newState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBookingCustomer(newCustomer: NewBookingCustomerDetails, currentState: NewBooking | null) {
|
export const useAppStore = create<State & Actions>()((set) => ({
|
||||||
if(currentState == null) {
|
searchFilter: defaultSearchFilter,
|
||||||
return currentState;
|
currentBooking: null,
|
||||||
}
|
bookingState: defaultBookingState,
|
||||||
|
|
||||||
const newState: NewBooking = {
|
setSearchFilter: (newFilter) => set(() => ({ searchFilter: newFilter })),
|
||||||
...currentState,
|
resetSearchFilter: () => set(() => ({ searchFilter: defaultSearchFilter })),
|
||||||
customerDetails: newCustomer
|
|
||||||
};
|
|
||||||
return newState;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAppStore = create<AppState>()((set) => ({
|
setCurrentBooking: (newBooking) =>
|
||||||
searchFilter: defaultSearchFilter,
|
set(() => ({ currentBooking: newBooking })),
|
||||||
setSearchFilter: (newFilter) => set(() => ({ searchFilter: newFilter })),
|
resetCurrentBooking: () => set(() => ({ currentBooking: null })),
|
||||||
newBookingData: null,
|
initCurrentBooking: (arrival, departure) =>
|
||||||
setNewBooking: (newBooking) => set(() => ({ newBookingData: newBooking })),
|
set(() => ({ currentBooking: getDefaultBooking(arrival, departure) })),
|
||||||
resetBookingState: (arrival, departure) =>
|
currentBookingAddRoom: (newRoom) =>
|
||||||
set(() => ({ newBookingData: getDefaultBookingData(arrival, departure) })),
|
set((state) => ({
|
||||||
addNewBookingRoom: (newRoom: NewBookingRoom) =>
|
currentBooking: addNewBookingRoom(newRoom, state.currentBooking),
|
||||||
set((state) => ({ newBookingData: addNewBookingRoomToCurrentState(newRoom, state.newBookingData) })),
|
})),
|
||||||
setBookingCustomer: (newCustomer: NewBookingCustomerDetails) =>
|
currentBookingSetCustomer: (newCustomer) =>
|
||||||
set((state) => ({newBookingData: setBookingCustomer(newCustomer, state.newBookingData)}))
|
set((state) => ({
|
||||||
}))
|
currentBooking: setBookingCustomer(newCustomer, state.currentBooking),
|
||||||
|
})),
|
||||||
|
|
||||||
|
setBookingState: (newState) =>
|
||||||
|
set((state) => ({
|
||||||
|
bookingState: SetBookingState(newState, state.bookingState),
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
export type BookingState = {
|
||||||
|
state: eBookingState;
|
||||||
|
lastSearchDate: Date;
|
||||||
|
};
|
||||||
|
|
||||||
|
export enum eBookingState {
|
||||||
|
None = "NONE",
|
||||||
|
Searched = "SEARCHED",
|
||||||
|
Booking = "BOOKING",
|
||||||
|
Booked = "BOOKED",
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SetBookingState(
|
||||||
|
newState: eBookingState,
|
||||||
|
currentAppBookingState: BookingState,
|
||||||
|
) {
|
||||||
|
const newAppState: BookingState = {
|
||||||
|
...currentAppBookingState,
|
||||||
|
state: newState,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (newState == eBookingState.Searched) {
|
||||||
|
newAppState.lastSearchDate = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
return newAppState;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
export const c_somniaRooms_notice_text =
|
||||||
|
"Powered by SomniaRooms, an Open-Source hospitality booking platform!";
|
||||||
|
export const c_sominaRooms_webpage = "https://somnia.dev";
|
||||||
|
|
||||||
|
export const ConstsNav = {
|
||||||
|
page_Home: "/home",
|
||||||
|
page_Contact: "/contact",
|
||||||
|
page_Search: "/search",
|
||||||
|
page_Book: "/book",
|
||||||
|
page_Success: "/success",
|
||||||
|
};
|
||||||
|
|
||||||
|
//TMP - The following texts should be replaced for a proper intl system.
|
||||||
|
export const ConstsTexts = {
|
||||||
|
navToContact_maxAllowedNightCount:
|
||||||
|
"We are sorry, but the selected date range is too large. Search for a smaller range or contact us for a personalized quote.",
|
||||||
|
navToContact_maxAllowedGuestNumber:
|
||||||
|
"We are sorry, group bookings are not allowed. Contact us for a personalized quote.",
|
||||||
|
contactUsAlertDialog_title: "Contact us!",
|
||||||
|
contactUsAlertDialog_text:
|
||||||
|
"This booking seems like a big deal... Contact us for a personalized quote!",
|
||||||
|
};
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import { useAPIConfigVarList } from "@/api/api-configVars";
|
||||||
|
import { getConfigVarFromList } from "./utils";
|
||||||
|
import { eConfigVarKeys } from "@/model/ConfigVar";
|
||||||
|
|
||||||
|
import { useAPIRoomCategoryList } from "@/api/api-roomCategories";
|
||||||
|
import { useAPIRoomPrices } from "@/api/api-roomSearch";
|
||||||
|
import { RoomCategory } from "@/model/RoomCategory";
|
||||||
|
import { RoomPrice, SearchPeriodRequest } from "@/model/RoomSearch";
|
||||||
|
|
||||||
|
export function useConfigVariable(
|
||||||
|
key: eConfigVarKeys,
|
||||||
|
defaultValue: string,
|
||||||
|
): {
|
||||||
|
value: string;
|
||||||
|
isLoading: boolean;
|
||||||
|
} {
|
||||||
|
const { configVarList, isLoading } = useAPIConfigVarList();
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return {
|
||||||
|
value: defaultValue,
|
||||||
|
isLoading: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const configVar = getConfigVarFromList(configVarList, key);
|
||||||
|
|
||||||
|
return { value: configVar?.value ?? defaultValue, isLoading: isLoading };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useConfigVariableAsNumber(
|
||||||
|
key: eConfigVarKeys,
|
||||||
|
defaultValue: number,
|
||||||
|
): {
|
||||||
|
value: number;
|
||||||
|
isLoading: boolean;
|
||||||
|
} {
|
||||||
|
const rs = useConfigVariable(key, defaultValue.toString());
|
||||||
|
return {
|
||||||
|
value: rs.isLoading ? defaultValue : parseFloat(rs.value),
|
||||||
|
isLoading: rs.isLoading,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRoomCategory(roomCategoryId: number): {
|
||||||
|
value: RoomCategory | null;
|
||||||
|
isLoading: boolean;
|
||||||
|
} {
|
||||||
|
const { roomCategoryList, isLoading, isError } = useAPIRoomCategoryList();
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return {
|
||||||
|
value: null,
|
||||||
|
isLoading: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (isError) {
|
||||||
|
return {
|
||||||
|
value: null,
|
||||||
|
isLoading: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const roomCategoryItem = roomCategoryList?.find(
|
||||||
|
(i) => i.id == roomCategoryId,
|
||||||
|
);
|
||||||
|
|
||||||
|
return { value: roomCategoryItem ?? null, isLoading: isLoading };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRoomPrice(
|
||||||
|
filter: SearchPeriodRequest | null,
|
||||||
|
roomCategoryId: number,
|
||||||
|
): {
|
||||||
|
value: RoomPrice[];
|
||||||
|
isLoading: boolean;
|
||||||
|
} {
|
||||||
|
const { roomPriceList, isLoading, isError } = useAPIRoomPrices(filter);
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return {
|
||||||
|
value: [],
|
||||||
|
isLoading: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (isError) {
|
||||||
|
return {
|
||||||
|
value: [],
|
||||||
|
isLoading: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const roomPrice = roomPriceList?.find(
|
||||||
|
(i) => i.roomCategoryId == roomCategoryId,
|
||||||
|
);
|
||||||
|
|
||||||
|
return { value: roomPrice?.prices ?? [], isLoading: isLoading };
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
|
import { useAppStore } from "@/store";
|
||||||
|
import { getNightCountFromSearchFilter, makeDayUTCDate } from "./utils";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
import { eBookingState } from "./AppStateManager";
|
||||||
|
import { useConfigVariableAsNumber } from "./apiHooks";
|
||||||
|
import { eConfigVarKeys } from "@/model/ConfigVar";
|
||||||
|
import { NewBooking } from "@/model/Bookings";
|
||||||
|
|
||||||
|
export function useBookingStateDispacher(): {
|
||||||
|
setBookingStateSearched: (sf: SearchFilter) => void;
|
||||||
|
setBookingStateBooking: () => void;
|
||||||
|
setBookingStateBooked: () => void;
|
||||||
|
} {
|
||||||
|
const setAppBookingState = useAppStore((state) => state.setBookingState);
|
||||||
|
const setAppSearchFilter = useAppStore((state) => state.setSearchFilter);
|
||||||
|
const initAppBooking = useAppStore((state) => state.initCurrentBooking);
|
||||||
|
|
||||||
|
const fnSearched = useCallback(
|
||||||
|
(sf: SearchFilter) => {
|
||||||
|
setAppSearchFilter(sf);
|
||||||
|
setAppBookingState(eBookingState.Searched);
|
||||||
|
|
||||||
|
initAppBooking(
|
||||||
|
makeDayUTCDate(sf.dateRange.from),
|
||||||
|
makeDayUTCDate(sf.dateRange.to),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[setAppBookingState, setAppSearchFilter, initAppBooking],
|
||||||
|
);
|
||||||
|
|
||||||
|
const fnBooking = useCallback(() => {
|
||||||
|
setAppBookingState(eBookingState.Booking);
|
||||||
|
}, [setAppBookingState]);
|
||||||
|
const fnBooked = useCallback(() => {
|
||||||
|
setAppBookingState(eBookingState.Booked);
|
||||||
|
}, [setAppBookingState]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
setBookingStateSearched: fnSearched,
|
||||||
|
setBookingStateBooking: fnBooking,
|
||||||
|
setBookingStateBooked: fnBooked,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//This checks may be moved into "useBookingStateDispacher".
|
||||||
|
// That way, the logic may be more general and separated from the components and buttons
|
||||||
|
// and the dialog may use global state.
|
||||||
|
export function useCheckForNightCount(sf: SearchFilter | null): {
|
||||||
|
isOverApiMax: boolean;
|
||||||
|
shouldShowContactDialog: boolean;
|
||||||
|
isLoading: boolean;
|
||||||
|
} {
|
||||||
|
const {
|
||||||
|
value: varApiMaxAllowedNights,
|
||||||
|
isLoading: isLoadingVarMaxAllowedNights,
|
||||||
|
} = useConfigVariableAsNumber(eConfigVarKeys.varAPIMaxAllowedNightAmount, -1);
|
||||||
|
const {
|
||||||
|
value: varNightCountForContactDialog,
|
||||||
|
isLoading: isLoadingVarNightCountForContact,
|
||||||
|
} = useConfigVariableAsNumber(
|
||||||
|
eConfigVarKeys.varNightCountForContactDialog,
|
||||||
|
-1,
|
||||||
|
);
|
||||||
|
const areVariablesLoading =
|
||||||
|
isLoadingVarMaxAllowedNights || isLoadingVarNightCountForContact;
|
||||||
|
|
||||||
|
const filterNightCount = getNightCountFromSearchFilter(sf);
|
||||||
|
if (filterNightCount == null || areVariablesLoading) {
|
||||||
|
return {
|
||||||
|
isOverApiMax: false,
|
||||||
|
shouldShowContactDialog: false,
|
||||||
|
isLoading: areVariablesLoading,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const doCheckForMaxAllowedNights = varApiMaxAllowedNights > -1;
|
||||||
|
const doCheckForContactAlert = varNightCountForContactDialog > -1;
|
||||||
|
return {
|
||||||
|
isOverApiMax:
|
||||||
|
doCheckForMaxAllowedNights && filterNightCount > varApiMaxAllowedNights,
|
||||||
|
shouldShowContactDialog:
|
||||||
|
doCheckForContactAlert &&
|
||||||
|
filterNightCount >= varNightCountForContactDialog,
|
||||||
|
isLoading: areVariablesLoading,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useCheckForGuestNumber(bookingData: NewBooking | null): {
|
||||||
|
isOverApiMax: boolean;
|
||||||
|
shouldShowContactDialog: boolean;
|
||||||
|
isLoading: boolean;
|
||||||
|
} {
|
||||||
|
const {
|
||||||
|
value: varApiMaxAllowedGuests,
|
||||||
|
isLoading: isLoadingVarMaxAllowedGuests,
|
||||||
|
} = useConfigVariableAsNumber(eConfigVarKeys.varAPIMaxAllowedGuestNumber, -1);
|
||||||
|
const {
|
||||||
|
value: varGuestNumberForContactDialog,
|
||||||
|
isLoading: isLoadingVarGuestNumberForContact,
|
||||||
|
} = useConfigVariableAsNumber(
|
||||||
|
eConfigVarKeys.varGuestNumberForContactDialog,
|
||||||
|
-1,
|
||||||
|
);
|
||||||
|
const areVariablesLoading =
|
||||||
|
isLoadingVarMaxAllowedGuests || isLoadingVarGuestNumberForContact;
|
||||||
|
|
||||||
|
if (bookingData == null || areVariablesLoading) {
|
||||||
|
return {
|
||||||
|
isOverApiMax: false,
|
||||||
|
shouldShowContactDialog: false,
|
||||||
|
isLoading: areVariablesLoading,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//Calculate guest number in current booking data.
|
||||||
|
const totalGuestNumber = bookingData.rooms.reduce((acc, r) => {
|
||||||
|
return acc + r.guestNumber * r.amount;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
const doCheckForMaxAllowedGuests = varApiMaxAllowedGuests > -1;
|
||||||
|
const doCheckForContactAlert = varGuestNumberForContactDialog > -1;
|
||||||
|
return {
|
||||||
|
isOverApiMax:
|
||||||
|
doCheckForMaxAllowedGuests && totalGuestNumber > varApiMaxAllowedGuests,
|
||||||
|
shouldShowContactDialog:
|
||||||
|
doCheckForContactAlert &&
|
||||||
|
totalGuestNumber >= varGuestNumberForContactDialog,
|
||||||
|
isLoading: areVariablesLoading,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { SearchPeriodRequest } from "@/model/RoomSearch";
|
||||||
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
|
import { ConfigVar } from "@/model/ConfigVar";
|
||||||
|
import { differenceInDays } from "date-fns";
|
||||||
|
|
||||||
|
export function makeDayUTCDate(date: Date | undefined): Date {
|
||||||
|
if (!date) {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Date(
|
||||||
|
date.getFullYear(),
|
||||||
|
date.getMonth(),
|
||||||
|
date.getDate(),
|
||||||
|
23,
|
||||||
|
59,
|
||||||
|
59,
|
||||||
|
999,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isValidSearchFilter(
|
||||||
|
sf: SearchFilter | null,
|
||||||
|
): sf is SearchFilter {
|
||||||
|
if (sf?.dateRange?.from && sf?.dateRange?.to) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getNightCountFromSearchFilter(
|
||||||
|
sf: SearchFilter | null,
|
||||||
|
): number | null {
|
||||||
|
if (!isValidSearchFilter(sf)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return differenceInDays(sf.dateRange.to!, sf.dateRange.from!);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeSearchPeriodRequestFromSearchFilter(
|
||||||
|
sf: SearchFilter,
|
||||||
|
): SearchPeriodRequest | null {
|
||||||
|
if (!isValidSearchFilter(sf)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
startDate: sf.dateRange.from!.toISOString(),
|
||||||
|
endDate: sf.dateRange.to!.toISOString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getConfigVarFromList(
|
||||||
|
varList: ConfigVar[] | undefined,
|
||||||
|
key: string,
|
||||||
|
): ConfigVar | undefined {
|
||||||
|
if (!varList) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return varList.find((v) => v.key === key);
|
||||||
|
}
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
import plugin from 'tailwindcss-animate';
|
|
||||||
|
|
||||||
/** @type {import('tailwindcss').Config} */
|
|
||||||
export default {
|
|
||||||
darkMode: ["class"],
|
|
||||||
content: [
|
|
||||||
'./pages/**/*.{ts,tsx}',
|
|
||||||
'./components/**/*.{ts,tsx}',
|
|
||||||
'./app/**/*.{ts,tsx}',
|
|
||||||
'./src/**/*.{ts,tsx}',
|
|
||||||
],
|
|
||||||
prefix: "",
|
|
||||||
theme: {
|
|
||||||
container: {
|
|
||||||
center: true,
|
|
||||||
padding: "2rem",
|
|
||||||
screens: {
|
|
||||||
"2xl": "1400px",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extend: {
|
|
||||||
colors: {
|
|
||||||
border: "hsl(var(--border))",
|
|
||||||
input: "hsl(var(--input))",
|
|
||||||
ring: "hsl(var(--ring))",
|
|
||||||
background: "hsl(var(--background))",
|
|
||||||
foreground: "hsl(var(--foreground))",
|
|
||||||
primary: {
|
|
||||||
DEFAULT: "hsl(var(--primary))",
|
|
||||||
foreground: "hsl(var(--primary-foreground))",
|
|
||||||
},
|
|
||||||
secondary: {
|
|
||||||
DEFAULT: "hsl(var(--secondary))",
|
|
||||||
foreground: "hsl(var(--secondary-foreground))",
|
|
||||||
},
|
|
||||||
destructive: {
|
|
||||||
DEFAULT: "hsl(var(--destructive))",
|
|
||||||
foreground: "hsl(var(--destructive-foreground))",
|
|
||||||
},
|
|
||||||
muted: {
|
|
||||||
DEFAULT: "hsl(var(--muted))",
|
|
||||||
foreground: "hsl(var(--muted-foreground))",
|
|
||||||
},
|
|
||||||
accent: {
|
|
||||||
DEFAULT: "hsl(var(--accent))",
|
|
||||||
foreground: "hsl(var(--accent-foreground))",
|
|
||||||
},
|
|
||||||
popover: {
|
|
||||||
DEFAULT: "hsl(var(--popover))",
|
|
||||||
foreground: "hsl(var(--popover-foreground))",
|
|
||||||
},
|
|
||||||
card: {
|
|
||||||
DEFAULT: "hsl(var(--card))",
|
|
||||||
foreground: "hsl(var(--card-foreground))",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
borderRadius: {
|
|
||||||
lg: "var(--radius)",
|
|
||||||
md: "calc(var(--radius) - 2px)",
|
|
||||||
sm: "calc(var(--radius) - 4px)",
|
|
||||||
},
|
|
||||||
keyframes: {
|
|
||||||
"accordion-down": {
|
|
||||||
from: { height: "0" },
|
|
||||||
to: { height: "var(--radix-accordion-content-height)" },
|
|
||||||
},
|
|
||||||
"accordion-up": {
|
|
||||||
from: { height: "var(--radix-accordion-content-height)" },
|
|
||||||
to: { height: "0" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
animation: {
|
|
||||||
"accordion-down": "accordion-down 0.2s ease-out",
|
|
||||||
"accordion-up": "accordion-up 0.2s ease-out",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
plugins: [plugin],
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
// ...
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-3
@@ -2,9 +2,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": [
|
"@/*": ["./src/*"]
|
||||||
"./src/*"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
|
|||||||
+6
-5
@@ -1,10 +1,11 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from "vite";
|
||||||
import react from '@vitejs/plugin-react-swc'
|
import react from "@vitejs/plugin-react-swc";
|
||||||
import path from "path"
|
import path from "path";
|
||||||
|
import tailwindcss from "@tailwindcss/vite";
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react(), tailwindcss()],
|
||||||
server: {
|
server: {
|
||||||
host: true,
|
host: true,
|
||||||
port: 3000,
|
port: 3000,
|
||||||
@@ -14,4 +15,4 @@ export default defineConfig({
|
|||||||
"@": path.resolve(__dirname, "./src"),
|
"@": path.resolve(__dirname, "./src"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user