diff --git a/apps/admin/src/pages/ProductEditPage.tsx b/apps/admin/src/pages/ProductEditPage.tsx index c10d72a..f01f137 100644 --- a/apps/admin/src/pages/ProductEditPage.tsx +++ b/apps/admin/src/pages/ProductEditPage.tsx @@ -33,9 +33,13 @@ export default function ProductEditPage() { const [success, setSuccess] = useState(false) // Form State + const [activeLang, setActiveLang] = useState('th') + const languages = ['th', 'en', 'ja', 'zh', 'vi', 'ko'] + const [categoryId, setCategoryId] = useState(0) - const [description, setDescription] = useState('') - const [details, setDetails] = useState('') + const [name, setName] = useState>({}) + const [description, setDescription] = useState>({}) + const [details, setDetails] = useState>({}) const [variants, setVariants] = useState[]>([]) const [images, setImages] = useState[]>([]) @@ -101,7 +105,7 @@ export default function ProductEditPage() { const fetchData = async () => { try { const [prodRes, catRes, rawRes] = await Promise.all([ - fetch(`${API_BASE}/products/${id}`), + fetch(`${API_BASE}/products/${id}?lang=all`), fetch(`${API_BASE}/categories`), fetch(`${API_BASE}/raw-materials`) ]) @@ -116,8 +120,12 @@ export default function ProductEditPage() { setCategories(catData) setRawMaterials(rawData) setCategoryId(prodData.categoryId) - setDescription(prodData.description || '') - setDetails(prodData.details || '') + + const parseTranslatable = (val: any) => typeof val === 'object' && val !== null ? val : { th: val || '' } + setName(parseTranslatable(prodData.name)) + setDescription(parseTranslatable(prodData.description)) + setDetails(parseTranslatable(prodData.details)) + setVariants(prodData.variants || []) setImages(prodData.images || []) } catch (err: any) { @@ -221,6 +229,7 @@ export default function ProductEditPage() { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ categoryId, + name, description, details, variants: variants.map(v => ({ @@ -324,18 +333,35 @@ export default function ProductEditPage() {
{/* Basic Info */}
-
- -

Basic Information

+
+
+ +

Basic Information

+
+
+ {languages.map(lang => ( + + ))} +
- -
- {product?.scent.name} (ReadOnly) -
-

Scent properties are linked to the global library.

+ + setName({ ...name, [activeLang]: e.target.value })} + placeholder={`e.g. Scented Candle (${activeLang})`} + className="w-full px-4 py-3 bg-night-950 border border-white/10 focus:border-cyan-glow/40 rounded-xl outline-none text-sm text-white transition-all shadow-inner" + /> +

Scent Name: {product?.scent.name}

@@ -352,22 +378,22 @@ export default function ProductEditPage() {
- +