diff --git a/TODO.org b/TODO.org
index 607003d..b684f2a 100644
--- a/TODO.org
+++ b/TODO.org
@@ -4,15 +4,14 @@
:END:
* TODO Calculate age on the camp form
-* TODO Update MT Form in Rust server and upload data to NC
-** TODO Add any updated questions and redesign the page to fit the next trips
-** DONE Add functionality for uploading all data to the NC tables
-** TODO Add a backup sqlite db so that we can still retain the info in multiple places
-** TODO Make sure the form is asynchronous so that users will get their page popping back immediately
-** TODO Make sure form has better validation
+* TODO Create a way to add some kids to nextcloud tables fast
* DONE Create unit tests in order to automatically make sure things work
** DONE Break down the api to functions that are testable
-* TODO Create a way to add some kids to nextcloud tables fast
+* DONE Update MT Form in Rust server and upload data to NC
+** DONE Add any updated questions and redesign the page to fit the next trips
+** DONE Add functionality for uploading all data to the NC tables
+** DONE Make sure the form is asynchronous so that users will get their page popping back immediately
+** DONE Make sure form has better validation
* DONE Add registration cost and info to home page, thank you page, and thank you responses
SCHEDULED: <2024-04-25 Thu 09:00>
* DONE Post health form to nextcloud tables
diff --git a/layouts/shortcodes/mt-form.html b/layouts/shortcodes/mt-form.html
index ddaeeff..b50bec3 100644
--- a/layouts/shortcodes/mt-form.html
+++ b/layouts/shortcodes/mt-form.html
@@ -386,6 +386,23 @@
Later - Send $25 to the TFC Office
+
+
+
+
+
+
+
+
+
diff --git a/src/api/health_form.rs b/src/api/health_form.rs
index 8285e03..51749a2 100644
--- a/src/api/health_form.rs
+++ b/src/api/health_form.rs
@@ -364,6 +364,14 @@ pub async fn health_form(MultipartForm(mut form): MultipartForm) ->
Err(e) => error!("There was an error sending email: {e}"),
}
+ let map = HashMap::from(&form);
+ actix_rt::spawn(store_form(map).map(|r| match r {
+ Ok(_) => {
+ info!("Successfully stored health form in nextcloud!")
+ }
+ Err(e) => error!("There was an error storing form in nextcloud: {e}"),
+ }));
+
let full_name = format!("{} {}", form.first_name.0, form.last_name.0);
match form.registration.0.as_str() {
"now" => {
@@ -372,7 +380,7 @@ pub async fn health_form(MultipartForm(mut form): MultipartForm) ->
.insert_header(("Access-Control-Expose-Headers", "*"))
.insert_header((
"HX-Redirect",
- "https://secure.myvanco.com/L-Z772/campaign/C-13JPJ",
+ "https://secure.myvanco.com/L-Z772/campaign/C-13DM3",
))
.finish()
}
@@ -393,10 +401,9 @@ pub async fn health_form(MultipartForm(mut form): MultipartForm) ->
h2 {
"Thank you, " (full_name) "!"
}
- p { "Can't wait to see you at camp!" }
p {
class { "" }
- "If you'd like to pay for your registration go to the donate tab in the top right when you are ready and find the camp registration option."
+ "If you'd like to pay for your registration go to the donate tab in the top right when you are ready and find the right registration option."
}
}
};
@@ -423,3 +430,27 @@ pub async fn health_form(MultipartForm(mut form): MultipartForm) ->
}
// HttpResponse::Ok().body("hi")
}
+
+async fn store_form(map: HashMap) -> Result<()> {
+ let client = Client::new();
+ let mut json = HashMap::new();
+ json.insert("data", map);
+
+ let res = client
+ .post("https://staff.tfcconnection.org/ocs/v2.php/apps/tables/api/2/tables/4/rows")
+ .basic_auth("chris", Some("2VHeGxeC^Zf9KqFK^G@Pt!zu2q^6@b"))
+ .header("OCS-APIRequest", "true")
+ .header("Content-Type", "application/json")
+ .json(&json)
+ .send()
+ .await?;
+ if res.status().is_success() {
+ let res = res.text().await.unwrap();
+ Ok(())
+ } else {
+ Err(eyre!(
+ "Problem in storing data: {:?}",
+ res.error_for_status()
+ ))
+ }
+}
diff --git a/src/api/mt_form.rs b/src/api/mt_form.rs
index 2ab5531..126f583 100644
--- a/src/api/mt_form.rs
+++ b/src/api/mt_form.rs
@@ -68,6 +68,8 @@ struct MtForm {
#[multipart(rename = "final-agreement")]
final_agreement: Text,
registration: Text,
+ #[multipart(rename = "health-form")]
+ health_form: Text,
#[multipart(rename = "image")]
file: Option,
}
@@ -364,7 +366,7 @@ impl MtForm {
.unwrap(),
)
.to("Chris Cochrun ".parse().unwrap())
- .to("Ethan Rose ".parse().unwrap())
+ // .to("Ethan Rose ".parse().unwrap())
.subject(email_subject)
.multipart(multi)
.wrap_err("problemss")
@@ -391,7 +393,58 @@ pub async fn mt_form(MultipartForm(form): MultipartForm) -> HttpResponse
}
Err(e) => error!("error sending email {e}"),
};
- HttpResponse::Ok().body(format!("Thank you {}, you can ", name))
+ match form.registration.0.as_str() {
+ "now" => {
+ if form.health_form.0.as_str() == "yes" {
+ HttpResponse::Ok()
+ .insert_header(("Access-Control-Expose-Headers", "*"))
+ .insert_header(("HX-Redirect", "/health-form?registration=now"))
+ .finish()
+ } else {
+ HttpResponse::Ok()
+ .insert_header(("Access-Control-Expose-Headers", "*"))
+ .insert_header((
+ "HX-Redirect",
+ "https://secure.myvanco.com/L-Z772/campaign/C-13DM3",
+ ))
+ .finish()
+ }
+ }
+ "later" => {
+ if form.health_form.0.as_str() == "yes" {
+ HttpResponse::Ok()
+ .insert_header(("Access-Control-Expose-Headers", "*"))
+ .insert_header(("HX-Redirect", "/health-form?registration=later"))
+ .finish()
+ } else {
+ HttpResponse::Ok().body(
+ html! {
+ h2 { "Thank you! {}" (name)}
+ p { "You can go to the health form "
+ a href="/health-form" { "here" }
+ " or you can pay for mission trip "
+ a href="https://secure.myvanco.com/L-Z772/campaign/C-13DM3" { "here" }
+ }
+ }
+ .into_string(),
+ )
+ }
+ }
+ _ => {
+ error!("There wasn't an option for the registration passed in.");
+ HttpResponse::Ok().body(
+ html! {
+ h2 { "Thank you! {}" (name)}
+ p { "You can go to the health form "
+ a href="/health-form" { "here" }
+ " or you can pay for mission trip "
+ a href="https://secure.myvanco.com/L-Z772/campaign/C-13DM3" { "here" }
+ }
+ }
+ .into_string(),
+ )
+ }
+ }
}
async fn store_form(map: HashMap) -> Result<()> {
@@ -465,6 +518,7 @@ mod test {
relevant_notes: Text(String::from("Willing to take the ring")),
final_agreement: Text(String::from("yes")),
registration: Text(String::from("later")),
+ health_form: Text(String::from("yes")),
file: None,
}
}
@@ -484,7 +538,7 @@ mod test {
async fn test_email() {
let mut form = form();
assert!(!form.first_name.is_empty());
- match form.send_email().await {
+ match form.send_email() {
Ok(_) => assert!(true, "passed emailing test"),
Err(e) => assert!(false, "Failed emailing test: {e}"),
}