Platform Settings: - Add PlatformSettings utility in init-alpine.js with 5-min cache - Add Display tab in /admin/settings for rows_per_page config - Integrate PlatformSettings.getRowsPerPage() in all paginated pages - Standardize default per_page to 20 across all admin pages - Add documentation at docs/frontend/shared/platform-settings.md Architecture Rules: - Add JS-010: enforce PlatformSettings usage for pagination - Add JS-011: enforce standard pagination structure - Add JS-012: detect double /api/v1 prefix in apiClient calls - Implement all rules in validate_architecture.py Vendor Filter (Tom Select): - Add vendor filter to marketplace-products, vendor-products, customers, inventory, and vendor-themes pages - Add selectedVendor display panel with clear button - Add localStorage persistence for vendor selection - Fix double /api/v1 prefix in vendor-selector.js Bug Fixes: - Remove duplicate PlatformSettings from utils.js - Fix customers.js pagination structure (page_size → per_page) - Fix code-quality-violations.js pagination structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
320 lines
14 KiB
HTML
320 lines
14 KiB
HTML
{# app/templates/admin/customers.html #}
|
|
{% extends "admin/base.html" %}
|
|
{% from 'shared/macros/headers.html' import page_header_flex, refresh_button %}
|
|
{% from 'shared/macros/alerts.html' import loading_state, error_state %}
|
|
{% from 'shared/macros/tables.html' import table_wrapper, table_header %}
|
|
{% from 'shared/macros/pagination.html' import pagination %}
|
|
|
|
{% block title %}Customers{% endblock %}
|
|
|
|
{% block alpine_data %}adminCustomers(){% endblock %}
|
|
|
|
{% block extra_head %}
|
|
<!-- Tom Select CSS with local fallback -->
|
|
<link
|
|
rel="stylesheet"
|
|
href="https://cdn.jsdelivr.net/npm/tom-select@2.4.1/dist/css/tom-select.default.min.css"
|
|
onerror="this.onerror=null; this.href='{{ url_for('static', path='shared/css/vendor/tom-select.default.min.css') }}';"
|
|
/>
|
|
<style>
|
|
/* Tom Select dark mode overrides */
|
|
.dark .ts-wrapper .ts-control {
|
|
background-color: rgb(55 65 81);
|
|
border-color: rgb(75 85 99);
|
|
color: rgb(209 213 219);
|
|
}
|
|
.dark .ts-wrapper .ts-control input {
|
|
color: rgb(209 213 219);
|
|
}
|
|
.dark .ts-wrapper .ts-control input::placeholder {
|
|
color: rgb(156 163 175);
|
|
}
|
|
.dark .ts-dropdown {
|
|
background-color: rgb(55 65 81);
|
|
border-color: rgb(75 85 99);
|
|
color: rgb(209 213 219);
|
|
}
|
|
.dark .ts-dropdown .option {
|
|
color: rgb(209 213 219);
|
|
}
|
|
.dark .ts-dropdown .option.active {
|
|
background-color: rgb(147 51 234);
|
|
color: white;
|
|
}
|
|
.dark .ts-dropdown .option:hover {
|
|
background-color: rgb(75 85 99);
|
|
}
|
|
.dark .ts-wrapper.focus .ts-control {
|
|
border-color: rgb(147 51 234);
|
|
box-shadow: 0 0 0 1px rgb(147 51 234);
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<!-- Page Header with Vendor Selector -->
|
|
{% call page_header_flex(title='Customer Management', subtitle='Manage customers across all vendors') %}
|
|
<div class="flex items-center gap-4">
|
|
<!-- Vendor Autocomplete (Tom Select) -->
|
|
<div class="w-80">
|
|
<select id="vendor-select" x-ref="vendorSelect" placeholder="Filter by vendor...">
|
|
</select>
|
|
</div>
|
|
{{ refresh_button(loading_var='loading', onclick='resetAndLoad()', variant='secondary') }}
|
|
</div>
|
|
{% endcall %}
|
|
|
|
<!-- Selected Vendor Info -->
|
|
<div x-show="selectedVendor" x-transition class="mb-6 p-3 bg-purple-50 dark:bg-purple-900/20 rounded-lg border border-purple-200 dark:border-purple-800">
|
|
<div class="flex items-center justify-between">
|
|
<div class="flex items-center gap-3">
|
|
<div class="w-8 h-8 rounded-full bg-purple-100 dark:bg-purple-900 flex items-center justify-center">
|
|
<span class="text-sm font-semibold text-purple-600 dark:text-purple-300" x-text="selectedVendor?.name?.charAt(0).toUpperCase()"></span>
|
|
</div>
|
|
<div>
|
|
<span class="font-medium text-purple-800 dark:text-purple-200" x-text="selectedVendor?.name"></span>
|
|
<span class="ml-2 text-xs text-purple-600 dark:text-purple-400 font-mono" x-text="selectedVendor?.vendor_code"></span>
|
|
</div>
|
|
</div>
|
|
<button @click="clearVendorFilter()" class="text-purple-600 dark:text-purple-400 hover:text-purple-800 dark:hover:text-purple-200 text-sm flex items-center gap-1">
|
|
<span x-html="$icon('x', 'w-4 h-4')"></span>
|
|
Clear filter
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{{ loading_state('Loading customers...') }}
|
|
|
|
{{ error_state('Error loading customers') }}
|
|
|
|
<!-- Stats Cards -->
|
|
<div x-show="!loading" class="grid gap-6 mb-8 md:grid-cols-2 xl:grid-cols-4">
|
|
<!-- Card: Total Customers -->
|
|
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
|
|
<div class="p-3 mr-4 text-blue-500 bg-blue-100 rounded-full dark:text-blue-100 dark:bg-blue-500">
|
|
<span x-html="$icon('user-group', 'w-5 h-5')"></span>
|
|
</div>
|
|
<div>
|
|
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
|
|
Total Customers
|
|
</p>
|
|
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.total || 0">
|
|
0
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Card: Active Customers -->
|
|
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
|
|
<div class="p-3 mr-4 text-green-500 bg-green-100 rounded-full dark:text-green-100 dark:bg-green-500">
|
|
<span x-html="$icon('user-check', 'w-5 h-5')"></span>
|
|
</div>
|
|
<div>
|
|
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
|
|
Active
|
|
</p>
|
|
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.active || 0">
|
|
0
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Card: With Orders -->
|
|
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
|
|
<div class="p-3 mr-4 text-purple-500 bg-purple-100 rounded-full dark:text-purple-100 dark:bg-purple-500">
|
|
<span x-html="$icon('shopping-bag', 'w-5 h-5')"></span>
|
|
</div>
|
|
<div>
|
|
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
|
|
With Orders
|
|
</p>
|
|
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.with_orders || 0">
|
|
0
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Card: Total Spent -->
|
|
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
|
|
<div class="p-3 mr-4 text-orange-500 bg-orange-100 rounded-full dark:text-orange-100 dark:bg-orange-500">
|
|
<span x-html="$icon('currency-euro', 'w-5 h-5')"></span>
|
|
</div>
|
|
<div>
|
|
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
|
|
Total Revenue
|
|
</p>
|
|
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="formatCurrency(stats.total_spent || 0)">
|
|
0
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Search and Filters -->
|
|
<div x-show="!loading" class="mb-6 px-4 py-3 bg-white rounded-lg shadow-md dark:bg-gray-800">
|
|
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
|
<!-- Search Bar -->
|
|
<div class="flex-1 max-w-md">
|
|
<div class="relative">
|
|
<input
|
|
type="text"
|
|
x-model="filters.search"
|
|
@input.debounce.300ms="resetAndLoad()"
|
|
placeholder="Search by name, email, or customer number..."
|
|
class="w-full pl-10 pr-4 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:bg-gray-700 dark:text-gray-300"
|
|
>
|
|
<div class="absolute inset-y-0 left-0 flex items-center pl-3">
|
|
<span x-html="$icon('search', 'w-5 h-5 text-gray-400')"></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Status Filter -->
|
|
<div class="flex items-center gap-4">
|
|
<select
|
|
x-model="filters.is_active"
|
|
@change="resetAndLoad()"
|
|
class="px-4 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg focus:border-purple-400 focus:outline-none dark:bg-gray-700 dark:text-gray-300"
|
|
>
|
|
<option value="">All Status</option>
|
|
<option value="true">Active</option>
|
|
<option value="false">Inactive</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Customers Table -->
|
|
<div x-show="!loading" class="w-full overflow-hidden rounded-lg shadow-xs">
|
|
<div class="w-full overflow-x-auto">
|
|
<table class="w-full whitespace-no-wrap">
|
|
<thead>
|
|
<tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800">
|
|
<th class="px-4 py-3">Customer</th>
|
|
<th class="px-4 py-3">Vendor</th>
|
|
<th class="px-4 py-3">Customer #</th>
|
|
<th class="px-4 py-3">Orders</th>
|
|
<th class="px-4 py-3">Total Spent</th>
|
|
<th class="px-4 py-3">Status</th>
|
|
<th class="px-4 py-3">Joined</th>
|
|
<th class="px-4 py-3">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
|
|
<!-- Loading state -->
|
|
<template x-if="loadingCustomers && customers.length === 0">
|
|
<tr>
|
|
<td colspan="8" class="px-4 py-8 text-center text-gray-500 dark:text-gray-400">
|
|
<span x-html="$icon('spinner', 'w-6 h-6 mx-auto mb-2')"></span>
|
|
<p>Loading customers...</p>
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
|
|
<!-- Empty state -->
|
|
<template x-if="!loadingCustomers && customers.length === 0">
|
|
<tr>
|
|
<td colspan="8" class="px-4 py-8 text-center text-gray-500 dark:text-gray-400">
|
|
<span x-html="$icon('user-group', 'w-12 h-12 mx-auto mb-2 text-gray-300')"></span>
|
|
<p class="font-medium">No customers found</p>
|
|
<p class="text-sm mt-1">Try adjusting your search or filters</p>
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
|
|
<!-- Customer rows -->
|
|
<template x-for="customer in customers" :key="customer.id">
|
|
<tr class="text-gray-700 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-700">
|
|
<!-- Customer -->
|
|
<td class="px-4 py-3">
|
|
<div class="flex items-center text-sm">
|
|
<div class="relative hidden w-8 h-8 mr-3 rounded-full md:block bg-gray-200 dark:bg-gray-700 flex items-center justify-center">
|
|
<span x-html="$icon('user', 'w-4 h-4 text-gray-500')"></span>
|
|
</div>
|
|
<div>
|
|
<p class="font-semibold" x-text="customer.first_name && customer.last_name ? customer.first_name + ' ' + customer.last_name : customer.email"></p>
|
|
<p class="text-xs text-gray-600 dark:text-gray-400" x-text="customer.email"></p>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
|
|
<!-- Vendor -->
|
|
<td class="px-4 py-3 text-sm">
|
|
<span x-text="customer.vendor_code || customer.vendor_name || '-'"></span>
|
|
</td>
|
|
|
|
<!-- Customer Number -->
|
|
<td class="px-4 py-3 text-sm">
|
|
<span class="font-mono text-xs" x-text="customer.customer_number"></span>
|
|
</td>
|
|
|
|
<!-- Orders -->
|
|
<td class="px-4 py-3 text-sm">
|
|
<span x-text="customer.total_orders || 0"></span>
|
|
</td>
|
|
|
|
<!-- Total Spent -->
|
|
<td class="px-4 py-3 text-sm">
|
|
<span x-text="formatCurrency(customer.total_spent || 0)"></span>
|
|
</td>
|
|
|
|
<!-- Status -->
|
|
<td class="px-4 py-3 text-xs">
|
|
<span
|
|
class="px-2 py-1 font-semibold leading-tight rounded-full"
|
|
:class="customer.is_active
|
|
? 'text-green-700 bg-green-100 dark:bg-green-700 dark:text-green-100'
|
|
: 'text-red-700 bg-red-100 dark:bg-red-700 dark:text-red-100'"
|
|
x-text="customer.is_active ? 'Active' : 'Inactive'"
|
|
></span>
|
|
</td>
|
|
|
|
<!-- Joined -->
|
|
<td class="px-4 py-3 text-sm">
|
|
<span x-text="formatDate(customer.created_at)"></span>
|
|
</td>
|
|
|
|
<!-- Actions -->
|
|
<td class="px-4 py-3">
|
|
<div class="flex items-center space-x-2 text-sm">
|
|
<button
|
|
@click="toggleStatus(customer)"
|
|
class="px-2 py-1 text-xs font-medium leading-5 rounded-lg"
|
|
:class="customer.is_active
|
|
? 'text-red-600 hover:bg-red-100 dark:text-red-400 dark:hover:bg-red-700/50'
|
|
: 'text-green-600 hover:bg-green-100 dark:text-green-400 dark:hover:bg-green-700/50'"
|
|
:title="customer.is_active ? 'Deactivate' : 'Activate'"
|
|
>
|
|
<span x-html="customer.is_active ? $icon('x-circle', 'w-4 h-4') : $icon('check-circle', 'w-4 h-4')"></span>
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Pagination -->
|
|
{{ pagination() }}
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_scripts %}
|
|
<!-- Tom Select JS with local fallback -->
|
|
<script>
|
|
(function() {
|
|
var script = document.createElement('script');
|
|
script.src = 'https://cdn.jsdelivr.net/npm/tom-select@2.4.1/dist/js/tom-select.complete.min.js';
|
|
script.onerror = function() {
|
|
console.warn('Tom Select CDN failed, loading local copy...');
|
|
var fallbackScript = document.createElement('script');
|
|
fallbackScript.src = '{{ url_for("static", path="shared/js/vendor/tom-select.complete.min.js") }}';
|
|
document.head.appendChild(fallbackScript);
|
|
};
|
|
document.head.appendChild(script);
|
|
})();
|
|
</script>
|
|
<script src="{{ url_for('static', path='admin/js/customers.js') }}"></script>
|
|
{% endblock %}
|