register has dropdown now

This commit is contained in:
filipriec
2025-08-29 22:07:04 +02:00
parent a09c804595
commit 60eb1c9f51
6 changed files with 149 additions and 60 deletions

View File

@@ -0,0 +1,36 @@
// src/pages/register/suggestions.rs
use anyhow::Result;
use async_trait::async_trait;
use canvas::{SuggestionItem, SuggestionsProvider};
// Keep the async provider if you want, but add this sync helper and shared data.
const ROLES: &[&str] = &["admin", "moderator", "accountant", "viewer"];
pub fn role_suggestions_sync(query: &str) -> Vec<SuggestionItem> {
let q = query.to_lowercase();
ROLES
.iter()
.filter(|r| q.is_empty() || r.to_lowercase().contains(&q))
.map(|r| SuggestionItem {
display_text: (*r).to_string(),
value_to_store: (*r).to_string(),
})
.collect()
}
pub struct RoleSuggestionsProvider;
#[async_trait]
impl SuggestionsProvider for RoleSuggestionsProvider {
async fn fetch_suggestions(
&mut self,
field_index: usize,
query: &str,
) -> Result<Vec<SuggestionItem>> {
if field_index != 4 {
return Ok(Vec::new());
}
Ok(role_suggestions_sync(query))
}
}