Files
Woka_Native_iOS/WOKA/SideBarNav/Controller/ContactSupportVC.swift

163 lines
6.3 KiB
Swift
Raw Normal View History

//
// ContactSupportVC.swift
// WOKA
//
// Created by Bilal on 04/06/2024.
//
import UIKit
import RSKPlaceholderTextView
class ContactSupportVC: UIViewController {
@IBOutlet weak var supportGirlImage: UIImageView!
@IBOutlet weak var bottomArrow: UIImageView!
@IBOutlet weak var subjectMainStack: UIStackView!
@IBOutlet weak var subjectStack: UIStackView!
@IBOutlet weak var messageStack: UIStackView!
@IBOutlet weak var subjectLabel: UILabel!
@IBOutlet weak var messageTextView: RSKPlaceholderTextView!
@IBOutlet weak var submitBtn: LocalisedElementsButton!
@IBOutlet weak var emailStack: UIStackView!
@IBOutlet weak var nameStack: UIStackView!
@IBOutlet weak var emailTF: TextFieldShadow!
@IBOutlet weak var nameTF: TextFieldShadow!
@IBOutlet weak var assistanceLabel: UILabel!
var vm = ContactSupportVM()
// MARK: - View LifeCycle
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Woka Support"
vm.vc = self
vm.initView()
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
if self.isMovingFromParent {
// Back button was pressed
PersistentStorage.shared.addOthersCount()
}
}
// MARK: - Button Click Handler
@IBAction func submitBtnTapped(_ sender: LocalisedElementsButton) {
PersistentStorage.shared.addOthersCount()
/*
if user is guest check for name and email
*/
if AuthFunc.shareInstance.getUserType() == 3{
if emailTF.text != nil{
//validate email fiirst
let emailValidate = EmailValidation(email: emailTF.text!).validate()
if emailValidate != .isCorrect{
emailTF.rightView?.isHidden = false
emailTF.setError(emailValidate.rawValue.localized(loc: AuthFunc.shareInstance.languageSelected.rawValue), show: true)
return
}
}
if nameTF.text!.count < 3{
/*
Check for username
*/
nameTF.rightView?.isHidden = false
nameTF.setError(K.ConstantString.shortName.localized(loc: AuthFunc.shareInstance.languageSelected.rawValue), show: true)
return
}
}
if subjectLabel.text?.lowercased() == "select subject" || subjectLabel.text == nil{
let sb = UIStoryboard(name: K.StoryBoard.customAlerts, bundle: nil)
let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.CustomAlerts.alertCustomVC) as! AlertCustomVC
vcPush.contentLabel = "Please select subject".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
vcPush.mainTitleText = "Error".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
vcPush.modalPresentationStyle = .overCurrentContext
vcPush.modalTransitionStyle = .crossDissolve
self.present(vcPush, animated: true)
return
}
if messageTextView.text.count < 3 || messageTextView.text == nil{
let sb = UIStoryboard(name: K.StoryBoard.customAlerts, bundle: nil)
let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.CustomAlerts.alertCustomVC) as! AlertCustomVC
vcPush.contentLabel = "Message is too short".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
vcPush.mainTitleText = "Error".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
vcPush.modalPresentationStyle = .overCurrentContext
vcPush.modalTransitionStyle = .crossDissolve
self.present(vcPush, animated: true)
return
}
if AuthFunc.shareInstance.getUserType() == 3{ // He is Guest
vm.guestContactSupportApiCall()
}else{
vm.contactSupportApiCall()
}
}
}
// MARK: - Textfield, TextView Delegate
extension ContactSupportVC : UITextFieldDelegate , UITextViewDelegate{
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool{
switch textField{
case emailTF:
if let rightView = textField.rightView {
// Hide the right view
rightView.isHidden = true
// Check if the right view is hidden
if rightView.isHidden {
// If hidden, hide the associated error view
if let errorView = errorViews.object(forKey: emailTF) {
errorView.isHidden = true
}
}
}
return ValidatorClass.sharedInstanec.limitCharacter(length: 255,textField, shouldChangeCharactersIn: range, replacementString: string)
case nameTF:
textField.hideError()
if !string.nameCharacterOnly(){return false}
return ValidatorClass.sharedInstanec.limitCharacter(length: 50,textField, shouldChangeCharactersIn: range, replacementString: string)
default:
return true
}
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if !text.nameCharacterOnly(){return false}
return ValidatorClass.sharedInstanec.limitCharacterTV(length: 200,textView, shouldChangeCharactersIn: range, replacementString: text)
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
switch textField{
case emailTF:
nameTF.becomeFirstResponder()
case nameTF:
textField.resignFirstResponder()
default:
break
}
return true
}
}