ok
This commit is contained in:
40
src/App.js
40
src/App.js
@@ -194,42 +194,31 @@ function App() {
|
||||
if (!productModalRequest || !subscriptions) return;
|
||||
|
||||
const { productId, authorizedUri, unauthorizedUri } = productModalRequest;
|
||||
|
||||
console.log(subscriptions)
|
||||
const hasAccess = subscriptions && subscriptions.some(
|
||||
sub => sub.product_id === productId || sub.product_parent_id === productId
|
||||
);
|
||||
console.log("hasAccess:", hasAccess);
|
||||
|
||||
console.log(hasAccess)
|
||||
if (hasAccess) {
|
||||
if (authorizedUri) {
|
||||
let finalUri = decodeURIComponent(authorizedUri);
|
||||
const token = document.cookie.match(/(^| )token=([^;]+)/)?.[2];
|
||||
|
||||
// --- ambil product_name distinct berdasarkan productId/parent ---
|
||||
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
|
||||
if (finalUri.includes('token=null') || finalUri.includes('token=')) {
|
||||
const url = new URL(finalUri);
|
||||
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]);
|
||||
url.searchParams.set('token', token || '');
|
||||
finalUri = url.toString();
|
||||
}
|
||||
|
||||
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', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
itemsId: [productId],
|
||||
withChildren: true,
|
||||
@@ -238,7 +227,9 @@ function App() {
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (Array.isArray(data) && data.length > 0) {
|
||||
// Process the raw data to group children under their parent
|
||||
const processed = processProducts(data);
|
||||
// Set the first product (which should be the parent with children nested)
|
||||
setSelectedProduct(processed[0]);
|
||||
setShowedModal('product');
|
||||
}
|
||||
@@ -249,9 +240,12 @@ function App() {
|
||||
if (unauthorizedUri) {
|
||||
window.location.href = decodeURIComponent(unauthorizedUri);
|
||||
} else {
|
||||
|
||||
fetch('https://bot.kediritechnopark.com/webhook/store-production/products', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
itemsId: [productId],
|
||||
withChildren: true,
|
||||
@@ -260,7 +254,9 @@ function App() {
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (Array.isArray(data) && data.length > 0) {
|
||||
// Process the raw data to group children under their parent
|
||||
const processed = processProducts(data);
|
||||
// Set the first product (which should be the parent with children nested)
|
||||
setSelectedProduct(processed[0]);
|
||||
setShowedModal('product');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user