add: single_use products

This commit is contained in:
trisua 2025-08-08 14:17:40 -04:00
parent 7fbc732290
commit e5e6d5cddb
12 changed files with 149 additions and 7 deletions

View file

@ -77,6 +77,18 @@
("oninput" "event.preventDefault(); update_on_sale_from_form(event.target.checked)"))
(span
(str (text "economy:label.on_sale"))))
(label
("for" "single_use")
("class" "flex items_center gap_2")
(input
("type" "checkbox")
("id" "single_use")
("name" "single_use")
("class" "w_content")
("checked" "{{ product.single_use }}")
("oninput" "event.preventDefault(); update_single_use_from_form(event.target.checked)"))
(span
(str (text "economy:label.single_use"))))
(div
("class" "flex flex_col gap_1")
(label
@ -240,6 +252,27 @@
});
}
async function update_single_use_from_form(single_use) {
await trigger(\"atto::debounce\", [\"products::update\"]);
fetch(\"/api/v1/products/{{ product.id }}/single_use\", {
method: \"POST\",
headers: {
\"Content-Type\": \"application/json\",
},
body: JSON.stringify({
single_use,
}),
})
.then((res) => res.json())
.then((res) => {
trigger(\"atto::toast\", [
res.ok ? \"success\" : \"error\",
res.message,
]);
});
}
async function update_price_from_form(e) {
e.preventDefault();
await trigger(\"atto::debounce\", [\"products::update\"]);

View file

@ -28,12 +28,19 @@
(icon (text "badge-cent"))
(text "{{ product.price }}"))
(text "{% if user.id != product.owner -%}")
(text "{% if not already_purchased -%}")
(button
("onclick" "purchase()")
("disabled" "{{ product.stock == 0 }}")
(icon (text "piggy-bank"))
(str (text "economy:action.buy")))
(text "{% else %}")
(span
("class" "green flex items_center gap_2")
(icon (text "circle-check"))
(str (text "economy:label.already_purchased")))
(text "{%- endif %}")
(text "{% else %}")
(a
("class" "button")
("href" "/product/{{ product.id }}/edit")