diff --git a/src/layouts/vehicle-parts/vehicle-parts.vue b/src/layouts/vehicle-parts/vehicle-parts.vue index f6d99bcf4..86936637d 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.vue +++ b/src/layouts/vehicle-parts/vehicle-parts.vue @@ -154,8 +154,40 @@ export default { }, forwardButtonAction() { - const p = this.PartsFromApi; - const pickedParts = ''; + + // Temporary solution to prevent the user from going forward if they have not selected anything. + // will be replaced by validation in the future. + if(Object.keys(this.glassParts).length === 0) { + throw new Error("No parts selected"); + } + + const selectedGlassPartNumbers = []; + const matchedParts = []; + + // Compile all selected parts from the page. + for (let [key, value] of Object.entries(this.glassParts)) { + for (let [glassKey, glassValue] of Object.entries(value)) { + selectedGlassPartNumbers.push(glassValue[0]); + } + } + + // Match them to the parts from the API. + for (let [key, value] of Object.entries(this.PartsFromApi.partsOrQuestions)) { + for (let [partKey, partValue] of Object.entries(value.parts)) { + const currentPart = this.PartsFromApi.partsOrQuestions[key].parts[partKey]; + const isMatched = selectedGlassPartNumbers.some(p => p === currentPart.partNumber); + + if (isMatched) { + matchedParts.push(currentPart); + } + } + } + + // If no parts could be matched, throw an error. + if(matchedParts.length === 0) { + throw new Error("Could not match any parts to the selected parts"); + } + } },