Commit Graph
62 Commits
Author SHA1 Message Date
Andymick a13be65796 Fix: use personalised pricing for items with design elements at checkout 2026-07-18 10:22:02 +01:00
Andymick 0145f425b1 Add filter to show only personalised orders 2026-07-18 10:13:21 +01:00
Andymick 64b57b8680 Add 'Personalised' badge to orders with custom designs 2026-07-18 10:12:51 +01:00
Andymick 095e8ad459 Add error handling to checkout page database queries 2026-07-18 10:08:08 +01:00
Andymick f6c464372f Disable add to bag button if no personalization added and show prompt message 2026-07-18 10:01:54 +01:00
Andymick 755b7e786d Fix: check both elementsFront and elementsBack for price update 2026-07-18 09:58:40 +01:00
Andymick 0038d792b0 Update 'Add to bag' button price to show personalized price when design elements are added 2026-07-18 09:57:41 +01:00
Andymick a9513e7284 Add 'For personalized design' label to product price 2026-07-18 09:56:11 +01:00
Andymick de06222190 Switch database from SQLite to PostgreSQL 2026-07-18 09:36:53 +01:00
Andymick cee1013a7a Add error handling to customers/mailing list page 2026-07-18 08:54:32 +01:00
Andymick a891acca63 Add error handling to orders page 2026-07-18 08:54:21 +01:00
Andymick 2db94f6bd3 Add error handling to accounts/ledger page 2026-07-18 08:54:04 +01:00
Andymick 3b5d1947dd Add error handling to stock page for Prisma queries 2026-07-18 08:53:05 +01:00
Andymick cf1d40b1c1 Fix color name detection with fuzzy matching, fix checkout syntax errors, add error handling for products page 2026-07-18 08:44:59 +01:00
AndymickandClaude Haiku 4.5 c6850372cb Fix outer try-catch block structure in checkout route
The outer try block (starting at line 32) was missing its closing catch block.
Added catch block to properly close the outer try statement.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 07:32:47 +01:00
AndymickandClaude Haiku 4.5 52950b7f8e Remove duplicate catch block in checkout route
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 07:24:01 +01:00
AndymickandClaude Haiku 4.5 1481b6e466 Redesign product cards with unique, professional styling
- Split layout: image + info with left border accent
- Product names prominently displayed using serif font
- Unique left border that animates on hover
- Better visual hierarchy and spacing
- Smooth animations (scale, color transitions)
- Clear "Explore" CTA with arrow
- Distinctive design that stands out from generic e-commerce sites

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 07:19:36 +01:00
AndymickandClaude Haiku 4.5 f5fbf1f338 Add hydration safety to AccountMenu
- Add mounted state to prevent hydration mismatches
- Only render component after hydration completes
- Close logout dialog when clicking outside
- Prevent logout dialog from showing unexpectedly

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 07:16:23 +01:00
AndymickandClaude Haiku 4.5 0cafa62713 Fix logout cookie name mismatch
The logout API was deleting 'session' but the actual customer session
cookie is named 'customer_session' (from auth.ts SESSION_COOKIE).

This fix ensures the logout properly clears the customer session, so users
are actually logged out when the browser closes.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 07:14:40 +01:00
AndymickandClaude Haiku 4.5 345e4b9656 Fix cart clearing on success page
Use empty dependency array to ensure clear() runs once on mount.
Add logging and also clear isCheckingOut flag.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 07:10:17 +01:00
AndymickandClaude Haiku 4.5 24a20d0caa Fix nested try-catch structure in checkout route
Add missing catch and closing brace for outer try block.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 07:08:46 +01:00
AndymickandClaude Haiku 4.5 b7ad243941 Fix syntax error in checkout route - remove extra closing brace
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 07:06:21 +01:00
AndymickandClaude Haiku 4.5 6ca99fa118 Fix cart clearing when navigating to checkout
The handleCheckout function on the cart page was navigating to /checkout
without setting the isCheckingOut flag, causing LogoutOnUnload to clear the
cart during navigation.

Now sets the flag BEFORE navigating so LogoutOnUnload skips clearing the cart.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 07:05:07 +01:00
AndymickandClaude Haiku 4.5 eff9a72409 Improve debug logging for checkout flow
Add emoji-prefixed logs to make debugging easier:
- 💳 Checkout button clicked
- ✓ Flag set/skipped actions
- 🚪 LogoutOnUnload handler
- 📡 API fetch
- 📦 API response
- 🔗 Stripe redirect
- 🗑️ Cart clearing

This makes it much easier to see the flow in the console.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:59:59 +01:00
AndymickandClaude Haiku 4.5 7434b68a79 Add debug logging for checkout and LogoutOnUnload
Add console logs to track:
- When isCheckingOut flag is set in checkout button
- When LogoutOnUnload handleUnload is called
- Whether isCheckingOut flag is detected
- When redirecting to Stripe URL

