Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Commit

Permalink
Updated Accountviews
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobortolan committed Sep 12, 2023
1 parent ceba6e7 commit 006f4f7
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 57 deletions.
18 changes: 8 additions & 10 deletions mobile/Views/AccountPage/AccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ struct AccountView: View {
.navigationBarItems(leading: Button("Settings") {
isSettingsPresented.toggle()
})
.sheet(isPresented: $isSettingsPresented) {
NavigationView {
SettingsView()
.navigationBarItems(trailing: Button("Close") {
isSettingsPresented.toggle()
})
.navigationBarTitle("Settings", displayMode: .inline)
}
.modifier(ErrorViewModifier())
}
.background(
NavigationLink("", destination: SettingsView()
.navigationBarTitle("Settings", displayMode: .inline)
.modifier(ErrorViewModifier()),
isActive: $isSettingsPresented
)
.opacity(0)
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion mobile/Views/AccountPage/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct ProfileView: View {
.font(.headline)
.fontWeight(.light)
Spacer()
if let websiteURL = URL(string: "https://about.embloy.com"),
if let websiteURL = URL(string: "http://about.embloy.com"),
let websiteName = getWebsiteName(from: websiteURL.absoluteString) {
Link(destination: websiteURL, label: {
Text(websiteName)
Expand Down
36 changes: 14 additions & 22 deletions mobile/Views/AccountPage/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,25 @@ struct SettingsView: View {
var body: some View {
NavigationView {
VStack(spacing: 0) {
tabView

HStack {
HStack(spacing: 30) {
Spacer()

Button(action: {
selectedTab = .updateUser
}) {
Image(systemName: "person.circle")
.resizable()
.frame(width: 20, height: 20)
.padding()
Image(systemName: "person")
.font(.system(size: 20))
.foregroundColor(selectedTab == .updateUser ? .blue : .gray)
}

Spacer()

Button(action: {
selectedTab = .updateUserPreferences
}) {
Image(systemName: "gearshape.fill")
.resizable()
.frame(width: 20, height: 20)
.padding()
Image(systemName: "gear")
.font(.system(size: 20))
.foregroundColor(selectedTab == .updateUserPreferences ? .blue : .gray)
}

Spacer()
Expand All @@ -53,14 +49,18 @@ struct SettingsView: View {
selectedTab = .aboutApp
}) {
Image(systemName: "info.circle")
.resizable()
.frame(width: 20, height: 20)
.padding()
.font(.system(size: 20))
.foregroundColor(selectedTab == .aboutApp ? .blue : .gray)
}

Spacer()
}
.padding(.top, 10)
.background(Color(UIColor.systemBackground))

Divider()

tabView
}
.navigationBarTitle("", displayMode: .inline)
.navigationBarHidden(true)
Expand All @@ -79,11 +79,3 @@ struct SettingsView: View {
}
}
}
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
let errorHandlingManager = ErrorHandlingManager()
let authenticationManager = AuthenticationManager(errorHandlingManager: errorHandlingManager)

SettingsView().environmentObject(errorHandlingManager).environmentObject(authenticationManager)
}
}
82 changes: 60 additions & 22 deletions mobile/Views/AccountPage/UpdateUserView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ struct UpdateUserView: View {
}
})
.keyboardType(.emailAddress)
.foregroundColor(isEmailValid ? .primary : .red)
.foregroundColor(isEmailValid ? .primary : Color("AlertColor"))

TextField("First Name", text: $user.firstName, onEditingChanged: { editing in
if !editing {
isFirstNameValid = Validator.isValidName(user.firstName)
}
})
.foregroundColor(isFirstNameValid ? .primary : .red)
.foregroundColor(isFirstNameValid ? .primary : Color("AlertColor"))

TextField("Last Name", text: $user.lastName, onEditingChanged: { editing in
if !editing {
isLastNameValid = Validator.isValidName(user.lastName)
}
})
.foregroundColor(isLastNameValid ? .primary : .red)
.foregroundColor(isLastNameValid ? .primary : Color("AlertColor"))

TextField("Phone Number", text: Binding(
get: { user.phone ?? "" },
Expand All @@ -77,13 +77,13 @@ struct UpdateUserView: View {
if !editing {
isPhoneValid = Validator.isValidPhone(user.phone)
}})
.foregroundColor(isPhoneValid ? .primary : .red)
.foregroundColor(isPhoneValid ? .primary : Color("AlertColor"))

DatePicker("Date of Birth", selection: Binding(
get: { user.dateOfBirth ?? maximumDateOfBirth },
set: { user.dateOfBirth = $0 }
), in: reasonableMinimumDate...maximumDateOfBirth, displayedComponents: .date)
.foregroundColor(isDateOfBirthValid ? .primary : .red)
.foregroundColor(isDateOfBirthValid ? .primary : Color("AlertColor"))
.datePickerStyle(CompactDatePickerStyle())
}

Expand All @@ -92,7 +92,7 @@ struct UpdateUserView: View {
get: { user.address ?? "" },
set: { user.address = $0 }
))
.foregroundColor(isAddressValid ? .primary : .red)
.foregroundColor(isAddressValid ? .primary : Color("AlertColor"))

TextField("City", text: Binding(
get: { user.city ?? "" },
Expand All @@ -118,7 +118,7 @@ struct UpdateUserView: View {
.keyboardType(.URL)
.autocapitalization(.none)
.disableAutocorrection(true)
.foregroundColor(isLinkedInURLValid ? .primary : .red)
.foregroundColor(isLinkedInURLValid ? .primary : Color("AlertColor"))

TextField("Twitter URL", text:Binding(
get: { user.twitterURL ?? "" },
Expand All @@ -127,7 +127,7 @@ struct UpdateUserView: View {
.keyboardType(.URL)
.autocapitalization(.none)
.disableAutocorrection(true)
.foregroundColor(isTwitterURLValid ? .primary : .red)
.foregroundColor(isTwitterURLValid ? .primary : Color("AlertColor"))

TextField("Facebook URL", text: Binding(
get: { user.facebookURL ?? "" },
Expand All @@ -136,7 +136,7 @@ struct UpdateUserView: View {
.keyboardType(.URL)
.autocapitalization(.none)
.disableAutocorrection(true)
.foregroundColor(isFacebookURLValid ? .primary : .red)
.foregroundColor(isFacebookURLValid ? .primary : Color("AlertColor"))

TextField("Instagram URL", text: Binding(
get: { user.instagramURL ?? "" },
Expand All @@ -145,7 +145,7 @@ struct UpdateUserView: View {
.keyboardType(.URL)
.autocapitalization(.none)
.disableAutocorrection(true)
.foregroundColor(isInstagramURLValid ? .primary : .red)
.foregroundColor(isInstagramURLValid ? .primary : Color("AlertColor"))
}

}
Expand All @@ -156,13 +156,16 @@ struct UpdateUserView: View {
print("ValidateFields: \(validateFields())")
}) {
Text("Update Profile")
.fontWeight(.bold)
.multilineTextAlignment(.center)
.foregroundColor(.blue)
}
.disabled(isUpdating)
Section {
Button(action: {
isShowingDeleteConfirmationAlert = true
}) {
Text("Delete Profile").foregroundColor(Color("AlertColor"))
Text("Delete Profile").fontWeight(.bold).foregroundColor(Color("AlertColor")).multilineTextAlignment(.center)
}.alert(isPresented: $isShowingDeleteConfirmationAlert) {
Alert(
title: Text("Confirm Deletion"),
Expand All @@ -184,29 +187,64 @@ struct UpdateUserView: View {
}

private func validateFields() -> Bool {
var errorMessages: [String] = []

isEmailValid = Validator.isValidEmail(user.email)
if !isEmailValid {
errorMessages.append("Invalid email")
}

isFirstNameValid = Validator.isValidName(user.firstName)
if !isFirstNameValid {
errorMessages.append("Invalid first name")
}

isLastNameValid = Validator.isValidName(user.lastName)
if !isLastNameValid {
errorMessages.append("Invalid last name")
}

isPhoneValid = Validator.isValidPhone(user.phone)
isDateOfBirthValid = true
isAddressValid = true
// TODO: Implement address validation
if !isPhoneValid {
errorMessages.append("Invalid phone number")
}

isDateOfBirthValid = true // You may implement this validation separately
if !isDateOfBirthValid {
errorMessages.append("Invalid date of birth")
}

isAddressValid = true // Implement address validation separately
if !isAddressValid {
errorMessages.append("Invalid address")
}

isLinkedInURLValid = Validator.isValidLinkedInURL(user.linkedinURL)
if !isLinkedInURLValid {
errorMessages.append("Invalid LinkedIn URL")
}

isTwitterURLValid = Validator.isValidTwitterURL(user.twitterURL)
if !isTwitterURLValid {
errorMessages.append("Invalid Twitter URL")
}

isFacebookURLValid = Validator.isValidFacebookURL(user.facebookURL)
if !isFacebookURLValid {
errorMessages.append("Invalid Facebook URL")
}

isInstagramURLValid = Validator.isValidInstagramURL(user.instagramURL)
if !isInstagramURLValid {
errorMessages.append("Invalid Instagram URL")
}

print("isEmailValid \(isEmailValid)")
print("isFirstNameValid \(isFirstNameValid)")
print("isLastNameValid \(isLastNameValid)")
print("isPhoneValid \(isPhoneValid)")
print("isDateOfBirthValid \(isDateOfBirthValid)")
print("isAddressValid \(isAddressValid)")
// Set the error message
errorHandlingManager.errorMessage = errorMessages.joined(separator: "\n")

// Return true if all fields are valid
return isEmailValid && isFirstNameValid && isLastNameValid && isPhoneValid && isDateOfBirthValid && isAddressValid && isLinkedInURLValid && isTwitterURLValid && isFacebookURLValid && isInstagramURLValid
return errorMessages.isEmpty
}

func updateUser(iteration: Int) {
print("Iteration \(iteration)")
isUpdating = true
Expand Down
46 changes: 44 additions & 2 deletions mobile/Views/Components/ApplicationPopup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ struct ApplicationPopup: View {

@Binding var isVisible: Bool
@Binding var message: String
@State var cvData: Data?
@State private var isLoading = false

@State private var isPickingDocument = false
var job: Job

var body: some View {
Expand Down Expand Up @@ -50,8 +51,34 @@ struct ApplicationPopup: View {
.padding()
.frame(width: 350, height: 300)

if job.cvRequired {
Button(action: {
isPickingDocument.toggle()
}) {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color("FeedBgColor"))
.cornerRadius(10)
.overlay(
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color("SuccessColor"))
.border(Color("FgColor"), width: 3)
.padding(.horizontal, 10.0)
.overlay(
Text("UPLOAD CV [\(String(describing: job.allowedCvFormat))]")
.font(.headline)
.fontWeight(.black)
.foregroundColor(Color.white)
)
)
}
.padding()
.cornerRadius(10)
.fileImporter(isPresented: $isPickingDocument, allowedContentTypes: [.pdf], onCompletion: handleDocumentSelection)
}


Button(action: {
applicationManager.submitApplication(iteration: 0, jobId: job.jobId, userId: authenticationManager.current.userId, message: message)
applicationManager.submitApplication(iteration: 0, jobId: job.jobId, userId: authenticationManager.current.userId, message: message, cv: cvData)
isVisible = false
}) {
RoundedRectangle(cornerRadius: 10)
Expand All @@ -72,9 +99,24 @@ struct ApplicationPopup: View {
}
.padding()
.cornerRadius(10)

}
)
)
}
}

private func handleDocumentSelection(result: Result<URL, Error>) {
if case .success(let url) = result {
do {
cvData = try Data(contentsOf: url)
} catch {
// Handle error while reading file data
print("Error reading file data: \(error)")
}
} else if case .failure(let error) = result {
// Handle document picker error
print("Document picker error: \(error)")
}
}
}

0 comments on commit 006f4f7

Please sign in to comment.