emails funktionieren

This commit is contained in:
2023-01-31 22:26:26 +01:00
parent c708a4b79b
commit 00aae2dfca
12 changed files with 323 additions and 86 deletions
+9 -17
View File
@@ -3,10 +3,9 @@ use std::collections::{HashMap, HashSet};
use gloo::console::log;
use requests::{fetch_slots, fetch_teachers, fetch_unavailable, send_appointments};
use serde::{Deserialize, Serialize};
use terminwahl_typen::{
AppointmentSlot, AppointmentSlots, IdType, PlannedAppointment, RequestState, SlotId, Teacher,
Teachers,
AppointmentSlot, AppointmentSlots, IdType, Nutzer, PlannedAppointment, RequestState, SlotId,
Teacher, Teachers,
};
use web_sys::HtmlInputElement;
use yew::prelude::*;
@@ -38,13 +37,6 @@ pub struct App {
successfully_saved: Option<RequestState>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Nutzer {
name: String,
schüler: String,
email: String,
}
impl From<Result<Msg, Msg>> for Msg {
fn from(value: Result<Msg, Msg>) -> Self {
match value {
@@ -54,12 +46,6 @@ impl From<Result<Msg, Msg>> for Msg {
}
}
impl Nutzer {
fn validate(&self) -> bool {
!self.name.is_empty() && !self.email.is_empty() && !self.schüler.is_empty()
}
}
impl Component for App {
type Message = Msg;
type Properties = ();
@@ -137,7 +123,13 @@ impl Component for App {
if (1..=3).contains(&self.appointments.len()) {
let values = self.appointments.clone().into_values();
let appointments: Vec<PlannedAppointment> = values.collect();
ctx.link().send_future(send_appointments(appointments));
ctx.link().send_future(send_appointments(
appointments,
self.nutzer
.as_ref()
.expect("This should always exist")
.clone(),
));
true
} else {
true
+6 -3
View File
@@ -1,5 +1,5 @@
use gloo::net::http::{Method, Request};
use terminwahl_typen::{PlannedAppointment, RequestState};
use terminwahl_typen::{Nutzer, PlannedAppointment, RequestState};
use crate::Msg;
@@ -39,10 +39,13 @@ pub async fn fetch_unavailable() -> Result<Msg, Msg> {
Ok(Msg::ReceivedUnavailable(response))
}
pub async fn send_appointments(appointments: Vec<PlannedAppointment>) -> Result<Msg, Msg> {
pub async fn send_appointments(
appointments: Vec<PlannedAppointment>,
nutzer: Nutzer,
) -> Result<Msg, Msg> {
let response = Request::new("/send/appointments")
.method(Method::POST)
.json(&appointments)
.json(&(&appointments, &nutzer))
.map_err(|_| Msg::AppointmentsSent(RequestState::Error))?
.send()
.await;