- Created ErrorMessageParser utility for both iOS (Swift) and Android (Kotlin) - Parser detects JSON-formatted error messages and extracts user-friendly text - Identifies when data objects (not errors) are returned and provides generic messages - Updated all API error handling to pass raw error bodies instead of concatenating - Applied ErrorMessageParser across all ViewModels and screens on both platforms - Fixed ContractorApi and DocumentApi to not concatenate error bodies with messages - Updated ApiResultHandler to automatically parse all error messages - Error messages now show "Request failed. Please check your input and try again." instead of raw JSON 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
175 lines
6.5 KiB
Swift
175 lines
6.5 KiB
Swift
import SwiftUI
|
|
|
|
struct VerifyResetCodeView: View {
|
|
@ObservedObject var viewModel: PasswordResetViewModel
|
|
@FocusState private var isCodeFocused: Bool
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
var body: some View {
|
|
NavigationView {
|
|
Form {
|
|
// Header Section
|
|
Section {
|
|
VStack(spacing: 12) {
|
|
Image(systemName: "envelope.badge.fill")
|
|
.font(.system(size: 60))
|
|
.foregroundStyle(.blue.gradient)
|
|
.padding(.vertical)
|
|
|
|
Text("Check Your Email")
|
|
.font(.title2)
|
|
.fontWeight(.bold)
|
|
|
|
Text("We sent a 6-digit code to")
|
|
.font(.subheadline)
|
|
.foregroundColor(.secondary)
|
|
|
|
Text(viewModel.email)
|
|
.font(.subheadline)
|
|
.fontWeight(.semibold)
|
|
.foregroundColor(.primary)
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.vertical)
|
|
}
|
|
.listRowBackground(Color.clear)
|
|
|
|
// Info Section
|
|
Section {
|
|
Label {
|
|
Text("Code expires in 15 minutes")
|
|
.fontWeight(.semibold)
|
|
} icon: {
|
|
Image(systemName: "clock.fill")
|
|
.foregroundColor(.orange)
|
|
}
|
|
}
|
|
|
|
// Code Input Section
|
|
Section {
|
|
TextField("000000", text: $viewModel.code)
|
|
.font(.system(size: 32, weight: .semibold, design: .rounded))
|
|
.multilineTextAlignment(.center)
|
|
.keyboardType(.numberPad)
|
|
.focused($isCodeFocused)
|
|
.onChange(of: viewModel.code) { _, newValue in
|
|
// Limit to 6 digits
|
|
if newValue.count > 6 {
|
|
viewModel.code = String(newValue.prefix(6))
|
|
}
|
|
// Only allow numbers
|
|
viewModel.code = newValue.filter { $0.isNumber }
|
|
viewModel.clearError()
|
|
}
|
|
} header: {
|
|
Text("Verification Code")
|
|
} footer: {
|
|
Text("Enter the 6-digit code from your email")
|
|
}
|
|
|
|
// Error/Success Messages
|
|
if let errorMessage = viewModel.errorMessage {
|
|
Section {
|
|
Label {
|
|
Text(errorMessage)
|
|
.foregroundColor(.red)
|
|
} icon: {
|
|
Image(systemName: "exclamationmark.triangle.fill")
|
|
.foregroundColor(.red)
|
|
}
|
|
}
|
|
}
|
|
|
|
if let successMessage = viewModel.successMessage {
|
|
Section {
|
|
Label {
|
|
Text(successMessage)
|
|
.foregroundColor(.green)
|
|
} icon: {
|
|
Image(systemName: "checkmark.circle.fill")
|
|
.foregroundColor(.green)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Verify Button
|
|
Section {
|
|
Button(action: {
|
|
viewModel.verifyResetCode()
|
|
}) {
|
|
HStack {
|
|
Spacer()
|
|
if viewModel.isLoading {
|
|
ProgressView()
|
|
} else {
|
|
Label("Verify Code", systemImage: "checkmark.shield.fill")
|
|
.fontWeight(.semibold)
|
|
}
|
|
Spacer()
|
|
}
|
|
}
|
|
.disabled(viewModel.code.count != 6 || viewModel.isLoading)
|
|
}
|
|
|
|
// Help Section
|
|
Section {
|
|
VStack(spacing: 12) {
|
|
Text("Didn't receive the code?")
|
|
.font(.subheadline)
|
|
.foregroundColor(.secondary)
|
|
|
|
Button(action: {
|
|
// Clear code and go back to request new one
|
|
viewModel.code = ""
|
|
viewModel.clearError()
|
|
viewModel.currentStep = .requestCode
|
|
}) {
|
|
Text("Send New Code")
|
|
.font(.subheadline)
|
|
.fontWeight(.semibold)
|
|
}
|
|
|
|
Text("Check your spam folder if you don't see it")
|
|
.font(.caption)
|
|
.foregroundColor(.secondary)
|
|
.multilineTextAlignment(.center)
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.listRowBackground(Color.clear)
|
|
}
|
|
.navigationTitle("Verify Code")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.navigationBarBackButtonHidden(true)
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
Button(action: {
|
|
viewModel.moveToPreviousStep()
|
|
}) {
|
|
HStack(spacing: 4) {
|
|
Image(systemName: "chevron.left")
|
|
.font(.system(size: 16))
|
|
Text("Back")
|
|
.font(.subheadline)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.onAppear {
|
|
isCodeFocused = true
|
|
}
|
|
.handleErrors(
|
|
error: viewModel.errorMessage,
|
|
onRetry: { viewModel.verifyResetCode() }
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
let vm = PasswordResetViewModel()
|
|
vm.email = "test@example.com"
|
|
vm.currentStep = .verifyCode
|
|
return VerifyResetCodeView(viewModel: vm)
|
|
}
|