From 653249287d6175371fb4ca0334bddf6b1a180f1e Mon Sep 17 00:00:00 2001
From: Josef Rokos
Date: Mon, 19 Feb 2024 17:39:37 +0100
Subject: [PATCH] Added checkbox to booking form - remember customer
---
src/backend/customer.rs | 22 ++++++++++++++++++++++
src/backend/data.rs | 6 +++++-
src/backend/reservation.rs | 10 ++++++++++
src/locales/catalogues.rs | 3 ++-
src/pages/public.rs | 29 +++++++++++++++++++++++++----
5 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/src/backend/customer.rs b/src/backend/customer.rs
index 085a362..6c6c93e 100644
--- a/src/backend/customer.rs
+++ b/src/backend/customer.rs
@@ -9,6 +9,8 @@ cfg_if! { if #[cfg(feature = "ssr")] {
use sqlx::Error;
use std::ops::DerefMut;
use leptos::expect_context;
+ use leptos_actix::extract;
+ use actix_session::Session;
pub async fn find_customer_by_email(email: &str, tx: &mut Transaction<'_, Postgres>) -> Option {
let customer = query_as::<_, Customer>("SELECT * FROM customer WHERE email = $1")
@@ -50,6 +52,12 @@ cfg_if! { if #[cfg(feature = "ssr")] {
.await?;
Ok(find_customer_by_email(email, tx).await.ok_or(Error::RowNotFound)?)
}
+
+ pub async fn remember_customer(customer: Customer) -> Result<(), ServerFnError> {
+ let session: Session = extract().await?;
+ session.insert("customer", customer)?;
+ Ok(())
+ }
}}
#[server]
@@ -66,4 +74,18 @@ pub async fn get_customers() -> Result>, ServerFnError
.await?;
Ok(ApiResponse::Data(customers))
+}
+
+#[server]
+pub async fn get_remembered() -> Result
}>
{move || {
+ get_customer.get().map(|c| match c {
+ Err(_) => {},
+ Ok(c) => {
+ if let Some(c) = c {
+ customer.set(c);
+ }
+ }
+ });
form_data.get().map(|u| match u {
Err(e) => {
view! {{e.to_string()}
}}
@@ -216,7 +228,7 @@ pub fn Public() -> impl IntoView {
id="full_name"
class="form-control"
placeholder={trl("Enter full name")}
- //prop:value={move || opener.empty()}
+ prop:value={move || customer.get().full_name}
name="reservation[full_name]"
/>
@@ -229,7 +241,7 @@ pub fn Public() -> impl IntoView {
id="email"
class="form-control"
placeholder={trl("Enter e-mail address")}
- //prop:value={move || opener.empty()}
+ prop:value={move || customer.get().email}
name="reservation[email]"
/>
@@ -242,7 +254,7 @@ pub fn Public() -> impl IntoView {
id="phone"
class="form-control"
placeholder={trl("Enter phone number")}
- //prop:value={move || opener.empty()}
+ prop:value={move || customer.get().phone}
name="reservation[phone]"
/>
@@ -260,6 +272,15 @@ pub fn Public() -> impl IntoView {
/>
+
+
+