Skip to main content

max / makenotwork

5.6 KB · 114 lines History Blame Raw
1 {%- import "partials/_ui.html" as ui -%}
2 <div id="promo-codes-list">
3 {% if promo_codes.is_empty() %}
4 {% call ui::empty_state("", "No promo codes yet. Create one above to offer discounts, free access, or trial periods to your fans.") %}
5 {% else %}
6 <table class="data-table">
7 <thead>
8 <tr>
9 <th>Code</th>
10 <th>Type</th>
11 <th>Uses</th>
12 <th>Scope</th>
13 <th>Schedule</th>
14 <th></th>
15 </tr>
16 </thead>
17 <tbody>
18 {% for code in promo_codes %}
19 <tr{% if code.is_expired %} class="promo-codes-row--expired"{% else if code.is_not_yet_active %} class="promo-codes-row--pending"{% endif %}>
20 <td>
21 <code class="key-code" title="Click to copy" onclick="navigator.clipboard.writeText('{{ code.code }}')">
22 {{ code.code }}
23 </code>
24 </td>
25 <td>{{ code.description }}</td>
26 <td>
27 {% if code.use_count > 0 %}
28 <button class="btn-link btn-sm" type="button"
29 onclick="showPromoRedemptions('{{ code.id }}', '{{ code.code }}')"
30 title="Show who redeemed this code">
31 {{ code.use_count }}{% if let Some(max) = code.max_uses %} / {{ max }}{% else %} / &infin;{% endif %}
32 </button>
33 {% else %}
34 {{ code.use_count }}{% if let Some(max) = code.max_uses %} / {{ max }}{% else %} / &infin;{% endif %}
35 {% endif %}
36 </td>
37 <td>
38 {% if let Some(title) = code.item_title %}
39 {{ title }}
40 {% else if let Some(title) = code.project_title %}
41 {{ title }}
42 {% else %}
43 All items
44 {% endif %}
45 </td>
46 <td class="promo-codes-schedule">
47 {% if let Some(start) = code.starts_at %}
48 <div{% if code.is_not_yet_active %} class="promo-codes-schedule-pending"{% endif %}>
49 {% if code.is_not_yet_active %}Starts{% else %}Started{% endif %} {{ start }}
50 </div>
51 {% endif %}
52 {% if let Some(exp) = code.expires_at %}
53 <div{% if code.is_expired %} class="promo-codes-schedule-expired"{% endif %}>
54 {% if code.is_expired %}Expired{% else %}Expires{% endif %} {{ exp }}
55 </div>
56 {% endif %}
57 {% if code.starts_at.is_none() && code.expires_at.is_none() %}
58 <span class="promo-codes-schedule-none">No schedule</span>
59 {% endif %}
60 </td>
61 <td class="promo-codes-actions">
62 <button class="btn-secondary small promo-codes-edit-btn"
63 onclick="this.closest('tr').nextElementSibling.classList.toggle('hidden')">Edit</button>
64 <button class="btn btn-sm btn-danger"
65 hx-delete="/api/promo-codes/{{ code.id }}"
66 hx-target="#promo-codes-list"
67 hx-swap="outerHTML"
68 hx-confirm="Delete this code? It will no longer be usable.">
69 Delete
70 </button>
71 </td>
72 </tr>
73 <tr class="hidden promo-codes-edit-row">
74 <td colspan="6" class="promo-codes-edit-cell">
75 <form class="promo-codes-edit-form"
76 hx-put="/api/promo-codes/{{ code.id }}"
77 hx-target="#promo-codes-list"
78 hx-swap="outerHTML">
79 <div>
80 <label class="promo-codes-edit-label">Max uses</label>
81 <input type="number" name="max_uses" min="1" placeholder="Unlimited"
82 value="{{ code.max_uses_raw }}"
83 class="promo-codes-edit-input input--sm w-100">
84 </div>
85 <div>
86 <label class="promo-codes-edit-label">Starts</label>
87 <input type="date" name="starts_at"
88 value="{{ code.starts_at_raw.as_deref().unwrap_or_default() }}"
89 class="promo-codes-edit-input input--sm">
90 </div>
91 <div>
92 <label class="promo-codes-edit-label">Expires</label>
93 <input type="date" name="expires_at"
94 value="{{ code.expires_at_raw.as_deref().unwrap_or_default() }}"
95 class="promo-codes-edit-input input--sm">
96 </div>
97 <button class="btn-secondary small promo-codes-edit-save" type="submit">Save</button>
98 </form>
99 </td>
100 </tr>
101 {% endfor %}
102 </tbody>
103 </table>
104
105 <div class="promo-codes-bulk-row">
106 <button class="btn-secondary small promo-codes-bulk-btn"
107 hx-delete="/api/promo-codes/expired"
108 hx-target="#promo-codes-list"
109 hx-swap="outerHTML"
110 hx-confirm="Delete all expired promo codes?">Delete all expired</button>
111 </div>
112 {% endif %}
113 </div>
114