refactor(FE): Allow null for select fields and track id fields

This commit is contained in:
rstubryan
2026-01-12 14:12:12 +07:00
parent 8516929056
commit bf834cf79b
3 changed files with 90 additions and 38 deletions
@@ -204,7 +204,8 @@ const ExpenseRequestForm = ({
{
cost_items: [
{
nonstock: undefined,
nonstock: null,
nonstock_id: 0,
quantity: undefined,
price: undefined,
notes: '',
@@ -226,7 +227,8 @@ const ExpenseRequestForm = ({
{
cost_items: [
{
nonstock: undefined,
nonstock: null,
nonstock_id: 0,
quantity: undefined,
price: undefined,
notes: '',
@@ -251,7 +253,8 @@ const ExpenseRequestForm = ({
kandang_id: kandangItem.id,
cost_items: existingExpenseNonstock?.cost_items || [
{
nonstock: undefined,
nonstock: null,
nonstock_id: 0,
quantity: undefined,
price: undefined,
notes: '',
@@ -266,10 +269,20 @@ const ExpenseRequestForm = ({
const supplierChangeHandler = (val: OptionType | OptionType[] | null) => {
formik.setFieldTouched('supplier', true);
formik.setFieldValue('supplier', val);
const supplierId = Array.isArray(val) ? val[0]?.value : val?.value;
formik.setFieldValue('supplier_id', supplierId ?? 0);
};
const requestDocumentsChangeHandler = (val: File[]) => {
formik.setFieldTouched('documents', true);
const invalidFiles = val.filter((file) => file.size > 5 * 1024 * 1024);
if (invalidFiles.length > 0) {
toast.error('Ukuran dokumen maksimal 5 MB!');
return;
}
formik.setFieldValue('documents', val);
};
@@ -585,7 +598,7 @@ const ExpenseRequestForm = ({
type='submit'
color='primary'
isLoading={formik.isSubmitting}
disabled={!formik.isValid || formik.isSubmitting}
disabled={formik.isSubmitting}
className='px-4'
>
Submit