Commit Graph
211 Commits
Author SHA1 Message Date
Andymick f92ed2709c Add: Weight field to product admin pages
Added weight (in kilograms) field to both create and edit product pages.
Admins can now set the weight for each product, which is converted to
grams and stored in the database for Royal Mail shipping calculations.
2026-07-19 06:50:23 +01:00
Andymick e150f2aed9 Feature: Royal Mail shipping integration with weight-based postage
Added:
- Weight field (weightGrams) to Product model for storing item weights
- Shipping fields to Order model (shippingCost, shippingCountry, shippingService)
- Royal Mail shipping service (royalmail-shipping.ts) with:
  * Domestic and international postage calculations
  * Integration ready for Royal Mail API (currently uses estimated rates)
  * Support for multiple shipping services
  * Clear international delivery time warnings
- Shipping quotes API endpoint (/api/checkout/shipping-quotes)
- Checkout integration to calculate and include shipping cost

Weight is stored in grams, displayed to users in kilograms.
Shipping cost is calculated based on total cart weight and destination country.
2026-07-19 06:46:35 +01:00
Andymick 9b9745e6e2 Add: Prominent 'Shop plain items' section to homepage
Added a standout section that highlights customers can buy plain items
without personalization. Features:
- Eye-catching orange gradient background
- Clear messaging about skipping the design step
- Direct link to plain items collection
- Positioned between path choice and gallery sections
2026-07-19 06:38:14 +01:00
Andymick df6aeb1dfe Fix: Add custom photo as editable design element instead of background
When a custom photo is provided (from photo request), automatically add it
as an editable image element on the design canvas instead of replacing
the product background. This allows the admin to:
- Move and position the photo on the product
- Resize and rotate the photo
- Add text and other design elements on top
- Edit it just like any other design element
2026-07-18 21:13:23 +01:00
Andymick 77c0fc6d0d Remove debug logging - custom photo feature working correctly 2026-07-18 21:12:17 +01:00
Andymick ec6a76925d Debug: Add logging to verify custom photo fetch 2026-07-18 21:10:47 +01:00
Andymick d1b82e9fe9 Debug: Add logging for custom photo prop 2026-07-18 21:10:34 +01:00
Andymick 66a900cb44 Refactor: Move start design server action to separate file
Extracted the server action logic from the component into a dedicated
actions.ts file for better code organization.
2026-07-18 21:09:49 +01:00
Andymick a12c269a3d Feature: Add product selection when starting design from photo request
Added intermediate page (/admin/custom-requests/[id]/start-design) that
lets the admin choose which product to design the photo on. Shows the
photo request details and all available products with the originally
requested product pre-selected.
2026-07-18 21:07:56 +01:00
Andymick 0d9aef5003 Fix: Pass photo request ID instead of data URL
Changed approach to pass customRequestId query parameter instead of
the full data URL. The design canvas page now fetches the photo from
the database using the request ID, avoiding URL length issues and
making the URL cleaner.
2026-07-18 21:05:36 +01:00
Andymick 8e7d242c58 Fix: Route photo requests to design canvas instead of approval upload
When admin clicks 'Start a design for this' on a photo request, now routes
to the design canvas at /made-to-order/{productSlug} with the custom photo
passed as a query parameter. The DesignCanvas component now accepts and
displays the custom photo as the background for designing.

Changes:
- Updated photo request link to go to design canvas page
- Added customPhoto query parameter to pass custom image URL
- Updated DesignCanvas to accept and use customPhoto prop
- Modified renderPhoto() to display custom photo when provided
- Updated getPhotoInfo() to use custom photo for compositing
2026-07-18 20:58:44 +01:00
Andymick 3029efcb9a Fix: Import revalidatePath from correct module
Import revalidatePath from 'next/cache' instead of 'next/navigation'.
This fixes the 'revalidatePath is not a function' error when updating
order tracking information.
2026-07-18 20:47:14 +01:00
Andymick 4ec39d8618 Fix: Remove function prop from client component
Remove onSuccess callback from SyncRoyalMailButton since event handlers
cannot be passed to client components from server components. The button
already shows success/error messages, so the callback wasn't necessary.
2026-07-18 20:41:16 +01:00
Andymick 466f11a866 Fix: Refresh page after updating order tracking details
Add revalidatePath() call to updateOrderTracking server action so the
admin order page refreshes after updating tracking info. This ensures
the displayed data matches the database immediately.
2026-07-18 20:39:57 +01:00
Andymick c476f92a66 Feature: Royal Mail tracking integration (hybrid approach)
Add ability to sync shipment tracking data from Royal Mail API:

