Fix error component, add to all pages
Some checks failed
Build Crate / build (push) Failing after 1m48s
Some checks failed
Build Crate / build (push) Failing after 1m48s
This commit is contained in:
@@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
use crate::components::error_block::ErrorBlock;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
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") {
|
||||
h3 (class="text-xl font-medium text-gray-900 dark:text-white"){"Forgot Password"}
|
||||
|
||||
(match state.error.get().as_ref() != "" {
|
||||
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,}},
|
||||
})
|
||||
// Add component for handling error messages
|
||||
ErrorBlock(error = state.error.clone())
|
||||
|
||||
div {
|
||||
label (class="text-sm font-medium text-gray-900 block mb-2 dark:text-gray-300") {"Username"}
|
||||
|
||||
@@ -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") {
|
||||
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())
|
||||
|
||||
div {
|
||||
|
||||
@@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
use crate::components::error_block::ErrorBlock;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
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") {
|
||||
h3 (class="text-xl font-medium text-gray-900 dark:text-white"){"Register"}
|
||||
|
||||
|
||||
(match state.error.get().as_ref() != "" {
|
||||
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,}},
|
||||
})
|
||||
// Add component for handling error messages
|
||||
ErrorBlock(error = state.error.clone())
|
||||
|
||||
div {
|
||||
label (class="text-sm font-medium text-gray-900 block mb-2 dark:text-gray-300") {"Username"}
|
||||
|
||||
@@ -15,18 +15,19 @@ pub struct ErrorBlockProps {
|
||||
error: RcSignal<String>,
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn ErrorBlock<G: Html>(cx: Scope, props: ErrorBlockProps) -> View<G> {
|
||||
let is_empty = create_selector(cx, || props.error.get().is_empty());
|
||||
#[component(inline_props)]
|
||||
pub fn ErrorBlock<'a, G: Html>(cx: Scope<'a>, error: RcSignal<String>) -> View<G> {
|
||||
let error = create_ref(cx, error);
|
||||
let is_empty = create_selector(cx, || error.get().is_empty());
|
||||
view! { cx,
|
||||
(match *is_empty.get() {
|
||||
(match !(*is_empty.get()) {
|
||||
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 {(*props.error.get())}
|
||||
p {(*error.get())}
|
||||
}
|
||||
}
|
||||
}},
|
||||
|
||||
Reference in New Issue
Block a user