Keep Studio business branding in verified client storage
This commit is contained in:
+27
-1
@@ -12,7 +12,11 @@
|
||||
function escapeText(value) {
|
||||
return String(value ?? '').replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[char]));
|
||||
}
|
||||
if (typeof module === 'object' && module.exports) { module.exports = { scopedStorage, escapeText }; return; }
|
||||
function whatsappUrl(phone) {
|
||||
const digits = String(phone || '').replace(/[\s().-]/g, '').replace(/^\+/, '');
|
||||
return /^[1-9]\d{6,14}$/.test(digits) ? 'https://wa.me/' + digits : '';
|
||||
}
|
||||
if (typeof module === 'object' && module.exports) { module.exports = { scopedStorage, escapeText, whatsappUrl }; return; }
|
||||
|
||||
async function start() {
|
||||
const gate = document.getElementById('studioWorkspaceGate');
|
||||
@@ -56,6 +60,7 @@
|
||||
local: scopedStorage(localStorage, workspace.clientId),
|
||||
session: scopedStorage(sessionStorage, workspace.clientId),
|
||||
escapeText,
|
||||
whatsappUrl,
|
||||
apiUrl(path) {
|
||||
const url = new URL(path, location.origin);
|
||||
if (url.origin !== location.origin || !url.pathname.startsWith('/api/')) throw new Error('Invalid Studio API URL');
|
||||
@@ -72,6 +77,27 @@
|
||||
document.dispatchEvent(new Event('aura-studio-ready'));
|
||||
document.querySelectorAll('body > :not(#studioWorkspaceGate):not(script)').forEach(el => el.inert = false);
|
||||
gate.hidden = true;
|
||||
const brandForm = document.getElementById('workspaceBrandForm');
|
||||
const brandStatus = document.getElementById('workspaceBrandStatus');
|
||||
if (brandForm) {
|
||||
const brand = workspace.brand || { name: workspace.name, website: '', phone: '' };
|
||||
['name', 'website', 'phone'].forEach(key => { brandForm.elements[key].value = brand[key] || ''; });
|
||||
brandForm.querySelector('button').disabled = !workspace.canWriteProducts;
|
||||
brandForm.onsubmit = async event => {
|
||||
event.preventDefault();
|
||||
const submit = brandForm.querySelector('button');
|
||||
submit.disabled = true; brandStatus.textContent = 'সংরক্ষণ হচ্ছে…';
|
||||
try {
|
||||
const result = await fetch(runtime.apiUrl('/api/brand'), {
|
||||
method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(Object.fromEntries(['name', 'website', 'phone'].map(key => [key, brandForm.elements[key].value])))
|
||||
});
|
||||
const saved = await result.json();
|
||||
if (!result.ok || saved.success !== true) throw new Error(saved.error || 'সংরক্ষণ হয়নি।');
|
||||
location.reload();
|
||||
} catch (error) { brandStatus.textContent = error.message; submit.disabled = !workspace.canWriteProducts; }
|
||||
};
|
||||
}
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button'; button.className = 'pill-btn';
|
||||
button.textContent = workspace.name || workspace.tenant;
|
||||
|
||||
Reference in New Issue
Block a user