Admin portal, public pages, footer, site config
This commit is contained in:
+405
-201
@@ -10,6 +10,55 @@ interface ImageRecord {
|
||||
uploaded_at: string;
|
||||
}
|
||||
|
||||
interface Room {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
price: string;
|
||||
photos: string[];
|
||||
}
|
||||
|
||||
interface RoomForm {
|
||||
id?: number;
|
||||
name: string;
|
||||
description: string;
|
||||
price: string;
|
||||
photos: string | string[];
|
||||
}
|
||||
|
||||
interface MenuItem {
|
||||
id: number;
|
||||
category: string;
|
||||
name: string;
|
||||
description: string;
|
||||
price: string;
|
||||
is_daily_special: boolean;
|
||||
}
|
||||
|
||||
interface Place {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
photo: string | null;
|
||||
distance_km: string | null;
|
||||
visit_time: string | null;
|
||||
suggestion: string | null;
|
||||
}
|
||||
|
||||
interface Review {
|
||||
id: number;
|
||||
author_name: string;
|
||||
rating: number;
|
||||
text: string;
|
||||
approved: boolean;
|
||||
}
|
||||
|
||||
interface User {
|
||||
id: number;
|
||||
username: string;
|
||||
role: 'admin' | 'user';
|
||||
}
|
||||
|
||||
const gold = '#E8A849';
|
||||
const navy = '#001321';
|
||||
const warm = '#a6683c';
|
||||
@@ -20,54 +69,67 @@ export default function AdminPage() {
|
||||
const [count, setCount] = useState(0);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
const [logoUrl, setLogoUrl] = useState('');
|
||||
const [faviconUrl, setFaviconUrl] = useState('');
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
|
||||
const [rooms, setRooms] = useState<Room[]>([]);
|
||||
const [roomForm, setRoomForm] = useState<RoomForm>({ name: '', description: '', price: '', photos: '' });
|
||||
const [editingRoom, setEditingRoom] = useState<number | null>(null);
|
||||
|
||||
const [menu, setMenu] = useState<MenuItem[]>([]);
|
||||
const [menuForm, setMenuForm] = useState<Partial<MenuItem>>({ category: '', name: '', description: '', price: '', is_daily_special: false });
|
||||
const [editingMenu, setEditingMenu] = useState<number | null>(null);
|
||||
|
||||
const [places, setPlaces] = useState<Place[]>([]);
|
||||
const [placeForm, setPlaceForm] = useState<Partial<Place>>({ name: '', description: '', photo: '', distance_km: '', visit_time: '', suggestion: '' });
|
||||
const [editingPlace, setEditingPlace] = useState<number | null>(null);
|
||||
|
||||
const [reviews, setReviews] = useState<Review[]>([]);
|
||||
|
||||
const [users, setUsers] = useState<User[]>([]);
|
||||
const [userForm, setUserForm] = useState({ username: '', password: '', role: 'user' as 'admin' | 'user' });
|
||||
|
||||
const [footer, setFooter] = useState({
|
||||
facebook_url: '', instagram_url: '', whatsapp_url: '', address: '', phone: '', email: '',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/admin/images', { credentials: 'same-origin' })
|
||||
.then(async (res) => {
|
||||
if (!res.ok) {
|
||||
if (res.status === 401) {
|
||||
router.push('/login');
|
||||
return;
|
||||
}
|
||||
if (res.status === 401) { router.push('/login'); return; }
|
||||
throw new Error('Failed to load images');
|
||||
}
|
||||
const data = await res.json();
|
||||
setImages(data.images || []);
|
||||
setCount(data.count || 0);
|
||||
})
|
||||
.catch((err) => setError(err.message))
|
||||
.finally(() => setLoading(false));
|
||||
.catch((err) => setError(err.message));
|
||||
|
||||
fetch('/api/site-assets?key=logo')
|
||||
.then(async (res) => {
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
if (data.data) setLogoUrl(data.data);
|
||||
})
|
||||
.catch(() => {});
|
||||
fetch('/api/rooms').then((r) => r.json()).then((j) => setRooms(j.data || [])).catch(() => {});
|
||||
fetch('/api/menu').then((r) => r.json()).then((j) => setMenu(j.data || [])).catch(() => {});
|
||||
fetch('/api/places').then((r) => r.json()).then((j) => setPlaces(j.data || [])).catch(() => {});
|
||||
fetch('/api/admin/reviews', { credentials: 'same-origin' }).then((r) => r.json()).then((j) => setReviews(j.data || [])).catch(() => {});
|
||||
fetch('/api/admin/users', { credentials: 'same-origin' }).then((r) => r.json()).then((j) => setUsers(j.data || [])).catch(() => {});
|
||||
|
||||
fetch('/api/site-assets?key=favicon')
|
||||
.then(async (res) => {
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
if (data.data) setFaviconUrl(data.data);
|
||||
})
|
||||
.catch(() => {});
|
||||
fetch('/api/site-assets').then((res) => res.json()).then((json) => {
|
||||
const c = json.data || {};
|
||||
setFooter({
|
||||
facebook_url: c.facebook_url || '', instagram_url: c.instagram_url || '', whatsapp_url: c.whatsapp_url || '',
|
||||
address: c.address || '', phone: c.phone || '', email: c.email || '',
|
||||
});
|
||||
if (c.logo) setLogoUrl(c.logo);
|
||||
if (c.favicon) setFaviconUrl(c.favicon);
|
||||
}).catch(() => {});
|
||||
|
||||
setLoading(false);
|
||||
}, [router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!faviconUrl) return;
|
||||
let link = document.querySelector("link[rel~='icon']") as HTMLLinkElement | null;
|
||||
if (!link) {
|
||||
link = document.createElement('link');
|
||||
link.rel = 'icon';
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
link.href = faviconUrl;
|
||||
}, [faviconUrl]);
|
||||
const notify = (msg: string) => {
|
||||
setMessage(msg);
|
||||
setTimeout(() => setMessage(null), 4000);
|
||||
};
|
||||
|
||||
const updateAsset = async (key: string, value: string) => {
|
||||
const res = await fetch('/api/site-assets', {
|
||||
@@ -76,18 +138,24 @@ export default function AdminPage() {
|
||||
body: JSON.stringify({ key, value }),
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
if (!res.ok) {
|
||||
setError('Failed to save ' + key);
|
||||
return;
|
||||
}
|
||||
setMessage(`${key} updated. Refresh the page to see the change.`);
|
||||
setTimeout(() => setMessage(null), 4000);
|
||||
if (!res.ok) { setError('Failed to save ' + key); return; }
|
||||
notify(`${key} updated.`);
|
||||
};
|
||||
|
||||
const saveFooter = async () => {
|
||||
const res = await fetch('/api/site-assets', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ values: footer }),
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
if (!res.ok) { setError('Failed to save footer'); return; }
|
||||
notify('Footer info updated.');
|
||||
};
|
||||
|
||||
const handleUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const files = e.target.files;
|
||||
if (!files) return;
|
||||
|
||||
Array.from(files).forEach((file) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = async () => {
|
||||
@@ -98,10 +166,7 @@ export default function AdminPage() {
|
||||
body: JSON.stringify({ filename: file.name, data }),
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
if (!res.ok) {
|
||||
setError('Upload failed');
|
||||
return;
|
||||
}
|
||||
if (!res.ok) { setError('Upload failed'); return; }
|
||||
const result = await res.json();
|
||||
setImages((prev) => [result.image, ...prev]);
|
||||
setCount((prev) => prev + 1);
|
||||
@@ -112,26 +177,108 @@ export default function AdminPage() {
|
||||
};
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
const res = await fetch(`/api/admin/images?id=${id}`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
const res = await fetch(`/api/admin/images?id=${id}`, { method: 'DELETE', credentials: 'same-origin' });
|
||||
if (res.ok) {
|
||||
setImages((prev) => prev.filter((img) => img.id !== id));
|
||||
setCount((prev) => prev - 1);
|
||||
}
|
||||
};
|
||||
|
||||
const api = async (url: string, method: string, body?: object) => {
|
||||
const res = await fetch(url, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const j = await res.json().catch(() => ({}));
|
||||
throw new Error(j.error || 'Request failed');
|
||||
}
|
||||
return res.json();
|
||||
};
|
||||
|
||||
const saveRoom = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
const photosValue = roomForm.photos || [];
|
||||
const photosArray: string[] = typeof photosValue === 'string' ? (photosValue as unknown as string).split(',').map((s: string) => s.trim()) : photosValue;
|
||||
const payload = { ...roomForm, photos: photosArray };
|
||||
if (editingRoom) {
|
||||
await api(`/api/rooms/${editingRoom}`, 'PUT', payload);
|
||||
setRooms((prev) => prev.map((r) => (r.id === editingRoom ? { ...r, ...payload } as Room : r)));
|
||||
setEditingRoom(null);
|
||||
} else {
|
||||
const json = await api('/api/rooms', 'POST', payload);
|
||||
setRooms((prev) => [...prev, json.data]);
|
||||
}
|
||||
setRoomForm({ name: '', description: '', price: '', photos: [] });
|
||||
notify('Room saved.');
|
||||
};
|
||||
|
||||
const editRoom = (r: Room) => { setRoomForm({ ...r, photos: r.photos.join(', ') }); setEditingRoom(r.id); };
|
||||
const deleteRoom = async (id: number) => { await api(`/api/rooms/${id}`, 'DELETE'); setRooms((prev) => prev.filter((r) => r.id !== id)); };
|
||||
|
||||
const saveMenu = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (editingMenu) {
|
||||
await api(`/api/menu/${editingMenu}`, 'PUT', menuForm);
|
||||
setMenu((prev) => prev.map((m) => (m.id === editingMenu ? { ...m, ...menuForm } as MenuItem : m)));
|
||||
setEditingMenu(null);
|
||||
} else {
|
||||
const json = await api('/api/menu', 'POST', menuForm);
|
||||
setMenu((prev) => [...prev, json.data]);
|
||||
}
|
||||
setMenuForm({ category: '', name: '', description: '', price: '', is_daily_special: false });
|
||||
notify('Menu item saved.');
|
||||
};
|
||||
|
||||
const editMenu = (m: MenuItem) => { setMenuForm({ ...m }); setEditingMenu(m.id); };
|
||||
const deleteMenu = async (id: number) => { await api(`/api/menu/${id}`, 'DELETE'); setMenu((prev) => prev.filter((m) => m.id !== id)); };
|
||||
|
||||
const savePlace = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (editingPlace) {
|
||||
await api(`/api/places/${editingPlace}`, 'PUT', placeForm);
|
||||
setPlaces((prev) => prev.map((p) => (p.id === editingPlace ? { ...p, ...placeForm } as Place : p)));
|
||||
setEditingPlace(null);
|
||||
} else {
|
||||
const json = await api('/api/places', 'POST', placeForm);
|
||||
setPlaces((prev) => [...prev, json.data]);
|
||||
}
|
||||
setPlaceForm({ name: '', description: '', photo: '', distance_km: '', visit_time: '', suggestion: '' });
|
||||
notify('Place saved.');
|
||||
};
|
||||
|
||||
const editPlace = (p: Place) => { setPlaceForm({ ...p }); setEditingPlace(p.id); };
|
||||
const deletePlace = async (id: number) => { await api(`/api/places/${id}`, 'DELETE'); setPlaces((prev) => prev.filter((p) => p.id !== id)); };
|
||||
|
||||
const approveReview = async (id: number) => {
|
||||
await api(`/api/admin/reviews/${id}`, 'PUT', { approved: true });
|
||||
setReviews((prev) => prev.map((r) => (r.id === id ? { ...r, approved: true } : r)));
|
||||
};
|
||||
|
||||
const deleteReview = async (id: number) => { await api(`/api/admin/reviews/${id}`, 'DELETE'); setReviews((prev) => prev.filter((r) => r.id !== id)); };
|
||||
|
||||
const saveUser = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
const json = await api('/api/admin/users', 'POST', userForm);
|
||||
setUsers((prev) => [...prev, json.user]);
|
||||
setUserForm({ username: '', password: '', role: 'user' });
|
||||
notify('User created.');
|
||||
};
|
||||
|
||||
const deleteUser = async (id: number) => { await api(`/api/admin/users/${id}`, 'DELETE'); setUsers((prev) => prev.filter((u) => u.id !== id)); };
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<main style={{ padding: '2rem', color: warm, fontSize: '18px' }}>
|
||||
<p>Loading gallery...</p>
|
||||
<p>Loading admin...</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<main style={{ padding: '2rem', maxWidth: '72rem', margin: '0 auto' }}>
|
||||
<main style={{ padding: '2rem', maxWidth: '80rem', margin: '0 auto' }}>
|
||||
<h1 style={{ fontSize: 'clamp(28px, 4vw, 42px)', fontWeight: 400, fontStyle: 'italic', color: navy, margin: '0 0 0.5rem' }}>
|
||||
Admin Portal
|
||||
</h1>
|
||||
@@ -141,164 +288,221 @@ export default function AdminPage() {
|
||||
{error && <p style={{ color: '#c23b22', marginBottom: '1rem' }}>{error}</p>}
|
||||
{message && <p style={{ color: '#3b7a22', marginBottom: '1rem' }}>{message}</p>}
|
||||
|
||||
<section
|
||||
style={{
|
||||
marginBottom: '2rem',
|
||||
padding: '1.5rem',
|
||||
background: '#f5f0e8',
|
||||
borderRadius: '16px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '1rem',
|
||||
}}
|
||||
>
|
||||
<h2 style={{ fontSize: '18px', color: navy, margin: 0 }}>Brand Assets</h2>
|
||||
<div style={{ display: 'grid', gap: '1rem', gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))' }}>
|
||||
<label style={{ display: 'flex', flexDirection: 'column', gap: '0.4rem', fontSize: '13px', color: '#555' }}>
|
||||
Navbar logo
|
||||
<input
|
||||
type="text"
|
||||
value={logoUrl}
|
||||
onChange={(e) => setLogoUrl(e.target.value)}
|
||||
placeholder="Paste image data URL or upload a small image below"
|
||||
style={{ padding: '0.6rem 0.8rem', borderRadius: '10px', border: '1px solid rgba(1,13,30,0.18)' }}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
onClick={() => updateAsset('logo', logoUrl)}
|
||||
disabled={!logoUrl}
|
||||
style={{
|
||||
padding: '0.7rem 1.2rem',
|
||||
background: gold,
|
||||
color: navy,
|
||||
border: 'none',
|
||||
borderRadius: '999px',
|
||||
cursor: logoUrl ? 'pointer' : 'not-allowed',
|
||||
fontWeight: 600,
|
||||
alignSelf: 'end',
|
||||
}}
|
||||
>
|
||||
Save logo
|
||||
</button>
|
||||
|
||||
<label style={{ display: 'flex', flexDirection: 'column', gap: '0.4rem', fontSize: '13px', color: '#555' }}>
|
||||
Favicon
|
||||
<input
|
||||
type="text"
|
||||
value={faviconUrl}
|
||||
onChange={(e) => setFaviconUrl(e.target.value)}
|
||||
placeholder="Paste image data URL or upload a small image below"
|
||||
style={{ padding: '0.6rem 0.8rem', borderRadius: '10px', border: '1px solid rgba(1,13,30,0.18)' }}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
onClick={() => updateAsset('favicon', faviconUrl)}
|
||||
disabled={!faviconUrl}
|
||||
style={{
|
||||
padding: '0.7rem 1.2rem',
|
||||
background: gold,
|
||||
color: navy,
|
||||
border: 'none',
|
||||
borderRadius: '999px',
|
||||
cursor: faviconUrl ? 'pointer' : 'not-allowed',
|
||||
fontWeight: 600,
|
||||
alignSelf: 'end',
|
||||
}}
|
||||
>
|
||||
Save favicon
|
||||
</button>
|
||||
<Section title="Brand Assets">
|
||||
<div style={{ display: 'grid', gap: '1rem', gridTemplateColumns: '1fr auto', alignItems: 'end' }}>
|
||||
<Text label="Navbar logo" value={logoUrl} onChange={setLogoUrl} />
|
||||
<Button onClick={() => updateAsset('logo', logoUrl)} disabled={!logoUrl}>Save logo</Button>
|
||||
<Text label="Favicon" value={faviconUrl} onChange={setFaviconUrl} />
|
||||
<Button onClick={() => updateAsset('favicon', faviconUrl)} disabled={!faviconUrl}>Save favicon</Button>
|
||||
</div>
|
||||
<p style={{ margin: 0, fontSize: '13px', color: '#777' }}>
|
||||
<p style={{ margin: '1rem 0 0', fontSize: '13px', color: '#777' }}>
|
||||
Tip: click an uploaded gallery image to preview, copy its data URL, and paste it above.
|
||||
</p>
|
||||
</section>
|
||||
</Section>
|
||||
|
||||
<label
|
||||
style={{
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
gap: '0.5rem',
|
||||
padding: '0.75rem 1.25rem',
|
||||
background: gold,
|
||||
color: navy,
|
||||
borderRadius: '999px',
|
||||
cursor: 'pointer',
|
||||
fontWeight: 600,
|
||||
marginBottom: '1.5rem',
|
||||
transition: 'transform .12s, box-shadow .15s',
|
||||
}}
|
||||
onMouseEnter={(e) => {
|
||||
e.currentTarget.style.transform = 'translateY(-1px)';
|
||||
e.currentTarget.style.boxShadow = '0 6px 18px rgba(232,168,73,0.35)';
|
||||
}}
|
||||
onMouseLeave={(e) => {
|
||||
e.currentTarget.style.transform = 'translateY(0)';
|
||||
e.currentTarget.style.boxShadow = 'none';
|
||||
}}
|
||||
>
|
||||
+ Upload images
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple
|
||||
onChange={handleUpload}
|
||||
style={{ display: 'none' }}
|
||||
/>
|
||||
</label>
|
||||
{images.length === 0 ? (
|
||||
<p style={{ color: '#777' }}>No images uploaded yet.</p>
|
||||
) : (
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(auto-fill, minmax(200px, 1fr))',
|
||||
gap: '1.25rem',
|
||||
}}
|
||||
>
|
||||
{images.map((img) => (
|
||||
<div
|
||||
key={img.id}
|
||||
style={{
|
||||
borderRadius: '16px',
|
||||
overflow: 'hidden',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
background: '#f5f0e8',
|
||||
boxShadow: '0 1px 2px rgba(1,13,30,0.08)',
|
||||
transition: 'transform .2s, box-shadow .2s',
|
||||
}}
|
||||
onMouseEnter={(e) => {
|
||||
e.currentTarget.style.transform = 'translateY(-2px)';
|
||||
e.currentTarget.style.boxShadow = '0 6px 18px rgba(14,47,71,0.16)';
|
||||
}}
|
||||
onMouseLeave={(e) => {
|
||||
e.currentTarget.style.transform = 'translateY(0)';
|
||||
e.currentTarget.style.boxShadow = '0 1px 2px rgba(1,13,30,0.08)';
|
||||
}}
|
||||
>
|
||||
<img
|
||||
src={img.data}
|
||||
alt={img.filename}
|
||||
style={{ width: '100%', height: '180px', objectFit: 'cover' }}
|
||||
/>
|
||||
<button
|
||||
onClick={() => handleDelete(img.id)}
|
||||
style={{
|
||||
padding: '0.65rem',
|
||||
background: '#c23b22',
|
||||
color: '#fff',
|
||||
border: 'none',
|
||||
cursor: 'pointer',
|
||||
fontSize: '14px',
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
<Section title="Footer / Contact">
|
||||
<div style={{ display: 'grid', gap: '1rem', gridTemplateColumns: 'repeat(auto-fit, minmax(260px, 1fr))' }}>
|
||||
<Text label="Facebook URL" value={footer.facebook_url} onChange={(v) => setFooter({ ...footer, facebook_url: v })} />
|
||||
<Text label="Instagram URL" value={footer.instagram_url} onChange={(v) => setFooter({ ...footer, instagram_url: v })} />
|
||||
<Text label="WhatsApp URL" value={footer.whatsapp_url} onChange={(v) => setFooter({ ...footer, whatsapp_url: v })} />
|
||||
<Text label="Address" value={footer.address} onChange={(v) => setFooter({ ...footer, address: v })} />
|
||||
<Text label="Phone" value={footer.phone} onChange={(v) => setFooter({ ...footer, phone: v })} />
|
||||
<Text label="Email" value={footer.email} onChange={(v) => setFooter({ ...footer, email: v })} />
|
||||
</div>
|
||||
)}
|
||||
<div style={{ marginTop: '1rem' }}>
|
||||
<Button onClick={saveFooter}>Save footer info</Button>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<Section title="Image Gallery">
|
||||
<label style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem', padding: '0.75rem 1.25rem', background: gold, color: navy, borderRadius: '999px', cursor: 'pointer', fontWeight: 600, marginBottom: '1.5rem' }}>
|
||||
+ Upload images
|
||||
<input type="file" accept="image/*" multiple onChange={handleUpload} style={{ display: 'none' }} />
|
||||
</label>
|
||||
{images.length === 0 ? (
|
||||
<p style={{ color: '#777' }}>No images uploaded yet.</p>
|
||||
) : (
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(200px, 1fr))', gap: '1.25rem' }}>
|
||||
{images.map((img) => (
|
||||
<div key={img.id} style={{ borderRadius: '16px', overflow: 'hidden', display: 'flex', flexDirection: 'column', background: '#f5f0e8' }}>
|
||||
<img src={img.data} alt={img.filename} style={{ width: '100%', height: '180px', objectFit: 'cover' }} />
|
||||
<button onClick={() => handleDelete(img.id)} style={{ padding: '0.65rem', background: '#c23b22', color: '#fff', border: 'none', cursor: 'pointer', fontSize: '14px', fontWeight: 600 }}>Delete</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title="Rooms">
|
||||
<form onSubmit={saveRoom} style={{ display: 'grid', gap: '1rem', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', marginBottom: '1.5rem' }}>
|
||||
<Text label="Name" value={roomForm.name || ''} onChange={(v) => setRoomForm({ ...roomForm, name: v })} />
|
||||
<Text label="Price / night" value={roomForm.price || ''} onChange={(v) => setRoomForm({ ...roomForm, price: v })} />
|
||||
<Text label="Photos (comma-separated URLs)" value={typeof roomForm.photos === 'string' ? roomForm.photos : roomForm.photos.join(', ')} onChange={(v) => setRoomForm({ ...roomForm, photos: v })} />
|
||||
<Text label="Description" value={roomForm.description || ''} onChange={(v) => setRoomForm({ ...roomForm, description: v })} />
|
||||
<div style={{ display: 'flex', gap: '0.5rem', alignItems: 'end' }}>
|
||||
<Button type="submit">{editingRoom ? 'Update room' : 'Add room'}</Button>
|
||||
{editingRoom && <SecondaryButton onClick={() => { setEditingRoom(null); setRoomForm({ name: '', description: '', price: '', photos: [] }); }}>Cancel</SecondaryButton>}
|
||||
</div>
|
||||
</form>
|
||||
<ListTable rows={rooms.map((r) => [r.name, `$${r.price}`, r.description.slice(0, 60)])} onEdit={(i) => editRoom(rooms[i])} onDelete={(i) => deleteRoom(rooms[i].id)} />
|
||||
</Section>
|
||||
|
||||
<Section title="Menu">
|
||||
<form onSubmit={saveMenu} style={{ display: 'grid', gap: '1rem', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', marginBottom: '1.5rem' }}>
|
||||
<Text label="Category" value={menuForm.category || ''} onChange={(v) => setMenuForm({ ...menuForm, category: v })} />
|
||||
<Text label="Name" value={menuForm.name || ''} onChange={(v) => setMenuForm({ ...menuForm, name: v })} />
|
||||
<Text label="Price" value={menuForm.price || ''} onChange={(v) => setMenuForm({ ...menuForm, price: v })} />
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: '0.5rem', fontSize: '14px', color: '#555' }}>
|
||||
<input type="checkbox" checked={menuForm.is_daily_special || false} onChange={(e) => setMenuForm({ ...menuForm, is_daily_special: e.target.checked })} />
|
||||
Daily special
|
||||
</label>
|
||||
<Text label="Description" value={menuForm.description || ''} onChange={(v) => setMenuForm({ ...menuForm, description: v })} />
|
||||
<div style={{ display: 'flex', gap: '0.5rem', alignItems: 'end' }}>
|
||||
<Button type="submit">{editingMenu ? 'Update item' : 'Add item'}</Button>
|
||||
{editingMenu && <SecondaryButton onClick={() => { setEditingMenu(null); setMenuForm({ category: '', name: '', description: '', price: '', is_daily_special: false }); }}>Cancel</SecondaryButton>}
|
||||
</div>
|
||||
</form>
|
||||
<ListTable rows={menu.map((m) => [m.category, m.name, `$${m.price}`, m.is_daily_special ? '★ Daily' : ''])} onEdit={(i) => editMenu(menu[i])} onDelete={(i) => deleteMenu(menu[i].id)} />
|
||||
</Section>
|
||||
|
||||
<Section title="Landscape Places">
|
||||
<form onSubmit={savePlace} style={{ display: 'grid', gap: '1rem', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', marginBottom: '1.5rem' }}>
|
||||
<Text label="Name" value={placeForm.name || ''} onChange={(v) => setPlaceForm({ ...placeForm, name: v })} />
|
||||
<Text label="Distance (km)" value={placeForm.distance_km || ''} onChange={(v) => setPlaceForm({ ...placeForm, distance_km: v })} />
|
||||
<Text label="Visit time" value={placeForm.visit_time || ''} onChange={(v) => setPlaceForm({ ...placeForm, visit_time: v })} />
|
||||
<Text label="Photo URL" value={placeForm.photo || ''} onChange={(v) => setPlaceForm({ ...placeForm, photo: v })} />
|
||||
<Text label="Description" value={placeForm.description || ''} onChange={(v) => setPlaceForm({ ...placeForm, description: v })} />
|
||||
<Text label="Suggestion" value={placeForm.suggestion || ''} onChange={(v) => setPlaceForm({ ...placeForm, suggestion: v })} />
|
||||
<div style={{ display: 'flex', gap: '0.5rem', alignItems: 'end' }}>
|
||||
<Button type="submit">{editingPlace ? 'Update place' : 'Add place'}</Button>
|
||||
{editingPlace && <SecondaryButton onClick={() => { setEditingPlace(null); setPlaceForm({ name: '', description: '', photo: '', distance_km: '', visit_time: '', suggestion: '' }); }}>Cancel</SecondaryButton>}
|
||||
</div>
|
||||
</form>
|
||||
<ListTable rows={places.map((p) => [p.name, `${p.distance_km || ''} km`, p.description.slice(0, 60)])} onEdit={(i) => editPlace(places[i])} onDelete={(i) => deletePlace(places[i].id)} />
|
||||
</Section>
|
||||
|
||||
<Section title="Pending Reviews">
|
||||
{reviews.length === 0 ? <p style={{ color: '#777' }}>No pending reviews.</p> : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
||||
{reviews.map((r) => (
|
||||
<div key={r.id} style={{ background: '#fff', padding: '1rem 1.25rem', borderRadius: '12px', boxShadow: '0 1px 3px rgba(1,13,30,0.06)' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '0.5rem' }}>
|
||||
<strong>{r.author_name}</strong>
|
||||
<span style={{ color: gold }}>{'★'.repeat(r.rating)}{'☆'.repeat(5 - r.rating)}</span>
|
||||
</div>
|
||||
<p style={{ margin: '0 0 0.75rem', color: '#555' }}>{r.text}</p>
|
||||
<div style={{ display: 'flex', gap: '0.5rem' }}>
|
||||
{!r.approved && <Button onClick={() => approveReview(r.id)}>Approve</Button>}
|
||||
<DangerButton onClick={() => deleteReview(r.id)}>Delete</DangerButton>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title="Users">
|
||||
<form onSubmit={saveUser} style={{ display: 'grid', gap: '1rem', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', marginBottom: '1.5rem' }}>
|
||||
<Text label="Username" value={userForm.username} onChange={(v) => setUserForm({ ...userForm, username: v })} />
|
||||
<Text label="Password" value={userForm.password} type="password" onChange={(v) => setUserForm({ ...userForm, password: v })} />
|
||||
<label style={{ display: 'flex', flexDirection: 'column', gap: '0.4rem', fontSize: '14px', color: '#555' }}>
|
||||
Role
|
||||
<select value={userForm.role} onChange={(e) => setUserForm({ ...userForm, role: e.target.value as 'admin' | 'user' })} style={{ padding: '0.6rem 0.8rem', borderRadius: '10px', border: '1px solid rgba(1,13,30,0.18)' }}>
|
||||
<option value="user">User</option>
|
||||
<option value="admin">Admin</option>
|
||||
</select>
|
||||
</label>
|
||||
<div style={{ display: 'flex', alignItems: 'end' }}>
|
||||
<Button type="submit">Create user</Button>
|
||||
</div>
|
||||
</form>
|
||||
<ListTable rows={users.map((u) => [u.username, u.role])} onDelete={(i) => deleteUser(users[i].id)} />
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function Section({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<section style={{ marginBottom: '2.5rem', padding: '1.5rem', background: '#f5f0e8', borderRadius: '16px' }}>
|
||||
<h2 style={{ fontSize: '20px', color: navy, margin: '0 0 1rem' }}>{title}</h2>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function Text({ label, value, onChange, type = 'text' }: { label: string; value: string; onChange: (v: string) => void; type?: string }) {
|
||||
return (
|
||||
<label style={{ display: 'flex', flexDirection: 'column', gap: '0.4rem', fontSize: '14px', color: '#555' }}>
|
||||
{label}
|
||||
<input
|
||||
type={type}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
style={{ padding: '0.6rem 0.8rem', borderRadius: '10px', border: '1px solid rgba(1,13,30,0.18)' }}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function Button({ children, onClick, type = 'button', disabled = false }: { children: React.ReactNode; onClick?: () => void; type?: 'button' | 'submit'; disabled?: boolean }) {
|
||||
return (
|
||||
<button
|
||||
type={type}
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
style={{
|
||||
padding: '0.7rem 1.2rem',
|
||||
background: disabled ? '#ccc' : gold,
|
||||
color: navy,
|
||||
border: 'none',
|
||||
borderRadius: '999px',
|
||||
cursor: disabled ? 'not-allowed' : 'pointer',
|
||||
fontWeight: 600,
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function SecondaryButton({ children, onClick }: { children: React.ReactNode; onClick: () => void }) {
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
style={{ padding: '0.7rem 1.2rem', background: 'transparent', color: warm, border: `1.5px solid ${warm}`, borderRadius: '999px', cursor: 'pointer', fontWeight: 600, whiteSpace: 'nowrap' }}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function DangerButton({ children, onClick }: { children: React.ReactNode; onClick: () => void }) {
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
style={{ padding: '0.5rem 1rem', background: '#c23b22', color: '#fff', border: 'none', borderRadius: '999px', cursor: 'pointer', fontWeight: 600, fontSize: '13px' }}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function ListTable({ rows, onEdit, onDelete }: { rows: string[][]; onEdit?: (index: number) => void; onDelete: (index: number) => void }) {
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}>
|
||||
{rows.map((row, i) => (
|
||||
<div key={i} style={{ background: '#fff', padding: '0.9rem 1.1rem', borderRadius: '12px', display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: '1rem' }}>
|
||||
<div style={{ display: 'flex', gap: '1rem', flexWrap: 'wrap', color: navy }}>
|
||||
{row.map((cell, j) => <span key={j}>{cell}</span>)}
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: '0.5rem', flexShrink: 0 }}>
|
||||
{onEdit && <Button onClick={() => onEdit(i)}>Edit</Button>}
|
||||
<DangerButton onClick={() => onDelete(i)}>Delete</DangerButton>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user