ok
This commit is contained in:
@@ -99,7 +99,7 @@ const LoginRegister = ({postLoginAction, setPostLoginAction}) => {
|
||||
postLoginAction(); // resume action (e.g., checkout)
|
||||
setPostLoginAction(null);
|
||||
}
|
||||
window.location.reload()
|
||||
// window.location.reload()
|
||||
} else {
|
||||
alert('Token tidak ditemukan pada respons login');
|
||||
}
|
||||
|
||||
@@ -33,30 +33,31 @@ const ProductDetail = ({ subscriptions, product, setPostLoginAction, setShowedMo
|
||||
const token = tokenCookie ? tokenCookie.split('=')[1] : '';
|
||||
|
||||
if (!token) {
|
||||
setPostLoginAction(() => () => onCheckout());
|
||||
setPostLoginAction(() => () => setShowedModal('product'));
|
||||
setShowedModal('login');
|
||||
return;
|
||||
}
|
||||
if (product.type == 'product') {
|
||||
|
||||
|
||||
const hasMatchingSubscription = Array.isArray(subscriptions) &&
|
||||
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
|
||||
if (product.children && product.children.length > 0) {
|
||||
setShowChildSelector(true);
|
||||
|
||||
if (hasMatchingSubscription) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -66,17 +67,21 @@ const ProductDetail = ({ subscriptions, product, setPostLoginAction, setShowedMo
|
||||
// No children, but has subscription match
|
||||
if (hasMatchingSubscription) {
|
||||
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);
|
||||
setShowSubscriptionSelector(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// No children, no matching subscription
|
||||
const itemsParam = JSON.stringify([product.id]);
|
||||
|
||||
@@ -62,7 +62,7 @@ const CoursePage = ({ subscriptions }) => {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ itemsId: productIds, type: 'product' }),
|
||||
body: JSON.stringify({ itemsId: productIds }),
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
@@ -73,9 +73,11 @@ const CoursePage = ({ subscriptions }) => {
|
||||
|
||||
// Cek fallback image dari parent jika image kosong dan sub_product_of ada
|
||||
let image = productData?.image || '';
|
||||
let description = productData?.description || '';
|
||||
if (!image && productData?.sub_product_of) {
|
||||
const parent = data.find(p => p.id === productData.sub_product_of);
|
||||
image = parent?.image || '';
|
||||
description = parent?.description || '';
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -83,7 +85,7 @@ const CoursePage = ({ subscriptions }) => {
|
||||
name: group.product_name,
|
||||
type: productData?.type || 'product',
|
||||
image: image,
|
||||
description: productData?.description || '',
|
||||
description: description,
|
||||
price: productData?.price || 0,
|
||||
currency: productData?.currency || 'IDR',
|
||||
duration: productData?.duration || {},
|
||||
|
||||
Reference in New Issue
Block a user