                 let alert = NSAlert(error: error)
                 alert.beginSheetModal(for: window, completionHandler: nil)
             }
+        }
+    }
+
+    private func submitRadarCompletion(success: Bool) {
+        self.progressIndicator.stopAnimation(self)
+        self.submitButton.isEnabled = true
+
+        if success {
+            if self.document?.fileURL != nil {
+                self.document?.save(self)
+            }
+
+            self.view.window?.close()
         }
     }
 


    @IBAction private func submitRadar(_ sender: Any) {
        for field in self.validatables where !field.isValid {
            return
        }

        guard let (username, password) = Keychain.get(.radar) else {
            return self.showError(message: "Submitting radar without username/password")
        }

        var radar = self.currentRadar()
        self.submitButton.isEnabled = false
        self.progressIndicator.startAnimation(self)

        let completion: (Bool) -> Void = { [weak self] success in
            self?.progressIndicator.stopAnimation(self)
            self?.submitButton.isEnabled = true
            if success {
                if self?.document?.fileURL != nil {
                    self?.document?.save(self)
                }

                self?.view.window?.close()
            }
        }

        let appleRadar = Sonar(service: .appleRadar(appleID: username, password: password))
        appleRadar.loginThenCreate(

                        radar: radar, getTwoFactorCode: { closure in
                            assertionFailure("Didn't handle Open Radar two factor")
                            closure(nil)
                    }) { [weak self] result in
                        switch result {
                            case .success:
                                self?.submitRadarCompletion(success: true)
                            case .failure(let error):
                                self?.showError(message: error.message)
                                self?.submitRadarCompletion(success: false)
                        }
                    }
                case .failure(let error):
                    self?.showError(message: error.message)
                    self?.submitRadarCompletion(success: false)
            }
        }
    }
