Add fallback handling and new statuses for vehicles
Updated `getProductName` to support a fallback value for unknown products. Enhanced vehicle logic to handle and display "unknown" vehicles in UI with proper categorization. Added error handling and user feedback using SweetAlert2 for subscription actions.
This commit is contained in:
@@ -308,8 +308,9 @@ const getIconColor = (scan) => {
|
||||
// Determine the icon color based on the vehicle's status
|
||||
const colors = {
|
||||
verified: 'has-text-success', // Used when the vehicles owner is verified
|
||||
unverified: 'has-text-warning', // Used when the vehicles owner is unverified
|
||||
unverified: 'has-text-warning', // Used when the vehicles owner is unverified, but the vehicle has previously been used in a transaction
|
||||
barred: 'has-text-danger', // Used when the vehicles owner is barred
|
||||
unknown: 'has-text-grey', // Used when the vehicle has never been registered
|
||||
}
|
||||
let iconColor = colors.unverified; // Default color
|
||||
|
||||
@@ -321,6 +322,13 @@ const getIconColor = (scan) => {
|
||||
function isBarred(vehicle) {
|
||||
return !!vehicle.barred;
|
||||
}
|
||||
// Check if the vehicle is unknown
|
||||
function isUnknown(vehicle) {
|
||||
return !vehicle.seen_before;
|
||||
}
|
||||
if (isUnknown(scan)) {
|
||||
iconColor = colors.unknown;
|
||||
}
|
||||
if (isVerified(scan)) {
|
||||
iconColor = colors.verified;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ const isVehicleAddonApplied = (addon) => {
|
||||
:editFunction="SessionUser.objects.vehicles.showEditObjectFieldForm"
|
||||
column="type"
|
||||
:parse-function="(value) => {
|
||||
return SessionUser.objects.products.functions.getProductName(value);
|
||||
return SessionUser.objects.products.functions.getProductName(value, 'Ukendt');
|
||||
}"
|
||||
/>
|
||||
<!-- Wash Subscription -->
|
||||
|
||||
@@ -14,9 +14,10 @@ export const products_cache = ref(null);
|
||||
/**
|
||||
* Get the product name
|
||||
* @param id
|
||||
* @param fallback
|
||||
* @returns {string}
|
||||
*/
|
||||
export const getProductName = (id) => {
|
||||
export const getProductName = (id, fallback = null) => {
|
||||
if (products_cache.value === null) {
|
||||
products_cache.value = [];
|
||||
SessionUser.objects.products.get.all().then((products) => {
|
||||
@@ -24,7 +25,7 @@ export const getProductName = (id) => {
|
||||
});
|
||||
}
|
||||
const product = products_cache.value.find((product) => product.id === parseInt(id));
|
||||
return product ? product.name : SessionUser.objects.global.language.no_data;
|
||||
return product ? product.name : fallback === null ? SessionUser.objects.global.language.no_data : fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script>
|
||||
import {ObjectsGlobal} from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
|
||||
import {SessionUser} from "@/components/session/token/SessionUser.vue";
|
||||
import Swal from "sweetalert2";
|
||||
|
||||
|
||||
/**
|
||||
@@ -37,6 +38,11 @@ export const Vehicles = {
|
||||
// Get all the products, that has 'subscription_allowed' set to true
|
||||
let products = await SessionUser.objects.products.get.all();
|
||||
products = products.filter((product) => product.subscription_allowed === true && product.category !== 4);
|
||||
// Add a default option (0, unknown)
|
||||
products.unshift({
|
||||
id: 0,
|
||||
name: "Ukendt"
|
||||
});
|
||||
// Map the products to the options
|
||||
return products.map((product) => {
|
||||
return {
|
||||
@@ -113,7 +119,14 @@ export const Vehicles = {
|
||||
id,
|
||||
"wash_subscription",
|
||||
ObjectsGlobal.parse.boolean(wash_subscription)
|
||||
)
|
||||
).catch((error) => {
|
||||
Swal.fire({
|
||||
title: "Fejl",
|
||||
text: error.response.data.data.message,
|
||||
icon: "error",
|
||||
});
|
||||
throw error;
|
||||
});
|
||||
},
|
||||
reference: async (id, reference) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
|
||||
@@ -36,6 +36,7 @@ const slots = defineSlots()
|
||||
{{ title }}
|
||||
</span>
|
||||
<!-- Page subtitle (If any) -->
|
||||
<!--
|
||||
<span
|
||||
class="is-size-6"
|
||||
v-if="subtitle"
|
||||
@@ -43,6 +44,7 @@ const slots = defineSlots()
|
||||
>
|
||||
{{ subtitle }}
|
||||
</span>
|
||||
-->
|
||||
</div>
|
||||
<!-- Header slot -->
|
||||
<div class="column">
|
||||
|
||||
Reference in New Issue
Block a user