Restore to commit 74e578279624c6045ca440a3459ebfa1f8d54191
This commit is contained in:
190
chat/public/test-upload.html
Normal file
190
chat/public/test-upload.html
Normal file
@@ -0,0 +1,190 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test Upload Media Button</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.test-section {
|
||||
border: 1px solid #ccc;
|
||||
padding: 20px;
|
||||
margin: 20px 0;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.composer-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
label.ghost {
|
||||
padding: 10px 16px;
|
||||
background: #f0f0f0;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
label.ghost:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
button {
|
||||
padding: 10px 16px;
|
||||
background: #008060;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
#status {
|
||||
margin-top: 15px;
|
||||
padding: 10px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
min-height: 30px;
|
||||
}
|
||||
.attachment-preview {
|
||||
margin-top: 10px;
|
||||
padding: 10px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 4px;
|
||||
display: none;
|
||||
}
|
||||
.attachment-preview.active {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Upload Media Button Test</h1>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Test 1: Free Plan User (Should show upgrade modal)</h2>
|
||||
<p>Account Plan: <strong id="plan1">hobby</strong></p>
|
||||
<div class="composer-actions">
|
||||
<span id="upload-media-btn-1" class="ghost" title="Upload an image">Upload media</span>
|
||||
<input id="upload-media-input-1" type="file" accept="image/*" multiple style="display:none" />
|
||||
<button onclick="alert('Send button clicked')">Send</button>
|
||||
</div>
|
||||
<div id="attachment-preview-1" class="attachment-preview"></div>
|
||||
<div id="status-1" style="margin-top: 15px; padding: 10px; background: #f8f9fa; border-radius: 4px;"></div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Test 2: Paid Plan User (Should open file picker)</h2>
|
||||
<p>Account Plan: <strong id="plan2">business</strong></p>
|
||||
<div class="composer-actions">
|
||||
<span id="upload-media-btn-2" class="ghost" title="Upload an image">Upload media</span>
|
||||
<input id="upload-media-input-2" type="file" accept="image/*" multiple style="display:none" />
|
||||
<button onclick="alert('Send button clicked')">Send</button>
|
||||
</div>
|
||||
<div id="attachment-preview-2" class="attachment-preview"></div>
|
||||
<div id="status-2" style="margin-top: 15px; padding: 10px; background: #f8f9fa; border-radius: 4px;"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Mock state object
|
||||
const state1 = {
|
||||
accountPlan: 'hobby',
|
||||
models: [{ name: 'test-model', supportsMedia: false }]
|
||||
};
|
||||
|
||||
const state2 = {
|
||||
accountPlan: 'business',
|
||||
models: [{ name: 'test-model', supportsMedia: true }]
|
||||
};
|
||||
|
||||
function setupUploadButton(buttonId, inputId, previewId, statusId, state) {
|
||||
const el = {
|
||||
uploadMediaBtn: document.getElementById(buttonId),
|
||||
uploadMediaInput: document.getElementById(inputId),
|
||||
attachmentPreview: document.getElementById(previewId),
|
||||
modelSelect: { value: 'test-model' }
|
||||
};
|
||||
|
||||
function isPaidPlanClient() {
|
||||
const plan = (state.accountPlan || '').toLowerCase();
|
||||
return plan === 'business' || plan === 'enterprise';
|
||||
}
|
||||
|
||||
function currentModelSupportsMedia() {
|
||||
const selectedModelId = el.modelSelect?.value;
|
||||
if (!selectedModelId) return false;
|
||||
const model = state.models.find((m) => (m.name || m.id || m) === selectedModelId);
|
||||
return model?.supportsMedia === true;
|
||||
}
|
||||
|
||||
function setStatus(msg) {
|
||||
document.getElementById(statusId).textContent = msg;
|
||||
}
|
||||
|
||||
function showUpgradeModal() {
|
||||
alert('You are already on the Enterprise plan with full access.');
|
||||
setStatus('Enterprise plan detected - no upgrade needed.');
|
||||
}
|
||||
|
||||
// THIS IS THE FIXED CODE
|
||||
if (el.uploadMediaBtn && el.uploadMediaInput) {
|
||||
console.log('Upload media elements found for ' + buttonId);
|
||||
el.uploadMediaBtn.addEventListener('click', (e) => {
|
||||
console.log('Upload media button clicked, isPaidPlanClient:', isPaidPlanClient());
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// Check if user is on free plan
|
||||
if (!isPaidPlanClient()) {
|
||||
showUpgradeModal();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if model supports media
|
||||
if (!currentModelSupportsMedia()) {
|
||||
setStatus('This model does not support image uploads. Please select a different model that supports media.');
|
||||
return;
|
||||
}
|
||||
|
||||
// For paid users with media-supporting models, trigger file input click
|
||||
console.log('Triggering file input click');
|
||||
el.uploadMediaInput.value = '';
|
||||
el.uploadMediaInput.click();
|
||||
});
|
||||
|
||||
el.uploadMediaInput.addEventListener('change', () => {
|
||||
const files = el.uploadMediaInput.files ? Array.from(el.uploadMediaInput.files) : [];
|
||||
|
||||
// Reset input immediately to allow same file selection again
|
||||
el.uploadMediaInput.value = '';
|
||||
|
||||
if (files.length > 0) {
|
||||
setStatus(`✓ Selected ${files.length} file(s): ${files.map(f => f.name).join(', ')}`);
|
||||
el.attachmentPreview.innerHTML = `<p>Attached ${files.length} file(s)</p>`;
|
||||
el.attachmentPreview.classList.add('active');
|
||||
|
||||
// Briefly highlight the upload button to show feedback
|
||||
el.uploadMediaBtn.style.color = '#4ade80';
|
||||
el.uploadMediaBtn.style.fontWeight = 'bold';
|
||||
setTimeout(() => {
|
||||
el.uploadMediaBtn.style.color = '';
|
||||
el.uploadMediaBtn.style.fontWeight = '';
|
||||
}, 2000);
|
||||
} else {
|
||||
setStatus('No files selected');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('Upload media elements NOT found');
|
||||
}
|
||||
}
|
||||
|
||||
// Setup both test scenarios
|
||||
setupUploadButton('upload-media-btn-1', 'upload-media-input-1', 'attachment-preview-1', 'status-1', state1);
|
||||
setupUploadButton('upload-media-btn-2', 'upload-media-input-2', 'attachment-preview-2', 'status-2', state2);
|
||||
|
||||
console.log('Test page loaded. Click the Upload media buttons to test the functionality.');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user