Fix error component, add to all pages
Some checks failed
Build Crate / build (push) Failing after 1m48s

This commit is contained in:
2024-08-29 22:43:55 -04:00
parent d523373b8e
commit 510158f381
4 changed files with 16 additions and 33 deletions

View File

@@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
use sycamore::prelude::*; use sycamore::prelude::*;
use web_sys::Event; use web_sys::Event;
use crate::components::error_block::ErrorBlock;
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(client)] { if #[cfg(client)] {
use crate::{ use crate::{
@@ -114,19 +116,8 @@ fn forgot_password_form_capsule<G: Html>(
div (class="space-y-6 px-6 lg:px-8 pb-4 sm:pb-6 xl:pb-8") { div (class="space-y-6 px-6 lg:px-8 pb-4 sm:pb-6 xl:pb-8") {
h3 (class="text-xl font-medium text-gray-900 dark:text-white"){"Forgot Password"} h3 (class="text-xl font-medium text-gray-900 dark:text-white"){"Forgot Password"}
(match state.error.get().as_ref() != "" { // Add component for handling error messages
true => { view!{cx, ErrorBlock(error = state.error.clone())
div (role="alert") {
div (class="bg-red-500 text-white font-bold rounded-t px-4 py-2") {
"Error"
}
div (class="border border-t-0 border-red-400 rounded-b bg-red-100 px-4 py-3 text-red-700"){
p {(state.error.get())}
}
}
}},
false => {view!{cx,}},
})
div { div {
label (class="text-sm font-medium text-gray-900 block mb-2 dark:text-gray-300") {"Username"} label (class="text-sm font-medium text-gray-900 block mb-2 dark:text-gray-300") {"Username"}

View File

@@ -152,6 +152,7 @@ fn login_form_capsule<G: Html>(
div (class="space-y-6 px-6 lg:px-8 pb-4 sm:pb-6 xl:pb-8") { div (class="space-y-6 px-6 lg:px-8 pb-4 sm:pb-6 xl:pb-8") {
h3 (class="text-xl font-medium text-gray-900 dark:text-white"){"Sign in"} h3 (class="text-xl font-medium text-gray-900 dark:text-white"){"Sign in"}
// Add component for handling error messages
ErrorBlock(error = state.error.clone()) ErrorBlock(error = state.error.clone())
div { div {

View File

@@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
use sycamore::prelude::*; use sycamore::prelude::*;
use web_sys::Event; use web_sys::Event;
use crate::components::error_block::ErrorBlock;
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(client)] { if #[cfg(client)] {
use crate::{ use crate::{
@@ -125,20 +127,8 @@ fn register_form_capsule<G: Html>(
div (class="space-y-6 px-6 lg:px-8 pb-4 sm:pb-6 xl:pb-8") { div (class="space-y-6 px-6 lg:px-8 pb-4 sm:pb-6 xl:pb-8") {
h3 (class="text-xl font-medium text-gray-900 dark:text-white"){"Register"} h3 (class="text-xl font-medium text-gray-900 dark:text-white"){"Register"}
// Add component for handling error messages
(match state.error.get().as_ref() != "" { ErrorBlock(error = state.error.clone())
true => { view!{cx,
div (role="alert") {
div (class="bg-red-500 text-white font-bold rounded-t px-4 py-2") {
"Error"
}
div (class="border border-t-0 border-red-400 rounded-b bg-red-100 px-4 py-3 text-red-700"){
p {(state.error.get())}
}
}
}},
false => {view!{cx,}},
})
div { div {
label (class="text-sm font-medium text-gray-900 block mb-2 dark:text-gray-300") {"Username"} label (class="text-sm font-medium text-gray-900 block mb-2 dark:text-gray-300") {"Username"}

View File

@@ -15,18 +15,19 @@ pub struct ErrorBlockProps {
error: RcSignal<String>, error: RcSignal<String>,
} }
#[component] #[component(inline_props)]
pub fn ErrorBlock<G: Html>(cx: Scope, props: ErrorBlockProps) -> View<G> { pub fn ErrorBlock<'a, G: Html>(cx: Scope<'a>, error: RcSignal<String>) -> View<G> {
let is_empty = create_selector(cx, || props.error.get().is_empty()); let error = create_ref(cx, error);
let is_empty = create_selector(cx, || error.get().is_empty());
view! { cx, view! { cx,
(match *is_empty.get() { (match !(*is_empty.get()) {
true => { view!{cx, true => { view!{cx,
div (role="alert") { div (role="alert") {
div (class="bg-red-500 text-white font-bold rounded-t px-4 py-2") { div (class="bg-red-500 text-white font-bold rounded-t px-4 py-2") {
"Error" "Error"
} }
div (class="border border-t-0 border-red-400 rounded-b bg-red-100 px-4 py-3 text-red-700"){ div (class="border border-t-0 border-red-400 rounded-b bg-red-100 px-4 py-3 text-red-700"){
p {(*props.error.get())} p {(*error.get())}
} }
} }
}}, }},