diff --git a/frontend/src/App.css b/frontend/src/App.css index 9043e0e..8c6c340 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -1,42 +1,11 @@ #root { + width: 100%; max-width: 1280px; + min-width: 375px; margin: 0 auto; - padding: 2rem; text-align: center; } -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: filter 300ms; -} -.logo:hover { - filter: drop-shadow(0 0 2em #646cffaa); -} -.logo.react:hover { - filter: drop-shadow(0 0 2em #61dafbaa); -} - -@keyframes logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} - -@media (prefers-reduced-motion: no-preference) { - a:nth-of-type(2) .logo { - animation: logo-spin infinite 20s linear; - } -} - -.card { - padding: 2em; -} - .mainText { color: #5f5e5e; } diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 0211fa7..1f309a6 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,16 +1,13 @@ import './App.css' +import Greeting from './components/Greeting' +import Hosting from './components/Hosting' function App() { return ( <> -

Приглашение на Новый год 2025-2026 🎄

-

- Дорогие, Пятки! 🦶 - -Приглашаем вас отпраздновать предстоящий Новый Год 2025-2026 с нами в сосновой избе, в которой, ко всему прочему, будет праздноваться годовщина нашей жизни в ней! - -Мы ожидаем вас с 30.12.2025. Праздник обычно длится до 01.01.2025, но если вам будет безумно плохо, то иожно остаться и до второго числа. -

+ +
+ ) } diff --git a/frontend/src/components/Greeting.tsx b/frontend/src/components/Greeting.tsx new file mode 100644 index 0000000..1bfe1a2 --- /dev/null +++ b/frontend/src/components/Greeting.tsx @@ -0,0 +1,16 @@ +function Greeting() { + return ( + <> +

Приглашение на Новый год 2025-2026 🎄

+

+ Дорогие, Пятки! 🦶 + + Приглашаем вас отпраздновать предстоящий Новый Год 2025-2026 с нами в сосновой избе, в которой, ко всему прочему, будет праздноваться годовщина нашей жизни в ней! + + Мы ожидаем вас с 30.12.2025. Праздник обычно длится до 01.01.2025, но если вам будет безумно плохо, то иожно остаться и до второго числа. +

+ + ) +} + +export default Greeting; \ No newline at end of file diff --git a/frontend/src/components/Hosting.tsx b/frontend/src/components/Hosting.tsx new file mode 100644 index 0000000..66c0164 --- /dev/null +++ b/frontend/src/components/Hosting.tsx @@ -0,0 +1,84 @@ +import { useState } from "react"; +import useFetchHosting from "../utils/fetchHosting"; + + +interface ReserveButtonProps { + update: (name: string, id: number) => void, + reservedBy: string, + id: number, +} + +const ReserveButton: React.FC = (props) => { + const { reservedBy, update, id } = props; + const [name, setName] = useState(reservedBy); + const isReserved = reservedBy !== ''; + + const handleReserve = async () => { + if (name.trim()) { + await update(name, id); // Call the update function from props with the name and id + } + }; + + return ( + <> + setName(e.target.value)} + placeholder="Введите ваше имя" + disabled={isReserved} // Disable if already reserved + /> + + + ); +}; + +function Hosting() { + + const { data, error, loading, update } = useFetchHosting(); + return ( + <> +

Поселение

+

+ Мы готовы вас приютить в наших 150 квадратах. Хоть дом и кажется большим, + но больше 5 гостей уместить будет сложно (но возможно!). При этом, если + вы не хотите тесниться, то рядом с нами есть + отель, + а так же + кэмпинг-виллы + (Лучше бронировать заранее если есть надобность. Оба в 1-1,5км от нашего дома). +
+ На данный момент мы можем вместить 5 гостей без лишних усилий. + Это подразумевает: +

+ {loading &&
Loading...
} + {error &&
Error
} + {data && ( +
+ + + + + + + + + + {Object.entries(data).map(([id, item]) => ( + + + + + + ))} + +
РазмещениеВместительностьБронирование
{item.name}{item.capacity}{}
+
+ )} + + ); +} + +export default Hosting; \ No newline at end of file diff --git a/frontend/src/types/index.d.ts b/frontend/src/types/index.d.ts new file mode 100644 index 0000000..924532b --- /dev/null +++ b/frontend/src/types/index.d.ts @@ -0,0 +1,11 @@ +// src/types/index.d.ts + +export interface Furniture { + reservedBy: string; + name: string; + capacity: number; +} + +export interface Hosting { + [key: number]: Furniture; +} diff --git a/frontend/src/utils/fetchHosting.tsx b/frontend/src/utils/fetchHosting.tsx new file mode 100644 index 0000000..1a01675 --- /dev/null +++ b/frontend/src/utils/fetchHosting.tsx @@ -0,0 +1,76 @@ +import { useState, useEffect } from 'react'; +import type { Hosting } from '../types'; + +const mockData: Hosting = { + 1: { + reservedBy: "", + name: "Матрац 160см", + capacity: 2 + }, + 2: { + reservedBy: "Vasya", + name: "Кровать 120см", + capacity: 2 + }, + 3: { + reservedBy: "", + name: "Диван", + capacity: 1 + }, +}; + +const useFetchHosting = () => { + const [data, setData] = useState(mockData); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(false); + + const fetchData = async () => { + setLoading(true); + setError(null); + try { + const response = await fetch('https://example.backend.com/hosting'); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + const result = await response.json(); + setData(result); + } catch (error) { + setError(error instanceof Error ? error.message : 'Unknown error'); + } finally { + setLoading(false); + } + }; + + const updateData = async (name: string, id: number) => { + setLoading(true); + setError(null); + try { + const response = await fetch(`https://example.backend.com/hosting/${id}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ reservedBy: name }) + }); + + if (!response.ok) { + throw new Error('Network response was not ok'); + } + + // Optional: Fetch the updated data after reservation + await fetchData(); + } catch (error) { + setError(error instanceof Error ? error.message : 'Unknown error'); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + //fetchData(); // Initial fetch on mount + }, []); + + return { data, error, loading, refetch: fetchData, update: updateData }; +}; + +export default useFetchHosting;