-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSignUpPageView.swift
70 lines (60 loc) · 1.73 KB
/
SignUpPageView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// SignUpPageView.swift
// MobileAcebook
//
// Created by Fara on 17/04/2024.
//
import SwiftUI
struct SignUpPageView: View {
@State private var user = User(email: "", username: "", password: "")
@State private var signUpError: Error? = nil
@State private var isSignedUp = false
var body: some View {
NavigationView {
VStack {
Image("makers-logo")
.resizable()
.scaledToFit()
.frame(width: 200, height: 200)
.accessibilityIdentifier("makers-logo")
TextField("Email", text: $user.email)
.padding()
.autocapitalization(/*@START_MENU_TOKEN@*/.none/*@END_MENU_TOKEN@*/)
SecureField("Password", text: $user.password)
.padding()
.autocapitalization(/*@START_MENU_TOKEN@*/.none/*@END_MENU_TOKEN@*/)
TextField("Username", text: $user.username)
.padding()
.autocapitalization(/*@START_MENU_TOKEN@*/.none/*@END_MENU_TOKEN@*/)
Button("Sign Up") {
Task {
do {
let authService = AuthenticationService()
try await authService.signUp(user: user)
isSignedUp = true
} catch {
signUpError = error
}
}
}
.padding()
.background(Color.blue)
.foregroundColor(.white)
.font(.headline)
.cornerRadius(8)
if let error = signUpError {
Text("Error: \(error.localizedDescription)")
}
NavigationLink(destination: WelcomePageView(), isActive: $isSignedUp) {
EmptyView()
}
}
.padding()
}
}
}
struct SignUpPageView_Previews: PreviewProvider {
static var previews: some View {
SignUpPageView()
}
}