mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
63 lines
2.4 KiB
Swift
63 lines
2.4 KiB
Swift
import SwiftUI
|
|
import AppleAPI
|
|
|
|
struct SignInSMSView: View {
|
|
@EnvironmentObject var appState: AppState
|
|
@Binding var isPresented: Bool
|
|
@State private var code: String = ""
|
|
let trustedPhoneNumber: AuthOptionsResponse.TrustedPhoneNumber
|
|
let authOptions: AuthOptionsResponse
|
|
let sessionData: AppleSessionData
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading) {
|
|
Text("Enter the \(authOptions.securityCode.length) digit code sent to \(trustedPhoneNumber.numberWithDialCode): ")
|
|
|
|
HStack {
|
|
Spacer()
|
|
PinCodeTextField(code: $code, numberOfDigits: authOptions.securityCode.length)
|
|
Spacer()
|
|
}
|
|
.padding()
|
|
|
|
HStack {
|
|
Button("Cancel", action: { isPresented = false })
|
|
.keyboardShortcut(.cancelAction)
|
|
Spacer()
|
|
if appState.isProcessingRequest {
|
|
ProgressView()
|
|
.progressViewStyle(CircularProgressViewStyle())
|
|
.scaleEffect(x: 0.5, y: 0.5, anchor: .center)
|
|
.padding(.trailing, 22)
|
|
} else {
|
|
Button("Continue", action: { appState.submitSecurityCode(.sms(code: code, phoneNumberId: trustedPhoneNumber.id), sessionData: sessionData) })
|
|
.keyboardShortcut(.defaultAction)
|
|
.disabled(code.count != authOptions.securityCode.length)
|
|
}
|
|
}
|
|
.frame(height: 25)
|
|
}
|
|
.padding()
|
|
.alert(item: $appState.authError) { error in
|
|
Alert(title: Text(error.title),
|
|
message: Text(verbatim: error.message),
|
|
dismissButton: .default(Text("OK")))
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SignInSMSView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SignInSMSView(
|
|
isPresented: .constant(true),
|
|
trustedPhoneNumber: .init(id: 0, numberWithDialCode: "(•••) •••-••90"),
|
|
authOptions: AuthOptionsResponse(
|
|
trustedPhoneNumbers: nil,
|
|
trustedDevices: nil,
|
|
securityCode: .init(length: 6)
|
|
),
|
|
sessionData: AppleSessionData(serviceKey: "", sessionID: "", scnt: "")
|
|
)
|
|
.environmentObject(AppState())
|
|
}
|
|
}
|