diff --git a/frontend/controllers/donation-controller.ts b/frontend/controllers/donation-controller.ts index fd423d6..56648bd 100644 --- a/frontend/controllers/donation-controller.ts +++ b/frontend/controllers/donation-controller.ts @@ -2,29 +2,33 @@ import { Controller } from "@hotwired/stimulus"; class DonationController extends Controller { static targets = ["input"]; + inputTargets: any; setInputs(value: number) { // If the new value is one of the radios, select them // Else unselect all radios if (value) { - this.inputTargets.forEach((input) => { - if (input.type === "radio") { - input.checked = parseFloat(input.value) === value; - } else { - input.value = value; + this.inputTargets.forEach( + (input: { type: string; checked: boolean; value: string | number }) => { + if (input.type === "radio") { + input.checked = parseFloat(input.value as string) === value; + } else { + input.value = String(value); + } } - }); + ); } else { - this.inputTargets.forEach((input) => { - if (input.type === "radio") { - input.checked = false; - } else { - input.value = "0"; + this.inputTargets.forEach( + (input: { type: string; checked: boolean; value: string }) => { + if (input.type === "radio") { + input.checked = false; + } else { + input.value = "0"; + } } - }); + ); } } - update(e: InputEvent) { let value = parseFloat((e.target as HTMLInputElement)?.value || "0") || 0; this.setInputs(value); diff --git a/frontend/controllers/product-controller.ts b/frontend/controllers/product-controller.ts index 87a1fac..c4d13a3 100644 --- a/frontend/controllers/product-controller.ts +++ b/frontend/controllers/product-controller.ts @@ -44,24 +44,33 @@ export default class ShopifyBuyControllerBase extends Controller { } updateAddToCartButton() { - const selectedOption = this.variantSelectorTarget.options[this.variantSelectorTarget.selectedIndex]; + const selectedOption = + this.variantSelectorTarget.options[ + this.variantSelectorTarget.selectedIndex + ]; const selectedVariantId = selectedOption.value; - const inventoryQuantity = selectedOption.getAttribute('data-inventory-quantity'); - const inventoryPolicy = selectedOption.getAttribute('data-inventory-policy'); - this.addToCartButtonTarget.setAttribute('data-product-variant-id-param', selectedVariantId); + const inventoryQuantity = selectedOption.getAttribute( + "data-inventory-quantity" + ); + const inventoryPolicy = selectedOption.getAttribute( + "data-inventory-policy" + ); + this.addToCartButtonTarget.setAttribute( + "data-product-variant-id-param", + selectedVariantId + ); - if (Number(inventoryQuantity) == 0 && inventoryPolicy == 'deny') { - this.addToCartButtonTarget.setAttribute('disabled', 'true'); + if (Number(inventoryQuantity) == 0 && inventoryPolicy == "deny") { + this.addToCartButtonTarget.setAttribute("disabled", "true"); } else { - this.addToCartButtonTarget.removeAttribute('disabled'); + this.addToCartButtonTarget.removeAttribute("disabled"); } -} + } private LOCALSTORAGE_CHECKOUT_ID = "checkoutId"; - get checkoutId() { - return window.localStorage - .getItem(this.LOCALSTORAGE_CHECKOUT_ID) - ?.toString(); + get checkoutId(): string | number { + const id = window.localStorage.getItem(this.LOCALSTORAGE_CHECKOUT_ID); + return id ? id.toString() : ""; } set checkoutId(id: string | number) { @@ -81,7 +90,9 @@ export default class ShopifyBuyControllerBase extends Controller { }); if (this.checkoutId) { - this.checkoutValue = await this.client.checkout.fetch(this.checkoutId); + this.checkoutValue = await this.client.checkout.fetch( + this.checkoutId.toString() + ); } let checkoutIsExpired = false; @@ -336,4 +347,4 @@ function currency( function length(arr: any[]) { if (!arr) return 0; return arr.length || 0; -} \ No newline at end of file +} diff --git a/frontend/main.ts b/frontend/main.ts index e457de5..3f681a0 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -6,7 +6,13 @@ import "bootstrap"; import initialiseSentry from "./sentry"; import initialisePosthog from "./posthog"; import { startApp } from "groundwork-django"; -const controllers = import.meta.glob("./controllers/*-controller.ts"); +import { ControllerConstructor } from "@hotwired/stimulus"; + +const controllers = import.meta.glob("./controllers/*-controller.ts") as Record< + string, + () => Promise<{ default: ControllerConstructor }> +>; + Turbo.session.drive = false; initialisePosthog(); diff --git a/package.json b/package.json index 8a5a743..32c172c 100644 --- a/package.json +++ b/package.json @@ -48,5 +48,4 @@ "vite": "^5.0.2" }, "packageManager": "yarn@1.22.22" - }