mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-42): add Product API and form validation schema with product flags
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
import * as Yup from 'yup';
|
||||||
|
|
||||||
|
export const ProductFormSchema = Yup.object({
|
||||||
|
name: Yup.string().required('Nama wajib diisi!'),
|
||||||
|
brand: Yup.string().required('Merek wajib diisi!'),
|
||||||
|
sku: Yup.string().required('SKU wajib diisi!'),
|
||||||
|
uom: Yup.object({
|
||||||
|
value: Yup.number().min(1).required(),
|
||||||
|
label: Yup.string().required(),
|
||||||
|
}).nullable(),
|
||||||
|
uom_id: Yup.number().required('Satuan wajib diisi!').typeError('Satuan wajib diisi!'),
|
||||||
|
product_category: Yup.object({
|
||||||
|
value: Yup.number().min(1).required(),
|
||||||
|
label: Yup.string().required(),
|
||||||
|
}).nullable(),
|
||||||
|
product_category_id: Yup.number()
|
||||||
|
.required('Kategori produk wajib diisi!')
|
||||||
|
.typeError('Kategori produk wajib diisi!'),
|
||||||
|
product_price: Yup.number()
|
||||||
|
.required('Harga produk wajib diisi!')
|
||||||
|
.typeError('Harga produk wajib diisi!')
|
||||||
|
.min(0, 'Harga produk tidak boleh kurang dari 0!'),
|
||||||
|
selling_price: Yup.number()
|
||||||
|
.required('Harga jual wajib diisi!')
|
||||||
|
.typeError('Harga jual wajib diisi!')
|
||||||
|
.min(0, 'Harga jual tidak boleh kurang dari 0!'),
|
||||||
|
tax: Yup.number()
|
||||||
|
.required('Pajak wajib diisi!')
|
||||||
|
.typeError('Pajak wajib diisi!')
|
||||||
|
.min(0, 'Pajak tidak boleh kurang dari 0!')
|
||||||
|
.max(100, 'Pajak tidak boleh lebih dari 100%!'),
|
||||||
|
expiry_period: Yup.number()
|
||||||
|
.required('Periode kadaluarsa wajib diisi!')
|
||||||
|
.typeError('Periode kadaluarsa wajib diisi!')
|
||||||
|
.min(0, 'Periode kadaluarsa tidak boleh kurang dari 0!'),
|
||||||
|
supplier: Yup.object({
|
||||||
|
value: Yup.number().min(1).required(),
|
||||||
|
label: Yup.string().required(),
|
||||||
|
}).nullable(),
|
||||||
|
supplier_ids: Yup.array()
|
||||||
|
.of(Yup.number().typeError('Supplier tidak valid!'))
|
||||||
|
.min(1, 'Minimal harus ada 1 supplier!')
|
||||||
|
.required('Supplier wajib diisi!'),
|
||||||
|
flags: Yup.array()
|
||||||
|
.of(Yup.string())
|
||||||
|
.min(1, 'Minimal harus ada 1 flag!')
|
||||||
|
.required('Flag wajib diisi!'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const UpdateProductFormSchema = ProductFormSchema;
|
||||||
|
|
||||||
|
export type ProductFormValues = Yup.InferType<typeof ProductFormSchema>;
|
||||||
|
|
||||||
@@ -107,3 +107,16 @@ export const WAREHOUSE_TYPE_OPTIONS = [
|
|||||||
value: 'KANDANG',
|
value: 'KANDANG',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const PRODUCT_FLAG_OPTIONS = [
|
||||||
|
{ label: 'DOC', value: 'DOC' },
|
||||||
|
{ label: 'PAKAN', value: 'PAKAN' },
|
||||||
|
{ label: 'PRE-STARTER', value: 'PRE-STARTER' },
|
||||||
|
{ label: 'STARTER', value: 'STARTER' },
|
||||||
|
{ label: 'FINISHER', value: 'FINISHER' },
|
||||||
|
{ label: 'OVK', value: 'OVK' },
|
||||||
|
{ label: 'OBAT', value: 'OBAT' },
|
||||||
|
{ label: 'VITAMIN', value: 'VITAMIN' },
|
||||||
|
{ label: 'KIMIA', value: 'KIMIA' },
|
||||||
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ import {
|
|||||||
ProductCategory,
|
ProductCategory,
|
||||||
UpdateProductCategoryPayload,
|
UpdateProductCategoryPayload,
|
||||||
} from '@/types/api/master-data/product-category';
|
} from '@/types/api/master-data/product-category';
|
||||||
|
import {
|
||||||
|
CreateProductPayload,
|
||||||
|
Product,
|
||||||
|
UpdateProductPayload,
|
||||||
|
} from '@/types/api/master-data/product';
|
||||||
|
|
||||||
export const UomApi = new BaseApiService<
|
export const UomApi = new BaseApiService<
|
||||||
Uom,
|
Uom,
|
||||||
@@ -64,4 +69,10 @@ export const ProductCategoryApi = new BaseApiService<
|
|||||||
ProductCategory,
|
ProductCategory,
|
||||||
CreateProductCategoryPayload,
|
CreateProductCategoryPayload,
|
||||||
UpdateProductCategoryPayload
|
UpdateProductCategoryPayload
|
||||||
>('/master-data/product-categories');
|
>('/master-data/product-categories');
|
||||||
|
|
||||||
|
export const ProductApi = new BaseApiService<
|
||||||
|
Product,
|
||||||
|
CreateProductPayload,
|
||||||
|
UpdateProductPayload
|
||||||
|
>('/master-data/products');
|
||||||
|
|||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
import { BaseMetadata } from '@/types/api/api-general';
|
||||||
|
import { Uom } from '@/types/api/master-data/uom';
|
||||||
|
import { ProductCategory } from '@/types/api/master-data/product-category';
|
||||||
|
import { Supplier } from '@/types/api/master-data/supplier';
|
||||||
|
|
||||||
|
export type BaseProduct = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
brand: string;
|
||||||
|
sku: string;
|
||||||
|
product_price: number;
|
||||||
|
selling_price?: number;
|
||||||
|
tax?: number;
|
||||||
|
expiry_period: number;
|
||||||
|
uom: Uom;
|
||||||
|
product_category: ProductCategory;
|
||||||
|
suppliers: Supplier[];
|
||||||
|
flags: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Product = BaseMetadata & BaseProduct;
|
||||||
|
|
||||||
|
export type CreateProductPayload = {
|
||||||
|
name: string;
|
||||||
|
brand: string;
|
||||||
|
sku: string;
|
||||||
|
uom_id: number;
|
||||||
|
product_category_id: number;
|
||||||
|
product_price: number;
|
||||||
|
selling_price: number;
|
||||||
|
tax: number;
|
||||||
|
expiry_period: number;
|
||||||
|
supplier_ids: number[];
|
||||||
|
flags: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UpdateProductPayload = CreateProductPayload;
|
||||||
Reference in New Issue
Block a user