-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin)!: enable or disable users (#223)
- Loading branch information
Showing
51 changed files
with
869 additions
and
142 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
admin: Admin | ||
are_you_sure_you_want_to_disable_this_user: Are you sure you want to disable this user? | ||
are_you_sure_you_want_to_enable_this_user: Are you sure you want to enable this user? | ||
disable: Disable | ||
enable: Enable | ||
users: Users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
admin: Admin | ||
are_you_sure_you_want_to_disable_this_user: ¿Estás seguro de que quieres deshabilitar este usuario? | ||
are_you_sure_you_want_to_enable_this_user: ¿Estás seguro de que quieres habilitar este usuario? | ||
disable: Deshabilitar | ||
enable: Habilitar | ||
users: Usuarios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
use leptos::prelude::*; | ||
|
||
use mango3_leptos_utils::async_t_string; | ||
use mango3_leptos_utils::i18n::{t, use_i18n}; | ||
use mango3_leptos_utils::i18n::use_i18n; | ||
use mango3_leptos_utils::utils::ToSignalTrait; | ||
|
||
use crate::components::AdminPageContainer; | ||
|
||
#[component] | ||
pub fn IndexPage() -> impl IntoView { | ||
let i18n = use_i18n(); | ||
let text_title = async_t_string!(i18n, shared.home).to_signal(); | ||
|
||
view! { | ||
<AdminPageContainer title=async_t_string!(i18n, shared.home).to_signal()> | ||
<h1 class="h1">{t!(i18n, shared.home)}</h1> | ||
<AdminPageContainer title=text_title> | ||
<h1 class="h1">{move || text_title.get()}</h1> | ||
</AdminPageContainer> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use leptos::prelude::*; | ||
use leptos_router::components::Outlet; | ||
|
||
use mango3_leptos_utils::async_t_string; | ||
use mango3_leptos_utils::components::{Menu, MenuItem}; | ||
use mango3_leptos_utils::i18n::use_i18n; | ||
use mango3_leptos_utils::icons::{HomeOutlined, UsersOutlined}; | ||
|
||
#[component] | ||
pub fn IndexParentPage() -> impl IntoView { | ||
let i18n = use_i18n(); | ||
|
||
view! { | ||
<div class="flex grow gap-4"> | ||
<Menu> | ||
<MenuItem href="/" icon=HomeOutlined label=async_t_string!(i18n, shared.home) /> | ||
<MenuItem href="/users" icon=UsersOutlined label=async_t_string!(i18n, admin.users) /> | ||
</Menu> | ||
|
||
<div class="grow ml-4"> | ||
<Outlet /> | ||
</div> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
mod index_page; | ||
mod index_parent_page; | ||
mod users_page; | ||
|
||
pub use index_page::IndexPage; | ||
pub use index_parent_page::IndexParentPage; | ||
pub use users_page::UsersPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
use leptos::either::EitherOf3; | ||
use leptos::prelude::*; | ||
|
||
use mango3_leptos_utils::async_t_string; | ||
use mango3_leptos_utils::components::{ | ||
ConfirmationDialog, InfiniteScroll, InfiniteScrollControllerTrait, InfiniteScrollLocalResourceController, UserCard, | ||
UserTag, | ||
}; | ||
use mango3_leptos_utils::context::use_basic_config; | ||
use mango3_leptos_utils::i18n::{t, use_i18n}; | ||
use mango3_leptos_utils::models::{ActionFormResp, UserPreviewResp}; | ||
use mango3_leptos_utils::utils::ToSignalTrait; | ||
|
||
use crate::components::AdminPageContainer; | ||
use crate::server_functions::{get_users, AttemptToDisableUser, AttemptToEnableUser}; | ||
|
||
#[component] | ||
pub fn UsersPage() -> impl IntoView { | ||
let i18n = use_i18n(); | ||
let basic_config = use_basic_config(); | ||
let controller = InfiniteScrollLocalResourceController::new(|after| { | ||
LocalResource::new(move || async move { get_users(after.get()).await }) | ||
}); | ||
let text_title = async_t_string!(i18n, admin.users).to_signal(); | ||
let server_action_disable_user = ServerAction::<AttemptToDisableUser>::new(); | ||
let action_value_disable_user = server_action_disable_user.value(); | ||
let server_action_enable_user = ServerAction::<AttemptToEnableUser>::new(); | ||
let action_value_enable_user = server_action_enable_user.value(); | ||
let disable_user = RwSignal::<Option<UserPreviewResp>>::new(None); | ||
let enable_user = RwSignal::<Option<UserPreviewResp>>::new(None); | ||
let show_disable_confirmation = RwSignal::new(false); | ||
let show_enable_confirmation = RwSignal::new(false); | ||
|
||
Effect::new({ | ||
let controller = controller.clone(); | ||
move || { | ||
let response = ActionFormResp::from(action_value_disable_user); | ||
|
||
if let Some(true) = response.success { | ||
controller.clear_and_refetch(); | ||
enable_user.set(None); | ||
} | ||
} | ||
}); | ||
|
||
Effect::new({ | ||
let controller = controller.clone(); | ||
move || { | ||
let response = ActionFormResp::from(action_value_enable_user); | ||
|
||
if let Some(true) = response.success { | ||
controller.clear_and_refetch(); | ||
enable_user.set(None); | ||
} | ||
} | ||
}); | ||
|
||
view! { | ||
<AdminPageContainer title=text_title> | ||
<h1 class="h1">{move || text_title.get()}</h1> | ||
|
||
<section class="max-w-[720px] w-full mx-auto"> | ||
<ConfirmationDialog | ||
is_open=show_disable_confirmation | ||
on_accept=move || { | ||
let user = disable_user.get().unwrap(); | ||
server_action_disable_user | ||
.dispatch(AttemptToDisableUser { | ||
id: user.id.clone(), | ||
}); | ||
} | ||
> | ||
<div>{t!(i18n, admin.are_you_sure_you_want_to_disable_this_user)}</div> | ||
|
||
{move || disable_user.get().map(|user| view! { <UserTag class="justify-center my-3" user=user /> })} | ||
</ConfirmationDialog> | ||
|
||
<ConfirmationDialog | ||
is_open=show_enable_confirmation | ||
on_accept=move || { | ||
let user = enable_user.get().unwrap(); | ||
server_action_enable_user | ||
.dispatch(AttemptToEnableUser { | ||
id: user.id.clone(), | ||
}); | ||
} | ||
> | ||
<div>{t!(i18n, admin.are_you_sure_you_want_to_enable_this_user)}</div> | ||
|
||
{move || enable_user.get().map(|user| view! { <UserTag class="justify-center my-3" user=user /> })} | ||
</ConfirmationDialog> | ||
|
||
<InfiniteScroll controller=controller key=|user: &UserPreviewResp| user.id.clone() let:user> | ||
<UserCard | ||
user=user.clone() | ||
hashtags_base_url=basic_config.home_url.clone() | ||
actions=move || { | ||
let user = user.clone(); | ||
if user.is_disabled { | ||
EitherOf3::A( | ||
view! { | ||
<button | ||
class="btn btn-ghost font-bold" | ||
on:click=move |_| { | ||
enable_user.set(Some(user.clone())); | ||
show_enable_confirmation.set(true); | ||
} | ||
> | ||
{t!(i18n, admin.enable)} | ||
</button> | ||
}, | ||
) | ||
} else if user.role == "user" { | ||
EitherOf3::B( | ||
view! { | ||
<button | ||
class="btn btn-ghost font-bold" | ||
on:click=move |_| { | ||
disable_user.set(Some(user.clone())); | ||
show_disable_confirmation.set(true); | ||
} | ||
> | ||
{t!(i18n, admin.disable)} | ||
</button> | ||
}, | ||
) | ||
} else { | ||
EitherOf3::C(()) | ||
} | ||
} | ||
/> | ||
</InfiniteScroll> | ||
</section> | ||
</AdminPageContainer> | ||
} | ||
} |
Oops, something went wrong.