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