Initial attempt to extract vin-capture business logic
This commit is contained in:
parent
749db4c06c
commit
8085759892
2 changed files with 32 additions and 26 deletions
|
|
@ -37,17 +37,17 @@
|
||||||
@focus="$emit('focus', $event.target.value)" />
|
@focus="$emit('focus', $event.target.value)" />
|
||||||
<button v-if="includeSearchIcon" type="submit" aria-label="Search button" />
|
<button v-if="includeSearchIcon" type="submit" aria-label="Search button" />
|
||||||
<template v-if="!isDisabled">
|
<template v-if="!isDisabled">
|
||||||
<label class="camera-icon-input" v-show="includeCameraIcon && !isLoading">
|
<label class="camera-icon-input" v-show="includeCameraIcon && !isImageLoading">
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
id="vin-input"
|
id="vin-input"
|
||||||
accept="image/jpeg,image/png"
|
accept="image/jpeg,image/png"
|
||||||
aria-label="Camera icon/button"
|
aria-label="Camera icon/button"
|
||||||
data-test="image-upload"
|
data-test="image-upload"
|
||||||
@change="submitImage" />
|
@change="imageChanged" />
|
||||||
</label>
|
</label>
|
||||||
<loader
|
<loader
|
||||||
v-show="includeCameraIcon && isLoading"
|
v-show="includeCameraIcon && isImageLoading"
|
||||||
loaderColor="blue"
|
loaderColor="blue"
|
||||||
class="loading-icon"></loader>
|
class="loading-icon"></loader>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -93,12 +93,12 @@ export default {
|
||||||
cornerStyle: String, // Rounded or square. Square is default.
|
cornerStyle: String, // Rounded or square. Square is default.
|
||||||
includeSearchIcon: Boolean,
|
includeSearchIcon: Boolean,
|
||||||
includeCameraIcon: Boolean,
|
includeCameraIcon: Boolean,
|
||||||
|
isImageLoading: Boolean,
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const propsClone = Object.assign({}, props);
|
const propsClone = Object.assign({}, props);
|
||||||
const modelValue = propsClone.modelValue;
|
const modelValue = propsClone.modelValue;
|
||||||
let initialValue;
|
let initialValue;
|
||||||
let isLoading = ref(false);
|
|
||||||
|
|
||||||
switch (typeof modelValue) {
|
switch (typeof modelValue) {
|
||||||
case "number":
|
case "number":
|
||||||
|
|
@ -128,29 +128,11 @@ export default {
|
||||||
validate,
|
validate,
|
||||||
meta,
|
meta,
|
||||||
errors,
|
errors,
|
||||||
isLoading,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async submitImage(e) {
|
imageChanged(e) {
|
||||||
this.isLoading = true;
|
this.$emit("fileChanged", e.target.files[0]);
|
||||||
await this.dispatchStoreAction(storeActions.LOOKUP_VIN_BY_IMAGE, e.target.files[0])
|
|
||||||
.then(async (response) => {
|
|
||||||
if (response.data.length > 0) {
|
|
||||||
this.value = response.data[0];
|
|
||||||
|
|
||||||
// Wait for DOM to update before firing change event to handle validation.
|
|
||||||
await this.$nextTick();
|
|
||||||
|
|
||||||
document.getElementById(this.inputId).dispatchEvent(new Event("change"));
|
|
||||||
} else {
|
|
||||||
this.$emit("imageLookupError");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
this.$emit("imageLookupError");
|
|
||||||
});
|
|
||||||
this.isLoading = false;
|
|
||||||
e.target.value = null;
|
e.target.value = null;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,11 @@
|
||||||
:isDisabled="vinPopulatedOnPageLoad"
|
:isDisabled="vinPopulatedOnPageLoad"
|
||||||
maxLength="17"
|
maxLength="17"
|
||||||
includeCameraIcon
|
includeCameraIcon
|
||||||
|
@file-changed="submitImage"
|
||||||
:mask="vinMask"
|
:mask="vinMask"
|
||||||
@image-lookup-error="displayVinScanAlert"
|
:isImageLoading="isVinLoading"
|
||||||
data-test="vin-lookup-field" />
|
data-test="vin-lookup-field"
|
||||||
|
ref="vinLookupQuestion" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -199,6 +201,7 @@ export default {
|
||||||
displayVinNotFoundAlert: false,
|
displayVinNotFoundAlert: false,
|
||||||
displayMatchedDifferentVehicleAlert: false,
|
displayMatchedDifferentVehicleAlert: false,
|
||||||
displayVinScanFailedAlert: false,
|
displayVinScanFailedAlert: false,
|
||||||
|
isVinLoading: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -395,6 +398,27 @@ export default {
|
||||||
displayVinScanAlert() {
|
displayVinScanAlert() {
|
||||||
this.displayVinScanFailedAlert = true;
|
this.displayVinScanFailedAlert = true;
|
||||||
},
|
},
|
||||||
|
async submitImage(e) {
|
||||||
|
this.isVinLoading = true;
|
||||||
|
await this.dispatchStoreAction(storeActions.LOOKUP_VIN_BY_IMAGE, e)
|
||||||
|
.then(async (response) => {
|
||||||
|
if (response.data.length > 0) {
|
||||||
|
const result = response.data[0];
|
||||||
|
|
||||||
|
this.vin = result;
|
||||||
|
|
||||||
|
this.$refs.vinLookupQuestion.handleChange(result);
|
||||||
|
|
||||||
|
this.resetAlerts();
|
||||||
|
} else {
|
||||||
|
this.displayVinScanAlert();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
this.displayVinScanAlert();
|
||||||
|
});
|
||||||
|
this.isVinLoading = false;
|
||||||
|
},
|
||||||
resetAlerts() {
|
resetAlerts() {
|
||||||
this.displayMatchedDifferentVehicleAlert = false;
|
this.displayMatchedDifferentVehicleAlert = false;
|
||||||
this.displayNonServiceableZipAlert = false;
|
this.displayNonServiceableZipAlert = false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue