Files
oldvine/client/public/add-category.html
yotakii 9dda03b40d edit
2026-01-13 16:07:35 +03:00

61 lines
2.0 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Add Room Category</title>
</head>
<body style="font-family: sans-serif; max-width: 720px; margin: 40px auto;">
<h2>Add Room Category (Admin)</h2>
<p>Make sure you are logged in to /admin/login first.</p>
<label>Name</label><br />
<input id="name" style="width:100%;padding:8px" value="Deluxe" /><br /><br />
<label>Slug (lowercase, no spaces)</label><br />
<input id="slug" style="width:100%;padding:8px" value="deluxe" /><br /><br />
<label>Description</label><br />
<textarea id="description" style="width:100%;padding:8px" rows="4">Deluxe rooms</textarea><br /><br />
<button id="btn" style="padding:10px 16px">Create Category</button>
<pre id="out" style="background:#111;color:#0f0;padding:12px;margin-top:16px;white-space:pre-wrap"></pre>
<script>
document.getElementById("btn").onclick = async () => {
const token = localStorage.getItem("adminToken");
if (!token) {
document.getElementById("out").textContent = "❌ No adminToken found. Please login at /admin/login first.";
return;
}
const payload = {
name: document.getElementById("name").value.trim(),
slug: document.getElementById("slug").value.trim(),
description: document.getElementById("description").value.trim(),
images: [],
features: [],
isActive: true,
displayOrder: 1
};
try {
const res = await fetch("http://localhost:5080/api/room-categories", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + token
},
body: JSON.stringify(payload)
});
const data = await res.json();
document.getElementById("out").textContent = "Status: " + res.status + "\n" + JSON.stringify(data, null, 2);
} catch (e) {
document.getElementById("out").textContent = "❌ Error: " + e.message;
}
};
</script>
</body>
</html>