diff --git a/src/lib/components/ButtonGroup.svelte b/src/lib/components/ButtonGroup.svelte new file mode 100644 index 00000000..e4b1d2b4 --- /dev/null +++ b/src/lib/components/ButtonGroup.svelte @@ -0,0 +1,162 @@ + + +
+ + diff --git a/src/lib/components/HarnessSelector/HarnessSelector.svelte b/src/lib/components/HarnessSelector/HarnessSelector.svelte index 0afa38f7..53a89d8b 100644 --- a/src/lib/components/HarnessSelector/HarnessSelector.svelte +++ b/src/lib/components/HarnessSelector/HarnessSelector.svelte @@ -69,7 +69,7 @@ let inputValue = ""; let inputRef; - $: filteredItems = $harnesses.filter(item => + $: filteredItems = $harnesses.filter(item => normalizeDiacritics(item.car.toLowerCase()).match(normalizeDiacritics(inputValue.toLowerCase())) ); diff --git a/src/lib/components/ProductDescriptions/CommaFour.svelte b/src/lib/components/ProductDescriptions/CommaFour.svelte index 0f15aa5b..aecb9d26 100644 --- a/src/lib/components/ProductDescriptions/CommaFour.svelte +++ b/src/lib/components/ProductDescriptions/CommaFour.svelte @@ -2,6 +2,7 @@ import Product from "$lib/components/Product.svelte"; import NoteCard from "$lib/components/NoteCard.svelte"; import CheckboxCard from "$lib/components/CheckboxCard.svelte"; + import ButtonGroup from "$lib/components/ButtonGroup.svelte"; import Accordion from "$lib/components/Accordion.svelte"; import Badge from "$lib/components/Badge.svelte"; import HarnessSelector from "$lib/components/HarnessSelector/HarnessSelector.svelte"; @@ -19,6 +20,7 @@ import { onMount } from 'svelte'; import { getProduct } from '$lib/utils/shopify'; import { products as productsData } from '$lib/data/products.js'; + import Button from "$lib/components/Button.svelte"; export let product; let additionalProductIds = []; @@ -48,6 +50,7 @@ let selectedHarness = null; let tradeInVariantId = null; let tradeInChecked = false; + let tradeInValue = null; let backordered = null; const updateAdditionalProductIds = () => { @@ -60,31 +63,44 @@ } } + const updateDisableBuyButtonText = () => { + if (!selectedHarness) { + disableBuyButtonText = "SELECT YOUR CAR"; + } else if (tradeInValue === null) { + disableBuyButtonText = "SELECT TRADE IN"; + } else if (selectedHarness === NO_HARNESS_OPTION) { + disableBuyButtonText = null; + } else { + disableBuyButtonText = null; + } + } + const handleHarnessSelection = (value) => { selectedHarness = value; updateAdditionalProductIds(); if (value === NO_HARNESS_OPTION) { backordered = null; - disableBuyButtonText = null; } else if (value) { backordered = value.currentlyNotInStock ? `ships in ${(value.backordered || '1-12 weeks')}` : null; - disableBuyButtonText = null; } else { backordered = null; - disableBuyButtonText = "SELECT YOUR CAR"; } backordered = '1-12 weeks'; + updateDisableBuyButtonText(); } - const handleTradeInToggle = () => { - tradeInChecked = !tradeInChecked; + const handleTradeInSelection = (value) => { + tradeInValue = value; + tradeInChecked = value === 'trade-in'; updateAdditionalProductIds(); + updateDisableBuyButtonText(); } onMount(async () => { // Autofill trade-in checkbox const urlParams = new URLSearchParams(window.location.search); if (urlParams.get('trade-in') === '1') { + tradeInValue = 'trade-in'; tradeInChecked = true; } @@ -124,10 +140,28 @@ showNoHarnessOption={true} > -