mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
refactor: update CreateExpensePayload, UpdateExpensePayload, and CreateExpenseRealizationPayload types
This commit is contained in:
@@ -41,28 +41,28 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
||||
val: OptionType | OptionType[] | null
|
||||
) => {
|
||||
formik.setFieldTouched(
|
||||
`cost_per_kandangs[${kandangExpenseIdx}].cost_items[${expenseIdx}].nonstock`,
|
||||
`expense_nonstocks[${kandangExpenseIdx}].cost_items[${expenseIdx}].nonstock`,
|
||||
true
|
||||
);
|
||||
formik.setFieldValue(
|
||||
`cost_per_kandangs[${kandangExpenseIdx}].cost_items[${expenseIdx}].nonstock`,
|
||||
`expense_nonstocks[${kandangExpenseIdx}].cost_items[${expenseIdx}].nonstock`,
|
||||
val
|
||||
);
|
||||
};
|
||||
|
||||
const addExpenseItemHandler = (kandangExpenseIdx: number) => {
|
||||
const newExpensesValue = [
|
||||
...formik.values.cost_per_kandangs[kandangExpenseIdx].cost_items,
|
||||
...formik.values.expense_nonstocks[kandangExpenseIdx].cost_items,
|
||||
{
|
||||
nonstock: undefined,
|
||||
total_cost: undefined,
|
||||
price: undefined,
|
||||
quantity: undefined,
|
||||
notes: '',
|
||||
},
|
||||
];
|
||||
|
||||
formik.setFieldValue(
|
||||
`cost_per_kandangs[${kandangExpenseIdx}].cost_items`,
|
||||
`expense_nonstocks[${kandangExpenseIdx}].cost_items`,
|
||||
newExpensesValue
|
||||
);
|
||||
};
|
||||
@@ -71,28 +71,28 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
||||
kandangExpenseIdx: number,
|
||||
expenseIdx: number
|
||||
) => {
|
||||
const path = `cost_per_kandangs[${kandangExpenseIdx}].cost_items`;
|
||||
const path = `expense_nonstocks[${kandangExpenseIdx}].cost_items`;
|
||||
|
||||
// trims values, errors, and touched at expenseIdx
|
||||
removeArrayItemAndSync(formik, path, expenseIdx);
|
||||
};
|
||||
|
||||
const isExpenseRepeaterInputError = (
|
||||
column: 'nonstock' | 'quantity' | 'total_cost' | 'notes',
|
||||
column: 'nonstock' | 'quantity' | 'price' | 'notes',
|
||||
kandangExpenseIdx: number,
|
||||
expenseIdx: number
|
||||
) => {
|
||||
return (
|
||||
formik.touched.cost_per_kandangs?.[kandangExpenseIdx]?.cost_items?.[
|
||||
formik.touched.expense_nonstocks?.[kandangExpenseIdx]?.cost_items?.[
|
||||
expenseIdx
|
||||
]?.[column] &&
|
||||
Boolean(
|
||||
formik.errors.cost_per_kandangs?.[kandangExpenseIdx] instanceof
|
||||
formik.errors.expense_nonstocks?.[kandangExpenseIdx] instanceof
|
||||
Object &&
|
||||
formik.errors.cost_per_kandangs?.[kandangExpenseIdx].cost_items?.[
|
||||
formik.errors.expense_nonstocks?.[kandangExpenseIdx].cost_items?.[
|
||||
expenseIdx
|
||||
] instanceof Object &&
|
||||
formik.errors.cost_per_kandangs?.[kandangExpenseIdx].cost_items?.[
|
||||
formik.errors.expense_nonstocks?.[kandangExpenseIdx].cost_items?.[
|
||||
expenseIdx
|
||||
]?.[column]
|
||||
)
|
||||
@@ -113,7 +113,7 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
||||
</div>
|
||||
|
||||
<div className='w-full flex flex-col gap-6'>
|
||||
{(formik.values.cost_per_kandangs.length === 0 ||
|
||||
{(formik.values.expense_nonstocks.length === 0 ||
|
||||
!formik.values.supplier?.value) && (
|
||||
<div>
|
||||
<p className='text-sm text-gray-400 text-center'>
|
||||
@@ -122,9 +122,9 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
||||
</div>
|
||||
)}
|
||||
|
||||
{formik.values.cost_per_kandangs.length > 0 &&
|
||||
{formik.values.expense_nonstocks.length > 0 &&
|
||||
formik.values.supplier?.value &&
|
||||
formik.values.cost_per_kandangs.map(
|
||||
formik.values.expense_nonstocks.map(
|
||||
(kandangExpense, kandangExpenseIdx) => {
|
||||
const kandangName = formik.values.kandangs?.find(
|
||||
(kandang) => kandang.id === kandangExpense.kandang_id
|
||||
@@ -147,7 +147,7 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
||||
<tr>
|
||||
<th>Nonstock</th>
|
||||
<th>Total Kuantitas</th>
|
||||
<th>Total Biaya</th>
|
||||
<th>Harga Satuan</th>
|
||||
<th>Catatan</th>
|
||||
{type !== 'detail' && <th>Aksi</th>}
|
||||
</tr>
|
||||
@@ -178,10 +178,10 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
||||
<td className='p-2'>
|
||||
<NumberInput
|
||||
required
|
||||
name={`cost_per_kandangs[${kandangExpenseIdx}].cost_items[${expenseIdx}].quantity`}
|
||||
name={`expense_nonstocks[${kandangExpenseIdx}].cost_items[${expenseIdx}].quantity`}
|
||||
placeholder='Masukkan Total Kuantitas'
|
||||
value={
|
||||
formik.values.cost_per_kandangs[
|
||||
formik.values.expense_nonstocks[
|
||||
kandangExpenseIdx
|
||||
].cost_items[expenseIdx].quantity ?? ''
|
||||
}
|
||||
@@ -198,18 +198,17 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
||||
|
||||
<td className='p-2'>
|
||||
<NumberInput
|
||||
name={`cost_per_kandangs[${kandangExpenseIdx}].cost_items[${expenseIdx}].total_cost`}
|
||||
placeholder='Masukkan Total Biaya'
|
||||
name={`expense_nonstocks[${kandangExpenseIdx}].cost_items[${expenseIdx}].price`}
|
||||
placeholder='Masukkan Harga Satuan'
|
||||
value={
|
||||
formik.values.cost_per_kandangs[
|
||||
formik.values.expense_nonstocks[
|
||||
kandangExpenseIdx
|
||||
].cost_items[expenseIdx].total_cost ??
|
||||
''
|
||||
].cost_items[expenseIdx].price ?? ''
|
||||
}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
isError={isExpenseRepeaterInputError(
|
||||
'total_cost',
|
||||
'price',
|
||||
kandangExpenseIdx,
|
||||
expenseIdx
|
||||
)}
|
||||
@@ -224,10 +223,10 @@ const ExpenseRequestKandangDetailExpense: React.FC<
|
||||
|
||||
<td className='p-2'>
|
||||
<TextInput
|
||||
name={`cost_per_kandangs[${kandangExpenseIdx}].cost_items[${expenseIdx}].notes`}
|
||||
name={`expense_nonstocks[${kandangExpenseIdx}].cost_items[${expenseIdx}].notes`}
|
||||
placeholder='Tuliskan catatan'
|
||||
value={
|
||||
formik.values.cost_per_kandangs[
|
||||
formik.values.expense_nonstocks[
|
||||
kandangExpenseIdx
|
||||
].cost_items[expenseIdx].notes ?? ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user