This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import './App.css'
|
||||
import Survey from './components/Survey'
|
||||
import Admin from './components/Admin'
|
||||
|
||||
export default function App() {
|
||||
if (window.location.pathname === '/admin') {
|
||||
return <Admin />
|
||||
}
|
||||
|
||||
const scrollToQuestions = () => {
|
||||
document.getElementById('questions')?.scrollIntoView({ behavior: 'smooth' })
|
||||
}
|
||||
|
||||
174
frontend/src/components/Admin.css
Normal file
174
frontend/src/components/Admin.css
Normal file
@@ -0,0 +1,174 @@
|
||||
.admin-gate {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--cream);
|
||||
}
|
||||
|
||||
.admin-gate-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
width: 100%;
|
||||
max-width: 320px;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.admin-gate-title {
|
||||
font-family: 'Cormorant Garamond', serif;
|
||||
font-size: 2rem;
|
||||
font-weight: 300;
|
||||
color: var(--text);
|
||||
text-align: center;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.admin-gate-input {
|
||||
padding: 0.75rem 1rem;
|
||||
border: 1.5px solid var(--pink-light);
|
||||
background: none;
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
font-size: 1rem;
|
||||
color: var(--text);
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.admin-gate-input:focus {
|
||||
border-color: var(--pink);
|
||||
}
|
||||
|
||||
.admin-gate-error {
|
||||
color: var(--pink);
|
||||
font-size: 0.85rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.admin-gate-btn {
|
||||
padding: 0.875rem;
|
||||
background: var(--pink);
|
||||
color: #fff;
|
||||
border: none;
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.15em;
|
||||
text-transform: uppercase;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.admin-gate-btn:hover:not(:disabled) { background: #C2536A; }
|
||||
.admin-gate-btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
||||
|
||||
/* ── Admin panel ── */
|
||||
|
||||
.admin {
|
||||
min-height: 100vh;
|
||||
background: var(--cream);
|
||||
padding: 2rem;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 2rem;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.admin-title {
|
||||
font-family: 'Cormorant Garamond', serif;
|
||||
font-size: 2rem;
|
||||
font-weight: 300;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.admin-stats {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.admin-stat {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.admin-stat b {
|
||||
color: var(--pink);
|
||||
}
|
||||
|
||||
.admin-empty {
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
margin-top: 4rem;
|
||||
}
|
||||
|
||||
.admin-cards {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.admin-card {
|
||||
background: #fff;
|
||||
border: 1px solid var(--pink-light);
|
||||
padding: 1.25rem 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.admin-card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.admin-card-name {
|
||||
font-family: 'Cormorant Garamond', serif;
|
||||
font-size: 1.3rem;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.admin-card-date {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.admin-card-fields {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem 1.5rem;
|
||||
}
|
||||
|
||||
.admin-field {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.admin-field-label {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.admin-card-partner {
|
||||
border-top: 1px solid var(--pink-light);
|
||||
padding-top: 0.75rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.admin-partner-label {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 500;
|
||||
color: var(--pink);
|
||||
}
|
||||
110
frontend/src/components/Admin.tsx
Normal file
110
frontend/src/components/Admin.tsx
Normal file
@@ -0,0 +1,110 @@
|
||||
import { useState } from 'react'
|
||||
import './Admin.css'
|
||||
|
||||
interface Response {
|
||||
id: string
|
||||
name: string
|
||||
alcohol: string | null
|
||||
food: string | null
|
||||
with_partner: boolean
|
||||
partner_name: string | null
|
||||
partner_alcohol: string | null
|
||||
partner_food: string | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export default function Admin() {
|
||||
const [password, setPassword] = useState('')
|
||||
const [authed, setAuthed] = useState(false)
|
||||
const [error, setError] = useState(false)
|
||||
const [responses, setResponses] = useState<Response[]>([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const handleLogin = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setLoading(true)
|
||||
setError(false)
|
||||
try {
|
||||
const res = await fetch('/api/admin/responses', {
|
||||
headers: { 'x-admin-password': password },
|
||||
})
|
||||
if (res.status === 401) { setError(true); return }
|
||||
if (!res.ok) throw new Error()
|
||||
setResponses(await res.json())
|
||||
setAuthed(true)
|
||||
} catch {
|
||||
setError(true)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (!authed) {
|
||||
return (
|
||||
<div className="admin-gate">
|
||||
<form className="admin-gate-form" onSubmit={handleLogin}>
|
||||
<h1 className="admin-gate-title">Админ</h1>
|
||||
<input
|
||||
className="admin-gate-input"
|
||||
type="password"
|
||||
placeholder="Пароль"
|
||||
value={password}
|
||||
onChange={e => setPassword(e.target.value)}
|
||||
autoFocus
|
||||
/>
|
||||
{error && <p className="admin-gate-error">Неверный пароль</p>}
|
||||
<button className="admin-gate-btn" type="submit" disabled={loading}>
|
||||
{loading ? 'Загрузка...' : 'Войти'}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const total = responses.length
|
||||
const totalGuests = responses.reduce((acc, r) => acc + (r.with_partner ? 2 : 1), 0)
|
||||
|
||||
return (
|
||||
<div className="admin">
|
||||
<div className="admin-header">
|
||||
<h1 className="admin-title">Ответы гостей</h1>
|
||||
<div className="admin-stats">
|
||||
<span className="admin-stat"><b>{total}</b> анкет</span>
|
||||
<span className="admin-stat"><b>{totalGuests}</b> гостей</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{responses.length === 0 ? (
|
||||
<p className="admin-empty">Ответов пока нет</p>
|
||||
) : (
|
||||
<div className="admin-cards">
|
||||
{responses.map(r => (
|
||||
<div key={r.id} className="admin-card">
|
||||
<div className="admin-card-header">
|
||||
<span className="admin-card-name">{r.name}</span>
|
||||
<span className="admin-card-date">
|
||||
{new Date(r.created_at).toLocaleDateString('ru-RU', {
|
||||
day: 'numeric', month: 'long', hour: '2-digit', minute: '2-digit'
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
<div className="admin-card-fields">
|
||||
{r.alcohol && <div className="admin-field"><span className="admin-field-label">Алкоголь</span><span>{r.alcohol}</span></div>}
|
||||
{r.food && <div className="admin-field"><span className="admin-field-label">Не ест</span><span>{r.food}</span></div>}
|
||||
</div>
|
||||
{r.with_partner && (
|
||||
<div className="admin-card-partner">
|
||||
<span className="admin-partner-label">Пара: {r.partner_name}</span>
|
||||
<div className="admin-card-fields">
|
||||
{r.partner_alcohol && <div className="admin-field"><span className="admin-field-label">Алкоголь</span><span>{r.partner_alcohol}</span></div>}
|
||||
{r.partner_food && <div className="admin-field"><span className="admin-field-label">Не ест</span><span>{r.partner_food}</span></div>}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user