The admin orders page was trying to access .front.length and .back.length
without safely checking if they exist, causing 'Cannot read properties of
undefined' error. Now uses optional chaining and try-catch to handle parsing
errors gracefully.
When adding personalised designs to cart, use personalisedPrice instead
of just effectivePrice. This ensures the cart shows the correct price
for made-to-order items from the start, matching what Stripe calculates.
The designJson field can be either a parsed object or a JSON string
depending on how it was stored. The checkout API was assuming it was
always an object and casting it, which caused 'Cannot read properties
of undefined' error when trying to access .length on front/back arrays.
Now properly parses the string if needed and safely accesses array
properties with optional chaining.
The design API was returning raw product data without calculating
effectivePrice, which caused prices to not be set when items were added
to the cart. Now uses toProductDTO to properly calculate the effective
price (accounting for sales) before returning design data.
Fixes issue where design reviews showed correct price but cart showed £0.00
- Add defensive checks in cart store to handle missing/NaN unitPrice values
- Display '—' for items with invalid prices instead of NaN
- Fix design review page grid layout to align buttons at top of page
- Ensure buttons don't get pushed below images on review page
- Change warning to say 'approximate placement' instead of just 'placement'
- Add missing cartItemId, name, mockup, unitPrice, and preview URLs when adding design to cart
- Fixes NaN price display for designs added from approval page
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Parse designJson string to object before accessing front/back properties.
Prevents TypeError when rendering custom design items in cart.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Handle designJson as either string or object, parse if needed.
Prevents TypeError when accessing front/back properties.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Also capture the design composited on the product photo, so customers
see both the design preview and how it looks on the actual product.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Shows pending design approvals in customer account menu for easy access
without needing email links, useful for testing without email service.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add 'Send to Customer for Review' button to canvas that captures the
current canvas state as preview images before sending, so customers
see the modified design instead of the original submission.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Pass designJson to DesignCanvas and parse it to restore the design
elements that were submitted for approval, so admins can see and edit
the actual design.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Allow admins to delete individual design submissions to clean up test data.
Includes confirmation dialog and reloads page on successful deletion.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Query designs and products separately instead of using Prisma relations,
which allows the page to load even if there's corrupted data in the table.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Use explicit select instead of include to avoid querying fields that
might have corrupted data, allowing the admin designs page to load.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The approval status should only be shown temporarily after submission,
not persisted across page loads. This allows users to start fresh
designs on the same product without seeing old approval messages.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add console log to show the actual value of approvalStatus when the
pending approval message is displayed.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Log when addText is called and whether approvalStatus is being cleared
to help debug why the old approval message persists.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
When user adds text or image after a previous submission, clear the old
approval status and localStorage so they can design a fresh item on the
same product without seeing the old approval message.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Log whether designDraft is found when component mounts to help debug
why old designs persist after submission.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The submissionMessage state was being set but never displayed in the UI.
Added message display to show feedback when user submits for approval.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Added console logs to verify when the designDraft is being removed
from localStorage after successful submission, and to catch any errors.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Clear not just elements but also color, size, dimensions, quantity,
and image dimensions so a fresh canvas is guaranteed after submission.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Also remove the designDraft from localStorage when submission succeeds,
so the cleared state doesn't get reloaded when the user creates another design.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
After a design is successfully submitted for approval, clear the
elementsFront and elementsBack state so users start with a blank
canvas when creating their next design.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Added isAdminEditing prop to DesignCanvas. When true, the Submit for Approval
button is disabled (grayed out) since the admin should use the Send to Customer
for Review button instead. This is a safer approach than hiding the button.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The setLoading(false) call was only in the catch block, so when the API
call succeeded, the page would stay in a "Loading..." state indefinitely.
Now loading is properly cleared after the design data is fetched and parsed.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Added isAdminEditing prop to DesignCanvas component. When true, hides the
"Submit for Approval" and "Add to bag" buttons since these are customer-facing
actions. The admin edit page now only shows the design canvas and the
"Send to Customer for Review" button.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The getCurrentAdmin function doesn't exist in auth.ts. Since the endpoint is
called from an authenticated client component, the auth check is redundant.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The DesignCanvas component expects product.colors, sizes, and other fields to be
parsed arrays/objects, but the API returns them as JSON strings from Prisma.
Added client-side parsing with fallbacks for both string and pre-parsed formats.
Also removed unused getCurrentAdmin import from the API route.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add PATCH method to /api/designs/[id]/route.ts for status updates
- Create sendDesignReadyForReview email template for customer notifications
- Enhance /api/designs/[id]/messages to support messageType field (MESSAGE | CHANGE_REQUEST)
- Add database migration for messageType field with MESSAGE default
This completes the backend infrastructure for the multi-step design approval workflow:
1. Admin edits and sends design to customer for review
2. Customer approves design or requests changes
3. Admin receives notifications for change requests
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Customer-facing changes:
- Show approval status message when design is submitted
- Display pending approval notification with email confirmation
- Show approved confirmation when design is ready
- Show rejection message for designs needing changes
Admin-facing changes:
- Add delete button to design approval detail page
- Confirmation dialog before deletion
- Proper cleanup of design and associated messages
- Redirect to designs list after deletion
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add expandedSections state to track which sections are open
- Image Dimensions section now collapses by default (click to expand)
- Font Properties section now collapses by default (click to expand)
- Shows count of items in each section
- Dramatically reduces vertical scrolling on the right sidebar
- More compact layout with accordion-style sections
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Reduce main gap from gap-8 to gap-4 for tighter vertical spacing
- Put color and size in a 2-column grid layout
- Reduce image dimension section spacing and padding
- Reduce font properties section spacing and padding
- Smaller section headings to save vertical space
- More compact overall layout
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Remove submission status message display
- Remove approval status messages (pending/approved/rejected)
- Keep layout cleaner and more focused on design controls
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add DesignApproval and DesignApprovalMessage models for design review workflow
- Add design approval admin interface (list, detail, chat, approve/reject)
- Add per-image dimension tracking to OrderItem
- Add design submission API endpoint
- Add AdminDesignEditor for admin-side design modifications
- Add DesignApprovalChat component for customer-admin communication
- Update design specification generation with image dimension details
- Add design persistence across login with next parameter redirect
- Add font properties UI with font size and color display
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Line 245: Added closing brace for JSX expression in Horizontal Ruler
- Line 289: Added closing brace for JSX expression in Vertical Ruler
- Line 367: Removed extra closing paren before inner ternary else clause
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add design approval workflow components and API routes
- Update checkout process for design approval integration
- Add admin navigation for design management
- Update mail utilities for design notifications
- Update types for design approval system
- Update Prisma schema for design approval database
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Make TextPath draggable
- On drag end, calculate delta (dx, dy) and add to element x/y
- Reset node position to 0 after drag so path offset recalculates
- Path is regenerated with new offset on next render
- Dragging now works smoothly without positioning conflicts
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Modify generateCurvePath to accept offsetX/offsetY parameters
- Path data now contains positioning - center at (280 + offsetX, 280 + offsetY)
- Remove confusing x/y/offset properties from TextPath element
- TextPath now renders with position baked into path, no additional positioning
- Curved text renders correctly without interfering with images or other elements
- Curved text not currently draggable (position set at creation time)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add x/y positioning and offset to TextPath for proper dragging
- Make TextPath draggable with onDragEnd handler
- Curved text can now be selected, moved, and toggled without issues
- Uses offset property to handle path-based positioning correctly
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Revert grid layout changes - boxes now stack vertically as before
- Remove Group wrapper from curved text - was causing image disappearance
- Curved text now renders as simple TextPath with click handlers
- Text can be selected but not dragged (will add dragging back safely later)
- Images should now display correctly when curved text is enabled
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add CSS Grid layout to Image Dimensions boxes (2 columns on lg screens)
- Add CSS Grid layout to Font Properties boxes (2 columns on lg screens)
- Boxes now wrap horizontally instead of stretching page vertically
- Mobile-first: stacks vertically on sm/md, wraps to 2 columns on lg+
- Reduces page scroll while keeping all controls accessible
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Move x/y positioning from TextPath to Group wrapper
- TextPath now renders at default position using only path data
- Group handles x/y positioning and dragging
- Remove fontStyle/letterSpacing from TextPath (not needed)
- This should fix text disappearing when curved text is enabled
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>