- Create Royal Mail API service (src/lib/royalmail.ts) to fetch tracking status
- Add sync-tracking endpoint to pull latest status from Royal Mail
- Create SyncRoyalMailButton component for admin panel
- Add 'Sync from Royal Mail' button on order detail page
- Auto-update order status based on Royal Mail tracking status

Admin workflow:
1. Create shipping label in Royal Mail Click & Drop
2. Copy tracking number into tracking form
3. Click 'Sync from Royal Mail' to fetch and update status
4. System maps Royal Mail status to our order status (SHIPPED, DELIVERED, etc)

Uses Royal Mail's public tracking API - no special credentials required.
Supports manual label creation workflow (hybrid approach).
2026-07-18 20:36:40 +01:00
Andymick 440a735b8a Feature: Add order tracking and shipping status updates
- Add carrier, trackingNumber, and estimatedDeliveryDate fields to Order model
- Update order statuses: PENDING, PAID, PRINTING, PRINTED, SHIPPED, DELIVERED, FAILED
- Add admin UI on order detail page to update tracking information
- Display tracking info on customer account page in order history
- Server action to update order tracking and status

Customers can now see their shipping status and tracking details from
their account page. Admins can update order status and tracking info
from the order detail page.
2026-07-18 20:34:19 +01:00
Andymick f4a80d2a50 Improve: Cart clearing on success page with better state management
Use useCart.getState() to ensure we're clearing the current store state
and delete IndexedDB before clearing store. Add detailed logging to help
debug cart clearing issues. Ensures cart is completely emptied on checkout
success.
2026-07-18 20:29:51 +01:00
Andymick 05c68263f8 Fix: Update order status to PAID on checkout success page
When user reaches the success page after payment, update the order status
from PENDING to PAID. This ensures the admin panel shows the correct
status immediately after payment confirmation.
2026-07-18 20:24:35 +01:00
Andymick 43da81bd66 Fix: Ensure cart is completely cleared after payment success
ClearCartOnMount now explicitly deletes the IndexedDB storage in addition
to clearing the in-memory state. This prevents the cart from being
restored from IndexedDB on subsequent page loads after payment completes.

