mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-435,436): Add location_id to expense form and payload
This commit is contained in:
@@ -11,6 +11,7 @@ type ExpenseFormSchemaType = {
|
||||
value: number;
|
||||
label: string;
|
||||
};
|
||||
location_id: number;
|
||||
transaction_date?: string;
|
||||
kandangs?: { id: number; name: string }[];
|
||||
supplier?: {
|
||||
@@ -46,6 +47,8 @@ export const ExpenseRequestFormSchema: Yup.ObjectSchema<ExpenseFormSchemaType> =
|
||||
label: Yup.string().required(),
|
||||
}).required('Lokasi wajib diisi!'),
|
||||
|
||||
location_id: Yup.number().min(1).required('Lokasi wajib diisi!'),
|
||||
|
||||
transaction_date: Yup.string().required('Tanggal transaksi wajib diisi!'),
|
||||
kandangs: Yup.array()
|
||||
.of(
|
||||
@@ -128,6 +131,7 @@ export const getExpenseFormInitialValues = (
|
||||
label: initialValues.location.name,
|
||||
}
|
||||
: undefined,
|
||||
location_id: Number(initialValues?.location.id || 0),
|
||||
transaction_date: initialValues?.transaction_date
|
||||
? formatDate(initialValues.transaction_date, 'YYYY-MM-DD')
|
||||
: undefined,
|
||||
|
||||
@@ -108,6 +108,7 @@ const ExpenseRequestForm = ({
|
||||
|
||||
const expensePayload: CreateExpensePayload = {
|
||||
category: formik.values.category?.value as 'BOP' | 'NON-BOP',
|
||||
location_id: values.location_id as number,
|
||||
transaction_date: values?.transaction_date as string,
|
||||
supplier_id: values.supplier?.value as number,
|
||||
documents: values.documents as File[],
|
||||
@@ -130,6 +131,7 @@ const ExpenseRequestForm = ({
|
||||
case 'edit':
|
||||
const expenseUpdatePayload: UpdateExpensePayload = {
|
||||
category: formik.values.category?.value as 'BOP' | 'NON-BOP',
|
||||
location_id: values.location_id as number,
|
||||
transaction_date: values?.transaction_date as string,
|
||||
supplier_id: values.supplier?.value as number,
|
||||
documents: values.documents as File[],
|
||||
@@ -179,6 +181,9 @@ const ExpenseRequestForm = ({
|
||||
formik.setFieldTouched('location', true);
|
||||
formik.setFieldValue('location', val);
|
||||
|
||||
const locationId = Array.isArray(val) ? val[0]?.value : val?.value;
|
||||
formik.setFieldValue('location_id', locationId);
|
||||
|
||||
formik.setFieldValue('kandangs', []);
|
||||
formik.setFieldValue('expense_nonstocks', []);
|
||||
};
|
||||
@@ -454,7 +459,9 @@ const ExpenseRequestForm = ({
|
||||
)}
|
||||
|
||||
<ExpenseRequestKandangDetailExpense
|
||||
type={type}
|
||||
formik={formik}
|
||||
supplierId={formik.values.supplier?.value as number}
|
||||
className={{
|
||||
wrapper: 'col-span-12',
|
||||
}}
|
||||
|
||||
@@ -21,6 +21,7 @@ import { removeArrayItemAndSync } from '@/lib/utils/formik';
|
||||
interface ExpenseRequestKandangDetailExpenseProps {
|
||||
type?: 'add' | 'edit' | 'detail';
|
||||
formik: FormikContextType<ExpenseRequestFormValues>;
|
||||
supplierId?: number;
|
||||
className?: {
|
||||
wrapper?: string;
|
||||
};
|
||||
@@ -28,12 +29,18 @@ interface ExpenseRequestKandangDetailExpenseProps {
|
||||
|
||||
const ExpenseRequestKandangDetailExpense: React.FC<
|
||||
ExpenseRequestKandangDetailExpenseProps
|
||||
> = ({ type, formik, className }) => {
|
||||
> = ({ type, formik, supplierId, className }) => {
|
||||
const {
|
||||
setInputValue: setNonstockInputValue,
|
||||
options: nonstockOptions,
|
||||
isLoadingOptions: isLoadingNonstockOptions,
|
||||
} = useSelect<Nonstock>(NonstockApi.basePath, 'id', 'name');
|
||||
} = useSelect<Nonstock>(
|
||||
NonstockApi.basePath,
|
||||
'id',
|
||||
'name',
|
||||
'search',
|
||||
supplierId ? { supplier_id: String(supplierId) } : undefined
|
||||
);
|
||||
|
||||
const nonstockChangeHandler = (
|
||||
kandangExpenseIdx: number,
|
||||
|
||||
@@ -483,6 +483,7 @@ export class ExpenseApiService extends BaseApiService<
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append('category', payload.category);
|
||||
formData.append('location_id', String(payload.location_id));
|
||||
formData.append('transaction_date', payload.transaction_date);
|
||||
formData.append('supplier_id', String(payload.supplier_id));
|
||||
|
||||
@@ -505,6 +506,7 @@ export class ExpenseApiService extends BaseApiService<
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append('category', payload.category);
|
||||
formData.append('location_id', String(payload.location_id));
|
||||
formData.append('transaction_date', payload.transaction_date);
|
||||
formData.append('supplier_id', String(payload.supplier_id));
|
||||
|
||||
|
||||
Vendored
+2
@@ -57,6 +57,7 @@ export type Expense = BaseMetadata & BaseExpense;
|
||||
|
||||
export type CreateExpensePayload = {
|
||||
category: 'BOP' | 'NON-BOP';
|
||||
location_id: number;
|
||||
transaction_date: string;
|
||||
supplier_id: number;
|
||||
documents: File[];
|
||||
@@ -72,6 +73,7 @@ export type CreateExpensePayload = {
|
||||
};
|
||||
|
||||
export type UpdateExpensePayload = {
|
||||
location_id: number;
|
||||
category: 'BOP' | 'NON-BOP';
|
||||
transaction_date: string;
|
||||
supplier_id: number;
|
||||
|
||||
Reference in New Issue
Block a user