Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI run #480

Draft
wants to merge 2 commits into
base: production
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions frontend/controllers/donation-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 25 additions & 14 deletions frontend/controllers/product-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -336,4 +347,4 @@ function currency(
function length(arr: any[]) {
if (!arr) return 0;
return arr.length || 0;
}
}
8 changes: 7 additions & 1 deletion frontend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@
"vite": "^5.0.2"
},
"packageManager": "yarn@1.22.22"

}
Loading