mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-26 00:05:45 +00:00
refactor(FE): Treat kandang_id as optional and use expense id
This commit is contained in:
@@ -73,7 +73,14 @@ export const ExpenseRealizationFormSchema: Yup.ObjectSchema<ExpenseRealizationFo
|
|||||||
realizations: Yup.array()
|
realizations: Yup.array()
|
||||||
.of(
|
.of(
|
||||||
Yup.object({
|
Yup.object({
|
||||||
kandang_id: Yup.number().min(1, 'Wajib memilih kandang!').optional(),
|
kandang_id: Yup.number()
|
||||||
|
.optional()
|
||||||
|
.test('valid-kandang-id', 'Wajib memilih kandang!', (value) => {
|
||||||
|
if (value === undefined || value === null || value === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return value >= 1;
|
||||||
|
}),
|
||||||
cost_items: Yup.array()
|
cost_items: Yup.array()
|
||||||
.of(
|
.of(
|
||||||
Yup.object({
|
Yup.object({
|
||||||
@@ -175,7 +182,7 @@ export const getExpenseRealizationFormInitialValues = (
|
|||||||
: [];
|
: [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
kandang_id: kandangExpense.kandang_id,
|
kandang_id: kandangExpense.id,
|
||||||
cost_items: costItemsInitialValue,
|
cost_items: costItemsInitialValue,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -101,13 +101,23 @@ const ExpenseRealizationForm = ({
|
|||||||
|
|
||||||
values.realizations.forEach((realization) => {
|
values.realizations.forEach((realization) => {
|
||||||
realization.cost_items.forEach((costItem) => {
|
realization.cost_items.forEach((costItem) => {
|
||||||
const realizationItem = {
|
const realizationItem: {
|
||||||
|
expense_nonstock_id: number;
|
||||||
|
qty: number;
|
||||||
|
price: number;
|
||||||
|
notes: string;
|
||||||
|
kandang_id?: number;
|
||||||
|
} = {
|
||||||
expense_nonstock_id: costItem.nonstock?.value as number,
|
expense_nonstock_id: costItem.nonstock?.value as number,
|
||||||
qty: parseFloat(String(costItem.quantity)) as number,
|
qty: parseFloat(String(costItem.quantity)) as number,
|
||||||
price: parseFloat(String(costItem.price)) as number,
|
price: parseFloat(String(costItem.price)) as number,
|
||||||
notes: costItem.notes ?? '',
|
notes: costItem.notes ?? '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (realization.kandang_id && realization.kandang_id > 0) {
|
||||||
|
realizationItem.kandang_id = realization.kandang_id;
|
||||||
|
}
|
||||||
|
|
||||||
realizations.push(realizationItem);
|
realizations.push(realizationItem);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user