This helps diagnose why cart is still being cleared during checkout.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:53:56 +01:00
AndymickandClaude Haiku 4.5 4dfbffc9ce Suppress hydration warnings on body element
Add suppressHydrationWarning to body element in addition to html element
to properly suppress dark theme class mismatch warnings during React hydration.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:39:48 +01:00
AndymickandClaude Haiku 4.5 6c1053e985 Add typeof window checks for sessionStorage access in checkout
Prevents ReferenceError when sessionStorage is accessed during SSR or
server-side rendering contexts. Wraps all sessionStorage calls in
typeof window !== 'undefined' checks.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:38:01 +01:00
AndymickandClaude Haiku 4.5 570be6430c Add isCheckingOut flag to guest checkout flow
Guest checkout handler was missing the sessionStorage flag that prevents
LogoutOnUnload from clearing cart during Stripe redirect. Adds flag before
API call and removes on error.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:28:47 +01:00
AndymickandClaude Haiku 4.5 eda518d1be Fix cart clearing during Stripe checkout redirect
Use sessionStorage flag to prevent LogoutOnUnload from clearing cart and logging
out when navigating to Stripe checkout.

Changes:
- Checkout button sets 'isCheckingOut' flag in sessionStorage before API call
- LogoutOnUnload checks this flag and skips logout if checkout in progress
- Flag is removed if API returns an error
- Flag persists during navigation to Stripe URL

This ensures cart and login persist through Stripe payment flow.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:25:30 +01:00
AndymickandClaude Haiku 4.5 017b68f17b Fix React hydration mismatch errors
Add suppressHydrationWarning to html element to prevent hydration mismatch
caused by theme script setting dark class before React hydration completes.

The hydration errors were preventing checkout and other interactive features
from working properly. This tells React to ignore the mismatch on the html
element since we intentionally modify it before hydration.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:18:02 +01:00
AndymickandClaude Haiku 4.5 3d48e4d545 Add comprehensive logging to debug checkout issues
Added console.log statements to track:
- Client: API response status, data, and errors
- Server: Stripe configuration check, rate limiting, order creation, Stripe session creation

This will help identify exactly where the checkout flow is failing.

Check browser console for client-side errors and server logs for API errors.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:13:15 +01:00
AndymickandClaude Haiku 4.5 c9f5626984 Fix checkout loop by preventing logout during Stripe navigation
Critical fix: Don't clear cart or logout when navigating to Stripe checkout.

The issue was:
1. User clicks 'Continue to payment'
2. API call to /api/checkout succeeds
3. Client redirects to Stripe URL with window.location.href
4. This triggers beforeunload event
5. LogoutOnUnload component logs out and clears cart
6. User is logged out and cart is empty during checkout

Solution:
- Detect when /api/checkout is being called
- Set isCheckingOut flag
- Skip logout/cart-clear in beforeunload if checkout in progress
- User stays logged in and cart persists through Stripe flow

This allows logout on browser close but not during payment navigation.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:11:25 +01:00
AndymickandClaude Haiku 4.5 15e1f92490 Ensure session cookies are properly cleared on logout
Fix session persistence issue by:
- Using cookies().delete() method for both adminSession and session
- Adding explicit Set-Cookie headers with Max-Age=0 to force browser deletion
- This ensures cookies are cleared both via Next.js API and HTTP headers

Previously, sendBeacon logout calls weren't reliably deleting session cookies,
causing users to remain logged in after closing/reopening the browser.

This double approach ensures the cookies are removed from the browser cache.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:09:17 +01:00
AndymickandClaude Haiku 4.5 db1ca73827 Fix checkout loop issue caused by type mismatch in mode state
Critical fix: Update mode state type to include 'logged-in'.

The mode state was initialized with 'logged-in' but the TypeScript type
only allowed 'login' | 'guest' | null, causing the checkout flow to behave
unexpectedly and loop/clear the cart.

Type changed from:
  useState<'login' | 'guest' | null>(...)
To:
  useState<'logged-in' | 'login' | 'guest' | null>(...)

This fixes the checkout issue where customers couldn't complete purchases.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:06:29 +01:00
AndymickandClaude Haiku 4.5 0d575f5231 Move login activity items from Finance menu to Admin menu
- Move 'Admin login activity' from Financial submenu to top-level Admin menu
- Move 'Customer login activity' from Financial submenu to top-level Admin menu
- Keep Financial menu focused on accounting: Accounts, Reports, Bank Reconciliation, Audit Trail
- Login activity now easier to access at main menu level

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 06:04:47 +01:00
AndymickandClaude Haiku 4.5 8646b42438 Add download photo button to custom request detail page
- Create DownloadPhotoButton component for downloading customer photos
- Add download button before 'Start a design for this' button
- Allows admin to save photo locally for editing in design software before approval

