Added DataForm component for easier edit dialogs.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use leptos::*;
|
||||
use validator::Validate;
|
||||
use crate::backend::data::{ApiResponse, Company};
|
||||
use crate::components::data_form::ForValidation;
|
||||
|
||||
#[server(GetCompany, "/api", "Url", "get_company")]
|
||||
pub async fn get_company() -> Result<ApiResponse<Company>, ServerFnError> {
|
||||
@@ -44,3 +46,9 @@ pub async fn update_company(company: Company) -> Result<ApiResponse<()>, ServerF
|
||||
|
||||
Ok(ApiResponse::Data(()))
|
||||
}
|
||||
|
||||
impl ForValidation for UpdateCompany {
|
||||
fn entity(&self) -> &dyn Validate {
|
||||
&self.company
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
use cfg_if::cfg_if;
|
||||
use leptos::*;
|
||||
use validator::Validate;
|
||||
use crate::backend::data::{ApiResponse, PwdChange, User, UserProfile};
|
||||
use crate::components::data_form::ForValidation;
|
||||
|
||||
cfg_if! { if #[cfg(feature = "ssr")] {
|
||||
use sqlx::{query_as, Error, PgPool, query};
|
||||
@@ -110,6 +112,21 @@ pub async fn get_user() -> Result<Option<User>, ServerFnError> {
|
||||
Ok(logged_in_user().await)
|
||||
}
|
||||
|
||||
#[server(GetUsers, "/api", "Url", "get_users")]
|
||||
pub async fn get_users() -> Result<ApiResponse<Vec<User>>, ServerFnError> {
|
||||
use crate::backend::AppData;
|
||||
use actix_web::web::Data;
|
||||
use leptos_actix::extract;
|
||||
use crate::perm_check;
|
||||
|
||||
perm_check!(is_admin);
|
||||
|
||||
let pool = extract(|data: Data<AppData>| async move { data.db_pool().clone() }).await?;
|
||||
let users = sqlx::query_as::<_, User>(r#"SELECT * FROM "user""#).fetch_all(&pool).await?;
|
||||
|
||||
Ok(ApiResponse::Data(users))
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn update_profile(user: UserProfile) -> Result<ApiResponse<()>, ServerFnError> {
|
||||
use crate::backend::AppData;
|
||||
@@ -136,6 +153,12 @@ pub async fn update_profile(user: UserProfile) -> Result<ApiResponse<()>, Server
|
||||
Ok(ApiResponse::Data(()))
|
||||
}
|
||||
|
||||
impl ForValidation for UpdateProfile {
|
||||
fn entity(&self) -> &dyn Validate {
|
||||
&self.user
|
||||
}
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn change_pwd(new_pw: PwdChange) -> Result<ApiResponse<()>, ServerFnError> {
|
||||
use crate::backend::AppData;
|
||||
@@ -162,4 +185,10 @@ pub async fn change_pwd(new_pw: PwdChange) -> Result<ApiResponse<()>, ServerFnEr
|
||||
.await?;
|
||||
|
||||
Ok(ApiResponse::Data(()))
|
||||
}
|
||||
|
||||
impl ForValidation for ChangePwd {
|
||||
fn entity(&self) -> &dyn Validate {
|
||||
&self.new_pw
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user