ASPNetCore/Next/lib/product.ts

41 lines
957 B
TypeScript
Raw Normal View History

2021-03-29 07:08:26 +00:00
import { ProductListItem } from "../APIClient";
export interface ProductDataProps {
productID: string,
}
export interface DeleteProductProps extends ProductDataProps {
onDelete: (val) => void
}
export interface ProductListRowsProps {
products: ProductListItem[],
onDelete: (val) => void,
}
export interface ProductState {
product: ProductListItem[]
}
2021-03-29 09:53:55 +00:00
export interface ProductFormEntry {
name: string,
price: number,
}
2021-03-29 07:08:26 +00:00
export interface ProductFormState {
2021-03-29 09:53:55 +00:00
form: ProductFormEntry,
2021-03-29 07:08:26 +00:00
errors: string[],
busy: boolean,
2021-03-29 07:40:58 +00:00
}
2021-03-29 09:53:55 +00:00
export function validateForm(form: ProductFormEntry) {
let errors: {name: string[],price: string[]} = {
name: [],
price: [],
};
2021-03-29 07:40:58 +00:00
if (!form.name) {
2021-03-29 09:53:55 +00:00
errors.name.push("Name required");
2021-03-29 07:40:58 +00:00
}
if (!form.price) {
2021-03-29 09:53:55 +00:00
errors.price.push("Price required");
}
if (form.price < 0) {
errors.price.push("Price must be positive");
2021-03-29 07:40:58 +00:00
}
return errors;
2021-03-29 07:08:26 +00:00
}