123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- //
- // RegisterView.swift
- // Comedores Sociales
- //
- // Created by Hector Carrion on 10/24/20.
- //
-
- import SwiftUI
-
- struct RegisterView: View {
- @EnvironmentObject var registerVM: RegisterViewModel
-
- @State var name: String = ""
- @State var phoneNumber: String = ""
- @State var email: String = ""
- @State var password: String = ""
- @State var passwordConf: String = ""
- @State var urb: String = ""
- @State var city: String = ""
- @State var street: String = ""
- @State var org: String = ""
- @State var position: String = ""
- @State var zip: String = ""
- @Environment(\.colorScheme) var colorScheme
-
- @State private var showingAlert = false
- @State private var passwordsAlert = false
-
- var body: some View {
- VStack {
- Text("Details")
- .font(.largeTitle)
- .fontWeight(.semibold)
- .frame(width: 350, height: 25, alignment: .topLeading)
- .padding(.bottom, 20)
-
- ScrollView {
- Group {
- Group {
- TextField("Full Name", text: $name)
- .autocapitalization(.words)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- TextField("Email", text: $email)
- .disableAutocorrection(true)
- .autocapitalization(.none)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- SecureField("Password", text: $password)
- .autocapitalization(.none)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- SecureField("Password (confirmation)", text: $passwordConf)
- .autocapitalization(.none)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- }
- TextField("Phone Number", text: $phoneNumber)
- .keyboardType(.numberPad)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- TextField("Urbanization", text: $urb)
- .padding()
- .autocapitalization(.words)
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- TextField("Street", text: $street)
- .autocapitalization(.words)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- TextField("City", text: $city)
- .autocapitalization(.words)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- TextField("Zip Code", text: $zip)
- .keyboardType(.numberPad)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- TextField("Organization (optional)", text: $org)
- .autocapitalization(.words)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- .padding(.bottom, 5)
- TextField("Position (optional)", text: $position)
- .padding()
- .background(colorScheme == .dark ? darkGreyColor : lightGreyColor)
- .cornerRadius(5.0)
- //.padding(.bottom, 5)
-
- }.padding(5)
- }
-
- if registerVM.response == false {
- Text("Registration failed, please try again")
- //.offset(y: -5)
- .foregroundColor(.red)
- } else if registerVM.response == true {
- Text("Registration successful 🎉")
- //.offset(y: -5)
- .foregroundColor(.green)
- }
-
-
- Button(action: {
- print("register tapped")
-
- let registrationData = Registration(email: email, password: password, name: name, urb: urb, street: street, city: city, zip: zip, phone: phoneNumber, org: org, position: position)
-
- if password == passwordConf {
- if registrationData.isComplete() {
- registerVM.register(data: registrationData)
- } else {
- // Alert here
- self.showingAlert = true
- }
- } else {
- // Alert here
- self.passwordsAlert = true
- }
-
-
- }) {
- Text("Register")
- .font(.headline)
- .foregroundColor(.white)
- .padding()
- .frame(width: 220, height: 50)
- .background(Color.blue)
- .cornerRadius(5)
- .padding(.bottom, 5)
- }
-
-
- }.alert(isPresented: $showingAlert) {
- Alert(title: Text("Fields incomplete"), message: Text("Please enter a all required information"), dismissButton: .default(Text("OK")))}
- .alert(isPresented: $passwordsAlert) {
- Alert(title: Text("Passwords do not match"), message: Text("Please retype your password and try again"), dismissButton: .default(Text("OK")))}
- .padding()
- }
- }
-
- struct RegisterView_Previews: PreviewProvider {
- static var previews: some View {
- RegisterView()
- }
- }
|