Fixes issue where cart items remained in bag after successful checkout.
2026-07-18 20:23:45 +01:00
Andymick 06cfe52a95 Fix: Handle undefined designElements in design spec SVG rendering
The SVG element markers were trying to map over designElements without
checking if it was defined first. Now safely checks for array existence
before calling .map() to prevent errors when generating spec sheets.
2026-07-18 20:20:21 +01:00
Andymick 9dc62210b1 Improve: Design specification sheet now shows previews and info
- Always show design sections if preview images exist, even without elements
- Add design preview images to the spec sheet
- Add better error handling for designJson parsing
- Show more useful information even when elements table is empty
- Makes spec sheet more useful for reference and planning
2026-07-18 20:09:24 +01:00
Andymick 7a7e1964bf Fix: Safely parse designJson in admin order detail page
The order detail page was trying to access design.front.length and
design.back.length without safely checking if they exist. Now wraps
the parse in try-catch and uses optional chaining to handle errors
gracefully.
2026-07-18 20:04:07 +01:00
Andymick 404f17acb2 Fix: Show personalised price on design review page
Design review pages are always for personalised products, so display
the personalised price instead of the base effective price. This ensures
the preview page shows the same price that will be charged at checkout.
2026-07-18 20:02:48 +01:00
Andymick 121d469d06 Fix: Safely access designJson properties in admin orders page
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.
2026-07-18 19:59:52 +01:00
Andymick 6b2072b0a7 Fix: Use personalised price in design approval cart add
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.
2026-07-18 19:59:25 +01:00
Andymick fae1ce04c2 Fix: Handle designJson as string in checkout API
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.
2026-07-18 19:54:53 +01:00
Andymick 60cb73f8a4 Fix: Calculate effectivePrice in design API endpoints
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
2026-07-18 19:51:07 +01:00
Andymick 62ae2755f0 Fix price display issues and layout in design review page
- 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
2026-07-18 19:46:11 +01:00
AndymickandClaude Haiku 4.5 1b5a9f8d28 Update warning text and fix missing price in cart
- 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>
2026-07-18 19:36:01 +01:00
AndymickandClaude Haiku 4.5 904b0f5838 Fix all designJson access in cart page
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>
2026-07-18 19:32:02 +01:00
AndymickandClaude Haiku 4.5 f72e934943 Fix cart page error when reading designJson
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>
2026-07-18 19:29:45 +01:00
AndymickandClaude Haiku 4.5 548046d4bf Capture placement preview when sending design to customer
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>
2026-07-18 19:26:34 +01:00
AndymickandClaude Haiku 4.5 07b43ac53d Fix undefined params reference in send button
Use designId prop instead of undefined params variable.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 19:24:23 +01:00
AndymickandClaude Haiku 4.5 6f07c38145 Add design reviews section to customer account page
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>
2026-07-18 19:22:20 +01:00
AndymickandClaude Haiku 4.5 87b269e57c Capture canvas preview when admin sends design to customer
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>
2026-07-18 19:19:38 +01:00
AndymickandClaude Haiku 4.5 b97d015cd1 Load design elements for admin editing
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>
2026-07-18 19:15:53 +01:00
AndymickandClaude Haiku 4.5 c0797bc45c Fix field name in DELETE endpoint - use designId not designApprovalId
The DesignApprovalMessage model uses designId as the foreign key,
not designApprovalId.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 19:13:57 +01:00
AndymickandClaude Haiku 4.5 c982c983e5 Add delete button to design approvals page
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>
2026-07-18 19:13:03 +01:00
AndymickandClaude Haiku 4.5 0d2e874f14 Fetch designs without relations to avoid database corruption issues
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>
2026-07-18 19:11:19 +01:00
AndymickandClaude Haiku 4.5 ca11baf1ae Fix Prisma query by excluding problematic designImageDimensions field
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>
2026-07-18 19:10:19 +01:00
AndymickandClaude Haiku 4.5 ae09d22004 Don't persist approval status to localStorage
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>
2026-07-18 19:06:09 +01:00
AndymickandClaude Haiku 4.5 75518e3e5e Log approvalStatus value when rendering pending message
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>
2026-07-18 19:00:56 +01:00
AndymickandClaude Haiku 4.5 c9a7cab349 Add logging to debug approval status clearing
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>
2026-07-18 18:58:05 +01:00
AndymickandClaude Haiku 4.5 63ae432793 Clear old approval status when user starts designing new item
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>
2026-07-18 18:56:41 +01:00
AndymickandClaude Haiku 4.5 f64462c5fe Add logging to check if designDraft exists in localStorage
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>
2026-07-18 18:54:29 +01:00
AndymickandClaude Haiku 4.5 3a2bc24d69 Fix undefined customerName variable in design submission
Changed customerName to customer.name to use the actual customer object.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-18 18:52:44 +01:00
AndymickandClaude Haiku 4.5 8cba443f5a Display submission success/error message after design submission
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>
2026-07-18 18:51:39 +01:00
AndymickandClaude Haiku 4.5 b61ce99157 Add debugging logs for localStorage draft removal
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>
2026-07-18 18:48:06 +01:00
AndymickandClaude Haiku 4.5 746179885f Reset all design state when submission succeeds
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>
2026-07-18 18:46:43 +01:00
AndymickandClaude Haiku 4.5 dae1df444a Clear localStorage draft when design submitted for approval
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>
2026-07-18 18:44:48 +01:00