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>
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>
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>
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>
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>
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>
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>
- 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>
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>
- 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>
- 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>
- 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>
- 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>
- 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>
- 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>
- 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.
- 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>
- 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>
- Add CustomerLoginLog model to track customer login attempts
- Record successful and failed customer logins
- Capture email, IP address, and user agent for each attempt
- Create /admin/customer-login-logs page to view activity
- Show login stats (successes, failures, active customers)
- Display browser/device and IP for each login attempt
- Add "Customer login activity" link to admin menu
- Monitor customer access patterns and detect suspicious activity
- Last 30 days active customer count
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add AdminLoginLog model to track all login attempts
- Record successful and failed login attempts
- Capture IP address and user agent for each login
- Create /admin/login-logs page to view activity history
- Show login stats (successes, failures, last 30 days)
- Display browser/device and IP for each login
- Add "Login activity" link to admin menu
- Useful for security auditing and monitoring access
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add new HMRC Report tab to accounts reports
- Show total turnover (web + manual sales)
- Calculate cost of goods sold from purchases
- Display gross profit and profit margin
- Show operating expenses breakdown
- Calculate net profit before tax
- Estimate tax liability (19% corporation tax)
- Include HMRC checklist of what needs to be reported
- Help admin prepare for Self Assessment submission
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Install pdf-parse and tesseract.js for PDF/image processing
- Create /api/admin/parse-invoice endpoint to extract line items from invoices
- Parser extracts quantity and description from invoice text
- Attempts to match extracted items to products in database
- Update PurchaseForm with "Extract items" button
- Pre-fill purchase form with parsed items (user can edit/add more)
- Supports PDF files and image scans (JPG, PNG, etc)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add guest checkout flow: customers can now complete orders without creating an account
- New /checkout page with login or guest options
- Guest form collects: full name, email, phone, address
- Orders track guest info via guestName and guestPhone fields
- Update cart message to reflect guest option
- Add "Admin login" link to customer login page for clear navigation
- Update checkout API to accept and store guest information
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Created getReportData server action to fetch Orders, ManualSales, and
Expenses from database. Split reports page into server component (fetches
data) and client component (renders charts). Reports now display actual
business data instead of mock data - monthly profit, expense breakdown,
and cash flow tables.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>