mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
feat(FE-33): create suppliers table and forms
This commit is contained in:
@@ -13,15 +13,7 @@ export const CustomerFormSchema = Yup.object({
|
||||
type: Yup.object({
|
||||
value: Yup.string().required(),
|
||||
label: Yup.string().required(),
|
||||
})
|
||||
.oneOf(
|
||||
[
|
||||
{ value: 'INDIVIDUAL', label: 'INDIVIDUAL' },
|
||||
{ value: 'BISNIS', label: 'BISNIS' },
|
||||
],
|
||||
'Tipe harus INDIVIDUAL atau BISNIS'
|
||||
)
|
||||
.required('Tipe wajib diisi!'),
|
||||
}).required('Tipe wajib diisi!'),
|
||||
|
||||
address: Yup.string().required('Alamat wajib diisi!'),
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { CustomerFormValues } from './CustomerForm.schema';
|
||||
import { CustomerFormSchema, CustomerFormValues, UpdateCustomerFormSchema } from './CustomerForm.schema';
|
||||
import { useFormik } from 'formik';
|
||||
import Button from '@/components/Button';
|
||||
import { Icon } from '@iconify/react';
|
||||
@@ -22,7 +22,7 @@ import TextArea from '@/components/input/TextArea';
|
||||
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||
import useSWR from 'swr';
|
||||
import { UserApi } from '@/services/api/user';
|
||||
import { CUSTOMER_TYPE_OPTIONS } from '@/config/constant';
|
||||
import { TYPE_OPTIONS } from '@/config/constant';
|
||||
|
||||
interface CustomerFormProps {
|
||||
formType?: 'add' | 'edit' | 'detail';
|
||||
@@ -60,7 +60,7 @@ const CustomerForm = ({
|
||||
label: area.name,
|
||||
}))
|
||||
: [];
|
||||
const typeOptions = CUSTOMER_TYPE_OPTIONS;
|
||||
const typeOptions = TYPE_OPTIONS;
|
||||
|
||||
// Handler Event
|
||||
const createCustomerHandler = useCallback(
|
||||
@@ -121,7 +121,7 @@ const CustomerForm = ({
|
||||
|
||||
// Utils Functions
|
||||
const normalizeType = (type?: string | { value: string; label: string }) => {
|
||||
if (!type) return CUSTOMER_TYPE_OPTIONS[0];
|
||||
if (!type) return TYPE_OPTIONS[0];
|
||||
return typeof type === 'string' ? { value: type, label: type } : type;
|
||||
};
|
||||
|
||||
@@ -151,6 +151,7 @@ const CustomerForm = ({
|
||||
const formik = useFormik<CustomerFormValues>({
|
||||
initialValues: formikInitialValues,
|
||||
enableReinitialize: true,
|
||||
validationSchema: formType === 'edit' ? UpdateCustomerFormSchema : CustomerFormSchema,
|
||||
onSubmit: async (values) => {
|
||||
// reset error message
|
||||
setCustomerFormErrorMessage('');
|
||||
@@ -213,7 +214,6 @@ const CustomerForm = ({
|
||||
>
|
||||
{/* Fields Form */}
|
||||
<div className='flex flex-col gap-4'>
|
||||
{formik.values.picId}
|
||||
<TextInput
|
||||
required
|
||||
label='Nama'
|
||||
@@ -247,7 +247,7 @@ const CustomerForm = ({
|
||||
label='Tipe'
|
||||
value={
|
||||
typeOptions.find(
|
||||
(item) => item.value === formik.values.type.value
|
||||
(item) => item.value === formik.values.type?.value
|
||||
) ?? undefined
|
||||
}
|
||||
onChange={typeChangeHandler}
|
||||
|
||||
Reference in New Issue
Block a user