This commit is contained in:
2025-08-23 08:05:00 +00:00
parent a4d6f9ae43
commit 170d3aa432

View File

@@ -194,42 +194,31 @@ function App() {
if (!productModalRequest || !subscriptions) return; if (!productModalRequest || !subscriptions) return;
const { productId, authorizedUri, unauthorizedUri } = productModalRequest; const { productId, authorizedUri, unauthorizedUri } = productModalRequest;
console.log(subscriptions)
const hasAccess = subscriptions && subscriptions.some( const hasAccess = subscriptions && subscriptions.some(
sub => sub.product_id === productId || sub.product_parent_id === productId sub => sub.product_id === productId || sub.product_parent_id === productId
); );
console.log("hasAccess:", hasAccess); console.log(hasAccess)
if (hasAccess) { if (hasAccess) {
if (authorizedUri) { if (authorizedUri) {
let finalUri = decodeURIComponent(authorizedUri); let finalUri = decodeURIComponent(authorizedUri);
const token = document.cookie.match(/(^| )token=([^;]+)/)?.[2]; const token = document.cookie.match(/(^| )token=([^;]+)/)?.[2];
// --- ambil product_name distinct berdasarkan productId/parent --- if (finalUri.includes('token=null') || finalUri.includes('token=')) {
const relatedSubs = subscriptions.filter(
sub => sub.product_id === productId || sub.product_parent_id === productId
);
const distinctNames = [...new Set(relatedSubs.map(sub => sub.product_name))];
if (distinctNames.length > 1) {
// lebih dari 1 → pakai dashboard=true
const url = new URL(finalUri); const url = new URL(finalUri);
url.searchParams.set("token", token || ""); url.searchParams.set('token', token || '');
finalUri = url.toString();
} else if (distinctNames.length === 1) {
// hanya 1 → tambahkan productName=<nama> sebelum query lain
const url = new URL(finalUri);
url.searchParams.set("token", token || "");
url.searchParams.set("productName", distinctNames[0]);
finalUri = url.toString(); finalUri = url.toString();
} }
window.location.href = finalUri; window.location.href = finalUri;
} else { }
// fallback ambil detail produk via fetch else {// Assuming you already imported processProducts from './processProducts'
fetch('https://bot.kediritechnopark.com/webhook/store-production/products', { fetch('https://bot.kediritechnopark.com/webhook/store-production/products', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ body: JSON.stringify({
itemsId: [productId], itemsId: [productId],
withChildren: true, withChildren: true,
@@ -238,7 +227,9 @@ function App() {
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
if (Array.isArray(data) && data.length > 0) { if (Array.isArray(data) && data.length > 0) {
// Process the raw data to group children under their parent
const processed = processProducts(data); const processed = processProducts(data);
// Set the first product (which should be the parent with children nested)
setSelectedProduct(processed[0]); setSelectedProduct(processed[0]);
setShowedModal('product'); setShowedModal('product');
} }
@@ -249,9 +240,12 @@ function App() {
if (unauthorizedUri) { if (unauthorizedUri) {
window.location.href = decodeURIComponent(unauthorizedUri); window.location.href = decodeURIComponent(unauthorizedUri);
} else { } else {
fetch('https://bot.kediritechnopark.com/webhook/store-production/products', { fetch('https://bot.kediritechnopark.com/webhook/store-production/products', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ body: JSON.stringify({
itemsId: [productId], itemsId: [productId],
withChildren: true, withChildren: true,
@@ -260,7 +254,9 @@ function App() {
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
if (Array.isArray(data) && data.length > 0) { if (Array.isArray(data) && data.length > 0) {
// Process the raw data to group children under their parent
const processed = processProducts(data); const processed = processProducts(data);
// Set the first product (which should be the parent with children nested)
setSelectedProduct(processed[0]); setSelectedProduct(processed[0]);
setShowedModal('product'); setShowedModal('product');
} }