mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-26 05:13:24 +03:00
Extract common code.
This commit is contained in:
parent
9a4850ba10
commit
76208360ae
@ -373,42 +373,40 @@ sendFake =
|
||||
|
||||
sendEmailDataSource : EmailAddress -> String -> DataSource (Result SendGrid.Error ())
|
||||
sendEmailDataSource recipient apiKey =
|
||||
if sendFake then
|
||||
emailToMagicLink recipient
|
||||
|> DataSource.andThen
|
||||
(\magicLinkString ->
|
||||
let
|
||||
emailBody : String
|
||||
emailBody =
|
||||
"Welcome! Please confirm that this is your email address.\n" ++ magicLinkString
|
||||
in
|
||||
log emailBody
|
||||
emailToMagicLink recipient
|
||||
|> DataSource.andThen
|
||||
(\magicLinkString ->
|
||||
let
|
||||
message : NonemptyString
|
||||
message =
|
||||
String.Nonempty.NonemptyString 'W' ("elcome! Please confirm that this is your email address.\n" ++ magicLinkString)
|
||||
in
|
||||
if sendFake then
|
||||
message
|
||||
|> String.Nonempty.toString
|
||||
|> log
|
||||
|> DataSource.map Ok
|
||||
)
|
||||
|
||||
else
|
||||
let
|
||||
senderEmail : Maybe EmailAddress
|
||||
senderEmail =
|
||||
EmailAddress.fromString "dillon@incrementalelm.com"
|
||||
in
|
||||
senderEmail
|
||||
|> Maybe.map
|
||||
(\justSender ->
|
||||
emailToMagicLink recipient
|
||||
|> DataSource.andThen
|
||||
(\magicLinkString ->
|
||||
else
|
||||
let
|
||||
senderEmail : Maybe EmailAddress
|
||||
senderEmail =
|
||||
EmailAddress.fromString "dillon@incrementalelm.com"
|
||||
in
|
||||
senderEmail
|
||||
|> Maybe.map
|
||||
(\justSender ->
|
||||
SendGrid.textEmail
|
||||
{ subject = String.Nonempty.NonemptyString 'T' "odo app login"
|
||||
, to = List.Nonempty.fromElement recipient
|
||||
, content = String.Nonempty.NonemptyString 'W' ("elcome! Please confirm that this is your email address.\n" ++ magicLinkString)
|
||||
, content = message
|
||||
, nameOfSender = "Todo App"
|
||||
, emailAddressOfSender = justSender
|
||||
}
|
||||
|> sendEmail apiKey
|
||||
)
|
||||
)
|
||||
|> Maybe.withDefault (DataSource.fail "Expected a valid sender email address.")
|
||||
|> Maybe.withDefault (DataSource.fail "Expected a valid sender email address.")
|
||||
)
|
||||
|
||||
|
||||
sendEmail :
|
||||
|
Loading…
Reference in New Issue
Block a user