Multitenant implementation with custom Domain, theme per vendor

This commit is contained in:
2025-10-26 20:05:02 +01:00
parent 091067a729
commit c88775134d
27 changed files with 3267 additions and 838 deletions

View File

@@ -5,6 +5,7 @@ Admin API router aggregation.
This module combines all admin-related API endpoints:
- Authentication (login/logout)
- Vendor management (CRUD, bulk operations)
- Vendor domains management (custom domains, DNS verification)
- User management (status, roles)
- Dashboard and statistics
- Marketplace monitoring
@@ -20,6 +21,7 @@ from fastapi import APIRouter
from . import (
auth,
vendors,
vendor_domains,
users,
dashboard,
marketplace,
@@ -34,28 +36,56 @@ from . import (
router = APIRouter()
# ============================================================================
# Authentication & Authorization
# ============================================================================
# Include authentication endpoints
router.include_router(auth.router, tags=["admin-auth"])
# ============================================================================
# Vendor Management
# ============================================================================
# Include vendor management endpoints
router.include_router(vendors.router, tags=["admin-vendors"])
# Include vendor domains management endpoints
router.include_router(vendor_domains.router, tags=["admin-vendor-domains"])
# ============================================================================
# User Management
# ============================================================================
# Include user management endpoints
router.include_router(users.router, tags=["admin-users"])
# ============================================================================
# Dashboard & Statistics
# ============================================================================
# Include dashboard and statistics endpoints
router.include_router(dashboard.router, tags=["admin-dashboard"])
# ============================================================================
# Marketplace & Imports
# ============================================================================
# Include marketplace monitoring endpoints
router.include_router(marketplace.router, tags=["admin-marketplace"])
# Include monitoring endpoints (placeholder)
# router.include_router(monitoring.router, tags=["admin-monitoring"])
# ============================================================================
# Admin Models Integration
# Platform Administration
# ============================================================================
# Include monitoring endpoints (placeholder for future implementation)
# router.include_router(monitoring.router, tags=["admin-monitoring"])
# Include audit logging endpoints
router.include_router(audit.router, tags=["admin-audit"])
@@ -65,6 +95,7 @@ router.include_router(settings.router, tags=["admin-settings"])
# Include notifications and alerts endpoints
router.include_router(notifications.router, tags=["admin-notifications"])
# ============================================================================
# HTML Page Routes (Jinja2 Templates)
# ============================================================================
@@ -72,5 +103,6 @@ router.include_router(notifications.router, tags=["admin-notifications"])
# Include HTML page routes (these return rendered templates, not JSON)
router.include_router(pages.router, tags=["admin-pages"])
# Export the router
__all__ = ["router"]

View File

@@ -16,6 +16,7 @@ Routes:
- GET /vendors/create → Create vendor form (auth required)
- GET /vendors/{vendor_code} → Vendor details (auth required)
- GET /vendors/{vendor_code}/edit → Edit vendor form (auth required)
- GET /vendors/{vendor_code}/domains → Vendor domains management (auth required)
- GET /users → User management page (auth required)
- GET /imports → Import history page (auth required)
- GET /settings → Settings page (auth required)
@@ -166,6 +167,55 @@ async def admin_vendor_edit_page(
)
# ============================================================================
# VENDOR DOMAINS ROUTES
# ============================================================================
@router.get("/vendors/{vendor_code}/domains", response_class=HTMLResponse, include_in_schema=False)
async def admin_vendor_domains_page(
request: Request,
vendor_code: str = Path(..., description="Vendor code"),
current_user: User = Depends(get_current_admin_user),
db: Session = Depends(get_db)
):
"""
Render vendor domains management page.
Shows custom domains, verification status, and DNS configuration.
"""
return templates.TemplateResponse(
"admin/vendor-domains.html",
{
"request": request,
"user": current_user,
"vendor_code": vendor_code,
}
)
# ============================================================================
# VENDOR THEMES ROUTES
# ============================================================================
@router.get("/vendors/{vendor_code}/theme", response_class=HTMLResponse, include_in_schema=False)
async def admin_vendor_theme_page(
request: Request,
vendor_code: str = Path(..., description="Vendor code"),
current_user: User = Depends(get_current_admin_user),
db: Session = Depends(get_db)
):
"""
Render vendor theme customization page.
"""
return templates.TemplateResponse(
"admin/vendor-theme.html",
{
"request": request,
"user": current_user,
"vendor_code": vendor_code,
}
)
# ============================================================================
# USER MANAGEMENT ROUTES
# ============================================================================
@@ -257,6 +307,7 @@ async def admin_components_page(
}
)
@router.get("/icons", response_class=HTMLResponse, include_in_schema=False)
async def admin_icons_page(
request: Request,
@@ -275,6 +326,7 @@ async def admin_icons_page(
}
)
@router.get("/testing", response_class=HTMLResponse, include_in_schema=False)
async def admin_testing_hub(
request: Request,

View File

@@ -0,0 +1,328 @@
# app/api/v1/admin/vendor_domains.py
"""
Admin endpoints for managing vendor custom domains.
Follows the architecture pattern:
- Endpoints only handle HTTP layer
- Business logic in service layer
- Proper exception handling
- Pydantic schemas for validation
"""
import logging
from typing import List
from fastapi import APIRouter, Depends, Path, Body, Query
from sqlalchemy.orm import Session
from app.api.deps import get_current_admin_user
from app.core.database import get_db
from app.services.vendor_domain_service import vendor_domain_service
from app.exceptions import VendorNotFoundException
from models.schema.vendor_domain import (
VendorDomainCreate,
VendorDomainUpdate,
VendorDomainResponse,
VendorDomainListResponse,
DomainVerificationInstructions,
DomainVerificationResponse,
DomainDeletionResponse,
)
from models.database.user import User
from models.database.vendor import Vendor
router = APIRouter(prefix="/vendors")
logger = logging.getLogger(__name__)
def _get_vendor_by_id(db: Session, vendor_id: int) -> Vendor:
"""
Helper to get vendor by ID.
Args:
db: Database session
vendor_id: Vendor ID
Returns:
Vendor object
Raises:
VendorNotFoundException: If vendor not found
"""
vendor = db.query(Vendor).filter(Vendor.id == vendor_id).first()
if not vendor:
raise VendorNotFoundException(str(vendor_id), identifier_type="id")
return vendor
@router.post("/{vendor_id}/domains", response_model=VendorDomainResponse)
def add_vendor_domain(
vendor_id: int = Path(..., description="Vendor ID", gt=0),
domain_data: VendorDomainCreate = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_user),
):
"""
Add a custom domain to vendor (Admin only).
This endpoint:
1. Validates the domain format
2. Checks if domain is already registered
3. Generates verification token
4. Creates domain record (unverified, inactive)
5. Returns domain with verification instructions
**Domain Examples:**
- myshop.com
- shop.mybrand.com
- customstore.net
**Next Steps:**
1. Vendor adds DNS TXT record
2. Admin clicks "Verify Domain" to confirm ownership
3. Once verified, domain can be activated
**Raises:**
- 404: Vendor not found
- 409: Domain already registered
- 422: Invalid domain format or reserved subdomain
"""
domain = vendor_domain_service.add_domain(
db=db,
vendor_id=vendor_id,
domain_data=domain_data
)
return VendorDomainResponse(
id=domain.id,
vendor_id=domain.vendor_id,
domain=domain.domain,
is_primary=domain.is_primary,
is_active=domain.is_active,
is_verified=domain.is_verified,
ssl_status=domain.ssl_status,
verification_token=domain.verification_token,
verified_at=domain.verified_at,
ssl_verified_at=domain.ssl_verified_at,
created_at=domain.created_at,
updated_at=domain.updated_at,
)
@router.get("/{vendor_id}/domains", response_model=VendorDomainListResponse)
def list_vendor_domains(
vendor_id: int = Path(..., description="Vendor ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_user),
):
"""
List all domains for a vendor (Admin only).
Returns domains ordered by:
1. Primary domains first
2. Creation date (newest first)
**Raises:**
- 404: Vendor not found
"""
# Verify vendor exists
_get_vendor_by_id(db, vendor_id)
domains = vendor_domain_service.get_vendor_domains(db, vendor_id)
return VendorDomainListResponse(
domains=[
VendorDomainResponse(
id=d.id,
vendor_id=d.vendor_id,
domain=d.domain,
is_primary=d.is_primary,
is_active=d.is_active,
is_verified=d.is_verified,
ssl_status=d.ssl_status,
verification_token=d.verification_token if not d.is_verified else None,
verified_at=d.verified_at,
ssl_verified_at=d.ssl_verified_at,
created_at=d.created_at,
updated_at=d.updated_at,
)
for d in domains
],
total=len(domains)
)
@router.get("/domains/{domain_id}", response_model=VendorDomainResponse)
def get_domain_details(
domain_id: int = Path(..., description="Domain ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_user),
):
"""
Get detailed information about a specific domain (Admin only).
**Raises:**
- 404: Domain not found
"""
domain = vendor_domain_service.get_domain_by_id(db, domain_id)
return VendorDomainResponse(
id=domain.id,
vendor_id=domain.vendor_id,
domain=domain.domain,
is_primary=domain.is_primary,
is_active=domain.is_active,
is_verified=domain.is_verified,
ssl_status=domain.ssl_status,
verification_token=domain.verification_token if not domain.is_verified else None,
verified_at=domain.verified_at,
ssl_verified_at=domain.ssl_verified_at,
created_at=domain.created_at,
updated_at=domain.updated_at,
)
@router.put("/domains/{domain_id}", response_model=VendorDomainResponse)
def update_vendor_domain(
domain_id: int = Path(..., description="Domain ID", gt=0),
domain_update: VendorDomainUpdate = Body(...),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_user),
):
"""
Update domain settings (Admin only).
**Can update:**
- `is_primary`: Set as primary domain for vendor
- `is_active`: Activate or deactivate domain
**Important:**
- Cannot activate unverified domains
- Setting a domain as primary will unset other primary domains
- Cannot modify domain name (delete and recreate instead)
**Raises:**
- 404: Domain not found
- 400: Cannot activate unverified domain
"""
domain = vendor_domain_service.update_domain(
db=db,
domain_id=domain_id,
domain_update=domain_update
)
return VendorDomainResponse(
id=domain.id,
vendor_id=domain.vendor_id,
domain=domain.domain,
is_primary=domain.is_primary,
is_active=domain.is_active,
is_verified=domain.is_verified,
ssl_status=domain.ssl_status,
verification_token=None, # Don't expose token after updates
verified_at=domain.verified_at,
ssl_verified_at=domain.ssl_verified_at,
created_at=domain.created_at,
updated_at=domain.updated_at,
)
@router.delete("/domains/{domain_id}", response_model=DomainDeletionResponse)
def delete_vendor_domain(
domain_id: int = Path(..., description="Domain ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_user),
):
"""
Delete a custom domain (Admin only).
**Warning:** This is permanent and cannot be undone.
**Raises:**
- 404: Domain not found
"""
# Get domain details before deletion
domain = vendor_domain_service.get_domain_by_id(db, domain_id)
vendor_id = domain.vendor_id
domain_name = domain.domain
# Delete domain
message = vendor_domain_service.delete_domain(db, domain_id)
return DomainDeletionResponse(
message=message,
domain=domain_name,
vendor_id=vendor_id
)
@router.post("/domains/{domain_id}/verify", response_model=DomainVerificationResponse)
def verify_domain_ownership(
domain_id: int = Path(..., description="Domain ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_user),
):
"""
Verify domain ownership via DNS TXT record (Admin only).
**Verification Process:**
1. Queries DNS for TXT record: `_letzshop-verify.{domain}`
2. Checks if verification token matches
3. If found, marks domain as verified
**Requirements:**
- Vendor must have added TXT record to their DNS
- DNS propagation may take 5-15 minutes
- Record format: `_letzshop-verify.domain.com` TXT `{token}`
**After verification:**
- Domain can be activated
- Domain will be available for routing
**Raises:**
- 404: Domain not found
- 400: Already verified, or verification failed
- 502: DNS query failed
"""
domain, message = vendor_domain_service.verify_domain(db, domain_id)
return DomainVerificationResponse(
message=message,
domain=domain.domain,
verified_at=domain.verified_at,
is_verified=domain.is_verified
)
@router.get("/domains/{domain_id}/verification-instructions", response_model=DomainVerificationInstructions)
def get_domain_verification_instructions(
domain_id: int = Path(..., description="Domain ID", gt=0),
db: Session = Depends(get_db),
current_admin: User = Depends(get_current_admin_user),
):
"""
Get DNS verification instructions for domain (Admin only).
Returns step-by-step instructions for:
1. Where to add DNS records
2. What TXT record to create
3. Links to common registrars
4. Verification token
**Use this endpoint to:**
- Show vendors how to verify their domain
- Get the exact TXT record values
- Access registrar links
**Raises:**
- 404: Domain not found
"""
instructions = vendor_domain_service.get_verification_instructions(db, domain_id)
return DomainVerificationInstructions(
domain=instructions["domain"],
verification_token=instructions["verification_token"],
instructions=instructions["instructions"],
txt_record=instructions["txt_record"],
common_registrars=instructions["common_registrars"]
)

View File

@@ -61,6 +61,21 @@ class Settings(BaseSettings):
log_level: str = "INFO"
log_file: Optional[str] = None
# Platform domain configuration
platform_domain: str = "platform.com" # Your main platform domain
# Custom domain features
allow_custom_domains: bool = True # Enable/disable custom domains
require_domain_verification: bool = True # Require DNS verification
# SSL/TLS configuration for custom domains
ssl_provider: str = "letsencrypt" # or "cloudflare", "manual"
auto_provision_ssl: bool = False # Set to True if using automated SSL
# DNS verification
dns_verification_prefix: str = "_letzshop-verify"
dns_verification_ttl: int = 3600
model_config = {"env_file": ".env"} # Updated syntax for Pydantic v2

View File

@@ -6,6 +6,7 @@ This module provides frontend-friendly exceptions with consistent error codes,
messages, and HTTP status mappings.
"""
# Base exceptions
from .base import (
LetzShopException,
ValidationException,
@@ -19,6 +20,7 @@ from .base import (
ServiceUnavailableException,
)
# Authentication exceptions
from .auth import (
InvalidCredentialsException,
TokenExpiredException,
@@ -29,6 +31,34 @@ from .auth import (
UserAlreadyExistsException
)
# Admin exceptions
from .admin import (
UserNotFoundException,
UserStatusChangeException,
VendorVerificationException,
AdminOperationException,
CannotModifyAdminException,
CannotModifySelfException,
InvalidAdminActionException,
BulkOperationException,
)
# Marketplace import jon exceptions
from .marketplace_import_job import (
MarketplaceImportException,
ImportJobNotFoundException,
ImportJobNotOwnedException,
InvalidImportDataException,
ImportJobCannotBeCancelledException,
ImportJobCannotBeDeletedException,
MarketplaceConnectionException,
MarketplaceDataParsingException,
ImportRateLimitException,
InvalidMarketplaceException,
ImportJobAlreadyProcessingException,
)
# Marketplace product exceptions
from .marketplace_product import (
MarketplaceProductNotFoundException,
MarketplaceProductAlreadyExistsException,
@@ -38,6 +68,7 @@ from .marketplace_product import (
MarketplaceProductCSVImportException,
)
# Inventory exceptions
from .inventory import (
InventoryNotFoundException,
InsufficientInventoryException,
@@ -48,6 +79,7 @@ from .inventory import (
LocationNotFoundException
)
# Vendor exceptions
from .vendor import (
VendorNotFoundException,
VendorAlreadyExistsException,
@@ -59,6 +91,22 @@ from .vendor import (
VendorValidationException,
)
# Vendor domain exceptions
from .vendor_domain import (
VendorDomainNotFoundException,
VendorDomainAlreadyExistsException,
InvalidDomainFormatException,
ReservedDomainException,
DomainNotVerifiedException,
DomainVerificationFailedException,
DomainAlreadyVerifiedException,
MultiplePrimaryDomainsException,
DNSVerificationException,
MaxDomainsReachedException,
UnauthorizedDomainAccessException,
)
# Customer exceptions
from .customer import (
CustomerNotFoundException,
CustomerAlreadyExistsException,
@@ -69,6 +117,7 @@ from .customer import (
CustomerAuthorizationException,
)
# Team exceptions
from .team import (
TeamMemberNotFoundException,
TeamMemberAlreadyExistsException,
@@ -86,6 +135,7 @@ from .team import (
InvalidInvitationDataException,
)
# Product exceptions
from .product import (
ProductNotFoundException,
ProductAlreadyExistsException,
@@ -97,6 +147,7 @@ from .product import (
CannotDeleteProductWithOrdersException,
)
# Order exceptions
from .order import (
OrderNotFoundException,
OrderAlreadyExistsException,
@@ -105,31 +156,6 @@ from .order import (
OrderCannotBeCancelledException,
)
from .marketplace_import_job import (
MarketplaceImportException,
ImportJobNotFoundException,
ImportJobNotOwnedException,
InvalidImportDataException,
ImportJobCannotBeCancelledException,
ImportJobCannotBeDeletedException,
MarketplaceConnectionException,
MarketplaceDataParsingException,
ImportRateLimitException,
InvalidMarketplaceException,
ImportJobAlreadyProcessingException,
)
from .admin import (
UserNotFoundException,
UserStatusChangeException,
VendorVerificationException,
AdminOperationException,
CannotModifyAdminException,
CannotModifySelfException,
InvalidAdminActionException,
BulkOperationException,
)
__all__ = [
# Base exceptions
"LetzShopException",
@@ -196,6 +222,19 @@ __all__ = [
"MaxVendorsReachedException",
"VendorValidationException",
# Vendor Domain
"VendorDomainNotFoundException",
"VendorDomainAlreadyExistsException",
"InvalidDomainFormatException",
"ReservedDomainException",
"DomainNotVerifiedException",
"DomainVerificationFailedException",
"DomainAlreadyVerifiedException",
"MultiplePrimaryDomainsException",
"DNSVerificationException",
"MaxDomainsReachedException",
"UnauthorizedDomainAccessException",
# Product exceptions
"ProductNotFoundException",
"ProductAlreadyExistsException",

View File

@@ -0,0 +1,168 @@
# app/exceptions/vendor_domain.py
"""
Vendor domain management specific exceptions.
"""
from typing import Any, Dict, Optional
from .base import (
ResourceNotFoundException,
ConflictException,
ValidationException,
BusinessLogicException,
ExternalServiceException
)
class VendorDomainNotFoundException(ResourceNotFoundException):
"""Raised when a vendor domain is not found."""
def __init__(self, domain_identifier: str, identifier_type: str = "ID"):
if identifier_type.lower() == "domain":
message = f"Domain '{domain_identifier}' not found"
else:
message = f"Domain with ID '{domain_identifier}' not found"
super().__init__(
resource_type="VendorDomain",
identifier=domain_identifier,
message=message,
error_code="VENDOR_DOMAIN_NOT_FOUND",
)
class VendorDomainAlreadyExistsException(ConflictException):
"""Raised when trying to add a domain that already exists."""
def __init__(self, domain: str, existing_vendor_id: Optional[int] = None):
details = {"domain": domain}
if existing_vendor_id:
details["existing_vendor_id"] = existing_vendor_id
super().__init__(
message=f"Domain '{domain}' is already registered",
error_code="VENDOR_DOMAIN_ALREADY_EXISTS",
details=details,
)
class InvalidDomainFormatException(ValidationException):
"""Raised when domain format is invalid."""
def __init__(self, domain: str, reason: str = "Invalid domain format"):
super().__init__(
message=f"{reason}: {domain}",
field="domain",
details={"domain": domain, "reason": reason},
)
self.error_code = "INVALID_DOMAIN_FORMAT"
class ReservedDomainException(ValidationException):
"""Raised when trying to use a reserved domain."""
def __init__(self, domain: str, reserved_part: str):
super().__init__(
message=f"Domain cannot use reserved subdomain: {reserved_part}",
field="domain",
details={
"domain": domain,
"reserved_part": reserved_part
},
)
self.error_code = "RESERVED_DOMAIN"
class DomainNotVerifiedException(BusinessLogicException):
"""Raised when trying to activate an unverified domain."""
def __init__(self, domain_id: int, domain: str):
super().__init__(
message=f"Domain '{domain}' must be verified before activation",
error_code="DOMAIN_NOT_VERIFIED",
details={
"domain_id": domain_id,
"domain": domain
},
)
class DomainVerificationFailedException(BusinessLogicException):
"""Raised when domain verification fails."""
def __init__(self, domain: str, reason: str):
super().__init__(
message=f"Domain verification failed for '{domain}': {reason}",
error_code="DOMAIN_VERIFICATION_FAILED",
details={
"domain": domain,
"reason": reason
},
)
class DomainAlreadyVerifiedException(BusinessLogicException):
"""Raised when trying to verify an already verified domain."""
def __init__(self, domain_id: int, domain: str):
super().__init__(
message=f"Domain '{domain}' is already verified",
error_code="DOMAIN_ALREADY_VERIFIED",
details={
"domain_id": domain_id,
"domain": domain
},
)
class MultiplePrimaryDomainsException(BusinessLogicException):
"""Raised when trying to set multiple primary domains."""
def __init__(self, vendor_id: int):
super().__init__(
message=f"Vendor can only have one primary domain",
error_code="MULTIPLE_PRIMARY_DOMAINS",
details={"vendor_id": vendor_id},
)
class DNSVerificationException(ExternalServiceException):
"""Raised when DNS verification service fails."""
def __init__(self, domain: str, reason: str):
super().__init__(
service_name="DNS",
message=f"DNS verification failed for '{domain}': {reason}",
error_code="DNS_VERIFICATION_ERROR",
details={
"domain": domain,
"reason": reason
},
)
class MaxDomainsReachedException(BusinessLogicException):
"""Raised when vendor tries to add more domains than allowed."""
def __init__(self, vendor_id: int, max_domains: int):
super().__init__(
message=f"Maximum number of domains reached ({max_domains})",
error_code="MAX_DOMAINS_REACHED",
details={
"vendor_id": vendor_id,
"max_domains": max_domains
},
)
class UnauthorizedDomainAccessException(BusinessLogicException):
"""Raised when trying to access domain that doesn't belong to vendor."""
def __init__(self, domain_id: int, vendor_id: int):
super().__init__(
message=f"Unauthorized access to domain {domain_id}",
error_code="UNAUTHORIZED_DOMAIN_ACCESS",
details={
"domain_id": domain_id,
"vendor_id": vendor_id
},
)

View File

@@ -0,0 +1,458 @@
# app/services/vendor_domain_service.py
"""
Vendor domain service for managing custom domain operations.
This module provides classes and functions for:
- Adding and removing custom domains
- Domain verification via DNS
- Domain activation and deactivation
- Setting primary domains
- Domain validation and normalization
"""
import logging
import secrets
from typing import List, Tuple, Optional
from datetime import datetime, timezone
from sqlalchemy.orm import Session
from sqlalchemy import and_
from app.exceptions import (
VendorNotFoundException,
VendorDomainNotFoundException,
VendorDomainAlreadyExistsException,
InvalidDomainFormatException,
ReservedDomainException,
DomainNotVerifiedException,
DomainVerificationFailedException,
DomainAlreadyVerifiedException,
MultiplePrimaryDomainsException,
DNSVerificationException,
MaxDomainsReachedException,
UnauthorizedDomainAccessException,
ValidationException,
)
from models.schema.vendor_domain import VendorDomainCreate, VendorDomainUpdate
from models.database.vendor import Vendor
from models.database.vendor_domain import VendorDomain
logger = logging.getLogger(__name__)
class VendorDomainService:
"""Service class for vendor domain operations."""
def __init__(self):
self.max_domains_per_vendor = 10 # Configure as needed
self.reserved_subdomains = ['www', 'admin', 'api', 'mail', 'smtp', 'ftp', 'cpanel', 'webmail']
def add_domain(
self,
db: Session,
vendor_id: int,
domain_data: VendorDomainCreate
) -> VendorDomain:
"""
Add a custom domain to vendor.
Args:
db: Database session
vendor_id: Vendor ID to add domain to
domain_data: Domain creation data
Returns:
Created VendorDomain object
Raises:
VendorNotFoundException: If vendor not found
VendorDomainAlreadyExistsException: If domain already registered
MaxDomainsReachedException: If vendor has reached max domains
InvalidDomainFormatException: If domain format is invalid
"""
try:
# Verify vendor exists
vendor = self._get_vendor_by_id_or_raise(db, vendor_id)
# Check domain limit
self._check_domain_limit(db, vendor_id)
# Normalize domain
normalized_domain = VendorDomain.normalize_domain(domain_data.domain)
# Validate domain format
self._validate_domain_format(normalized_domain)
# Check if domain already exists
if self._domain_exists(db, normalized_domain):
existing_domain = db.query(VendorDomain).filter(
VendorDomain.domain == normalized_domain
).first()
raise VendorDomainAlreadyExistsException(
normalized_domain,
existing_domain.vendor_id if existing_domain else None
)
# If setting as primary, unset other primary domains
if domain_data.is_primary:
self._unset_primary_domains(db, vendor_id)
# Create domain record
new_domain = VendorDomain(
vendor_id=vendor_id,
domain=normalized_domain,
is_primary=domain_data.is_primary,
verification_token=secrets.token_urlsafe(32),
is_verified=False, # Requires DNS verification
is_active=False, # Cannot be active until verified
ssl_status="pending"
)
db.add(new_domain)
db.commit()
db.refresh(new_domain)
logger.info(f"Domain {normalized_domain} added to vendor {vendor_id}")
return new_domain
except (
VendorNotFoundException,
VendorDomainAlreadyExistsException,
MaxDomainsReachedException,
InvalidDomainFormatException,
ReservedDomainException
):
db.rollback()
raise
except Exception as e:
db.rollback()
logger.error(f"Error adding domain: {str(e)}")
raise ValidationException("Failed to add domain")
def get_vendor_domains(
self,
db: Session,
vendor_id: int
) -> List[VendorDomain]:
"""
Get all domains for a vendor.
Args:
db: Database session
vendor_id: Vendor ID
Returns:
List of VendorDomain objects
Raises:
VendorNotFoundException: If vendor not found
"""
try:
# Verify vendor exists
self._get_vendor_by_id_or_raise(db, vendor_id)
domains = db.query(VendorDomain).filter(
VendorDomain.vendor_id == vendor_id
).order_by(
VendorDomain.is_primary.desc(),
VendorDomain.created_at.desc()
).all()
return domains
except VendorNotFoundException:
raise
except Exception as e:
logger.error(f"Error getting vendor domains: {str(e)}")
raise ValidationException("Failed to retrieve domains")
def get_domain_by_id(
self,
db: Session,
domain_id: int
) -> VendorDomain:
"""
Get domain by ID.
Args:
db: Database session
domain_id: Domain ID
Returns:
VendorDomain object
Raises:
VendorDomainNotFoundException: If domain not found
"""
domain = db.query(VendorDomain).filter(VendorDomain.id == domain_id).first()
if not domain:
raise VendorDomainNotFoundException(str(domain_id))
return domain
def update_domain(
self,
db: Session,
domain_id: int,
domain_update: VendorDomainUpdate
) -> VendorDomain:
"""
Update domain settings.
Args:
db: Database session
domain_id: Domain ID
domain_update: Update data
Returns:
Updated VendorDomain object
Raises:
VendorDomainNotFoundException: If domain not found
DomainNotVerifiedException: If trying to activate unverified domain
"""
try:
domain = self.get_domain_by_id(db, domain_id)
# If setting as primary, unset other primary domains
if domain_update.is_primary:
self._unset_primary_domains(db, domain.vendor_id, exclude_domain_id=domain_id)
domain.is_primary = True
# If activating, check verification
if domain_update.is_active is True and not domain.is_verified:
raise DomainNotVerifiedException(domain_id, domain.domain)
# Update fields
if domain_update.is_active is not None:
domain.is_active = domain_update.is_active
db.commit()
db.refresh(domain)
logger.info(f"Domain {domain.domain} updated")
return domain
except (VendorDomainNotFoundException, DomainNotVerifiedException):
db.rollback()
raise
except Exception as e:
db.rollback()
logger.error(f"Error updating domain: {str(e)}")
raise ValidationException("Failed to update domain")
def delete_domain(
self,
db: Session,
domain_id: int
) -> str:
"""
Delete a custom domain.
Args:
db: Database session
domain_id: Domain ID
Returns:
Success message
Raises:
VendorDomainNotFoundException: If domain not found
"""
try:
domain = self.get_domain_by_id(db, domain_id)
domain_name = domain.domain
vendor_id = domain.vendor_id
db.delete(domain)
db.commit()
logger.info(f"Domain {domain_name} deleted from vendor {vendor_id}")
return f"Domain {domain_name} deleted successfully"
except VendorDomainNotFoundException:
db.rollback()
raise
except Exception as e:
db.rollback()
logger.error(f"Error deleting domain: {str(e)}")
raise ValidationException("Failed to delete domain")
def verify_domain(
self,
db: Session,
domain_id: int
) -> Tuple[VendorDomain, str]:
"""
Verify domain ownership via DNS TXT record.
The vendor must add a TXT record:
Name: _letzshop-verify.{domain}
Value: {verification_token}
Args:
db: Database session
domain_id: Domain ID
Returns:
Tuple of (verified_domain, message)
Raises:
VendorDomainNotFoundException: If domain not found
DomainAlreadyVerifiedException: If already verified
DomainVerificationFailedException: If verification fails
"""
try:
import dns.resolver
domain = self.get_domain_by_id(db, domain_id)
# Check if already verified
if domain.is_verified:
raise DomainAlreadyVerifiedException(domain_id, domain.domain)
# Query DNS TXT records
try:
txt_records = dns.resolver.resolve(
f"_letzshop-verify.{domain.domain}",
'TXT'
)
# Check if verification token is present
for txt in txt_records:
txt_value = txt.to_text().strip('"')
if txt_value == domain.verification_token:
# Verification successful
domain.is_verified = True
domain.verified_at = datetime.now(timezone.utc)
db.commit()
db.refresh(domain)
logger.info(f"Domain {domain.domain} verified successfully")
return domain, f"Domain {domain.domain} verified successfully"
# Token not found
raise DomainVerificationFailedException(
domain.domain,
"Verification token not found in DNS records"
)
except dns.resolver.NXDOMAIN:
raise DomainVerificationFailedException(
domain.domain,
f"DNS record _letzshop-verify.{domain.domain} not found"
)
except dns.resolver.NoAnswer:
raise DomainVerificationFailedException(
domain.domain,
"No TXT records found for verification"
)
except Exception as dns_error:
raise DNSVerificationException(
domain.domain,
str(dns_error)
)
except (
VendorDomainNotFoundException,
DomainAlreadyVerifiedException,
DomainVerificationFailedException,
DNSVerificationException
):
raise
except Exception as e:
logger.error(f"Error verifying domain: {str(e)}")
raise ValidationException("Failed to verify domain")
def get_verification_instructions(
self,
db: Session,
domain_id: int
) -> dict:
"""
Get DNS verification instructions for domain.
Args:
db: Database session
domain_id: Domain ID
Returns:
Dict with verification instructions
Raises:
VendorDomainNotFoundException: If domain not found
"""
domain = self.get_domain_by_id(db, domain_id)
return {
"domain": domain.domain,
"verification_token": domain.verification_token,
"instructions": {
"step1": "Go to your domain's DNS settings (at your domain registrar)",
"step2": "Add a new TXT record with the following values:",
"step3": "Wait for DNS propagation (5-15 minutes)",
"step4": "Click 'Verify Domain' button in admin panel"
},
"txt_record": {
"type": "TXT",
"name": "_letzshop-verify",
"value": domain.verification_token,
"ttl": 3600
},
"common_registrars": {
"Cloudflare": "https://dash.cloudflare.com",
"GoDaddy": "https://dcc.godaddy.com/manage/dns",
"Namecheap": "https://www.namecheap.com/myaccount/domain-list/",
"Google Domains": "https://domains.google.com"
}
}
# Private helper methods
def _get_vendor_by_id_or_raise(self, db: Session, vendor_id: int) -> Vendor:
"""Get vendor by ID or raise exception."""
vendor = db.query(Vendor).filter(Vendor.id == vendor_id).first()
if not vendor:
raise VendorNotFoundException(str(vendor_id), identifier_type="id")
return vendor
def _check_domain_limit(self, db: Session, vendor_id: int) -> None:
"""Check if vendor has reached maximum domain limit."""
domain_count = db.query(VendorDomain).filter(
VendorDomain.vendor_id == vendor_id
).count()
if domain_count >= self.max_domains_per_vendor:
raise MaxDomainsReachedException(vendor_id, self.max_domains_per_vendor)
def _domain_exists(self, db: Session, domain: str) -> bool:
"""Check if domain already exists in system."""
return db.query(VendorDomain).filter(
VendorDomain.domain == domain
).first() is not None
def _validate_domain_format(self, domain: str) -> None:
"""Validate domain format and check for reserved subdomains."""
# Check for reserved subdomains
first_part = domain.split('.')[0]
if first_part in self.reserved_subdomains:
raise ReservedDomainException(domain, first_part)
def _unset_primary_domains(
self,
db: Session,
vendor_id: int,
exclude_domain_id: Optional[int] = None
) -> None:
"""Unset all primary domains for vendor."""
query = db.query(VendorDomain).filter(
VendorDomain.vendor_id == vendor_id,
VendorDomain.is_primary == True
)
if exclude_domain_id:
query = query.filter(VendorDomain.id != exclude_domain_id)
query.update({"is_primary": False})
# Create service instance
vendor_domain_service = VendorDomainService()

File diff suppressed because it is too large Load Diff

View File

@@ -12,22 +12,26 @@
<h2 class="text-2xl font-semibold text-gray-700 dark:text-gray-200">
Icons Browser
</h2>
<a href="/admin/dashboard" class="flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:text-gray-300 dark:bg-gray-800 dark:border-gray-600 dark:hover:bg-gray-700">
<a href="/admin/dashboard"
class="flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:text-gray-300 dark:bg-gray-800 dark:border-gray-600 dark:hover:bg-gray-700">
<span x-html="$icon('arrow-left', 'w-4 h-4 mr-2')"></span>
Back to Dashboard
</a>
</div>
<!-- Introduction -->
<div class="mb-8 p-6 bg-gradient-to-r from-indigo-600 to-purple-600 rounded-lg shadow-lg text-white">
<!-- Introduction Card -->
<div class="bg-gradient-to-r from-purple-600 to-indigo-600 rounded-lg shadow-lg p-6 mb-8">
<div class="flex items-start">
<span x-html="$icon('photograph', 'w-10 h-10 mr-4 flex-shrink-0')"></span>
<div>
<h3 class="text-xl font-bold mb-2">Icon Library</h3>
<p class="text-indigo-100 mb-3">
Browse all <span x-text="allIcons.length"></span> available icons. Click any icon to copy its name or usage code.
<div class="flex-shrink-0 text-gray-700 dark:text-gray-200">
<span x-html="$icon('photograph', 'w-12 h-12')"></span>
</div>
<div class="ml-4">
<h3 class="text-xl font-bold mb-2 text-gray-700 dark:text-gray-200">Icon Library</h3>
<p class="text-gray-700 dark:text-gray-200 opacity-90">
Browse all <span x-text="allIcons.length"></span> available icons. Click any icon to copy its name or
usage code.
</p>
<div class="flex items-center gap-4 text-sm">
<div class="flex items-center gap-4 text-sm text-gray-700 dark:text-gray-200 opacity-90">
<div class="flex items-center">
<span x-html="$icon('check-circle', 'w-4 h-4 mr-1')"></span>
<span>Heroicons</span>
@@ -46,270 +50,279 @@
</div>
<!-- Search and Filter -->
<div class="mb-6 bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
<div class="flex flex-col md:flex-row gap-4">
<!-- Search Box -->
<div class="flex-1">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Search Icons
</label>
<div class="relative">
<div class="mb-6 bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
<div class="flex flex-col md:flex-row gap-4">
<!-- Search Box -->
<div class="flex-1">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Search Icons
</label>
<div class="relative">
<span 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>
</span>
<input
<input
type="text"
x-model="searchQuery"
@input="filterIcons()"
placeholder="Type to search... (e.g., 'user', 'arrow', 'check')"
class="w-full pl-10 pr-4 py-2 text-sm border border-gray-300 rounded-lg focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:bg-gray-700 dark:border-gray-600 dark:text-gray-300"
/>
</div>
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
Found <span x-text="filteredIcons.length"></span> icon(s)
</p>
/>
</div>
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
Found <span x-text="filteredIcons.length"></span> icon(s)
</p>
</div>
<!-- Category Pills -->
<div class="flex-1">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Filter by Category
</label>
<div class="flex flex-wrap gap-2">
<template x-for="category in categories.slice(0, 6)" :key="category.id">
<button
<!-- Category Pills -->
<div class="flex-1">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Filter by Category
</label>
<div class="flex flex-wrap gap-2">
<template x-for="category in categories.slice(0, 6)" :key="category.id">
<button
@click="setCategory(category.id)"
class="inline-flex items-center px-3 py-1 text-xs font-medium rounded-full transition-colors"
:class="activeCategory === category.id
? 'bg-purple-600 text-white'
: 'bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600'"
>
<span x-html="$icon(category.icon, 'w-3 h-3 mr-1')"></span>
<span x-text="category.name"></span>
<span class="ml-1 opacity-75" x-text="'(' + getCategoryCount(category.id) + ')'"></span>
</button>
</template>
</div>
>
<span x-html="$icon(category.icon, 'w-3 h-3 mr-1')"></span>
<span x-text="category.name"></span>
<span class="ml-1 opacity-75" x-text="'(' + getCategoryCount(category.id) + ')'"></span>
</button>
</template>
</div>
</div>
</div>
<!-- All Categories (Expandable) -->
<div class="mt-4 pt-4 border-t border-gray-200 dark:border-gray-700">
<details class="group">
<summary class="cursor-pointer text-sm font-medium text-purple-600 dark:text-purple-400 hover:text-purple-700 flex items-center">
<span x-html="$icon('chevron-right', 'w-4 h-4 mr-1 group-open:rotate-90 transition-transform')"></span>
Show All Categories
</summary>
<div class="mt-3 flex flex-wrap gap-2">
<template x-for="category in categories" :key="category.id">
<button
<!-- All Categories (Expandable) -->
<div class="mt-4 pt-4 border-t border-gray-200 dark:border-gray-700">
<details class="group">
<summary
class="cursor-pointer text-sm font-medium text-purple-600 dark:text-purple-400 hover:text-purple-700 flex items-center">
<span x-html="$icon('chevron-right', 'w-4 h-4 mr-1 group-open:rotate-90 transition-transform')"></span>
Show All Categories
</summary>
<div class="mt-3 flex flex-wrap gap-2">
<template x-for="category in categories" :key="category.id">
<button
@click="setCategory(category.id)"
class="inline-flex items-center px-3 py-1.5 text-xs font-medium rounded-lg transition-colors"
:class="activeCategory === category.id
? 'bg-purple-600 text-white'
: 'bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600'"
>
<span x-html="$icon(category.icon, 'w-4 h-4 mr-2')"></span>
<span x-text="category.name"></span>
<span class="ml-2 px-2 py-0.5 bg-black bg-opacity-10 rounded-full" x-text="getCategoryCount(category.id)"></span>
</button>
</template>
</div>
</details>
</div>
>
<span x-html="$icon(category.icon, 'w-4 h-4 mr-2')"></span>
<span x-text="category.name"></span>
<span class="ml-2 px-2 py-0.5 bg-black bg-opacity-10 rounded-full"
x-text="getCategoryCount(category.id)"></span>
</button>
</template>
</div>
</details>
</div>
</div>
<!-- Active Category Info -->
<div x-show="activeCategory !== 'all'" class="mb-4 flex items-center justify-between bg-purple-50 dark:bg-purple-900 dark:bg-opacity-20 border border-purple-200 dark:border-purple-700 rounded-lg px-4 py-3">
<div class="flex items-center">
<span x-html="$icon(getCategoryInfo(activeCategory).icon, 'w-5 h-5 text-purple-600 dark:text-purple-400 mr-2')"></span>
<span class="text-sm font-medium text-purple-900 dark:text-purple-200">
<!-- Active Category Info -->
<div x-show="activeCategory !== 'all'"
class="mb-4 flex items-center justify-between bg-purple-50 dark:bg-purple-900 dark:bg-opacity-20 border border-purple-200 dark:border-purple-700 rounded-lg px-4 py-3">
<div class="flex items-center">
<span x-html="$icon(getCategoryInfo(activeCategory).icon, 'w-5 h-5 text-purple-600 dark:text-purple-400 mr-2')"></span>
<span class="text-sm font-medium text-purple-900 dark:text-purple-200">
Showing <span x-text="getCategoryInfo(activeCategory).name"></span>
(<span x-text="filteredIcons.length"></span> icons)
</span>
</div>
<button
</div>
<button
@click="setCategory('all')"
class="text-sm text-purple-600 dark:text-purple-400 hover:text-purple-700 dark:hover:text-purple-300 flex items-center"
>
<span x-html="$icon('close', 'w-4 h-4 mr-1')"></span>
Clear Filter
</button>
</div>
<!-- Icons Grid -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
<!-- Empty State -->
<div x-show="filteredIcons.length === 0" class="text-center py-12">
<span x-html="$icon('exclamation', 'w-16 h-16 mx-auto text-gray-400 mb-4')"></span>
<h3 class="text-lg font-semibold text-gray-700 dark:text-gray-300 mb-2">No icons found</h3>
<p class="text-gray-500 dark:text-gray-400 mb-4">Try adjusting your search or filter</p>
<button
@click="searchQuery = ''; setCategory('all')"
class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700"
>
<span x-html="$icon('close', 'w-4 h-4 mr-1')"></span>
Clear Filter
Clear Filters
</button>
</div>
<!-- Icons Grid -->
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
<!-- Empty State -->
<div x-show="filteredIcons.length === 0" class="text-center py-12">
<span x-html="$icon('exclamation', 'w-16 h-16 mx-auto text-gray-400 mb-4')"></span>
<h3 class="text-lg font-semibold text-gray-700 dark:text-gray-300 mb-2">No icons found</h3>
<p class="text-gray-500 dark:text-gray-400 mb-4">Try adjusting your search or filter</p>
<button
@click="searchQuery = ''; setCategory('all')"
class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700"
>
Clear Filters
</button>
</div>
<!-- Icons Grid -->
<div x-show="filteredIcons.length > 0" class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8 gap-3">
<template x-for="icon in filteredIcons" :key="icon.name">
<div
<div x-show="filteredIcons.length > 0"
class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8 gap-3">
<template x-for="icon in filteredIcons" :key="icon.name">
<div
@click="selectIcon(icon.name)"
class="group relative flex flex-col items-center justify-center p-4 bg-gray-50 dark:bg-gray-900 rounded-lg hover:bg-purple-50 dark:hover:bg-purple-900 dark:hover:bg-opacity-20 cursor-pointer transition-all hover:shadow-md border-2 border-transparent hover:border-purple-300 dark:hover:border-purple-700"
:class="{ 'border-purple-500 bg-purple-50 dark:bg-purple-900 dark:bg-opacity-30': selectedIcon === icon.name }"
>
<!-- Icon -->
<div class="text-gray-600 dark:text-gray-400 group-hover:text-purple-600 dark:group-hover:text-purple-400 transition-colors">
<span x-html="$icon(icon.name, 'w-8 h-8')"></span>
</div>
<!-- Icon Name -->
<p class="mt-2 text-xs text-center text-gray-600 dark:text-gray-400 font-mono truncate w-full px-1" :title="icon.name" x-text="icon.name"></p>
<!-- Hover Actions -->
<div class="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 bg-opacity-90 dark:bg-opacity-90 rounded-lg">
<div class="flex gap-1">
<button
@click.stop="copyIconName(icon.name)"
class="p-2 bg-purple-600 text-white rounded hover:bg-purple-700 transition-colors"
title="Copy name"
>
<span x-html="$icon('duplicate', 'w-4 h-4')"></span>
</button>
<button
@click.stop="copyIconUsage(icon.name)"
class="p-2 bg-indigo-600 text-white rounded hover:bg-indigo-700 transition-colors"
title="Copy usage"
>
<span x-html="$icon('code', 'w-4 h-4')"></span>
</button>
</div>
</div>
</div>
</template>
</div>
</div>
<!-- Selected Icon Details -->
<div x-show="selectedIcon" class="mt-6 bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
<h3 class="text-lg font-semibold text-gray-800 dark:text-gray-200 mb-4">
Selected Icon: <span class="font-mono text-purple-600 dark:text-purple-400" x-text="selectedIcon"></span>
</h3>
<div class="grid md:grid-cols-2 gap-6">
<!-- Preview -->
<div>
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">Preview</h4>
<div class="bg-gray-50 dark:bg-gray-900 rounded-lg p-8 flex items-center justify-center gap-6">
<div class="text-gray-800 dark:text-gray-200">
<span x-html="$icon(selectedIcon, 'w-12 h-12')"></span>
</div>
<div class="text-gray-800 dark:text-gray-200">
<span x-html="$icon(selectedIcon, 'w-16 h-16')"></span>
</div>
<div class="text-gray-800 dark:text-gray-200">
<span x-html="$icon(selectedIcon, 'w-24 h-24')"></span>
</div>
</div>
</div>
<!-- Usage Code -->
<div>
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">Usage Code</h4>
<!-- Alpine.js Usage -->
<div class="mb-4">
<label class="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">Alpine.js (Recommended)</label>
<div class="relative">
<pre class="bg-gray-900 text-gray-100 rounded-lg p-3 text-xs overflow-x-auto"><code x-text="'x-html=&quot;$icon(\'' + selectedIcon + '\', \'w-5 h-5\')&quot;'"></code></pre>
<button
@click="copyIconUsage(selectedIcon)"
class="absolute top-2 right-2 p-1.5 bg-gray-800 text-gray-300 rounded hover:bg-gray-700 transition-colors"
title="Copy"
>
<span x-html="$icon('duplicate', 'w-4 h-4')"></span>
</button>
</div>
>
<!-- Icon -->
<div class="text-gray-600 dark:text-gray-400 group-hover:text-purple-600 dark:group-hover:text-purple-400 transition-colors">
<span x-html="$icon(icon.name, 'w-8 h-8')"></span>
</div>
<!-- Icon Name -->
<div>
<label class="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">Icon Name</label>
<div class="relative">
<pre class="bg-gray-900 text-gray-100 rounded-lg p-3 text-xs overflow-x-auto"><code x-text="selectedIcon"></code></pre>
<p class="mt-2 text-xs text-center text-gray-600 dark:text-gray-400 font-mono truncate w-full px-1"
:title="icon.name" x-text="icon.name"></p>
<!-- Hover Actions -->
<div class="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 bg-opacity-90 dark:bg-opacity-90 rounded-lg">
<div class="flex gap-1">
<button
@click="copyIconName(selectedIcon)"
class="absolute top-2 right-2 p-1.5 bg-gray-800 text-gray-300 rounded hover:bg-gray-700 transition-colors"
title="Copy"
@click.stop="copyIconName(icon.name)"
class="p-2 bg-purple-600 text-white rounded hover:bg-purple-700 transition-colors"
title="Copy name"
>
<span x-html="$icon('duplicate', 'w-4 h-4')"></span>
</button>
<button
@click.stop="copyIconUsage(icon.name)"
class="p-2 bg-indigo-600 text-white rounded hover:bg-indigo-700 transition-colors"
title="Copy usage"
>
<span x-html="$icon('code', 'w-4 h-4')"></span>
</button>
</div>
</div>
</div>
</template>
</div>
</div>
<!-- Selected Icon Details -->
<div x-show="selectedIcon" class="mt-6 bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
<h3 class="text-lg font-semibold text-gray-800 dark:text-gray-200 mb-4">
Selected Icon: <span class="font-mono text-purple-600 dark:text-purple-400" x-text="selectedIcon"></span>
</h3>
<div class="grid md:grid-cols-2 gap-6">
<!-- Preview -->
<div>
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">Preview</h4>
<div class="bg-gray-50 dark:bg-gray-900 rounded-lg p-8 flex items-center justify-center gap-6">
<div class="text-gray-800 dark:text-gray-200">
<span x-html="$icon(selectedIcon, 'w-12 h-12')"></span>
</div>
<div class="text-gray-800 dark:text-gray-200">
<span x-html="$icon(selectedIcon, 'w-16 h-16')"></span>
</div>
<div class="text-gray-800 dark:text-gray-200">
<span x-html="$icon(selectedIcon, 'w-24 h-24')"></span>
</div>
</div>
</div>
<!-- Size Examples -->
<div class="mt-6">
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">Common Sizes</h4>
<div class="bg-gray-50 dark:bg-gray-900 rounded-lg p-4">
<div class="flex items-center gap-8">
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-4 h-4')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-4 h-4</code>
</div>
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-5 h-5')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-5 h-5</code>
</div>
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-6 h-6')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-6 h-6</code>
</div>
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-8 h-8')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-8 h-8</code>
</div>
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-12 h-12')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-12 h-12</code>
</div>
<!-- Usage Code -->
<div>
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">Usage Code</h4>
<!-- Alpine.js Usage -->
<div class="mb-4">
<label class="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">Alpine.js
(Recommended)</label>
<div class="relative">
<pre class="bg-gray-900 text-gray-100 rounded-lg p-3 text-xs overflow-x-auto"><code
x-text="'x-html=&quot;$icon(\'' + selectedIcon + '\', \'w-5 h-5\')&quot;'"></code></pre>
<button
@click="copyIconUsage(selectedIcon)"
class="absolute top-2 right-2 p-1.5 bg-gray-800 text-gray-300 rounded hover:bg-gray-700 transition-colors"
title="Copy"
>
<span x-html="$icon('duplicate', 'w-4 h-4')"></span>
</button>
</div>
</div>
<!-- Icon Name -->
<div>
<label class="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">Icon Name</label>
<div class="relative">
<pre class="bg-gray-900 text-gray-100 rounded-lg p-3 text-xs overflow-x-auto"><code
x-text="selectedIcon"></code></pre>
<button
@click="copyIconName(selectedIcon)"
class="absolute top-2 right-2 p-1.5 bg-gray-800 text-gray-300 rounded hover:bg-gray-700 transition-colors"
title="Copy"
>
<span x-html="$icon('duplicate', 'w-4 h-4')"></span>
</button>
</div>
</div>
</div>
</div>
<!-- Usage Guide -->
<div class="mt-6 bg-blue-50 dark:bg-gray-800 border border-blue-200 dark:border-gray-700 rounded-lg p-6">
<h3 class="text-lg font-semibold text-gray-800 dark:text-gray-200 mb-3 flex items-center">
<span x-html="$icon('book-open', 'w-5 h-5 mr-2 text-blue-600')"></span>
How to Use Icons
</h3>
<div class="grid md:grid-cols-2 gap-6 text-sm">
<div>
<h4 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">In Alpine.js Templates</h4>
<p class="text-gray-600 dark:text-gray-400 mb-2">Use the <code class="px-1 py-0.5 bg-gray-200 dark:bg-gray-700 rounded">x-html</code> directive:</p>
<pre class="bg-gray-900 text-gray-100 rounded p-2 text-xs overflow-x-auto"><code>&lt;span x-html="$icon('home', 'w-5 h-5')"&gt;&lt;/span&gt;</code></pre>
</div>
<div>
<h4 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Customizing Size & Color</h4>
<p class="text-gray-600 dark:text-gray-400 mb-2">Use Tailwind classes:</p>
<pre class="bg-gray-900 text-gray-100 rounded p-2 text-xs overflow-x-auto"><code>&lt;span x-html="$icon('check', 'w-6 h-6 text-green-500')"&gt;&lt;/span&gt;</code></pre>
<!-- Size Examples -->
<div class="mt-6">
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">Common Sizes</h4>
<div class="bg-gray-50 dark:bg-gray-900 rounded-lg p-4">
<div class="flex items-center gap-8">
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-4 h-4')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-4 h-4</code>
</div>
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-5 h-5')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-5 h-5</code>
</div>
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-6 h-6')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-6 h-6</code>
</div>
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-8 h-8')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-8 h-8</code>
</div>
<div class="text-center">
<div class="text-gray-800 dark:text-gray-200 mb-1">
<span x-html="$icon(selectedIcon, 'w-12 h-12')"></span>
</div>
<code class="text-xs text-gray-600 dark:text-gray-400">w-12 h-12</code>
</div>
</div>
</div>
</div>
</div>
<!-- Usage Guide -->
<div class="mt-6 bg-blue-50 dark:bg-gray-800 border border-blue-200 dark:border-gray-700 rounded-lg p-6">
<h3 class="text-lg font-semibold text-gray-800 dark:text-gray-200 mb-3 flex items-center">
<span x-html="$icon('book-open', 'w-5 h-5 mr-2 text-blue-600')"></span>
How to Use Icons
</h3>
<div class="grid md:grid-cols-2 gap-6 text-sm">
<div>
<h4 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">In Alpine.js Templates</h4>
<p class="text-gray-600 dark:text-gray-400 mb-2">Use the <code
class="px-1 py-0.5 bg-gray-200 dark:bg-gray-700 rounded">x-html</code> directive:</p>
<pre class="bg-gray-900 text-gray-100 rounded p-2 text-xs overflow-x-auto"><code>&lt;span x-html="$icon('home', 'w-5 h-5')"&gt;&lt;/span&gt;</code></pre>
</div>
<div>
<h4 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Customizing Size & Color</h4>
<p class="text-gray-600 dark:text-gray-400 mb-2">Use Tailwind classes:</p>
<pre class="bg-gray-900 text-gray-100 rounded p-2 text-xs overflow-x-auto"><code>&lt;span x-html="$icon('check', 'w-6 h-6 text-green-500')"&gt;&lt;/span&gt;</code></pre>
</div>
</div>
</div>
{% endblock %}
{% block extra_scripts %}

View File

@@ -0,0 +1,11 @@
<DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>System-wide marketplace monitoring</title>
</head>
<body>
<-- System-wide marketplace monitoring -->
</body>
</html>

View File

@@ -0,0 +1,11 @@
<DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>System monitoring</title>
</head>
<body>
<-- System monitoring -->
</body>
</html>

View File

@@ -12,17 +12,22 @@
<h2 class="text-2xl font-semibold text-gray-700 dark:text-gray-200">
Testing Hub
</h2>
<a href="/admin/dashboard"
class="flex items-center px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:text-gray-300 dark:bg-gray-800 dark:border-gray-600 dark:hover:bg-gray-700">
<span x-html="$icon('arrow-left', 'w-4 h-4 mr-2')"></span>
Back to Dashboard
</a>
</div>
<!-- Introduction Card -->
<div class="bg-gradient-to-r from-purple-600 to-indigo-600 rounded-lg shadow-lg p-6 mb-8">
<div class="flex items-start">
<div class="flex-shrink-0 text-white">
<div class="flex-shrink-0 text-gray-700 dark:text-gray-200">
<span x-html="$icon('beaker', 'w-12 h-12')"></span>
</div>
<div class="ml-4">
<h3 class="text-xl font-bold mb-2 text-white">Testing & QA Tools</h3>
<p class="text-white opacity-90">
<h3 class="text-xl font-bold mb-2 text-gray-700 dark:text-gray-200">Testing & QA Tools</h3>
<p class="text-gray-700 dark:text-gray-200 opacity-90">
Comprehensive testing tools for manual QA, feature verification, and bug reproduction.
These pages help you test specific flows without writing code.
</p>
@@ -32,171 +37,192 @@
<!-- Quick Stats -->
<div class="grid gap-6 mb-8 md:grid-cols-2 xl:grid-cols-4">
<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('clipboard-list', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Test Suites</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.totalSuites"></p>
</div>
</div>
<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('clipboard-list', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Test Suites</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.totalSuites"></p>
</div>
</div>
<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('check-circle', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Test Cases</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.totalTests + '+'"></p>
</div>
</div>
<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('check-circle', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Test Cases</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.totalTests + '+'"></p>
</div>
</div>
<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('lightning-bolt', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Features Covered</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.coverage"></p>
</div>
</div>
<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('lightning-bolt', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Features Covered</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.coverage"></p>
</div>
</div>
<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('clock', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Quick Tests</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.avgDuration"></p>
</div>
</div>
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
<div class="p-3 mr-4 text-teal-500 bg-teal-100 rounded-full dark:text-teal-100 dark:bg-teal-500">
<span x-html="$icon('clock', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Quick Tests</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.avgDuration"></p>
</div>
</div>
</div>
<!-- Test Suites Grid -->
<div class="grid gap-6 mb-8 md:grid-cols-2">
<template x-for="suite in testSuites" :key="suite.id">
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden hover:shadow-xl transition-shadow duration-300">
<div class="p-4 bg-gradient-to-r" :class="getColorClasses(suite.color).gradient">
<div class="flex items-center justify-between">
<h3 class="text-xl font-semibold text-white flex items-center">
<span x-html="$icon(suite.icon, 'w-6 h-6 mr-2 text-white')"></span>
<span x-text="suite.name"></span>
</h3>
<span class="inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-red-600 bg-red-100 rounded-full dark:text-red-100 dark:bg-red-600">
<span x-text="suite.testCount"></span> Tests
</span>
</div>
</div>
<!-- Test Suites Grid -->
<div class="grid gap-6 mb-8 md:grid-cols-2">
<template x-for="suite in testSuites" :key="suite.id">
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden hover:shadow-xl transition-shadow duration-300">
<div class="p-4 bg-gradient-to-r" :class="getColorClasses(suite.color).gradient">
<div class="flex items-center justify-between">
<h3 class="text-xl font-semibold text-white flex items-center">
<span x-html="$icon(suite.icon, 'w-6 h-6 mr-2 text-white')"></span>
<span x-text="suite.name"></span>
</h3>
<span class="px-3 py-1 bg-white bg-opacity-25 rounded-full text-xs text-white font-semibold">
<span x-text="suite.testCount"></span> Tests
</span>
</div>
</div>
<div class="p-6">
<p class="text-gray-600 dark:text-gray-400 mb-4" x-text="suite.description"></p>
<div class="p-6">
<p class="text-gray-600 dark:text-gray-400 mb-4" x-text="suite.description"></p>
<div class="space-y-2 mb-6">
<template x-for="feature in suite.features" :key="feature">
<div class="flex items-start text-sm">
<span x-html="$icon('check-circle', 'w-4 h-4 text-green-500 mr-2 mt-0.5 flex-shrink-0')"></span>
<span class="text-gray-600 dark:text-gray-400" x-text="feature"></span>
</div>
</template>
</div>
<div class="flex gap-2">
<button
@click="goToTest(suite.url)"
class="flex-1 flex items-center justify-center px-4 py-2 text-sm font-medium text-white rounded-lg transition-colors"
:class="getColorClasses(suite.color).button">
<span x-html="$icon('play', 'w-4 h-4 mr-2 text-white')"></span>
Run Tests
</button>
<button class="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors">
<span x-html="$icon('information-circle', 'w-5 h-5')"></span>
</button>
</div>
</div>
<div class="space-y-2 mb-6">
<template x-for="feature in suite.features" :key="feature">
<div class="flex items-start text-sm">
<span x-html="$icon('check-circle', 'w-4 h-4 text-green-500 mr-2 mt-0.5 flex-shrink-0')"></span>
<span class="text-gray-600 dark:text-gray-400" x-text="feature"></span>
</div>
</template>
</div>
<!-- Best Practices -->
<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
<h2 class="mb-4 text-xl font-semibold text-gray-800 dark:text-gray-200 flex items-center">
<span x-html="$icon('light-bulb', 'w-6 h-6 mr-2 text-yellow-500')"></span>
Testing Best Practices
</h2>
<div class="grid md:grid-cols-2 gap-6">
<div>
<h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Before Testing</h3>
<ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Ensure FastAPI server is running on localhost:8000</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Open browser DevTools (F12) to see console logs</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Check Network tab for API requests</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Clear localStorage before starting fresh tests</span>
</li>
</ul>
</div>
<div>
<h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">During Testing</h3>
<ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Follow test steps in order</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Check expected results against actual behavior</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Look for errors in console and network tabs</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Take screenshots if you find bugs</span>
</li>
</ul>
</div>
</div>
<div class="flex gap-2">
<button
@click="goToTest(suite.url)"
class="flex-1 flex items-center justify-center px-4 py-2 text-sm font-medium text-white rounded-lg transition-colors"
:class="getColorClasses(suite.color).button">
<span x-html="$icon('play', 'w-4 h-4 mr-2 text-white')"></span>
Run Tests
</button>
<button class="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors">
<span x-html="$icon('information-circle', 'w-5 h-5')"></span>
</button>
</div>
<!-- Additional Resources -->
<div class="bg-blue-50 dark:bg-gray-800 border border-blue-200 dark:border-gray-700 rounded-lg p-6 mb-8">
<h3 class="mb-3 text-lg font-semibold text-gray-800 dark:text-gray-200 flex items-center">
<span x-html="$icon('book-open', 'w-5 h-5 mr-2 text-blue-600')"></span>
Additional Resources
</h3>
<div class="grid md:grid-cols-3 gap-4">
<a href="/admin/components" class="block p-4 bg-white dark:bg-gray-700 rounded-lg hover:shadow-md transition-shadow">
<h4 class="font-semibold text-gray-700 dark:text-gray-200 mb-1">Component Library</h4>
<p class="text-sm text-gray-600 dark:text-gray-400">View all available UI components</p>
</a>
<a href="/admin/icons" class="block p-4 bg-white dark:bg-gray-700 rounded-lg hover:shadow-md transition-shadow">
<h4 class="font-semibold text-gray-700 dark:text-gray-200 mb-1">Icons Browser</h4>
<p class="text-sm text-gray-600 dark:text-gray-400">Browse all available icons</p>
</a>
<a href="#" class="block p-4 bg-white dark:bg-gray-700 rounded-lg hover:shadow-md transition-shadow">
<h4 class="font-semibold text-gray-700 dark:text-gray-200 mb-1">API Documentation</h4>
<p class="text-sm text-gray-600 dark:text-gray-400">FastAPI endpoint reference</p>
</a>
</div>
</div>
</div>
</div>
</template>
</div>
<!-- Best Practices -->
<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
<h2 class="mb-4 text-xl font-semibold text-gray-800 dark:text-gray-200 flex items-center">
<span x-html="$icon('light-bulb', 'w-6 h-6 mr-2 text-yellow-500')"></span>
Testing Best Practices
</h2>
<div class="grid md:grid-cols-2 gap-6">
<div>
<h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Before Testing</h3>
<ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Ensure FastAPI server is running on localhost:8000</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Open browser DevTools (F12) to see console logs</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Check Network tab for API requests</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Clear localStorage before starting fresh tests</span>
</li>
</ul>
</div>
<div>
<h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">During Testing</h3>
<ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Follow test steps in order</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Check expected results against actual behavior</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Look for errors in console and network tabs</span>
</li>
<li class="flex items-start">
<span class="text-purple-600 mr-2"></span>
<span>Take screenshots if you find bugs</span>
</li>
</ul>
</div>
</div>
</div>
<!-- Additional Resources -->
<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
<h2 class="mb-4 text-xl font-semibold text-gray-800 dark:text-gray-200 flex items-center">
<span x-html="$icon('book-open', 'w-5 h-5 mr-2 text-blue-600')"></span>
Additional Resources
</h2>
<div class="grid md:grid-cols-3 gap-4">
<div>
<h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Component Library</h3>
<ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
<li class="flex items-start">
<a href="/admin/components">
<span class="text-purple-600 mr-2"></span>
<span>View all available UI components</span>
</a>
</li>
</ul>
</div>
<div>
<h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Icons Browser</h3>
<ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
<li class="flex items-start">
<a href="/admin/icons">
<span class="text-purple-600 mr-2"></span>
<span>Browse all available icons</span>
</a>
</li>
</ul>
</div>
<div>
<h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">API Documentation</h3>
<ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
<li class="flex items-start">
<a href="/docs">
<span class="text-purple-600 mr-2"></span>
<span>FastAPI endpoint reference</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_scripts %}

View File

@@ -13,7 +13,7 @@
Vendor Details
</h2>
<p class="text-sm text-gray-600 dark:text-gray-400 mt-1" x-show="vendor">
<span x-text="vendor?.vendor_code"></span>
<span x-text="vendorCode"></span>
<span class="text-gray-400 mx-2"></span>
<span x-text="vendor?.subdomain"></span>
</p>
@@ -25,6 +25,10 @@
<span x-html="$icon('edit', 'w-4 h-4 mr-2')"></span>
Edit Vendor
</a>
<a :href="`/admin/vendors/${vendorCode}/theme`"
class="px-4 py-2 text-sm font-medium text-purple-700 bg-white border border-purple-600 rounded-lg hover:bg-purple-50">
Customize Theme
</a>
<a href="/admin/vendors"
class="flex items-center px-4 py-2 text-sm font-medium leading-5 text-gray-700 transition-colors duration-150 bg-white border border-gray-300 rounded-lg dark:text-gray-400 dark:border-gray-600 dark:bg-gray-800 hover:border-gray-400 focus:outline-none">
<span x-html="$icon('arrow-left', 'w-4 h-4 mr-2')"></span>

View File

@@ -0,0 +1,297 @@
{# app/templates/admin/vendor-theme.html #}
{% extends "admin/base.html" %}
{% block title %}Vendor Theme - {{ vendor_code }}{% endblock %}
{% block alpine_data %}vendorThemeData(){% endblock %}
{% block content %}
<div class="container px-6 mx-auto grid">
<!-- Page Header -->
<div class="flex items-center justify-between my-6">
<div>
<h2 class="text-2xl font-semibold text-gray-700 dark:text-gray-200">
Vendor Theme
</h2>
<p class="text-sm text-gray-600 dark:text-gray-400 mt-1">
Customize appearance for <span x-text="vendor?.name"></span>
</p>
</div>
<div class="flex space-x-2">
<a :href="`/admin/vendors/${vendorCode}`"
class="flex items-center px-4 py-2 text-sm font-medium leading-5 text-gray-700 transition-colors duration-150 bg-white border border-gray-300 rounded-lg hover:border-gray-400 dark:text-gray-400 dark:border-gray-600 dark:bg-gray-800">
<span x-html="$icon('arrow-left', 'w-4 h-4 mr-2')"></span>
Back to Vendor
</a>
</div>
</div>
<!-- Loading State -->
<div x-show="loading" class="text-center py-12">
<span x-html="$icon('spinner', 'inline w-8 h-8 text-purple-600 animate-spin')"></span>
<p class="mt-2 text-gray-600 dark:text-gray-400">Loading theme...</p>
</div>
<!-- Main Content -->
<div x-show="!loading" class="grid gap-6 mb-8 md:grid-cols-3">
<!-- Theme Configuration Form (2 columns) -->
<div class="md:col-span-2">
<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
<h3 class="mb-4 text-lg font-semibold text-gray-700 dark:text-gray-200">
Theme Configuration
</h3>
<!-- Theme Preset Selector -->
<div class="mb-6 p-4 bg-purple-50 dark:bg-purple-900 dark:bg-opacity-20 rounded-lg border border-purple-200 dark:border-purple-800">
<h4 class="text-sm font-semibold text-purple-800 dark:text-purple-200 mb-2">
Quick Start: Choose a Preset
</h4>
<div class="grid grid-cols-2 md:grid-cols-4 gap-2">
<button @click="applyPreset('modern')"
class="px-3 py-2 text-sm font-medium text-purple-700 bg-white border border-purple-300 rounded-lg hover:bg-purple-50 dark:bg-gray-800 dark:text-purple-300 dark:border-purple-700">
Modern
</button>
<button @click="applyPreset('classic')"
class="px-3 py-2 text-sm font-medium text-blue-700 bg-white border border-blue-300 rounded-lg hover:bg-blue-50 dark:bg-gray-800 dark:text-blue-300 dark:border-blue-700">
Classic
</button>
<button @click="applyPreset('minimal')"
class="px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:bg-gray-800 dark:text-gray-300 dark:border-gray-700">
Minimal
</button>
<button @click="applyPreset('vibrant')"
class="px-3 py-2 text-sm font-medium text-orange-700 bg-white border border-orange-300 rounded-lg hover:bg-orange-50 dark:bg-gray-800 dark:text-orange-300 dark:border-orange-700">
Vibrant
</button>
</div>
</div>
<!-- Colors Section -->
<div class="mb-6">
<h4 class="mb-4 text-md font-semibold text-gray-700 dark:text-gray-200">Colors</h4>
<div class="grid gap-4 md:grid-cols-2">
<!-- Primary Color -->
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">Primary Color</span>
<div class="flex items-center mt-1 space-x-2">
<input type="color"
x-model="themeData.colors.primary"
class="h-10 w-20 border border-gray-300 rounded dark:border-gray-600 cursor-pointer">
<input type="text"
x-model="themeData.colors.primary"
class="block w-full text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple form-input">
</div>
</label>
<!-- Secondary Color -->
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">Secondary Color</span>
<div class="flex items-center mt-1 space-x-2">
<input type="color"
x-model="themeData.colors.secondary"
class="h-10 w-20 border border-gray-300 rounded dark:border-gray-600 cursor-pointer">
<input type="text"
x-model="themeData.colors.secondary"
class="block w-full text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple form-input">
</div>
</label>
<!-- Accent Color -->
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">Accent Color</span>
<div class="flex items-center mt-1 space-x-2">
<input type="color"
x-model="themeData.colors.accent"
class="h-10 w-20 border border-gray-300 rounded dark:border-gray-600 cursor-pointer">
<input type="text"
x-model="themeData.colors.accent"
class="block w-full text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple form-input">
</div>
</label>
</div>
</div>
<!-- Typography Section -->
<div class="mb-6">
<h4 class="mb-4 text-md font-semibold text-gray-700 dark:text-gray-200">Typography</h4>
<div class="grid gap-4 md:grid-cols-2">
<!-- Heading Font -->
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">Heading Font</span>
<select x-model="themeData.fonts.heading"
class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple form-select">
<option value="Inter, sans-serif">Inter</option>
<option value="Roboto, sans-serif">Roboto</option>
<option value="Poppins, sans-serif">Poppins</option>
<option value="Playfair Display, serif">Playfair Display</option>
<option value="Merriweather, serif">Merriweather</option>
<option value="Georgia, serif">Georgia</option>
</select>
</label>
<!-- Body Font -->
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">Body Font</span>
<select x-model="themeData.fonts.body"
class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple form-select">
<option value="Inter, sans-serif">Inter</option>
<option value="Open Sans, sans-serif">Open Sans</option>
<option value="Lato, sans-serif">Lato</option>
<option value="Source Sans Pro, sans-serif">Source Sans Pro</option>
<option value="Arial, sans-serif">Arial</option>
</select>
</label>
</div>
</div>
<!-- Layout Section -->
<div class="mb-6">
<h4 class="mb-4 text-md font-semibold text-gray-700 dark:text-gray-200">Layout</h4>
<div class="grid gap-4 md:grid-cols-2">
<!-- Product Layout Style -->
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">Product Layout</span>
<select x-model="themeData.layout.style"
class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple form-select">
<option value="grid">Grid</option>
<option value="list">List</option>
<option value="masonry">Masonry</option>
</select>
</label>
<!-- Header Style -->
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">Header Style</span>
<select x-model="themeData.layout.header"
class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple form-select">
<option value="fixed">Fixed</option>
<option value="static">Static</option>
<option value="transparent">Transparent</option>
</select>
</label>
</div>
</div>
<!-- Custom CSS Section -->
<div class="mb-6">
<h4 class="mb-4 text-md font-semibold text-gray-700 dark:text-gray-200">Advanced</h4>
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">Custom CSS</span>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-2">
Advanced: Add custom CSS rules (use with caution)
</p>
<textarea x-model="themeData.custom_css"
rows="6"
placeholder=".my-custom-class { color: red; }"
class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple form-textarea"></textarea>
</label>
</div>
<!-- Action Buttons -->
<div class="flex justify-between items-center">
<button @click="resetToDefault()"
:disabled="saving"
class="px-4 py-2 text-sm font-medium leading-5 text-red-700 transition-colors duration-150 bg-white border border-red-300 rounded-lg hover:bg-red-50 focus:outline-none disabled:opacity-50 dark:bg-gray-800 dark:text-red-400 dark:border-red-600">
Reset to Default
</button>
<button @click="saveTheme()"
:disabled="saving"
class="flex items-center px-4 py-2 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-lg hover:bg-purple-700 focus:outline-none disabled:opacity-50">
<span x-show="!saving">Save Theme</span>
<span x-show="saving" class="flex items-center">
<span x-html="$icon('spinner', 'w-4 h-4 mr-2 animate-spin')"></span>
Saving...
</span>
</button>
</div>
</div>
</div>
<!-- Preview Panel (1 column) -->
<div class="md:col-span-1">
<div class="px-4 py-3 bg-white rounded-lg shadow-md dark:bg-gray-800 sticky top-6">
<h3 class="mb-4 text-lg font-semibold text-gray-700 dark:text-gray-200">
Preview
</h3>
<!-- Theme Preview -->
<div class="space-y-4">
<!-- Colors Preview -->
<div>
<p class="text-xs font-semibold text-gray-600 dark:text-gray-400 mb-2">COLORS</p>
<div class="grid grid-cols-3 gap-2">
<div class="text-center">
<div class="h-12 rounded-lg border border-gray-200 dark:border-gray-700"
:style="`background-color: ${themeData.colors.primary}`"></div>
<p class="text-xs text-gray-600 dark:text-gray-400 mt-1">Primary</p>
</div>
<div class="text-center">
<div class="h-12 rounded-lg border border-gray-200 dark:border-gray-700"
:style="`background-color: ${themeData.colors.secondary}`"></div>
<p class="text-xs text-gray-600 dark:text-gray-400 mt-1">Secondary</p>
</div>
<div class="text-center">
<div class="h-12 rounded-lg border border-gray-200 dark:border-gray-700"
:style="`background-color: ${themeData.colors.accent}`"></div>
<p class="text-xs text-gray-600 dark:text-gray-400 mt-1">Accent</p>
</div>
</div>
</div>
<!-- Typography Preview -->
<div>
<p class="text-xs font-semibold text-gray-600 dark:text-gray-400 mb-2">TYPOGRAPHY</p>
<div class="space-y-2">
<p class="text-lg" :style="`font-family: ${themeData.fonts.heading}`">
Heading Font
</p>
<p class="text-sm" :style="`font-family: ${themeData.fonts.body}`">
Body text font example
</p>
</div>
</div>
<!-- Button Preview -->
<div>
<p class="text-xs font-semibold text-gray-600 dark:text-gray-400 mb-2">BUTTONS</p>
<button class="px-4 py-2 text-sm font-medium text-white rounded-lg w-full"
:style="`background-color: ${themeData.colors.primary}`">
Primary Button
</button>
</div>
<!-- Layout Preview -->
<div>
<p class="text-xs font-semibold text-gray-600 dark:text-gray-400 mb-2">LAYOUT</p>
<div class="text-xs space-y-1">
<p class="text-gray-700 dark:text-gray-300">
<span class="font-semibold">Product Layout:</span>
<span class="capitalize" x-text="themeData.layout.style"></span>
</p>
<p class="text-gray-700 dark:text-gray-300">
<span class="font-semibold">Header:</span>
<span class="capitalize" x-text="themeData.layout.header"></span>
</p>
</div>
</div>
<!-- Preview Link -->
<div class="pt-4 border-t border-gray-200 dark:border-gray-700">
<a :href="`http://${vendor?.subdomain}.localhost:8000`"
target="_blank"
class="flex items-center justify-center px-4 py-2 text-sm font-medium text-purple-700 bg-purple-50 border border-purple-300 rounded-lg hover:bg-purple-100 dark:bg-purple-900 dark:bg-opacity-20 dark:text-purple-300 dark:border-purple-700">
<span x-html="$icon('eye', 'w-4 h-4 mr-2')"></span>
View Live Shop
</a>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_scripts %}
<script src="{{ url_for('static', path='admin/js/vendor-theme.js') }}"></script>
{% endblock %}