-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add admin newsletter publish form
Also moved POST /newsletters to POST /admin/newsletters.
- Loading branch information
1 parent
88cf9dd
commit f3bd6dd
Showing
9 changed files
with
123 additions
and
173 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,50 @@ | ||
use actix_web::http::header::ContentType; | ||
use actix_web::http::StatusCode; | ||
use actix_web::HttpResponse; | ||
use actix_web_flash_messages::IncomingFlashMessages; | ||
use std::fmt::Write; | ||
|
||
pub async fn submit_newsletter_form() -> HttpResponse { | ||
HttpResponse::Ok().finish() | ||
pub async fn publish_newsletter_form(flash_messages: IncomingFlashMessages) -> HttpResponse { | ||
let mut msg_html = String::new(); | ||
for m in flash_messages.iter() { | ||
write!(msg_html, "<p><i>{}</i></p>", m.content()).unwrap(); | ||
} | ||
|
||
let html_body = format!( | ||
r#"<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | ||
<title>Submit Newsletter</title> | ||
</head> | ||
<body> | ||
{msg_html} | ||
<form action="/admin/newsletters" method="post"> | ||
<label> | ||
Title | ||
<br /> | ||
<input type="text" name="title" placeholder="Newsletter title" /> | ||
</label> | ||
<br /> | ||
<label> | ||
HTML Content | ||
<br /> | ||
<textarea name="html_content" placeholder="Newsletter content as HTML"></textarea> | ||
</label> | ||
<br /> | ||
<label> | ||
Text Content | ||
<br /> | ||
<textarea name="text_content" placeholder="Newsletter content as plain text"></textarea> | ||
</label> | ||
<br /> | ||
<button type="submit">Submit newsletter</button> | ||
</form> | ||
</body> | ||
</html>"# | ||
); | ||
|
||
HttpResponse::build(StatusCode::OK) | ||
.content_type(ContentType::html()) | ||
.body(html_body) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod get; | ||
mod post; | ||
|
||
pub use get::*; | ||
pub use get::publish_newsletter_form; | ||
pub use post::publish_newsletter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.