views(admin): add category and variant management pages
This commit is contained in:
1 parent
124da9db63
commit
c200aa2996
3 files changed
+149
No files matched your search
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
$editing = $category !== null && !empty($category['id']);
|
||||
$action = $editing ? '/admin/categories/' . (int) $category['id'] : '/admin/categories';
|
||||
$field = static fn (string $key) => $category[$key] ?? '';
|
||||
?>
|
||||
<div class="admin__head">
|
||||
<div>
|
||||
<p class="small muted"><a href="/admin/categories">Categories</a> / <?= $editing ? 'Edit' : 'New' ?></p>
|
||||
<h1 style="margin:0"><?= $editing ? e($category['name']) : 'New category' ?></h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form method="post" action="<?= e($action) ?>" style="max-width:600px">
|
||||
<input type="hidden" name="csrfToken" value="<?= e($csrfToken) ?>">
|
||||
<div class="panel panel--pad">
|
||||
<div class="field <?= isset($errors['name']) ? 'field--error' : '' ?>">
|
||||
<label for="name">Name</label>
|
||||
<input class="input" type="text" id="name" name="name" value="<?= e((string) $field('name')) ?>" required>
|
||||
<?php if (isset($errors['name'])): ?><span class="field__error"><?= e($errors['name']) ?></span><?php endif; ?>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="slug">Slug</label>
|
||||
<input class="input" type="text" id="slug" name="slug" value="<?= e((string) $field('slug')) ?>" placeholder="auto-generated from name">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="description">Description</label>
|
||||
<textarea class="textarea" id="description" name="description"><?= e((string) $field('description')) ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-lg" style="gap:12px">
|
||||
<button class="btn btn--primary" type="submit"><?= $editing ? 'Save changes' : 'Create category' ?></button>
|
||||
<a class="btn" href="/admin/categories">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,39 @@
|
||||
<div class="admin__head">
|
||||
<div>
|
||||
<h1 style="margin:0">Categories</h1>
|
||||
<p class="muted" style="margin:0"><?= count($categories) ?> categories.</p>
|
||||
</div>
|
||||
<a class="btn btn--primary" href="/admin/categories/create">New category</a>
|
||||
</div>
|
||||
|
||||
<?php if (empty($categories)): ?>
|
||||
<div class="empty">
|
||||
<h3>No categories yet</h3>
|
||||
<p class="muted">Add a category before creating products.</p>
|
||||
<a class="btn btn--primary mt" href="/admin/categories/create">New category</a>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="table-wrap">
|
||||
<table class="table">
|
||||
<thead><tr><th>Name</th><th>Slug</th><th class="num">Products</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($categories as $category): ?>
|
||||
<tr>
|
||||
<td style="font-weight:600"><?= e($category['name']) ?><div class="small muted"><?= e($category['description']) ?></div></td>
|
||||
<td class="mono muted">/<?= e($category['slug']) ?></td>
|
||||
<td class="num"><?= (int) $category['productCount'] ?></td>
|
||||
<td>
|
||||
<div class="row" style="gap:6px;justify-content:flex-end">
|
||||
<a class="btn btn--sm" href="/admin/categories/<?= (int) $category['id'] ?>/edit">Edit</a>
|
||||
<form method="post" action="/admin/categories/<?= (int) $category['id'] ?>/delete" onsubmit="return confirm('Delete this category?')">
|
||||
<input type="hidden" name="csrfToken" value="<?= e($csrfToken) ?>">
|
||||
<button class="btn btn--danger btn--sm" type="submit">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
Reference in new issue
Block a user