Skip to content
Repos

DevPlaceApp

C++ 1.9 KB49 lines Opens in site

Directory Raw Download

#pragma once
// Spec: FR-AUTH-01, PG-11, INV-shell 13. Create account, pushed inside the sign in navigation stack.
#include <memory>
#include <optional>
#include <string>

#include "ui/Controls.hpp"
#include "ui/Navigation.hpp"
#include "ui/TextInput.hpp"

namespace dp {

class SignUpScreen : public ui::Screen {
 public:
  SignUpScreen();
  ~SignUpScreen() override { *alive_ = false; }

  ui::ViewPtr body() override;
  std::string title() const override;
  TitleMode titleMode() const override { return TitleMode::Inline; }
  bool busy() const override { return isLoading_; }

  bool canSubmit() const;
  // First failing rule in the order of the Swift view model, nullopt when valid.
  std::optional<std::string> validationError() const;
  void signUp();

  void setUsername(std::string v) { username_ = std::move(v); }
  void setEmail(std::string v) { email_ = std::move(v); }
  void setPassword(std::string v) { password_ = std::move(v); }
  void setConfirm(std::string v) { confirm_ = std::move(v); }
  void setTosAccepted(bool v) { tosAccepted_ = v; }

 private:
  ui::ViewPtr field(const std::string& placeholder, std::string* value, bool secure, int minCount, int maxCount,
                    std::shared_ptr<ui::TextInputHandle> handle, std::shared_ptr<ui::TextInputHandle> next);

  std::shared_ptr<bool> alive_ = std::make_shared<bool>(true);
  std::string username_, email_, password_, confirm_;
  bool tosAccepted_ = false;
  bool isLoading_ = false;
  ui::CivilDate birth_ = ui::CivilDate::today();
  std::shared_ptr<ui::TextInputHandle> hUser_ = std::make_shared<ui::TextInputHandle>();
  std::shared_ptr<ui::TextInputHandle> hEmail_ = std::make_shared<ui::TextInputHandle>();
  std::shared_ptr<ui::TextInputHandle> hPass_ = std::make_shared<ui::TextInputHandle>();
  std::shared_ptr<ui::TextInputHandle> hConfirm_ = std::make_shared<ui::TextInputHandle>();
};

}  // namespace dp
39.9ms