Addresses user request: admin should be able to download photo from request
for editing before uploading final design to the approval flow.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 23:00:58 +01:00
AndymickandClaude Haiku 4.5 d134d3a93c Fix dark mode text visibility in all form inputs
Add bg-paper class to global input/textarea/select styling. Previously text-ink
was applied but inputs lacked background color, causing light text on light backgrounds.

Now all form inputs globally have:
- bg-paper for proper dark mode background
- text-ink for readable text in both light and dark modes

Fixes visibility issues on custom-request, contact, and all other form pages.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 22:56:53 +01:00
AndymickandClaude Haiku 4.5 b7379e379b Add login prompt when non-authenticated users add items to cart
- Create LoginPromptModal component for authentication encouragement
- Check customer authentication before adding items to cart
- Show modal for non-logged-in users with options to create account, log in, or continue as guest
- Allow guests to add items (stored in IndexedDB) while prompting to sign up
- Implemented in both StandardProductView (ready-made products) and DesignCanvas (personalized items)
- Add server action checkCustomerAuth() for authentication checks

Addresses user request: prompt guests to create account or log in when adding items to cart.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 22:53:36 +01:00
AndymickandClaude Haiku 4.5 0cc072fda4 Improve cart and dark mode UX
- Clear cart when customer logs out
- Hide cart bag button for non-authenticated users (only show for logged-in customers)
- Fix dark mode text visibility in all form inputs (input/textarea/select elements)

Addresses user request: cart should clear on logout and only be accessible to logged-in customers.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 22:47:43 +01:00
AndymickandClaude Haiku 4.5 c8dc3467f9 Rebuild documentation with comprehensive setup guide
- Rewrote README.md with current feature set (accounting, auth, checkout)
- Lists all major features: design tool, cart, customer accounts, dark mode
- Financial system overview: reports, bank reconciliation, audit trail
- Quick start for local development in 5 steps
- Configuration reference table
- Created SETUP_AND_BUILD.md with complete deployment guide:
  - Local development setup (prerequisites, environment, database)
  - Configuration reference for all .env variables
  - Database management (push, seed, backup, reset)
  - Feature setup (Stripe, email, CAPTCHA)
  - Production build process
  - Deployment options (self-hosted, Vercel, Docker)
  - Post-deployment checklist
  - Troubleshooting common issues
  - Maintenance tasks and security hardening

Helps new developers get running quickly and provides clear deployment path.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 22:34:49 +01:00
AndymickandClaude Haiku 4.5 3aa2b730bc Auto-logout users when page is closed
- Create LogoutOnUnload component that triggers logout on page close
- Uses beforeunload/unload events with navigator.sendBeacon() for reliability
- Create /api/logout endpoint that clears both admin and customer sessions
- Add LogoutOnUnload to root layout so it runs on all pages
- Works for both admin and customer users

Behavior:
- When user closes browser tab/window, logout happens automatically
- Session cookies are cleared via API endpoint
- Improves security by preventing session hijacking from closed windows

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 22:31:40 +01:00
AndymickandClaude Haiku 4.5 a2908e8ae1 Fix checkout page to hide login prompt when user is logged in
- Refactor checkout page into server component (page.tsx) + client component (client.tsx)
- Server component checks getCurrentCustomer() and passes isLoggedIn prop
- When logged in, show direct checkout button instead of login/guest options
- When not logged in, show login/guest choice as before
- Hides the 'Your cart will be saved...' message from logged-in users

Fixes: Login/guest prompt appearing even when user is already authenticated

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 22:26:14 +01:00
AndymickandClaude Haiku 4.5 84454da5c9 Fix login form text contrast in dark mode
- Add explicit text-ink color to username/email/password input fields
- Add explicit bg-paper background class to inputs for proper styling
- Fixes visibility issue where input text was too light to read in dark mode
- Improves contrast and readability for both admin and customer login forms

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 22:13:15 +01:00
AndymickandClaude Haiku 4.5 26ac37b1df Replace hex color codes with friendly color names for customers
- Add colorNames utility with 80+ standard color names
- Map hex codes to human-readable names (Black, Navy, Red, Teal, etc)
- Display color names in product page (with hex tooltip for reference)
- Show selected color name below color swatches
- Update shopping cart to display color names instead of hex codes
- Admin color picker shows both name and hex code for clarity

