From a3fbdfae8b1e9a4ce3daf95cb5a88aed0d1cb4ec Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 1 Jul 2024 16:18:19 -0500 Subject: [PATCH] working health form pieces too with much better logging --- layouts/shortcodes/camp-form.html | 9 +++- layouts/shortcodes/health-form.html | 3 +- src/api/health_form.rs | 83 +++++++++++++++-------------- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/layouts/shortcodes/camp-form.html b/layouts/shortcodes/camp-form.html index 5829e17..796385f 100644 --- a/layouts/shortcodes/camp-form.html +++ b/layouts/shortcodes/camp-form.html @@ -3,7 +3,14 @@
-
+ +

Camp Form

diff --git a/layouts/shortcodes/health-form.html b/layouts/shortcodes/health-form.html index cca4ebd..58ee0a1 100644 --- a/layouts/shortcodes/health-form.html +++ b/layouts/shortcodes/health-form.html @@ -219,7 +219,8 @@ diff --git a/src/api/health_form.rs b/src/api/health_form.rs index 1c95e02..87d1901 100644 --- a/src/api/health_form.rs +++ b/src/api/health_form.rs @@ -7,6 +7,7 @@ use lettre::{ transport::smtp::authentication::{Credentials, Mechanism}, Message, SmtpTransport, Transport, }; +use maud::html; #[derive(Debug, MultipartForm, Default)] struct HealthForm { @@ -18,6 +19,7 @@ struct HealthForm { parent_first_name: Option>, #[multipart(rename = "parent-last-name")] parent_last_name: Option>, + #[multipart(rename = "birth-date")] birthdate: Option>, street: Option>, city: Option>, @@ -25,13 +27,17 @@ struct HealthForm { zip: Option>, #[multipart(rename = "cell-phone")] parent_cellphone: Option>, + #[multipart(rename = "home-phone")] homephone: Option>, #[multipart(rename = "additional-emergency-contact")] contact: Option>, #[multipart(rename = "addtional-emergency-contact-phone")] contact_phone: Option>, + #[multipart(rename = "doctor-name")] doctorname: Option>, + #[multipart(rename = "doctor-city")] doctorcity: Option>, + #[multipart(rename = "doctor-phone")] doctorphone: Option>, #[multipart(rename = "medical-coverage")] medical: Option>, @@ -248,11 +254,10 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http .0 .clone(); log::info!("{first} {last} filled out a health form!"); - let email = markup::new! { - @markup::doctype() + let email = html! { html { head { - title { @format!("{} {} filled out a health form!", first, last) } + title { (first) " " (last) " filled out a health form!" } style { "table { border-collapse: collapse; width: 100% }" "td, th { padding: 8px }" @@ -263,116 +268,116 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http } } body { - h1 { @format!("Health form for {} {}!", first, last) } + h1 { "Health form for " (first) " " (last) "!" } hr; table { tr { th { "Name" } - td { @format!("{} {}", first, last) } + td { (first) " " (last) } } tr { th { "Parent" } - td { @parent } + td { (parent) } } tr { th { "Birthdate" } - td { @birthdate } + td { (birthdate) } } tr { th { "Street" } - td { @street } + td { (street) } } tr { th { "City" } - td { @city } + td { (city) } } tr { th { "State" } - td { @state } + td { (state) } } tr { th { "Zip" } - td { @zip } + td { (zip) } } tr { th { "Phone" } - td { @parent_cellphone } + td { (parent_cellphone) } } tr { th { "Home Phone" } - td { @homephone } + td { (homephone) } } tr { th { "Additional Emergency Contact" } - td { @contact } + td { (contact) } } tr { th { "Contact Phone" } - td { @contact_phone } + td { (contact_phone) } } tr { th { "Doctor" } - td { @doctorname } + td { (doctorname) } } tr { th { "Doctor City" } - td { @doctorcity } + td { (doctorcity) } } tr { th { "Doctor Phone" } - td { @doctorphone } + td { (doctorphone) } } tr { th { "Medical Coverage" } - td { @medical } + td { (medical) } } tr { th { "Insurance Provider" } - td { @insurance } + td { (insurance) } } tr { th { "Policy Number" } - td { @policy_number } + td { (policy_number) } } tr { th { "Allergies" } - td { @allergies } + td { (allergies) } } tr { th { "Other Allergies" } - td { @allergies_other } + td { (allergies_other) } } tr { th { "Specific Allergies" } - td { @specific_allergies } + td { (specific_allergies) } } tr { th { "Treatments" } - td { @treatment } + td { (treatment) } } tr { th { "Physical or mental conditions" } - td { @conditions } + td { (conditions) } } tr { th { "Last tetanus shot" } - td { @tetanus } + td { (tetanus) } } tr { th { "Swimming Ability" } - td { @swimming } + td { (swimming) } } tr { th { "Medication Schedule" } - td { @medication } + td { (medication) } } tr { th { "Other Relevant Info" } - td { @notes } + td { (notes) } } tr { th { "Final Agreement" } - td { @agreement } + td { (agreement) } } } } @@ -410,10 +415,10 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http let attachment = Attachment::new(filename).body(filebody.unwrap(), content_type); log::info!("{:?}", attachment); MultiPart::mixed() - .singlepart(SinglePart::html(email.to_string())) + .singlepart(SinglePart::html(email.into_string())) .singlepart(attachment) } else { - MultiPart::alternative_plain_html(String::from("Testing"), email.to_string()) + MultiPart::alternative_plain_html(String::from("Testing"), email.into_string()) }; log::info!("{:?}", multi); @@ -469,11 +474,11 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http } "later" => { log::info!("{} would like to pay later", full_name); - let html = markup::new! { + let html = html! { div { class { "mt-8" } h2 { - @format!("Thank you, {}!", full_name) + "Thank you, " (full_name) "!" } p { "Can't wait to see you at camp!" } p { @@ -482,15 +487,15 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http } } }; - HttpResponse::Ok().body(html.to_string()) + HttpResponse::Ok().body(html.into_string()) } _ => { log::error!("Got registration error....."); - let html = markup::new! { + let html = html! { div { class { "mt-8" } h2 { - @format!("Thank you, {}!", full_name) + "Thank you, " (full_name) "!" } p { "Can't wait to see you at camp!" } p { @@ -499,7 +504,7 @@ pub async fn health_form(MultipartForm(form): MultipartForm) -> Http } } }; - HttpResponse::Ok().body(html.to_string()) + HttpResponse::Ok().body(html.into_string()) } } // HttpResponse::Ok().body("hi")