Rev 47 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//// DeleteAccountView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 8/24/22.//import SwiftUIimport Networkimport Alamofireimport SwiftyJSONimport TTGSnackbarstruct DeleteAccountView: View {@EnvironmentObject private var networkMonitor : NetworkMonitor@EnvironmentObject private var appNavigation : AppNavigation@State private var presentAlert : Bool = false@State private var titleAlert : String = ""@State private var messageAlert : String = ""@State private var showProgressView : Bool = false@State private var code: String = "" {didSet {if code.count > 8 {code = String(pcode.prefix(8))AudioServicesPlayAlertSoundWithCompletion(SystemSoundID(kSystemSoundID_Vibrate)) { return }}}}private let appData = AppData.sharedInstancevar body: some View {ZStack {Color("color_window_background").edgesIgnoringSafeArea(.all)if self.showProgressView {ProgressView().progressViewStyle(CircularProgressViewStyle(tint: Color("color_progress_view_foreground"))).scaleEffect(3, anchor: .center).zIndex(100000)}VStack(spacing: 0) {HStack {Button(action: {withAnimation {appNavigation.subpageActive = .profile}}, label: {Image(systemName: "chevron.backward").frame(width: 32, height: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).aspectRatio(contentMode: .fit).foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground"))}).padding(.leading, 16)Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : Config.LANG_DELETE_ACCOUNT_TITLE).font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 )).foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground")).padding(.leading, 4)Spacer()}.edgesIgnoringSafeArea(.top).frame(height: 50).background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))Text(Config.LANG_DELETE_ACCOUNT_MESSAGE).font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_DELETE_ACCOUNT_TEXT))TextField("",text: self.$code).font(Font.custom(Config.FONT_NAME_REGULAR, size: 12)).textFieldStyle(PlainTextFieldStyle()).frame(height: 32).keyboardType(.default).autocapitalization(.none).foregroundColor(Color("color_textfield_foreground")).background(Color("color_textfield_background")).padding(.leading, 4).frame(width: UIScreen.main.bounds.width - 32, height: 35)Button(action: {}, label: {Text(Config.LANG_DELETE_ACCOUNT_BUTTON_SEND).font(Font.custom(Config.FONT_NAME_REGULAR, size: 13)).frame(width: UIScreen.main.bounds.width - 32, height: 35).foregroundColor(Color("color_button_foreground")).background(Color("color_button_background")).border(Color("color_button_border"), width: Config.BUTTON_BORDER_SIZE).cornerRadius(Config.BUTTON_BORDER_RADIUS)}).padding(.top, 16).padding(.leading, 16).padding(.trailing, 16)Spacer()HStack {Button(action: {}, label: {Text(Config.LANG_DELETE_ACCOUNT_BUTTON_REQUEST_CODE).font(Font.custom(Config.FONT_NAME_REGULAR, size: 13)).foregroundColor(Color("color_button_foreground")).background(Color("color_button_background")).border(Color("color_button_border"), width: Config.BUTTON_BORDER_SIZE).cornerRadius(Config.BUTTON_BORDER_RADIUS).padding(10)})Spacer()Button(action: {}, label: {Text(Config.LANG_DELETE_ACCOUNT_BUTTON_CANCEL).font(Font.custom(Config.FONT_NAME_REGULAR, size: 13)).foregroundColor(Color("color_button_foreground")).background(Color("color_button_background")).border(Color("color_button_border"), width: Config.BUTTON_BORDER_SIZE).cornerRadius(Config.BUTTON_BORDER_RADIUS).padding(10)})}.padding(.top, 16).padding(.leading, 16).padding(.trailing, 16)} .alert(isPresented: $presentAlert) {Alert(title: Text(self.titleAlert),message: Text(self.messageAlert),dismissButton: .default(Text(Config.LANG_COMMON_OK)))}}}func sendCode() -> Void{let parameters = [Constants.POST_COMMENT_FIELD_ADDED_ON: code]let headerSecurity : HeaderSecurity = HeaderSecurity()let headers: HTTPHeaders = [.init(name: Constants.HTTP_HEADER_SECURITY_TOKEN, value: appData.deviceUuid),.init(name: Constants.HTTP_HEADER_SECURITY_SECRET, value: headerSecurity.secret),.init(name: Constants.HTTP_HEADER_SECURITY_CREATED, value: String(headerSecurity.created)),.init(name: Constants.HTTP_HEADER_SECURITY_RAND, value: String(headerSecurity.rand)),.accept(Constants.HTTP_HEADER_ACCEPT)]self.showProgressView = trueAF.request(Config.URL_DELETE_ACCOUNT, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: headers).responseJSON{(response) inself.showProgressView = falseswitch response.result {case .success:let json = try? JSON(data: response.data!)if json?["success"] ?? "" != false {DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {withAnimation {appData.userUuid = ""appData.userFirstname = ""appData.userLastname = ""appData.userEmail = ""appData.userImage = ""appData.refreshContentActionRequired = falseappData.refreshContentMessage = ""appData.refreshContentMessageShowPending = falseappData.signoutActionRequired = falseappData.save()appNavigation.pageActive = .goodbyedeleteaccount}}} else {let message = json?["data"].string ?? ""if !message.isEmpty {self.titleAlert = Config.LANG_ERROR_GENERIC_TITLEself.messageAlert = messageself.presentAlert = true}}returncase .failure :self.titleAlert = Config.LANG_ERROR_COMMUNICATION_TITLEself.messageAlert = Config.LANG_ERROR_COMMUNICATION_MESSAGEself.presentAlert = truereturn}}}func getCode(){let headerSecurity : HeaderSecurity = HeaderSecurity()let headers: HTTPHeaders = [.init(name: Constants.HTTP_HEADER_SECURITY_TOKEN, value: appData.deviceUuid),.init(name: Constants.HTTP_HEADER_SECURITY_SECRET, value: headerSecurity.secret),.init(name: Constants.HTTP_HEADER_SECURITY_CREATED, value: String(headerSecurity.created)),.init(name: Constants.HTTP_HEADER_SECURITY_RAND, value: String(headerSecurity.rand)),.accept(Constants.HTTP_HEADER_ACCEPT)]self.showProgressView = trueAF.request(Config.URL_DELETE_ACCOUNT, method: .get, headers: headers).responseJSON{(response) inself.showProgressView = falseswitch response.result {case .success:let json = try? JSON(data: response.data!)let message = json?["data"].string ?? ""if !message.isEmpty {self.titleAlert = Config.LANG_ERROR_GENERIC_TITLEself.messageAlert = messageself.presentAlert = true}returncase .failure :self.titleAlert = Config.LANG_ERROR_COMMUNICATION_TITLEself.messageAlert = Config.LANG_ERROR_COMMUNICATION_MESSAGEself.presentAlert = truereturn}}}}struct DeleteAccountView_Previews: PreviewProvider {static var previews: some View {DeleteAccountView()}}