ok
This commit is contained in:
@@ -99,7 +99,7 @@ const LoginRegister = ({postLoginAction, setPostLoginAction}) => {
|
|||||||
postLoginAction(); // resume action (e.g., checkout)
|
postLoginAction(); // resume action (e.g., checkout)
|
||||||
setPostLoginAction(null);
|
setPostLoginAction(null);
|
||||||
}
|
}
|
||||||
window.location.reload()
|
// window.location.reload()
|
||||||
} else {
|
} else {
|
||||||
alert('Token tidak ditemukan pada respons login');
|
alert('Token tidak ditemukan pada respons login');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,49 +33,54 @@ const ProductDetail = ({ subscriptions, product, setPostLoginAction, setShowedMo
|
|||||||
const token = tokenCookie ? tokenCookie.split('=')[1] : '';
|
const token = tokenCookie ? tokenCookie.split('=')[1] : '';
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
setPostLoginAction(() => () => onCheckout());
|
setPostLoginAction(() => () => setShowedModal('product'));
|
||||||
setShowedModal('login');
|
setShowedModal('login');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (product.type == 'product') {
|
if (product.type == 'product') {
|
||||||
|
|
||||||
|
|
||||||
const hasMatchingSubscription = Array.isArray(subscriptions) &&
|
const hasMatchingSubscription = Array.isArray(subscriptions) &&
|
||||||
subscriptions.some(sub =>
|
subscriptions.some(sub =>
|
||||||
sub.product_name?.toLowerCase().includes(product.name.toLowerCase())
|
sub.product_id === product.id || sub.product_parent_id === product.id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Always show children selector first if product has children
|
||||||
// Always show children selector first if product has children
|
if (product.children && product.children.length > 0) {
|
||||||
if (product.children && product.children.length > 0) {
|
|
||||||
setShowChildSelector(true);
|
setShowChildSelector(true);
|
||||||
|
|
||||||
if (hasMatchingSubscription) {
|
if (hasMatchingSubscription) {
|
||||||
const matching = subscriptions.filter(sub =>
|
const matching = subscriptions.filter(sub =>
|
||||||
sub.product_name?.toLowerCase().includes(product.name.toLowerCase())
|
sub.product_id === product.id || sub.product_parent_id === product.id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (matching.length > 0) {
|
||||||
|
// ✅ Select only the first for each product_name
|
||||||
|
const uniqueByName = Array.from(
|
||||||
|
new Map(matching.map(sub => [sub.product_name, sub])).values()
|
||||||
);
|
);
|
||||||
const uniqueByName = Array.from(new Map(matching.map(sub => [sub.product_name, sub])).values());
|
|
||||||
|
|
||||||
if (uniqueByName.length > 0) {
|
|
||||||
setMatchingSubscriptions(uniqueByName);
|
setMatchingSubscriptions(uniqueByName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No children, but has subscription match
|
// No children, but has subscription match
|
||||||
if (hasMatchingSubscription) {
|
if (hasMatchingSubscription) {
|
||||||
const matching = subscriptions.filter(sub =>
|
const matching = subscriptions.filter(sub =>
|
||||||
sub.product_name?.toLowerCase().includes(product.name.toLowerCase())
|
sub.product_id === product.id || sub.product_parent_id === product.id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (matching.length > 0) {
|
||||||
|
const uniqueByName = Array.from(
|
||||||
|
new Map(matching.map(sub => [sub.product_name, sub])).values()
|
||||||
);
|
);
|
||||||
const uniqueByName = Array.from(new Map(matching.map(sub => [sub.product_name, sub])).values());
|
|
||||||
|
|
||||||
if (uniqueByName.length > 0) {
|
|
||||||
setMatchingSubscriptions(uniqueByName);
|
setMatchingSubscriptions(uniqueByName);
|
||||||
setShowSubscriptionSelector(true);
|
setShowSubscriptionSelector(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// No children, no matching subscription
|
// No children, no matching subscription
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ const CoursePage = ({ subscriptions }) => {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ itemsId: productIds, type: 'product' }),
|
body: JSON.stringify({ itemsId: productIds }),
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@@ -73,9 +73,11 @@ const CoursePage = ({ subscriptions }) => {
|
|||||||
|
|
||||||
// Cek fallback image dari parent jika image kosong dan sub_product_of ada
|
// Cek fallback image dari parent jika image kosong dan sub_product_of ada
|
||||||
let image = productData?.image || '';
|
let image = productData?.image || '';
|
||||||
|
let description = productData?.description || '';
|
||||||
if (!image && productData?.sub_product_of) {
|
if (!image && productData?.sub_product_of) {
|
||||||
const parent = data.find(p => p.id === productData.sub_product_of);
|
const parent = data.find(p => p.id === productData.sub_product_of);
|
||||||
image = parent?.image || '';
|
image = parent?.image || '';
|
||||||
|
description = parent?.description || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -83,7 +85,7 @@ const CoursePage = ({ subscriptions }) => {
|
|||||||
name: group.product_name,
|
name: group.product_name,
|
||||||
type: productData?.type || 'product',
|
type: productData?.type || 'product',
|
||||||
image: image,
|
image: image,
|
||||||
description: productData?.description || '',
|
description: description,
|
||||||
price: productData?.price || 0,
|
price: productData?.price || 0,
|
||||||
currency: productData?.currency || 'IDR',
|
currency: productData?.currency || 'IDR',
|
||||||
duration: productData?.duration || {},
|
duration: productData?.duration || {},
|
||||||
|
|||||||
Reference in New Issue
Block a user