|
1 | 1 | use crate::Route; |
2 | | -use crate::components::ui::button::{Button, ButtonShape, ButtonVariant}; |
3 | | -use crate::components::ui::card::{Card, CardActions, CardBody, CardTitle}; |
4 | | -use crate::components::ui::dialog::{ |
5 | | - Dialog, DialogAction, DialogContent, DialogTrigger, use_dialog, |
| 2 | +use crate::components::ui::{ |
| 3 | + button::{Button, ButtonShape, ButtonVariant}, |
| 4 | + card::{Card, CardActions, CardBody, CardTitle}, |
| 5 | + dialog::{Dialog, DialogAction, DialogContent, DialogTrigger, use_dialog}, |
| 6 | + events::eventlist::EventListGroups, |
| 7 | + form::input::Input, |
| 8 | + form::submit_button::SubmitButton, |
| 9 | + list::{ComplexList, ListDetails, ListRow}, |
| 10 | + toaster::{ToastOptions, use_toaster}, |
6 | 11 | }; |
7 | | -use crate::components::ui::events::eventlist::EventListGroups; |
8 | | -use crate::components::ui::form::input::Input; |
9 | | -use crate::components::ui::form::submit_button::SubmitButton; |
10 | | -use crate::components::ui::list::{ComplexList, ListDetails, ListRow}; |
11 | | -use crate::components::ui::toaster::{ToastOptions, use_toaster}; |
12 | | -use api::routes::groups::retrieve_group; |
13 | | -use api::routes::groups::{ |
14 | | - add_user_to_group, change_group_name, delete_group, remove_user_from_group, |
| 12 | +use api::routes::{ |
| 13 | + groups::{ |
| 14 | + add_user_to_group, change_group_name, delete_group, leave_group, remove_user_from_group, |
| 15 | + retrieve_group, |
| 16 | + }, |
| 17 | + users::{EMAIL_REGEX, UserInfo}, |
15 | 18 | }; |
16 | | -use api::routes::users::{EMAIL_REGEX, UserInfo}; |
17 | 19 | use dioxus::prelude::*; |
18 | | -use dioxus_free_icons::Icon; |
19 | | -use dioxus_free_icons::icons::ld_icons::{LdMail, LdMinus, LdPlus, LdUsers}; |
20 | | -use form_hooks::use_form::{use_form, use_on_submit}; |
21 | | -use form_hooks::use_form_field::use_form_field; |
22 | | -use form_hooks::validators; |
| 20 | +use dioxus_free_icons::{ |
| 21 | + Icon, |
| 22 | + icons::ld_icons::{LdLogOut, LdMail, LdMinus, LdPlus, LdTrash, LdUsers}, |
| 23 | +}; |
| 24 | +use form_hooks::{ |
| 25 | + use_form::{use_form, use_on_submit}, |
| 26 | + use_form_field::use_form_field, |
| 27 | + validators, |
| 28 | +}; |
23 | 29 | use regex::Regex; |
24 | 30 | use roommates::message_from_captured_error; |
25 | 31 |
|
@@ -133,7 +139,7 @@ pub fn EditGroup(group_id: i32) -> Element { |
133 | 139 | } |
134 | 140 | } |
135 | 141 | } |
136 | | - div { class: "relative flex flex-col md:w-1/6 overflow-y-auto w-full", |
| 142 | + div { class: "relative flex flex-col md:w-1/6 overflow-y-auto w-full pb-32", |
137 | 143 | ComplexList { |
138 | 144 | header: rsx! { |
139 | 145 | div { class: "flex justify-between items-center w-full", |
@@ -171,19 +177,31 @@ pub fn EditGroup(group_id: i32) -> Element { |
171 | 177 | } |
172 | 178 | } |
173 | 179 | } |
174 | | - div { |
| 180 | + div { class: "fixed bottom-16 lg:bottom-4 right-4 flex gap-3", |
175 | 181 | Dialog { |
176 | 182 | DialogTrigger { |
177 | | - variant: ButtonVariant::Primary, |
| 183 | + variant: ButtonVariant::Error, |
178 | 184 | shape: ButtonShape::Default, |
179 | 185 | ghost: false, |
180 | | - class: "fixed bottom-16 lg:bottom-4 right-4 btn btn-primary lg:btn-lg", |
181 | | - "Delete group" |
| 186 | + class: "btn lg:btn-lg", |
| 187 | + Icon { icon: LdTrash } |
182 | 188 | } |
183 | 189 | DialogContent { title: "Do you want to delete this group?", |
184 | 190 | DeleteGroup { group_id } |
185 | 191 | } |
186 | 192 | } |
| 193 | + Dialog { |
| 194 | + DialogTrigger { |
| 195 | + variant: ButtonVariant::Error, |
| 196 | + shape: ButtonShape::Default, |
| 197 | + ghost: false, |
| 198 | + class: "btn lg:btn-lg", |
| 199 | + Icon { icon: LdLogOut } |
| 200 | + } |
| 201 | + DialogContent { title: "Do you want to leave this group?", |
| 202 | + LeaveGroup { group_id } |
| 203 | + } |
| 204 | + } |
187 | 205 | } |
188 | 206 | } |
189 | 207 | } |
@@ -361,3 +379,44 @@ pub fn DeleteGroup(group_id: i32) -> Element { |
361 | 379 | } |
362 | 380 | } |
363 | 381 | } |
| 382 | + |
| 383 | +#[component] |
| 384 | +pub fn LeaveGroup(group_id: i32) -> Element { |
| 385 | + let mut toaster = use_toaster(); |
| 386 | + let dialog = use_dialog(); |
| 387 | + let mut leave_group = use_action(leave_group); |
| 388 | + let nav = navigator(); |
| 389 | + |
| 390 | + rsx! { |
| 391 | + DialogAction { |
| 392 | + Button { |
| 393 | + onclick: move |_| { |
| 394 | + dialog.close(); |
| 395 | + }, |
| 396 | + r#type: "button", |
| 397 | + variant: ButtonVariant::Secondary, |
| 398 | + "Cancel" |
| 399 | + } |
| 400 | + Button { |
| 401 | + onclick: move |_| async move { |
| 402 | + leave_group.call(group_id).await; |
| 403 | + if let Some(Err(error)) = leave_group.value() { |
| 404 | + toaster |
| 405 | + .error( |
| 406 | + "Leaving group failed!", |
| 407 | + ToastOptions::new().description(rsx! { |
| 408 | + span { {message_from_captured_error(&error)} } |
| 409 | + }), |
| 410 | + ); |
| 411 | + } else { |
| 412 | + toaster.success("Left group successfully!", ToastOptions::new()); |
| 413 | + nav.push(Route::GroupView {}); |
| 414 | + } |
| 415 | + }, |
| 416 | + r#type: "submit", |
| 417 | + variant: ButtonVariant::Primary, |
| 418 | + "Leave" |
| 419 | + } |
| 420 | + } |
| 421 | + } |
| 422 | +} |
0 commit comments