refactor(FE-316): Rename documents to document in uniformity

This commit is contained in:
rstubryan
2025-12-30 13:35:24 +07:00
parent 7c64870fed
commit 52cb440cb3
7 changed files with 46 additions and 46 deletions
@@ -90,8 +90,8 @@ const UniformityDetail: React.FC<UniformityDetailProps> = ({
label: 'Kandang',
},
{
id: 'documents-name',
value: 'documents-name',
id: 'document-name',
value: 'document-name',
label: 'File Uniformity',
},
{
@@ -123,7 +123,7 @@ const UniformityDetail: React.FC<UniformityDetailProps> = ({
'lokasi-farm': info_umum.lokasi_farm,
'project-flock': info_umum.project_flock,
kandang: info_umum.kandang,
'documents-name': info_umum.documents_name,
'document-name': info_umum.document_name,
'approval-status': statusValue,
};
@@ -148,7 +148,7 @@ const UniformityDetail: React.FC<UniformityDetailProps> = ({
return <span>-</span>;
}
if (id === 'documents-name') {
if (id === 'document-name') {
return (
<div className='flex items-center gap-2'>
<span>{valueMap[id]}</span>
@@ -214,7 +214,7 @@ const UniformityDetailsPreview = ({
{/* Header */}
<DrawerHeader
leftIcon=''
subtitle={info_umum?.documents_name ?? 'Uniformity Details'}
subtitle={info_umum?.document_name ?? 'Uniformity Details'}
subtitleClassName='text-sm text-neutral line-clamp-1'
showDivider={false}
>
@@ -20,16 +20,16 @@ type UniformityFormSchemaType = {
label: string;
} | null;
kandang_id: number;
documents: File | undefined;
document: File | undefined;
};
const FileSchema = Yup.mixed<File>()
.test('documentsSize', 'Ukuran file maksimal 2 MB', (value): boolean => {
.test('documentSize', 'Ukuran file maksimal 2 MB', (value): boolean => {
if (!value) return true;
if (value instanceof File) return value.size <= 2 * 1024 * 1024;
return false;
})
.test('documentsType', 'Format file harus Excel', (value): boolean => {
.test('documentType', 'Format file harus Excel', (value): boolean => {
if (!value) return true;
if (value instanceof File) {
const allowedTypes = [
@@ -74,7 +74,7 @@ export const UniformityFormSchema: Yup.ObjectSchema<UniformityFormSchemaType> =
.min(1, 'Kandang wajib diisi!')
.required('Kandang wajib diisi!')
.typeError('Kandang wajib diisi!'),
documents: FileSchema.required('File wajib diisi!'),
document: FileSchema.required('File wajib diisi!'),
});
export type UniformityFormValues = Yup.InferType<typeof UniformityFormSchema>;
@@ -83,8 +83,8 @@ export type UniformityFormData = {
date: string;
week: number;
project_flock_kandang_id: number;
documents: File | null;
documents_name: string;
document: File | null;
document_name: string;
};
export const getUniformityFormInitialValues = (
@@ -115,6 +115,6 @@ export const getUniformityFormInitialValues = (
}
: null,
kandang_id: initialValues?.kandang?.id ?? 0,
documents: undefined,
document: undefined,
};
};
@@ -246,12 +246,12 @@ const UniformityForm = ({
date: values.date,
week: values.week,
project_flock_kandang_id: projectFlockKandangId,
documents: values.documents as File,
documents_name: (values.documents as File).name,
document: values.document as File,
document_name: (values.document as File).name,
});
const payload: VerifyUniformityPayload = {
documents: values.documents as File,
document: values.document as File,
};
const res = await UniformityApi.verifyUniformity(payload);
@@ -325,17 +325,17 @@ const UniformityForm = ({
const handleFileChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const documents = e.target.files?.[0];
const document = e.target.files?.[0];
formik.setFieldTouched('documents', true);
formik.setFieldTouched('document', true);
if (!documents) {
formik.setFieldValue('documents', undefined);
if (!document) {
formik.setFieldValue('document', undefined);
return;
}
if (documents.size > 2 * 1024 * 1024) {
toast.error(`Ukuran file ${documents.name} maksimal 2 MB!`);
if (document.size > 2 * 1024 * 1024) {
toast.error(`Ukuran file ${document.name} maksimal 2 MB!`);
return;
}
@@ -345,12 +345,12 @@ const UniformityForm = ({
'text/csv',
];
if (!allowedTypes.includes(documents.type)) {
toast.error(`Format file ${documents.name} harus Excel atau CSV!`);
if (!allowedTypes.includes(document.type)) {
toast.error(`Format file ${document.name} harus Excel atau CSV!`);
return;
}
formik.setFieldValue('documents', documents);
formik.setFieldValue('document', document);
},
[]
);
@@ -363,7 +363,7 @@ const UniformityForm = ({
);
const handleRemoveFile = useCallback(() => {
formik.setFieldValue('documents', undefined);
formik.setFieldValue('document', undefined);
if (fileInputRef.current) {
fileInputRef.current.value = '';
}
@@ -528,14 +528,14 @@ const UniformityForm = ({
htmlFor='file-upload-input'
className={cn(
"w-full text-sm font-normal leading-5 after:content-['*'] after:ml-0.5 after:text-red-500",
formik.touched.documents &&
formik.errors.documents &&
formik.touched.document &&
formik.errors.document &&
'text-red-500'
)}
>
Upload File
</label>
{formik.values.documents && !isNextStep ? (
{formik.values.document && !isNextStep ? (
<button
onClick={handleRemoveFile}
className='cursor-pointer'
@@ -548,7 +548,7 @@ const UniformityForm = ({
className='text-gray-400 hover:text-gray-600'
/>
</button>
) : !formik.values.documents && !isNextStep ? (
) : !formik.values.document && !isNextStep ? (
<button className='cursor-pointer' type='button'>
<Tooltip
position='left'
@@ -568,7 +568,7 @@ const UniformityForm = ({
<section
className={cn(
'h-full w-full border rounded-2xl border-dashed cursor-pointer mt-2',
formik.touched.documents && formik.errors.documents
formik.touched.document && formik.errors.document
? 'border-red-500'
: 'border-gray-300'
)}
@@ -576,7 +576,7 @@ const UniformityForm = ({
document.getElementById('file-upload-input')?.click()
}
>
{formik.values.documents ? (
{formik.values.document ? (
<div className='flex flex-col items-center justify-center gap-2 my-10'>
<div className='border border-[#18181B]/25 rounded-2xl p-1 flex items-center justify-center'>
<Button
@@ -594,7 +594,7 @@ const UniformityForm = ({
</Button>
</div>
<span className='text-md font-semibold text-black line-clamp-2 text-center max-w-xs break-all'>
{formik.values.documents.name}
{formik.values.document.name}
</span>
</div>
) : (
@@ -667,15 +667,15 @@ const UniformityForm = ({
ref={fileInputRef}
type='file'
id='file-upload-input'
name='documents'
name='document'
accept='application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/csv'
onChange={handleFileChange}
className='hidden'
/>
{formik.touched.documents && formik.errors.documents && (
{formik.touched.document && formik.errors.document && (
<p className='w-full text-sm text-red-500 mt-2'>
{formik.errors.documents as string}
{formik.errors.document as string}
</p>
)}
</div>
@@ -51,7 +51,7 @@ const UniformityResultForm = () => {
};
const handleSubmit = async () => {
if (!uniformityFormData || !uniformityFormData.documents) {
if (!uniformityFormData || !uniformityFormData.document) {
toast.error('Form data is missing. Please try again.');
return;
}
@@ -63,7 +63,7 @@ const UniformityResultForm = () => {
date: uniformityFormData.date,
week: uniformityFormData.week,
project_flock_kandang_id: uniformityFormData.project_flock_kandang_id,
documents: uniformityFormData.documents,
document: uniformityFormData.document,
};
const res = await UniformityApi.createUniformity(payload);
@@ -236,7 +236,7 @@ const UniformityResultForm = () => {
{/* Header */}
<DrawerHeader
leftIcon=''
subtitle={uniformityFormData?.documents_name || 'Uniformity Result'}
subtitle={uniformityFormData?.document_name || 'Uniformity Result'}
subtitleClassName='text-sm text-neutral line-clamp-1'
showDivider={false}
>
+5 -5
View File
@@ -62,8 +62,8 @@ export class UniformityApiService extends BaseApiService<
payload.project_flock_kandang_id.toString()
);
if (payload.documents) {
formData.append('documents', payload.documents);
if (payload.document) {
formData.append('document', payload.document);
}
return await this.create(formData as unknown as CreateUniformityPayload);
@@ -73,8 +73,8 @@ export class UniformityApiService extends BaseApiService<
payload: VerifyUniformityPayload
): Promise<BaseApiResponse<VerifyUniformityResponse> | undefined> {
const formData = new FormData();
if (payload.documents) {
formData.append('documents', payload.documents);
if (payload.document) {
formData.append('document', payload.document);
}
return await this.customRequest<BaseApiResponse<VerifyUniformityResponse>>(
@@ -130,5 +130,5 @@ export class UniformityApiService extends BaseApiService<
}
export const UniformityApi = new UniformityApiService(
'http://localhost:4010/api/production/uniformities'
'production/uniformities'
);
+3 -3
View File
@@ -34,7 +34,7 @@ export type UniformityInfoUmum = {
lokasi_farm: string;
project_flock: string;
kandang: string;
documents_name: string;
document_name: string;
};
export type UniformitySampling = {
@@ -77,12 +77,12 @@ export type VerifyUniformityResponse = {
export type CreateUniformityPayload = {
date: string;
project_flock_kandang_id: number;
documents: File;
document: File;
week: number;
};
export type VerifyUniformityPayload = {
documents: File;
document: File;
};
// ==================== OTHER TYPES ====================