Skip to main content

max / makenotwork

5.6 KB · 116 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.") %}{% endcall %}
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" data-copy="{{ code.code }}" data-action="copyText">
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 data-action="showPromoRedemptions"
30 data-arg="{{ code.id }}"
31 data-arg2="{{ code.code }}"
32 title="Show who redeemed this code">
33 {{ code.use_count }}{% if let Some(max) = code.max_uses %} / {{ max }}{% else %} / &infin;{% endif %}
34 </button>
35 {% else %}
36 {{ code.use_count }}{% if let Some(max) = code.max_uses %} / {{ max }}{% else %} / &infin;{% endif %}
37 {% endif %}
38 </td>
39 <td>
40 {% if let Some(title) = code.item_title %}
41 {{ title }}
42 {% else if let Some(title) = code.project_title %}
43 {{ title }}
44 {% else %}
45 All items
46 {% endif %}
47 </td>
48 <td class="promo-codes-schedule">
49 {% if let Some(start) = code.starts_at %}
50 <div{% if code.is_not_yet_active %} class="promo-codes-schedule-pending"{% endif %}>
51 {% if code.is_not_yet_active %}Starts{% else %}Started{% endif %} {{ start }}
52 </div>
53 {% endif %}
54 {% if let Some(exp) = code.expires_at %}
55 <div{% if code.is_expired %} class="promo-codes-schedule-expired"{% endif %}>
56 {% if code.is_expired %}Expired{% else %}Expires{% endif %} {{ exp }}
57 </div>
58 {% endif %}
59 {% if code.starts_at.is_none() && code.expires_at.is_none() %}
60 <span class="promo-codes-schedule-none">No schedule</span>
61 {% endif %}
62 </td>
63 <td class="promo-codes-actions">
64 <button class="btn-secondary small promo-codes-edit-btn"
65 data-action="togglePromoEditRow">Edit</button>
66 <button class="btn btn-sm btn-danger"
67 hx-delete="/api/promo-codes/{{ code.id }}"
68 hx-target="#promo-codes-list"
69 hx-swap="outerHTML"
70 hx-confirm="Delete this code? It will no longer be usable.">
71 Delete
72 </button>
73 </td>
74 </tr>
75 <tr class="hidden promo-codes-edit-row">
76 <td colspan="6" class="promo-codes-edit-cell">
77 <form class="promo-codes-edit-form"
78 hx-put="/api/promo-codes/{{ code.id }}"
79 hx-target="#promo-codes-list"
80 hx-swap="outerHTML">
81 <div>
82 <label class="promo-codes-edit-label">Max uses</label>
83 <input type="number" name="max_uses" min="1" placeholder="Unlimited"
84 value="{{ code.max_uses_raw }}"
85 class="promo-codes-edit-input input--sm w-100">
86 </div>
87 <div>
88 <label class="promo-codes-edit-label">Starts</label>
89 <input type="date" name="starts_at"
90 value="{{ code.starts_at_raw.as_deref().unwrap_or_default() }}"
91 class="promo-codes-edit-input input--sm">
92 </div>
93 <div>
94 <label class="promo-codes-edit-label">Expires</label>
95 <input type="date" name="expires_at"
96 value="{{ code.expires_at_raw.as_deref().unwrap_or_default() }}"
97 class="promo-codes-edit-input input--sm">
98 </div>
99 <button class="btn-secondary small promo-codes-edit-save" type="submit">Save</button>
100 </form>
101 </td>
102 </tr>
103 {% endfor %}
104 </tbody>
105 </table>
106
107 <div class="promo-codes-bulk-row">
108 <button class="btn-secondary small promo-codes-bulk-btn"
109 hx-delete="/api/promo-codes/expired"
110 hx-target="#promo-codes-list"
111 hx-swap="outerHTML"
112 hx-confirm="Delete all expired promo codes?">Delete all expired</button>
113 </div>
114 {% endif %}
115 </div>
116