Skip to content

Commit

Permalink
Update changes on edit profile
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ahmed-anwer committed Jun 9, 2024
1 parent fff9390 commit 6e8c353
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 49 deletions.
66 changes: 19 additions & 47 deletions DotCall/Controllers/App/EditProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ class EditProfileViewController: UIViewController {
return
}

guard let emailCell = tableView.cellForRow(at: IndexPath(row: 0, section: 1)) as? NameViewCell,
let email = emailCell.textField.text, !email.isEmpty, isValidEmail(email) else {
showAlert(title: "Error", message: "Please enter a valid email address")
return
}

updateProfile(userId: UserProfile.shared.generalProfile.id ?? "" ,name: name, email: email)
updateProfile(userId: UserProfile.shared.generalProfile.id ?? "" ,name: name)
}


Expand All @@ -62,7 +57,7 @@ class EditProfileViewController: UIViewController {
extension EditProfileViewController: UITableViewDataSource{

func numberOfSections(in tableView: UITableView) -> Int {
return 2
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
Expand All @@ -72,33 +67,20 @@ extension EditProfileViewController: UITableViewDataSource{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "NameViewCell", for: indexPath) as! NameViewCell
cell.backgroundColor = .iosBoxBG
if indexPath.section == 0 {
cell.textField.placeholder = "Enter name"
cell.textField.text = UserProfile.shared.generalProfile.name
cell.textField.autocapitalizationType = .words
cell.textField.textContentType = .name
} else if indexPath.section == 1 {
cell.textField.placeholder = "Enter email"
cell.textField.text = UserProfile.shared.generalProfile.email
cell.textField.autocapitalizationType = .none
cell.textField.textContentType = .emailAddress
cell.textField.keyboardType = .emailAddress
}


cell.textField.placeholder = "Enter name"
cell.textField.text = UserProfile.shared.generalProfile.name
cell.textField.autocapitalizationType = .words
cell.textField.textContentType = .name
cell.selectionStyle = .none // Disable cell selection

return cell
}



func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "Name"
} else if section == 1 {
return "Email"
}

return nil
return "Name"
}

}
Expand All @@ -107,24 +89,18 @@ extension EditProfileViewController: UITableViewDataSource{

extension EditProfileViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
if section == 1 {
let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 50))
let label = UILabel(frame: CGRect(x: 15, y: 0, width: tableView.frame.size.width - 30, height: 50))
label.text = "Make sure to you use a valid email address."
label.textColor = .gray
label.textAlignment = .center
label.font = UIFont.systemFont(ofSize: 12)
footerView.addSubview(label)
return footerView
}
return nil
let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 50))
let label = UILabel(frame: CGRect(x: 15, y: 0, width: tableView.frame.size.width - 30, height: 50))
label.text = "Your name will be displayed to other users."
label.textColor = .gray
label.textAlignment = .center
label.font = UIFont.systemFont(ofSize: 12)
footerView.addSubview(label)
return footerView
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
if section == 1 {
return 50
}
return 0
return 50
}
}

Expand All @@ -151,7 +127,7 @@ private extension EditProfileViewController{
}


private func updateProfile(userId: String, name: String, email: String) {
private func updateProfile(userId: String, name: String) {
LoadingManager.shared.showLoadingScreen()
let urlString = "https://dot-call-a7ff3d8633ee.herokuapp.com/users/editProfile/\(userId)"
guard let url = URL(string: urlString) else { return }
Expand All @@ -164,7 +140,6 @@ private extension EditProfileViewController{
// Prepare the request body
let requestBody: [String: Any] = [
"name": name,
"email": email
]
guard let httpBody = try? JSONSerialization.data(withJSONObject: requestBody) else { return }
request.httpBody = httpBody
Expand All @@ -177,13 +152,10 @@ private extension EditProfileViewController{
print("Error: \(error)")
return
}
print("Profile updated successfully")
UserProfile.shared.generalProfile.email = email
UserProfile.shared.generalProfile.name = name

let defaults = UserDefaults.standard
defaults.set(name, forKey: "userName")
defaults.set(email, forKey: "userEmail")
defaults.synchronize()

DispatchQueue.main.async {
Expand Down
4 changes: 2 additions & 2 deletions DotCall/Views/AppStoryboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@
<action selector="GroupCallButtonPressed:" destination="vIa-XI-Guu" id="DU1-44-eZn"/>
</connections>
</barButtonItem>
<segmentedControl key="titleView" opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="bar" selectedSegmentIndex="0" id="jOp-3m-yRX">
<segmentedControl key="titleView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="bar" selectedSegmentIndex="0" id="jOp-3m-yRX">
<rect key="frame" x="109" y="5.6666666666666679" width="175" height="33"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<segments>
Expand Down Expand Up @@ -667,7 +667,7 @@
<inferredMetricsTieBreakers>
<segue reference="A8L-Xi-8eL"/>
<segue reference="yAh-kR-gK4"/>
<segue reference="6h1-WS-L4y"/>
<segue reference="ETg-9O-Otf"/>
</inferredMetricsTieBreakers>
<resources>
<image name="Profile" width="240" height="240"/>
Expand Down

0 comments on commit 6e8c353

Please sign in to comment.