Add copy-to-clipboard functionality for event invite links with visual feedback. The copy button now uses the Clipboard API via JavaScript eval to copy the link and displays a green checkmark icon for 2 seconds on successful copy.
416 lines
26 KiB
Rust
416 lines
26 KiB
Rust
use crate::components::AssignmentReveal;
|
|
use crate::server_fns;
|
|
use crate::Route;
|
|
use dioxus::prelude::*;
|
|
|
|
#[component]
|
|
pub fn EventPage(id: i32) -> Element {
|
|
let mut participants =
|
|
use_resource(move || async move { server_fns::get_participants(id).await });
|
|
let mut new_participant_name = use_signal(|| String::new());
|
|
let mut new_participant_email = use_signal(|| String::new());
|
|
let mut event_details = use_resource(move || async move { server_fns::get_my_events().await });
|
|
let mut user_role =
|
|
use_resource(move || async move { server_fns::get_user_role_in_event(id).await });
|
|
let mut current_user_id = use_signal(|| None::<i32>);
|
|
let mut is_admin = use_signal(|| false);
|
|
let mut edit_budget = use_signal(|| false);
|
|
let mut edit_date = use_signal(|| false);
|
|
let mut new_budget = use_signal(|| String::new());
|
|
let mut new_date = use_signal(|| String::new());
|
|
let mut show_copy_feedback = use_signal(|| false);
|
|
let mut show_notification = use_signal(|| false);
|
|
let navigator = use_navigator();
|
|
|
|
let invite_link = use_memo(move || {
|
|
if let Some(Ok(events)) = event_details.read().as_ref() {
|
|
if let Some(event) = events.iter().find(|e| e.id == id) {
|
|
new_budget.set(event.budget.clone());
|
|
new_date.set(event.date.clone());
|
|
return Some(format!("http://localhost:8080/join/{}", event.invite_token));
|
|
}
|
|
}
|
|
None
|
|
});
|
|
|
|
// Update admin status and current user ID based on user role
|
|
use_effect(move || {
|
|
if let Some(Ok(role)) = user_role.read().as_ref() {
|
|
is_admin.set(role.as_ref().map_or(false, |r| r == "Admin"));
|
|
}
|
|
});
|
|
|
|
// Get current user ID for self-check in role management
|
|
let mut user_id_resource =
|
|
use_resource(move || async move { server_fns::get_current_user_id().await });
|
|
|
|
use_effect(move || {
|
|
if let Some(Ok(user_id)) = user_id_resource.read().as_ref() {
|
|
current_user_id.set(Some(*user_id));
|
|
}
|
|
});
|
|
|
|
rsx! {
|
|
div {
|
|
class: "min-h-full py-12 px-4 sm:px-6 lg:px-8",
|
|
div {
|
|
class: "max-w-3xl mx-auto",
|
|
|
|
// Header
|
|
div {
|
|
class: "text-center mb-12",
|
|
h1 {
|
|
class: "text-4xl font-extrabold text-transparent bg-clip-text bg-gradient-to-r from-indigo-400 to-purple-400 mb-2",
|
|
"Event Details"
|
|
}
|
|
p { class: "text-slate-400", "Verwalte deine Wichtel-Runde" }
|
|
}
|
|
|
|
if let Some(link) = invite_link() {
|
|
div {
|
|
class: "mb-8 bg-slate-800/50 backdrop-blur-sm border border-white/10 rounded-2xl p-6 shadow-xl",
|
|
div {
|
|
class: "flex flex-col space-y-2",
|
|
label { class: "text-xs font-semibold text-indigo-400 uppercase tracking-wider", "Einladungslink" }
|
|
div {
|
|
class: "flex items-center gap-2 bg-black/30 rounded-lg p-1 border border-white/5",
|
|
code { class: "flex-1 p-3 font-mono text-sm text-slate-300 break-all bg-transparent", "{link}" }
|
|
button {
|
|
class: "p-2 text-slate-400 hover:text-white transition-colors",
|
|
title: "Kopieren",
|
|
onclick: move |_| {
|
|
let link = link.clone();
|
|
async move {
|
|
let mut eval = document::eval(r#"
|
|
let link = await dioxus.recv();
|
|
try {
|
|
await navigator.clipboard.writeText(link);
|
|
return true;
|
|
} catch (e) {
|
|
console.error(e);
|
|
return false;
|
|
}
|
|
"#);
|
|
eval.send(link).unwrap();
|
|
if let Ok(serde_json::Value::Bool(true)) = eval.recv().await {
|
|
show_copy_feedback.set(true);
|
|
let mut eval = document::eval(r#"
|
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
"#);
|
|
let _ = eval.await;
|
|
show_copy_feedback.set(false);
|
|
}
|
|
}
|
|
},
|
|
if show_copy_feedback() {
|
|
svg { class: "w-5 h-5 text-green-500", fill: "none", stroke: "currentColor", view_box: "0 0 24 24", path { stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", d: "M5 13l4 4L19 7" } }
|
|
} else {
|
|
svg { class: "w-5 h-5", fill: "none", stroke: "currentColor", view_box: "0 0 24 24", path { stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", d: "M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" } }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Administrative Controls (only for admins)
|
|
if is_admin() {
|
|
div {
|
|
class: "mb-8 bg-indigo-900/10 border border-indigo-500/20 rounded-2xl p-6 backdrop-blur-sm",
|
|
div {
|
|
class: "flex items-center gap-3 mb-6",
|
|
div { class: "p-2 bg-indigo-500/20 rounded-lg", svg { class: "w-5 h-5 text-indigo-400", fill: "none", stroke: "currentColor", view_box: "0 0 24 24", path { stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", d: "M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" } } }
|
|
h3 { class: "text-lg font-semibold text-white", "Verwaltung" }
|
|
}
|
|
|
|
div {
|
|
class: "space-y-4",
|
|
// Budget
|
|
div {
|
|
class: "group flex items-center justify-between p-3 rounded-xl hover:bg-white/5 transition-colors",
|
|
div {
|
|
p { class: "text-xs font-medium text-indigo-300 uppercase tracking-wider mb-1", "Budget" }
|
|
if edit_budget() {
|
|
input {
|
|
class: "bg-slate-900/50 border border-slate-600 rounded px-2 py-1 text-sm text-white focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 outline-none",
|
|
value: "{new_budget}",
|
|
oninput: move |e| new_budget.set(e.value()),
|
|
autofocus: true
|
|
}
|
|
} else {
|
|
p { class: "text-white font-medium", "{new_budget}" }
|
|
}
|
|
}
|
|
div {
|
|
if edit_budget() {
|
|
div {
|
|
class: "flex gap-2",
|
|
button {
|
|
class: "p-1.5 bg-green-500/20 text-green-400 rounded hover:bg-green-500/30 transition-colors",
|
|
onclick: move |_| async move {
|
|
if server_fns::update_event_budget(id, new_budget()).await.is_ok() {
|
|
edit_budget.set(false);
|
|
event_details.restart();
|
|
}
|
|
},
|
|
svg { class: "w-4 h-4", fill: "none", stroke: "currentColor", view_box: "0 0 24 24", path { stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", d: "M5 13l4 4L19 7" } }
|
|
}
|
|
button {
|
|
class: "p-1.5 bg-red-500/20 text-red-400 rounded hover:bg-red-500/30 transition-colors",
|
|
onclick: move |_| edit_budget.set(false),
|
|
svg { class: "w-4 h-4", fill: "none", stroke: "currentColor", view_box: "0 0 24 24", path { stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", d: "M6 18L18 6M6 6l12 12" } }
|
|
}
|
|
}
|
|
} else {
|
|
button {
|
|
class: "text-slate-500 hover:text-indigo-400 transition-colors",
|
|
onclick: move |_| edit_budget.set(true),
|
|
"Bearbeiten"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Date
|
|
div {
|
|
class: "group flex items-center justify-between p-3 rounded-xl hover:bg-white/5 transition-colors",
|
|
div {
|
|
p { class: "text-xs font-medium text-indigo-300 uppercase tracking-wider mb-1", "Datum" }
|
|
if edit_date() {
|
|
input {
|
|
class: "bg-slate-900/50 border border-slate-600 rounded px-2 py-1 text-sm text-white focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 outline-none",
|
|
r#type: "date",
|
|
value: "{new_date}",
|
|
oninput: move |e| new_date.set(e.value())
|
|
}
|
|
} else {
|
|
p { class: "text-white font-medium", "{new_date}" }
|
|
}
|
|
}
|
|
div {
|
|
if edit_date() {
|
|
div {
|
|
class: "flex gap-2",
|
|
button {
|
|
class: "p-1.5 bg-green-500/20 text-green-400 rounded hover:bg-green-500/30 transition-colors",
|
|
onclick: move |_| async move {
|
|
if server_fns::update_event_date(id, new_date()).await.is_ok() {
|
|
edit_date.set(false);
|
|
event_details.restart();
|
|
}
|
|
},
|
|
svg { class: "w-4 h-4", fill: "none", stroke: "currentColor", view_box: "0 0 24 24", path { stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", d: "M5 13l4 4L19 7" } }
|
|
}
|
|
button {
|
|
class: "p-1.5 bg-red-500/20 text-red-400 rounded hover:bg-red-500/30 transition-colors",
|
|
onclick: move |_| edit_date.set(false),
|
|
svg { class: "w-4 h-4", fill: "none", stroke: "currentColor", view_box: "0 0 24 24", path { stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", d: "M6 18L18 6M6 6l12 12" } }
|
|
}
|
|
}
|
|
} else {
|
|
button {
|
|
class: "text-slate-500 hover:text-indigo-400 transition-colors",
|
|
onclick: move |_| edit_date.set(true),
|
|
"Bearbeiten"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Danger Zone
|
|
div {
|
|
class: "mt-6 pt-6 border-t border-indigo-500/20",
|
|
button {
|
|
class: "text-sm text-red-400 hover:text-red-300 hover:underline transition-colors",
|
|
onclick: move |_| async move {
|
|
if let Ok(_) = server_fns::delete_event(id).await {
|
|
navigator.push(Route::Dashboard {});
|
|
}
|
|
},
|
|
"Event löschen"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Participants Section
|
|
div {
|
|
class: "bg-slate-800/50 backdrop-blur-sm border border-white/10 rounded-2xl p-6 shadow-xl mb-8",
|
|
h2 { class: "text-xl font-bold text-white mb-6 flex items-center gap-2",
|
|
span { class: "w-1 h-6 bg-gradient-to-b from-indigo-500 to-purple-500 rounded-full block" }
|
|
"Teilnehmer"
|
|
}
|
|
|
|
// Add Form
|
|
div {
|
|
class: "flex gap-3 mb-6",
|
|
input {
|
|
class: "flex-1 bg-slate-900/50 border border-slate-700 rounded-xl px-4 py-3 text-white placeholder-slate-500 focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 outline-none transition-all",
|
|
placeholder: "Name",
|
|
value: "{new_participant_name}",
|
|
oninput: move |e| new_participant_name.set(e.value())
|
|
}
|
|
input {
|
|
class: "flex-1 bg-slate-900/50 border border-slate-700 rounded-xl px-4 py-3 text-white placeholder-slate-500 focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 outline-none transition-all",
|
|
placeholder: "E-Mail (Optional)",
|
|
value: "{new_participant_email}",
|
|
oninput: move |e| new_participant_email.set(e.value())
|
|
}
|
|
button {
|
|
class: "bg-indigo-600 hover:bg-indigo-500 text-white px-6 py-3 rounded-xl font-medium shadow-lg shadow-indigo-600/20 transition-all",
|
|
disabled: !is_admin(),
|
|
onclick: move |_| async move {
|
|
if !is_admin() {
|
|
return;
|
|
}
|
|
let email = if new_participant_email().is_empty() { None } else { Some(new_participant_email()) };
|
|
if server_fns::add_participant(id, new_participant_name(), email).await.is_ok() {
|
|
participants.restart();
|
|
new_participant_name.set("".to_string());
|
|
new_participant_email.set("".to_string());
|
|
}
|
|
},
|
|
"Hinzufügen"
|
|
}
|
|
}
|
|
|
|
// List
|
|
{
|
|
let participants_list = participants();
|
|
match participants_list.as_ref() {
|
|
Some(Ok(list)) => {
|
|
let list = list.clone();
|
|
rsx! {
|
|
div {
|
|
class: "space-y-3",
|
|
for p in list {
|
|
{
|
|
let p_id = p.id;
|
|
rsx! {
|
|
div {
|
|
key: "{p_id}",
|
|
class: "group flex items-center justify-between p-4 bg-slate-700/30 border border-white/5 rounded-xl hover:bg-slate-700/50 transition-all",
|
|
div {
|
|
class: "flex items-center gap-4",
|
|
div {
|
|
class: "w-10 h-10 rounded-full bg-gradient-to-br from-slate-600 to-slate-700 flex items-center justify-center text-white font-bold border border-white/10",
|
|
"{p.name.chars().next().unwrap_or('?')}"
|
|
}
|
|
div {
|
|
p { class: "font-medium text-white", "{p.name}" }
|
|
if let Some(email) = &p.email {
|
|
p { class: "text-sm text-slate-400", "{email}" }
|
|
}
|
|
// Role badge
|
|
{
|
|
#[cfg(feature = "server")]
|
|
let role_str = match p.role {
|
|
crate::db::participants::Role::Admin => "Admin",
|
|
crate::db::participants::Role::Member => "Member",
|
|
};
|
|
#[cfg(not(feature = "server"))]
|
|
let role_str = p.role.as_str();
|
|
|
|
if role_str == "Admin" {
|
|
rsx! { span { class: "ml-2 px-2 py-1 text-xs font-semibold bg-indigo-600 text-white rounded-full", "Admin" } }
|
|
} else {
|
|
rsx! { span { class: "ml-2 px-2 py-1 text-xs font-semibold bg-slate-600 text-white rounded-full", "Member" } }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
div {
|
|
class: "flex items-center gap-2",
|
|
// Role management buttons (only for admins)
|
|
if is_admin() {
|
|
// Show different buttons based on current role
|
|
{
|
|
#[cfg(feature = "server")]
|
|
let role_str = match p.role {
|
|
crate::db::participants::Role::Admin => "Admin",
|
|
crate::db::participants::Role::Member => "Member",
|
|
};
|
|
#[cfg(not(feature = "server"))]
|
|
let role_str = p.role.as_str();
|
|
|
|
if role_str == "Member" {
|
|
rsx! {
|
|
button {
|
|
class: "text-xs px-3 py-1 bg-indigo-600 hover:bg-indigo-500 text-white rounded transition-colors",
|
|
onclick: move |_| async move {
|
|
if server_fns::change_participant_role(p_id, id).await.is_ok() {
|
|
participants.restart();
|
|
}
|
|
},
|
|
"Make Admin"
|
|
}
|
|
}
|
|
} else if role_str == "Admin" {
|
|
rsx! {
|
|
button {
|
|
class: "text-xs px-3 py-1 bg-red-600 hover:bg-red-500 text-white rounded transition-colors",
|
|
onclick: move |_| async move {
|
|
if server_fns::remove_admin_role(p_id, id).await.is_ok() {
|
|
participants.restart();
|
|
}
|
|
},
|
|
"Remove Admin"
|
|
}
|
|
}
|
|
} else {
|
|
rsx! {}
|
|
}
|
|
}
|
|
}
|
|
// Remove participant button (only for admins)
|
|
if is_admin() {
|
|
button {
|
|
class: "p-2 text-red-400 hover:text-red-300 transition-colors",
|
|
onclick: move |_| async move {
|
|
if server_fns::remove_participant(p_id).await.is_ok() {
|
|
participants.restart();
|
|
}
|
|
},
|
|
svg { class: "w-4 h-4", fill: "none", stroke: "currentColor", view_box: "0 0 24 24", path { stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", d: "M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" } }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Some(Err(e)) => rsx! { p { class: "text-red-400", "Error: {e}" } },
|
|
None => rsx! {
|
|
div { class: "flex justify-center py-8", div { class: "animate-spin rounded-full h-8 w-8 border-b-2 border-indigo-500" } }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Assignment Reveal Section (for participants)
|
|
AssignmentReveal { event_id: id }
|
|
|
|
// Draw Button (only for admins)
|
|
if is_admin() {
|
|
button {
|
|
class: "w-full py-4 bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-500 hover:to-pink-500 text-white text-lg font-bold rounded-2xl shadow-lg shadow-purple-600/20 hover:shadow-purple-600/40 transform hover:-translate-y-0.5 transition-all",
|
|
onclick: move |_| async move {
|
|
if let Err(e) = server_fns::draw_names(id).await {
|
|
println!("Error drawing names: {}", e);
|
|
} else {
|
|
println!("Names drawn!");
|
|
}
|
|
},
|
|
"🎲 Namen auslosen"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|