Improves UX for customers who don't understand hex color codes.
Keeps hex codes for internal data and system tooltips.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 20:08:56 +01:00
AndymickandClaude Haiku 4.5 47bc87692d Consolidate financial pages into Financial submenu
- Grouped accounts, reports, reconciliation, and audit logs under one menu
- All 6 financial tools now accessible from expandable Financial submenu
- Cleaner admin navigation with collapsible sections

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 17:31:05 +01:00
Andymick 560fbb3978 Fix build errors and prepare for deployment
- Fix const reassignment in Phase 2 reports export (use let for mutable vars)
- Fix TypeScript interface to match Prisma reconciliation schema
- Fix array comparison logic in bank CSV parsing
- Temporarily disable pdf-parse due to module compatibility issue (pre-existing)

All phases now build successfully with zero errors.
2026-07-17 16:58:51 +01:00
AndymickandClaude Haiku 4.5 7f88379d3b Phase 3: Bank reconciliation system
Added complete bank statement reconciliation workflow:

Database Schema:
- BankStatement: metadata for uploaded statements
- BankStatementLine: individual transactions from statements
- BankReconciliation: links system transactions to bank lines

Features:
- CSV import with flexible format detection (DD/MM/YYYY, YYYY-MM-DD dates)
- Auto-matching algorithm: exact amount+date = 100% confidence, fuzzy matching up to 7 days
- Manual matching UI for unmatched transactions
- Discrepancy detection (amount mismatches)
- Reconciliation dashboard with summary stats
- Statement history view with status tracking

Pages:
- /admin/accounts/reconciliation: Dashboard and statement list
- /admin/accounts/reconciliation?id=X: Statement detail with matching UI
- /admin/accounts/reconciliation/upload: CSV upload form

Server Actions:
- uploadBankStatement: CSV parsing and auto-matching
- manualMatch: User-initiated transaction linking
- unmatchBankLine: Remove incorrect match
- archiveStatement: Mark statement as complete
- markReconciled: Finalize reconciliation

Utils:
- parseCSV: Flexible bank statement parser
- autoMatchTransactions: Fuzzy matching algorithm
- getReconciliationSummary: Stats calculation

UI Components:
- ReconciliationClient: Interactive matching interface with tabs
- Manual match form: User-friendly transaction linking

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 15:58:23 +01:00
AndymickandClaude Haiku 4.5 2d55203c1c Phase 2 Complete: Comprehensive reporting UI with all features
Added 10 major enhancements:
1. KPI Dashboard with Year-to-Date (YTD) summary cards
2. Income breakdown by source (web vs manual sales)
3. Expense breakdown with pie chart visualization
4. Revenue vs Operating Expenses comparison chart
5. Growth metrics (Month-over-Month % changes)
6. Monthly drill-down modal (click bars/rows for transaction details)
7. UK Tax Year summary (April-April) with HMRC export
8. Sortable tables (click headers to sort by date/amount)
9. Better export options (all/income/expenses/tax-year formats)
10. Quick filters for expense categories

Features:
- 9 report tabs: KPIs, Trends, Monthly Profit, Income, Expenses, Revenue vs Expenses, Cash Flow, Tax Year, HMRC
- Interactive charts with click-to-drill functionality
- SVG visualizations for profit trends and expense distribution
- Real-time calculations for YTD, tax year, growth metrics
- Accountant-friendly exports with proper formatting
- UK tax compliance with April-April year tracking

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 15:41:16 +01:00
AndymickandClaude Haiku 4.5 78487affbd Phase 2: Better reporting UI with charts and exports
- Add CSV export utility for ledger data (generateLedgerCSV)
- Export formatters: pence to pounds, proper CSV escaping
- Date range filtering (from/to inputs) on reports page
- Export CSV button with proper formatting for accountants
- New \"Trends\" tab with visual profit trend chart
- SVG bar chart shows last 12 months of profit
- Charts color-coded: green (profit), red (loss)
- Shows monthly values and best/worst month stats
- Export functionality:
  - Filters by date range
  - Combines all income sources (orders + manual sales)
  - Includes COGS (purchases) and expenses
  - Generates PDF-ready CSV with summary rows
  - Downloads with proper date-stamped filename

CSV exports are formatted for accountants and tax software:
- Includes summary totals
- Proper date formatting (DD/MM/YYYY)
- Escaped descriptions for safe import
- Clear categorization

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 15:26:20 +01:00
AndymickandClaude Haiku 4.5 d56f942a88 Phase 1: Financial audit logging foundation
- Add FinancialAuditLog model to track all financial changes
- Log action (CREATE, UPDATE, DELETE) with before/after values
- Capture who made changes (IP address)
- Record timestamp and reason for change
- Create /admin/financial-audit page to view audit trail
- Add filtering by entity type, action, date range
- Show summary stats (total changes, deletions, etc)
- Integrate with purchases: log create and delete operations
- Red-flag deletions for security awareness
- Add "Financial audit trail" link to admin menu

This provides foundation for Phase 2 (reporting UI) and Phase 3 (bank reconciliation).
All financial changes are now traceable and auditable for compliance.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-17 15:23:05 +01:00