MC/website/control-panel/public/commerce-settings.mjs
2026-11-27 23:43:05 +00:00

7 lines
4.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const dashboard=document.getElementById('dashboard'),nav=dashboard?.querySelector('nav');
const definitions=[['items','Item Management','web.items.manage','Item Management','The website item-management integration will be connected here. Existing in-game item tools remain separate.','nav-clan-full-v2.webp'],['kits-exchange','Imperial Tailor','web.menu.inventory','Imperial Tailor','The kit catalogue, popularity filters and completed-sales data will be connected here during integration.','clan-atelier-v1.webp'],['shop-settings','Shop Settings','web.menu.inventory','Shop Settings','Your storefront preferences and purchase settings will appear here when the shop integration is ready.','nav-shop-v1.webp'],['exchange-settings','Exchange Settings','web.menu.inventory','Exchange Settings','Your trading preferences and listing settings will appear here when the Exchange integration is ready.','nav-exchange-full-v2.webp'],['shop-admin','Shop Management','web.shop.support','Shop Management','The sales team’s catalogue, promotions, order and payment controls will be connected here during shop integration.','nav-shop-v1.webp'],['exchange-settings-admin','Exchange Management','web.exchange.manage','Exchange Management','Staff trading policies and Exchange configuration will be connected here when this stage is implemented.','nav-exchange-full-v2.webp']];
const labels={'user-home':'Dashboard','staff-home':'Overview','game':'Linked Account','site-profile':'Profile','planetary-inventory':'Inventory','tickets':'Support Tickets','personal-bank':'Bank','staff-bank':'I.D. Revenue','staff-tickets':'Support Tickets','bans':'Bans & Appeals','forum-admin':'Forum Moderation','server-operations':'Server Management','website-posts':'News','quests-admin':'Quest Management','staff-manual':'Staff Guide','permissions':'Website Ranks','game-permissions':'In-game Ranks','git-admin':'Git Management'};
if(dashboard&&nav){for(const[id,label,permission,title,description,icon]of definitions){const section=document.createElement('section');section.id=id;section.hidden=true;section.className='commerce-settings-placeholder';const image=document.createElement('img');image.src='https://www.dunerealms.com/assets/'+icon;image.alt='';image.width=72;image.height=72;const small=document.createElement('p');small.textContent='INTEGRATION IN PROGRESS';const heading=document.createElement('h2');heading.textContent=title;const paragraph=document.createElement('p');paragraph.textContent=description;const note=document.createElement('p');note.textContent='Placeholder · Settings are not available yet.';note.className='commerce-placeholder-note';section.append(image,small,heading,paragraph,note);dashboard.append(section);const link=document.createElement('a');link.href='#'+id;link.textContent=label;link.hidden=true;link.dataset.commercePermission=permission;nav.append(link);}
let generation=0;const applySession=user=>{for(const[id,,permission]of definitions){const section=document.getElementById(id);if(section)section.hidden=!user?.permissions?.includes(permission);}};window.addEventListener('dune:session',e=>{generation++;applySession(e.detail);});const revision=generation;fetch('/api/auth/session',{cache:'no-store'}).then(r=>r.json()).then(d=>{if(revision===generation)applySession(d.user);}).catch(()=>applySession(null));
const rename=()=>{for(const menu of dashboard.querySelectorAll(':scope>nav')){const seen=new Set();for(const a of menu.querySelectorAll('a[href]')){if(seen.has(a.getAttribute('href')))a.remove();else seen.add(a.getAttribute('href'));}}for(const a of dashboard.querySelectorAll(':scope>nav a[href^="#"]')){if(a.hash==='#exchange'){a.href='#exchange-settings';a.textContent='Exchange Settings';}else if(a.hash==='#exchange-admin'&&a.textContent!=='Exchange Monitor'){a.textContent='Exchange Monitor';}else if(labels[a.hash.slice(1)]&&a.textContent!==labels[a.hash.slice(1)])a.textContent=labels[a.hash.slice(1)];if(['#personal-bank','#staff-bank'].includes(a.hash)&&!a.querySelector('.cp-uuid-icon')){const img=document.createElement('img');img.className='cp-uuid-icon';img.src='https://www.dunerealms.com/assets/uuid-link-imperial-v1.png';img.alt='Linked Minecraft account required';img.title='Linked Minecraft account required';img.width=22;img.height=22;a.append(img);}}};rename();new MutationObserver(rename).observe(dashboard,{childList:true,subtree:true});
}