mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat: create FinanceForm schema
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
'use client';
|
||||
import * as Yup from 'yup';
|
||||
|
||||
import { OptionType } from '@/components/input/SelectInput';
|
||||
import { CreateFinancePayload } from '@/types/api/finance';
|
||||
|
||||
export const FinanceFormSchema = Yup.object().shape({
|
||||
transactionType: Yup.object()
|
||||
.shape({
|
||||
value: Yup.string().required(),
|
||||
label: Yup.string().required(),
|
||||
})
|
||||
.nullable()
|
||||
.required('Jenis Transaksi Wajib diisi'),
|
||||
customerId: Yup.number()
|
||||
.nullable()
|
||||
.when('transactionType', {
|
||||
is: (val: { value: string }) => val?.value === 'REVENUE',
|
||||
then: (schema) => schema.required('Customer Wajib diisi'),
|
||||
otherwise: (schema) => schema.notRequired(),
|
||||
}),
|
||||
paymentDate: Yup.string().required('Tanggal Pembayaran Wajib diisi'),
|
||||
paymentMethod: Yup.object()
|
||||
.shape({
|
||||
value: Yup.string().required(),
|
||||
label: Yup.string().required(),
|
||||
})
|
||||
.nullable()
|
||||
.required('Metode Pembayaran Wajib diisi'),
|
||||
bankId: Yup.number()
|
||||
.nullable()
|
||||
.test('required-if-transfer', 'Bank Wajib diisi', function (value) {
|
||||
const paymentMethod = this.parent.paymentMethod;
|
||||
if (paymentMethod?.value === 'TRANSFER' && !value) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
supplierBankAccountNumber: Yup.string()
|
||||
.nullable()
|
||||
.test(
|
||||
'required-if-transfer',
|
||||
'Nomor Rekening Customer Wajib diisi',
|
||||
function (value) {
|
||||
const paymentMethod = this.parent.paymentMethod;
|
||||
if (paymentMethod?.value === 'TRANSFER' && !value) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
),
|
||||
referenceNumber: Yup.string().nullable(),
|
||||
amount: Yup.number()
|
||||
.typeError('Nominal harus berupa angka')
|
||||
.required('Nominal Wajib diisi'),
|
||||
notes: Yup.string().nullable(),
|
||||
});
|
||||
|
||||
export type FinanceFormValues = {
|
||||
transactionType: OptionType | null;
|
||||
customerId: number | null;
|
||||
customer: OptionType | null;
|
||||
paymentDate: string;
|
||||
paymentMethod: OptionType | null;
|
||||
bankId: number | null;
|
||||
bank: OptionType | null;
|
||||
supplierBankAccountNumber: string;
|
||||
referenceNumber: string;
|
||||
amount: string;
|
||||
notes: string;
|
||||
};
|
||||
Reference in New Issue
Block a user