mirror of
https://github.com/Nutomic/ibis.git
synced 2025-01-24 09:55:47 +00:00
Various fixes for profile editing
This commit is contained in:
parent
3cdb7d09ea
commit
a6b11d6395
6 changed files with 36 additions and 16 deletions
|
@ -126,3 +126,8 @@ pub async fn edit_list(
|
||||||
};
|
};
|
||||||
Ok(Json(DbEdit::view(params, &data)?))
|
Ok(Json(DbEdit::view(params, &data)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Trims the string param, and converts to None if it is empty
|
||||||
|
fn empty_to_none(val: &mut Option<String>) {
|
||||||
|
(*val) = val.as_ref().map(|s| s.trim().to_owned());
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::check_is_admin;
|
use super::{check_is_admin, empty_to_none};
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::{
|
backend::{
|
||||||
database::{conflict::DbConflict, read_jwt_secret, IbisData},
|
database::{conflict::DbConflict, read_jwt_secret, IbisData},
|
||||||
|
@ -147,8 +147,10 @@ pub(in crate::backend::api) async fn get_user(
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub(in crate::backend::api) async fn update_user_profile(
|
pub(in crate::backend::api) async fn update_user_profile(
|
||||||
data: Data<IbisData>,
|
data: Data<IbisData>,
|
||||||
Form(params): Form<UpdateUserForm>,
|
Form(mut params): Form<UpdateUserForm>,
|
||||||
) -> MyResult<Json<SuccessResponse>> {
|
) -> MyResult<Json<SuccessResponse>> {
|
||||||
|
empty_to_none(&mut params.display_name);
|
||||||
|
empty_to_none(&mut params.bio);
|
||||||
DbPerson::update_profile(¶ms, &data)?;
|
DbPerson::update_profile(¶ms, &data)?;
|
||||||
Ok(Json(SuccessResponse::default()))
|
Ok(Json(SuccessResponse::default()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,6 @@ impl ApiClient {
|
||||||
&self,
|
&self,
|
||||||
data: UpdateUserForm,
|
data: UpdateUserForm,
|
||||||
) -> Result<SuccessResponse, ServerFnError> {
|
) -> Result<SuccessResponse, ServerFnError> {
|
||||||
log::info!("{:?}", &data);
|
|
||||||
self.post("/api/v1/account/update", Some(data)).await
|
self.post("/api/v1/account/update", Some(data)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use leptos_router::components::Redirect;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Login() -> impl IntoView {
|
pub fn Login() -> impl IntoView {
|
||||||
let (login_response, set_login_response) = signal(None::<()>);
|
let (login_response, set_login_response) = signal(false);
|
||||||
let (login_error, set_login_error) = signal(None::<String>);
|
let (login_error, set_login_error) = signal(None::<String>);
|
||||||
let (wait_for_response, set_wait_for_response) = signal(false);
|
let (wait_for_response, set_wait_for_response) = signal(false);
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ pub fn Login() -> impl IntoView {
|
||||||
match result {
|
match result {
|
||||||
Ok(_res) => {
|
Ok(_res) => {
|
||||||
site().refetch();
|
site().refetch();
|
||||||
set_login_response.update(|v| *v = Some(()));
|
set_login_response.set(true);
|
||||||
set_login_error.update(|e| *e = None);
|
set_login_error.update(|e| *e = None);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -38,7 +38,7 @@ pub fn Login() -> impl IntoView {
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Show
|
<Show
|
||||||
when=move || login_response.get().is_some()
|
when=move || login_response.get()
|
||||||
fallback=move || {
|
fallback=move || {
|
||||||
view! {
|
view! {
|
||||||
<CredentialsForm
|
<CredentialsForm
|
||||||
|
|
|
@ -7,7 +7,7 @@ use log::info;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Register() -> impl IntoView {
|
pub fn Register() -> impl IntoView {
|
||||||
let (register_response, set_register_response) = signal(None::<()>);
|
let (register_response, set_register_response) = signal(false);
|
||||||
let (register_error, set_register_error) = signal(None::<String>);
|
let (register_error, set_register_error) = signal(None::<String>);
|
||||||
let (wait_for_response, set_wait_for_response) = signal(false);
|
let (wait_for_response, set_wait_for_response) = signal(false);
|
||||||
|
|
||||||
|
@ -17,19 +17,19 @@ pub fn Register() -> impl IntoView {
|
||||||
let credentials = RegisterUserForm { username, password };
|
let credentials = RegisterUserForm { username, password };
|
||||||
info!("Try to register new account for {}", credentials.username);
|
info!("Try to register new account for {}", credentials.username);
|
||||||
async move {
|
async move {
|
||||||
set_wait_for_response.update(|w| *w = true);
|
set_wait_for_response.set(true);
|
||||||
let result = CLIENT.register(credentials).await;
|
let result = CLIENT.register(credentials).await;
|
||||||
set_wait_for_response.update(|w| *w = false);
|
set_wait_for_response.set(false);
|
||||||
match result {
|
match result {
|
||||||
Ok(_res) => {
|
Ok(_res) => {
|
||||||
site().refetch();
|
site().refetch();
|
||||||
set_register_response.update(|v| *v = Some(()));
|
set_register_response.set(true);
|
||||||
set_register_error.update(|e| *e = None);
|
set_register_error.set(None);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let msg = err.to_string();
|
let msg = err.to_string();
|
||||||
log::warn!("Unable to register new account: {msg}");
|
log::warn!("Unable to register new account: {msg}");
|
||||||
set_register_error.update(|e| *e = Some(msg));
|
set_register_error.set(Some(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ pub fn Register() -> impl IntoView {
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Show
|
<Show
|
||||||
when=move || register_response.get().is_some()
|
when=move || register_response.get()
|
||||||
fallback=move || {
|
fallback=move || {
|
||||||
view! {
|
view! {
|
||||||
<CredentialsForm
|
<CredentialsForm
|
||||||
|
|
|
@ -9,6 +9,7 @@ use leptos::prelude::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn UserEditProfile() -> impl IntoView {
|
pub fn UserEditProfile() -> impl IntoView {
|
||||||
|
let (saved, set_saved) = signal(false);
|
||||||
let (submit_error, set_submit_error) = signal(None::<String>);
|
let (submit_error, set_submit_error) = signal(None::<String>);
|
||||||
|
|
||||||
let submit_action = Action::new(move |form: &UpdateUserForm| {
|
let submit_action = Action::new(move |form: &UpdateUserForm| {
|
||||||
|
@ -17,12 +18,14 @@ pub fn UserEditProfile() -> impl IntoView {
|
||||||
let result = CLIENT.update_user_profile(form).await;
|
let result = CLIENT.update_user_profile(form).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(_res) => {
|
Ok(_res) => {
|
||||||
set_submit_error.update(|e| *e = None);
|
site().refetch();
|
||||||
|
set_saved.set(true);
|
||||||
|
set_submit_error.set(None);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let msg = err.to_string();
|
let msg = err.to_string();
|
||||||
log::warn!("Unable to update profile: {msg}");
|
log::warn!("Unable to update profile: {msg}");
|
||||||
set_submit_error.update(|e| *e = Some(msg));
|
set_submit_error.set(Some(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +59,7 @@ pub fn UserEditProfile() -> impl IntoView {
|
||||||
id="displayname"
|
id="displayname"
|
||||||
class="w-80 input input-secondary input-bordered"
|
class="w-80 input input-secondary input-bordered"
|
||||||
prop:value=display_name
|
prop:value=display_name
|
||||||
|
value=display_name
|
||||||
on:change=move |ev| {
|
on:change=move |ev| {
|
||||||
let val = event_target_value(&ev);
|
let val = event_target_value(&ev);
|
||||||
set_display_name.set(val);
|
set_display_name.set(val);
|
||||||
|
@ -74,7 +78,9 @@ pub fn UserEditProfile() -> impl IntoView {
|
||||||
let val = evt.target().value();
|
let val = evt.target().value();
|
||||||
set_bio.set(val);
|
set_bio.set(val);
|
||||||
}
|
}
|
||||||
></textarea>
|
>
|
||||||
|
bio.get()
|
||||||
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
class="btn btn-primary"
|
class="btn btn-primary"
|
||||||
|
@ -89,6 +95,14 @@ pub fn UserEditProfile() -> impl IntoView {
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<Show when=move || saved.get()>
|
||||||
|
<div class="toast">
|
||||||
|
<div class="alert alert-info">
|
||||||
|
<span>Saved!</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue