mentorenwahl/frontend/src/components/graphql_errors.rs

35 lines
852 B
Rust

use yew::prelude::*;
#[derive(Properties, PartialEq)]
pub struct GraphQLErrorsProps {
pub errors: Option<Vec<String>>,
}
pub struct GraphQLErrors;
impl Component for GraphQLErrors {
type Message = ();
type Properties = GraphQLErrorsProps;
fn create(_ctx: &Context<Self>) -> Self {
Self
}
fn view(&self, ctx: &Context<Self>) -> Html {
html! {
if let Some(errors) = &ctx.props().errors {
<div>
<p style="color: red;">{ "Errors:" }</p>
<div>
{ for errors.iter().map(|e| html! { <p style="color: red;">{ e }</p> }) }
</div>
</div>
}
}
}
}
pub fn convert(errors: Option<Vec<graphql_client::Error>>) -> Option<Vec<String>> {
errors.map(|x| x.iter().map(|e| e.message.to_owned()).collect())
}