Skip to content

Commit 455de06

Browse files
committed
feat: add dedicated /my-shop/create page for product creation
WHAT CHANGED: - Created new dedicated page at /my-shop/create/page.tsx - Updated 'Create Product' button in /my-shop to route to /my-shop/create - Previously redirected to /shop (public shop page) WHY: - Follow site architecture: everything should have a dedicated page - Separates public shop (/shop) from product management (/my-shop) - Better UX: users stay within my-shop context for product management - Consistent with edit flow (/my-shop/edit/[id]) FEATURES: - Authentication check (redirects to /signin if not authenticated) - Client-side hydration handling (SSR safety) - Uses existing ProductCreationForm component - Redirects back to /my-shop after creation or cancellation - Proper logging for user actions ROUTING: - /shop → public shop (browse/buy) - /my-shop → manage your products - /my-shop/create → create new product - /my-shop/edit/[id] → edit existing product Build status: ✅ Successful
1 parent 90ac9b5 commit 455de06

2 files changed

Lines changed: 82 additions & 1 deletion

File tree

src/app/my-shop/create/page.tsx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
'use client';
2+
3+
import { useRouter } from 'next/navigation';
4+
import { useEffect, useState } from 'react';
5+
import { useAuthStore } from '@/stores/useAuthStore';
6+
import { ProductCreationForm } from '@/components/shop/ProductCreationForm';
7+
import { logger } from '@/services/core/LoggingService';
8+
9+
export default function CreateProductPage() {
10+
const router = useRouter();
11+
const { isAuthenticated, user } = useAuthStore();
12+
const [isClient, setIsClient] = useState(false);
13+
14+
// Client-side hydration check
15+
useEffect(() => {
16+
setIsClient(true);
17+
}, []);
18+
19+
// Redirect if not authenticated (only on client)
20+
if (isClient && (!isAuthenticated || !user)) {
21+
logger.warn('User not authenticated, redirecting to signin', {
22+
service: 'CreateProductPage',
23+
method: 'render',
24+
isAuthenticated,
25+
hasUser: !!user,
26+
});
27+
router.push('/signin');
28+
return (
29+
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-primary-50 to-accent-50">
30+
<div className="text-center">
31+
<h1 className="text-2xl font-bold text-primary-800 mb-4">Redirecting to Sign In...</h1>
32+
<p className="text-gray-600">Please sign in to create products.</p>
33+
</div>
34+
</div>
35+
);
36+
}
37+
38+
// Show loading during SSR
39+
if (!isClient) {
40+
return (
41+
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-primary-50 to-accent-50">
42+
<div className="text-center">
43+
<h1 className="text-2xl font-bold text-primary-800 mb-4">Loading...</h1>
44+
<p className="text-gray-600">Please wait while we load the creation form.</p>
45+
</div>
46+
</div>
47+
);
48+
}
49+
50+
const handleProductCreated = (productId: string) => {
51+
logger.info('Product created successfully, redirecting to my-shop', {
52+
service: 'CreateProductPage',
53+
method: 'handleProductCreated',
54+
productId,
55+
});
56+
57+
// Redirect to my-shop page after successful creation
58+
router.push('/my-shop');
59+
};
60+
61+
const handleCancel = () => {
62+
logger.info('Product creation cancelled, redirecting to my-shop', {
63+
service: 'CreateProductPage',
64+
method: 'handleCancel',
65+
});
66+
67+
// Go back to my-shop page
68+
router.push('/my-shop');
69+
};
70+
71+
return (
72+
<div className="min-h-screen bg-gradient-to-br from-primary-50 to-accent-50 py-8">
73+
<div className="container-width">
74+
<ProductCreationForm
75+
onProductCreated={handleProductCreated}
76+
onCancel={handleCancel}
77+
/>
78+
</div>
79+
</div>
80+
);
81+
}

src/app/my-shop/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export default function MyShopPage() {
120120
</div>
121121
<div className="mt-4 lg:mt-0">
122122
<button
123-
onClick={() => router.push('/shop')}
123+
onClick={() => router.push('/my-shop/create')}
124124
className="btn-primary-sm"
125125
>
126126
Create Product

0 commit comments

Comments
 (0)