diff --git a/components/pdp/ProductReviewsSection.tsx b/components/pdp/ProductReviewsSection.tsx index 62dd5f1..9869fbc 100644 --- a/components/pdp/ProductReviewsSection.tsx +++ b/components/pdp/ProductReviewsSection.tsx @@ -188,3 +188,4 @@ export function ProductReviewsSection({ ); } + diff --git a/components/pdp/ReviewCard.tsx b/components/pdp/ReviewCard.tsx index ccf0da5..4ab1beb 100644 --- a/components/pdp/ReviewCard.tsx +++ b/components/pdp/ReviewCard.tsx @@ -121,3 +121,4 @@ export function ReviewCard({ review }: { review: ProductReviewItem }) { ); } + diff --git a/components/pdp/ReviewSubmissionModal.tsx b/components/pdp/ReviewSubmissionModal.tsx index e0241aa..c4893fc 100644 --- a/components/pdp/ReviewSubmissionModal.tsx +++ b/components/pdp/ReviewSubmissionModal.tsx @@ -4,6 +4,7 @@ import React, { useState, useEffect } from 'react'; import { Star, X, Upload, CheckCircle2, AlertCircle, Loader2 } from 'lucide-react'; import { useAuthStore } from '@/store/authStore'; import { reviewService, ProductReviewItem } from '@/services/api/reviewService'; +import GoogleAuthModal from '@/components/auth/GoogleAuthModal'; interface ReviewSubmissionModalProps { productId: string; @@ -21,6 +22,29 @@ const RATING_DESCRIPTIONS: Record = { 5: 'Excellent - Highly recommended!', }; +function GoogleIcon({ className = 'w-4 h-4' }: { className?: string }) { + return ( + + + + + + + ); +} + export function ReviewSubmissionModal({ productId, productName, @@ -29,6 +53,7 @@ export function ReviewSubmissionModal({ onReviewSubmitted, }: ReviewSubmissionModalProps) { const customer = useAuthStore((s) => s.customer); + const bootstrapAuth = useAuthStore((s) => s.bootstrapAuth); const [rating, setRating] = useState(5); const [hoverRating, setHoverRating] = useState(null); @@ -41,14 +66,34 @@ export function ReviewSubmissionModal({ const [isSubmitting, setIsSubmitting] = useState(false); const [errorMsg, setErrorMsg] = useState(null); const [isSuccess, setIsSuccess] = useState(false); + const [showGoogleAuthModal, setShowGoogleAuthModal] = useState(false); + const [isGoogleAutofilled, setIsGoogleAutofilled] = useState(false); + // Restore session when modal opens + useEffect(() => { + if (isOpen) { + void bootstrapAuth(); + } + }, [isOpen, bootstrapAuth]); + + // Autofill name & email from logged in customer useEffect(() => { if (customer) { - const fullName = [customer.first_name, customer.last_name].filter(Boolean).join(' '); - if (fullName) setAuthorName(fullName); - if (customer.email) setAuthorEmail(customer.email); + const resolvedName = + (customer as any).name || + (customer as any).full_name || + [customer.first_name, customer.last_name].filter(Boolean).join(' ') || + customer.first_name || + ''; + if (resolvedName) { + setAuthorName((prev) => (prev ? prev : resolvedName)); + } + if (customer.email) { + setAuthorEmail((prev) => (prev ? prev : customer.email)); + } + setIsGoogleAutofilled(true); } - }, [customer]); + }, [customer, isOpen]); if (!isOpen) return null; @@ -226,12 +271,57 @@ export function ReviewSubmissionModal({ /> + {/* Google Autofill Banner / Action */} + {customer?.email ? ( +
+
+
+ +
+ + Auto-filled from Google: {customer.email} + +
+ + + Verified Sync + +
+ ) : ( +
+
+
+ +
+
+

Auto-fill with Google

+

1-click fetch name & verified buyer check

+
+
+ +
+ )} + {/* Name and Email */}
- +
+ + {isGoogleAutofilled && authorName && ( + + Auto-filled + + )} +
- +
+ + {isGoogleAutofilled && authorEmail && ( + + Verified + + )} +
)}
+ + {/* Google Auth Modal for 1-Click Auto-fill */} + setShowGoogleAuthModal(false)} + onSuccess={(data) => { + const resolvedName = + [data.first_name, data.last_name].filter(Boolean).join(' ') || + data.first_name || + data.name || + data.email?.split('@')[0] || + ''; + if (resolvedName) setAuthorName(resolvedName); + if (data.email) setAuthorEmail(data.email); + setIsGoogleAutofilled(true); + setShowGoogleAuthModal(false); + }} + />
); } + diff --git a/components/pdp/ReviewSummaryBreakdown.tsx b/components/pdp/ReviewSummaryBreakdown.tsx index 7df978f..49832d2 100644 --- a/components/pdp/ReviewSummaryBreakdown.tsx +++ b/components/pdp/ReviewSummaryBreakdown.tsx @@ -102,3 +102,4 @@ export function ReviewSummaryBreakdown({ ); } + diff --git a/services/api/client.ts b/services/api/client.ts index 64dcda8..b6f5fa3 100644 --- a/services/api/client.ts +++ b/services/api/client.ts @@ -155,6 +155,7 @@ export interface RestoredSession { customer_id: string; email: string; first_name: string; + last_name?: string; } /** @@ -177,6 +178,7 @@ export async function restoreCustomerSession(): Promise customer_id: data.customer_id, email: data.email, first_name: data.first_name, + last_name: data.last_name, }; } catch { return null; diff --git a/services/api/reviewService.ts b/services/api/reviewService.ts index 8044c01..1f3e4d8 100644 --- a/services/api/reviewService.ts +++ b/services/api/reviewService.ts @@ -100,3 +100,4 @@ export const reviewService = { return data.file_url || data.url || ''; }, }; + diff --git a/store/authStore.ts b/store/authStore.ts index 4227dab..c0e18e4 100644 --- a/store/authStore.ts +++ b/store/authStore.ts @@ -111,6 +111,7 @@ export const useAuthStore = create((set, get) => ({ customer_id: restored.customer_id, email: restored.email, first_name: restored.first_name, + last_name: restored.last_name, }; set({ accessToken: restored.access_token,