Add subscription tiers and responsive navigation
This commit is contained in:
1 parent
289f7eebbe
commit
de1d3d2d63
24 files changed
+1290
-602
No files matched your search
@@ -83,15 +83,18 @@
|
||||
|
||||
<!-- Pricing (with toggle) -->
|
||||
<div class="form-group pricing-group">
|
||||
<label>Pricing</label>
|
||||
<label>Access</label>
|
||||
<div class="pricing-toggle">
|
||||
<button type="button" id="freeBtn" class="price-option active">Free</button>
|
||||
<button type="button" id="paidBtn" class="price-option">Paid</button>
|
||||
<button type="button" id="tierBtn" class="price-option">Tier</button>
|
||||
</div>
|
||||
<div id="priceField">
|
||||
<input type="number" id="price" name="price" step="0.01" min="0" placeholder="Price in USD (e.g., 19.99)">
|
||||
<div id="tierField">
|
||||
<select id="subscriptionTier" name="subscriptionTier">
|
||||
<option value="">No tiers created yet</option>
|
||||
</select>
|
||||
<a class="tier-manage-link" href="subscription-tiers.html">Manage tiers</a>
|
||||
</div>
|
||||
<small class="form-hint">You can set a price later or keep it free.</small>
|
||||
<small class="form-hint">Free prompts are public. Tier prompts require a monthly creator subscription.</small>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button -->
|
||||
@@ -109,23 +112,24 @@
|
||||
<script>
|
||||
// Toggle between free and paid
|
||||
const freeBtn = document.getElementById('freeBtn');
|
||||
const paidBtn = document.getElementById('paidBtn');
|
||||
const priceField = document.getElementById('priceField');
|
||||
const priceInput = document.getElementById('price');
|
||||
const tierBtn = document.getElementById('tierBtn');
|
||||
const tierField = document.getElementById('tierField');
|
||||
const tierSelect = document.getElementById('subscriptionTier');
|
||||
const editPromptId = new URLSearchParams(location.search).get('id');
|
||||
const submitPromptBtn = document.getElementById('submitPromptBtn');
|
||||
let ownSubscriptionTiers = [];
|
||||
|
||||
freeBtn.addEventListener('click', () => {
|
||||
freeBtn.classList.add('active');
|
||||
paidBtn.classList.remove('active');
|
||||
priceField.style.display = 'none';
|
||||
priceInput.removeAttribute('required');
|
||||
tierBtn.classList.remove('active');
|
||||
tierField.style.display = 'none';
|
||||
tierSelect.removeAttribute('required');
|
||||
});
|
||||
paidBtn.addEventListener('click', () => {
|
||||
paidBtn.classList.add('active');
|
||||
tierBtn.addEventListener('click', () => {
|
||||
tierBtn.classList.add('active');
|
||||
freeBtn.classList.remove('active');
|
||||
priceField.style.display = 'block';
|
||||
priceInput.setAttribute('required', 'required');
|
||||
tierField.style.display = 'grid';
|
||||
tierSelect.setAttribute('required', 'required');
|
||||
});
|
||||
|
||||
// Image preview for example image
|
||||
@@ -171,6 +175,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSubscriptionTiers() {
|
||||
try {
|
||||
const response = await fetch('/api/v1/subscriptions/tiers', {
|
||||
credentials: 'same-origin'
|
||||
});
|
||||
if (response.status === 401) {
|
||||
location.href = '/login';
|
||||
return;
|
||||
}
|
||||
if (!response.ok) return;
|
||||
|
||||
ownSubscriptionTiers = await response.json();
|
||||
if (!ownSubscriptionTiers.length) {
|
||||
tierSelect.innerHTML = '<option value="">Create a tier first</option>';
|
||||
return;
|
||||
}
|
||||
|
||||
tierSelect.innerHTML = ownSubscriptionTiers
|
||||
.map((tier) => `<option value="${tier.level}">${tier.name} - $${Number(tier.monthlyPrice || 0).toFixed(2)}/mo</option>`)
|
||||
.join('');
|
||||
} catch {
|
||||
tierSelect.innerHTML = '<option value="">Tiers could not be loaded</option>';
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPromptForEdit() {
|
||||
if (!editPromptId) return;
|
||||
|
||||
@@ -202,9 +231,9 @@
|
||||
imagePreview.style.display = 'block';
|
||||
}
|
||||
|
||||
if (prompt.price != null && Number(prompt.price) > 0) {
|
||||
paidBtn.click();
|
||||
priceInput.value = Number(prompt.price);
|
||||
if (prompt.tierLevel != null) {
|
||||
tierBtn.click();
|
||||
tierSelect.value = String(prompt.tierLevel);
|
||||
} else {
|
||||
freeBtn.click();
|
||||
}
|
||||
@@ -224,8 +253,7 @@
|
||||
submitBtn.disabled = true;
|
||||
|
||||
try {
|
||||
const isPaid = paidBtn.classList.contains('active');
|
||||
const price = isPaid ? Number(priceInput.value || 0) : null;
|
||||
const isTier = tierBtn.classList.contains('active');
|
||||
const payload = {
|
||||
title: document.getElementById('title').value.trim(),
|
||||
description: document.getElementById('description').value.trim(),
|
||||
@@ -233,8 +261,8 @@
|
||||
content: document.getElementById('promptContent').value.trim(),
|
||||
exampleOutput: document.getElementById('exampleOutput').value.trim() || null,
|
||||
exampleImageUrl: exampleImageUrl || null,
|
||||
price,
|
||||
subscriptionTier: null,
|
||||
price: null,
|
||||
subscriptionTier: isTier ? Number(tierSelect.value) : null,
|
||||
slug: null
|
||||
};
|
||||
|
||||
@@ -300,7 +328,7 @@
|
||||
.then(r => r.text())
|
||||
.then(data => document.getElementById('topbar-container').innerHTML = data);
|
||||
|
||||
loadCategories().then(loadPromptForEdit);
|
||||
Promise.all([loadCategories(), loadSubscriptionTiers()]).then(loadPromptForEdit);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user