use crate::components::modal_box::DialogOpener;
use leptos::*;

#[component]
pub fn ServerErr(
    result: RwSignal<Option<Result<(), ServerFnError>>>,
    opener: DialogOpener,
) -> impl IntoView {
    view! {{move || {
        if let Some(val) = result.get() {
            if let Err(e) = val {
                view! {
                <div class="alert alert-danger">
                    "Server error: " {e.to_string()}
                </div>
                }
            } else {
                opener.hide();
                view! {<div></div>}
            }
        } else {
            view! {<div></div>}
        }
    }}
    }
}
