feat: Phase 5 — part counter update, replacement, replacement history
All checks were successful
Deploy to Production / deploy (push) Successful in 1m5s

This commit is contained in:
Johngreen
2026-02-10 13:55:49 +09:00
parent 581c845f54
commit 035d62f0e0
6 changed files with 698 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
import useSWR from 'swr';
import { fetcher, getTenantUrl } from './api';
import type { Tenant, Machine, MachineDetail, EquipmentPart, InspectionTemplate, InspectionSession } from './types';
import type { Tenant, Machine, MachineDetail, EquipmentPart, InspectionTemplate, InspectionSession, PartReplacementLog } from './types';
export function useTenants() {
const { data, error, isLoading, mutate } = useSWR<{ tenants: Tenant[] }>(
@@ -109,6 +109,22 @@ export function useTemplate(tenantId?: string, templateId?: string) {
};
}
export function useReplacements(tenantId?: string, partId?: string) {
const url = tenantId && partId ? `/api/${tenantId}/parts/${partId}/replacements` : null;
const { data, error, isLoading, mutate } = useSWR<{ replacements: PartReplacementLog[] }>(
url,
fetcher,
{ dedupingInterval: 2000 },
);
return {
replacements: data?.replacements || [],
error,
isLoading,
mutate,
};
}
export function useInspections(tenantId?: string, status?: string, templateId?: string) {
const params = new URLSearchParams();
if (status) params.set('status', status);

View File

@@ -132,6 +132,17 @@ export interface InspectionSession {
updated_at: string | null;
}
export interface PartReplacementLog {
id: string;
equipment_part_id: string;
replaced_by: string | null;
replaced_at: string | null;
counter_at_replacement: number;
lifecycle_pct_at_replacement: number;
reason: string | null;
notes: string | null;
}
export interface InspectionTemplate {
id: string;
tenant_id: string;