feat: Phase 5 — part counter update, replacement, replacement history
All checks were successful
Deploy to Production / deploy (push) Successful in 1m5s
All checks were successful
Deploy to Production / deploy (push) Successful in 1m5s
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user