personForm
  :: Maybe (Entity Person,Maybe (Entity PersonLogin))
  -> PhbForm T.Text PersonInput
personForm e = PersonInput
  <$> "name"              .: check nameErrMsg isNotEmpty (text name)
  <*> "email"             .: check emailErrMsg isNotEmpty (text email)
  <*> "department"        .: check departmentErrMsg isNotEmpty (text department)
  <*> "loginName"         .: optionalText loginName
  <*> "receivesHeartbeat" .: bool receivesHeartbeat
  <*> "logsTime"          .: bool logsTime
  where
    name              = e ^?_Just._1.eVal.personName
    email             = e ^?_Just._1.eVal.personEmail
    department        = e ^?_Just._1.eVal.personDepartment
    receivesHeartbeat = e ^?_Just._1.eVal.personReceivesHeartbeat
    logsTime          = e ^?_Just._1.eVal.personLogsTime
    loginName         = e ^?_Just._2._Just.eVal.personLoginLogin
    nameErrMsg        = "Name must not be empty"
    emailErrMsg       = "Email must not be empty"
    departmentErrMsg  = "Department must not be empty"
personForm
  :: Maybe (Entity Person,Maybe (Entity PersonLogin))
  -> PhbForm T.Text PersonInput
personForm e = PersonInput
  <$> "name"              .: check nameErrMsg isNotEmpty (text name)
  <*> "email"             .: check emailErrMsg isNotEmpty (text email)
  <*> "department"        .: check departmentErrMsg isNotEmpty (text department)
  <*> "loginName"         .: optionalText loginName
  <*> "receivesHeartbeat" .: bool receivesHeartbeat
  <*> "logsTime"          .: bool logsTime
  where
    name              = e ^?_Just._1.eVal.personName
    email             = e ^?_Just._1.eVal.personEmail
    department        = e ^?_Just._1.eVal.personDepartment
    receivesHeartbeat = e ^?_Just._1.eVal.personReceivesHeartbeat
    logsTime          = e ^?_Just._1.eVal.personLogsTime
    loginName         = e ^?_Just._2._Just.eVal.personLoginLogin
    nameErrMsg        = "Name must not be empty"
    emailErrMsg       = "Email must not be empty"
    departmentErrMsg  = "Department must not be empty"
personForm e = PersonInput
  <$> "name"              .: check nameErrMsg isNotEmpty (text name)
  <*> "email"             .: check emailErrMsg isNotEmpty (text email)
  <*> "department"        .: check departmentErrMsg isNotEmpty (text department)
  <*> "loginName"         .: optionalText loginName
  <*> "receivesHeartbeat" .: bool receivesHeartbeat
  <*> "logsTime"          .: bool logsTime
  where
    name              = e ^?_Just._1.eVal.personName
    email             = e ^?_Just._1.eVal.personEmail
    department        = e ^?_Just._1.eVal.personDepartment
    receivesHeartbeat = e ^?_Just._1.eVal.personReceivesHeartbeat
    logsTime          = e ^?_Just._1.eVal.personLogsTime
    loginName         = e ^?_Just._2._Just.eVal.personLoginLogin
    nameErrMsg        = "Name must not be empty"
    emailErrMsg       = "Email must not be empty"
    departmentErrMsg  = "Department must not be empty"