CEC-3086 Allow creating filters without interval (#237)

This commit is contained in:
arpanetus
2022-11-22 04:22:36 +06:00
committed by GitHub
parent 9888ab8a6c
commit 1ecc8943a3
15 changed files with 430 additions and 446 deletions

View File

@@ -1,5 +1,6 @@
import React, { useContext, useState } from "react";
import api from "../../services/fleetsAPI";
import { validateCANID, validateFilter, validateVIN } from "../../utils/validationSupplier";
const FleetContext = React.createContext();
@@ -200,7 +201,6 @@ export const FleetProvider = ({ children }) => {
setBusy(true);
validateFleetName(name);
validateCANID(can_id);
validateFilter(filter);
const result = await api.updateFleetCANFilter(name, can_id, filter, token);
@@ -278,30 +278,6 @@ const validateFleetName = (name) => {
if (name == null || !/^[\w-]+$/.test(name)) {
throw new Error("Invalid name");
}
}
const validateVIN = (vin) => {
if (vin == null || vin.length !== 17) {
throw new Error("Invalid VIN");
}
}
const validateFilter = (filter) => {
if (filter == null) {
throw new Error("No CAN filter data");
}
validateCANID(filter.can_id)
if (filter.interval == null || !/^\d+$/.test(filter.interval)) {
throw new Error("Invalid interval");
}
}
const validateCANID = (can_id) => {
if (can_id == null || !/^\d+(-\d+)?$/.test(can_id)) {
throw new Error("Invalid CAN ID");
}
}
};
export const useFleetContext = () => useContext(FleetContext);