05/05 Update the API to follow-up and resinspection

This commit is contained in:
Nguyen Ngo
2026-05-05 18:19:31 -04:00
parent 9d6b5e5bcb
commit b9e504b72c
8 changed files with 342 additions and 18 deletions
@@ -182,6 +182,19 @@ struct HistoryRowView: View {
.clipShape(Capsule())
}
}
// Follow-up badge
if inspection.followUpRequired {
HStack(spacing: 4) {
Image(systemName: "exclamationmark.arrow.circlepath")
.font(.caption2)
Text("Follow-up Required")
.font(.caption2.bold())
}
.padding(.horizontal, 8).padding(.vertical, 3)
.background(Color.orange.opacity(0.15))
.foregroundStyle(.orange)
.clipShape(Capsule())
}
}
.padding(.vertical, 4)
}
@@ -198,6 +211,7 @@ struct HistoryDetailView: View {
let inspection: APIInspectionSummary
@Environment(\.modelContext) private var context
@State private var showReInspect = false
// Look up the local copy by mobileLocalId present only for this-device submissions
private var localCopy: LocalInspection? {
@@ -230,6 +244,46 @@ struct HistoryDetailView: View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
// Follow-up required banner
if inspection.followUpRequired {
HStack(alignment: .top, spacing: 12) {
Image(systemName: "exclamationmark.arrow.circlepath")
.foregroundStyle(.orange)
.font(.title3)
VStack(alignment: .leading, spacing: 4) {
Text("Follow-up Inspection Required")
.font(.callout.bold())
.foregroundStyle(.orange)
if let note = inspection.followUpNote, !note.isEmpty {
Text(note)
.font(.callout)
.foregroundStyle(.secondary)
}
Button {
showReInspect = true
} label: {
Label("Start Re-inspection", systemImage: "arrow.uturn.right.circle.fill")
.font(.callout.bold())
}
.buttonStyle(.borderedProminent)
.tint(.orange)
.padding(.top, 4)
}
}
.padding(14)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.orange.opacity(0.1))
.clipShape(RoundedRectangle(cornerRadius: 12))
.padding(.horizontal, 24)
}
// Is a re-inspection parent link
if let parentId = inspection.parentInspectionId {
infoRow(icon: "arrow.uturn.right.circle",
text: "Re-inspection of inspection #\(parentId)")
.padding(.horizontal, 24)
}
// Summary card
summaryCard
@@ -266,6 +320,37 @@ struct HistoryDetailView: View {
.background(Color(.systemBackground))
.navigationTitle(inspection.templateName)
.navigationBarTitleDisplayMode(.inline)
.onAppear {
syncFollowUpToLocalCopy()
}
.sheet(isPresented: $showReInspect) {
StartInspectionView(
preFillTemplateId: inspection.templateId,
preFillFacilityId: inspection.facilityId,
parentServerId: inspection.id,
parentLocalId: inspection.mobileLocalId
)
}
}
/// Write the server's follow-up fields back onto the local SwiftData copy
/// so that MyInspectionsView and CompletedInspectionView reflect the latest state.
private func syncFollowUpToLocalCopy() {
guard let copy = localCopy else { return }
var changed = false
if copy.followUpRequired != inspection.followUpRequired {
copy.followUpRequired = inspection.followUpRequired
changed = true
}
if copy.followUpNote != inspection.followUpNote {
copy.followUpNote = inspection.followUpNote
changed = true
}
if copy.parentServerId != inspection.parentInspectionId {
copy.parentServerId = inspection.parentInspectionId
changed = true
}
if changed { try? context.save() }
}
// Summary card