refactor(FE-316): Support localized uniformity statuses and fields

This commit is contained in:
rstubryan
2025-12-31 10:17:39 +07:00
parent 640cf26970
commit 0090961ec0
4 changed files with 30 additions and 30 deletions
@@ -46,7 +46,12 @@ import Menu from '@/components/menu/Menu';
import MenuItem from '@/components/menu/MenuItem'; import MenuItem from '@/components/menu/MenuItem';
const isUniformityLocked = (uniformity: Uniformity): boolean => { const isUniformityLocked = (uniformity: Uniformity): boolean => {
return uniformity.status === 'APPROVED' || uniformity.status === 'REJECTED'; return (
uniformity.status === 'Disetujui' ||
uniformity.status === 'Ditolak' ||
uniformity.status === 'APPROVED' ||
uniformity.status === 'REJECTED'
);
}; };
interface UniformityPreviewData { interface UniformityPreviewData {
@@ -407,7 +412,9 @@ const UniformityTable = ({ refresh }: { refresh?: () => void }) => {
const canApproveReject = useMemo(() => { const canApproveReject = useMemo(() => {
return ( return (
selectedUniformities.length > 0 && selectedUniformities.length > 0 &&
selectedUniformities.every((u) => u.status === 'CREATED') selectedUniformities.every(
(u) => u.status === 'CREATED' || u.status === 'Pengajuan'
)
); );
}, [selectedUniformities]); }, [selectedUniformities]);
@@ -737,7 +744,7 @@ const UniformityTable = ({ refresh }: { refresh?: () => void }) => {
}, },
}, },
{ {
accessorKey: 'location.name', accessorKey: 'location_name',
header: 'Lokasi', header: 'Lokasi',
cell: (props) => props.row.original.location_name || '-', cell: (props) => props.row.original.location_name || '-',
}, },
@@ -88,33 +88,18 @@ export type UniformityFormData = {
}; };
export const getUniformityFormInitialValues = ( export const getUniformityFormInitialValues = (
initialValues?: Uniformity initialValues?: Partial<Uniformity>
): UniformityFormValues => { ): UniformityFormValues => {
return { return {
date: initialValues?.week ? '' : '', date: initialValues?.week ? '' : '',
week: initialValues?.week ?? 0, week: initialValues?.week ?? 0,
location: initialValues?.location location: null,
? { location_id: 0,
value: initialValues.location.id, project_flock: null,
label: initialValues.location.name, project_flock_id: 0,
} project_flock_kandang_id: initialValues?.project_flock_kandang_id ?? null,
: null, kandang: null,
location_id: initialValues?.location?.id ?? 0, kandang_id: 0,
project_flock: initialValues?.project_flock
? {
value: initialValues.project_flock.id,
label: initialValues.project_flock.flock_name,
}
: null,
project_flock_id: initialValues?.project_flock?.id ?? 0,
project_flock_kandang_id: initialValues?.project_flock_kandang_id ?? 0,
kandang: initialValues?.kandang
? {
value: initialValues.kandang.id,
label: initialValues.kandang.name,
}
: null,
kandang_id: initialValues?.kandang?.id ?? 0,
document: undefined, document: undefined,
}; };
}; };
@@ -27,20 +27,29 @@ export const getWeightStatusText = (status: string): string => {
export const statusColorMap: Record<string, string> = { export const statusColorMap: Record<string, string> = {
APPROVED: 'bg-[#00D39033]', APPROVED: 'bg-[#00D39033]',
Disetujui: 'bg-[#00D39033]',
REJECTED: 'bg-error/10', REJECTED: 'bg-error/10',
Ditolak: 'bg-error/10',
CREATED: 'bg-[#f3f3f4]', CREATED: 'bg-[#f3f3f4]',
Pengajuan: 'bg-[#f3f3f4]',
}; };
export const statusIndicatorColorMap: Record<string, string> = { export const statusIndicatorColorMap: Record<string, string> = {
APPROVED: 'bg-[#008000]', APPROVED: 'bg-[#008000]',
Disetujui: 'bg-[#008000]',
REJECTED: 'bg-error', REJECTED: 'bg-error',
Ditolak: 'bg-error',
CREATED: 'bg-[#D9D9D9]', CREATED: 'bg-[#D9D9D9]',
Pengajuan: 'bg-[#D9D9D9]',
}; };
export const statusTextMap: Record<string, string> = { export const statusTextMap: Record<string, string> = {
APPROVED: 'Disetujui', APPROVED: 'Disetujui',
Disetujui: 'Disetujui',
REJECTED: 'Ditolak', REJECTED: 'Ditolak',
Ditolak: 'Ditolak',
CREATED: 'Pengajuan', CREATED: 'Pengajuan',
Pengajuan: 'Pengajuan',
}; };
export const getStatusColor = (status: string): string => { export const getStatusColor = (status: string): string => {
+3 -4
View File
@@ -8,21 +8,20 @@ import { BaseApproval } from '@/types/api/approval/approval';
export type Uniformity = BaseMetadata & { export type Uniformity = BaseMetadata & {
id: number; id: number;
project_flock_kandang_id: number; project_flock_kandang_id: number;
location: Location;
project_flock: ProjectFlock;
location_name: string; location_name: string;
flock_name: string; flock_name: string;
kandang: Kandang;
kandang_name: string; kandang_name: string;
applied_at: string; applied_at: string;
week: number; week: number;
status: 'CREATED' | 'APPROVED' | 'REJECTED'; status: string;
uniformity: number; uniformity: number;
cv: number; cv: number;
chick_qty_of_weight: number; chick_qty_of_weight: number;
uniform_qty: number; uniform_qty: number;
mean_up: number; mean_up: number;
mean_down: number; mean_down: number;
standard_mean_weight: number | null;
standard_uniformity: number | null;
created_at: string; created_at: string;
created_by: number; created_by: number;
latest_approval?: BaseApproval; latest_approval?: BaseApproval;