Compare commits
9 commits
687c3943d4
...
af4dbdea91
| Author | SHA1 | Date | |
|---|---|---|---|
| af4dbdea91 | |||
| c61bcedb3a | |||
| a19b7883d6 | |||
| 73aea84e8e | |||
| 619b51e990 | |||
| bfd4aa10fb | |||
| 1a4d1cf73c | |||
| 06ba7fe85a | |||
| 535c285a33 |
12 changed files with 1711 additions and 875 deletions
2
.env
2
.env
|
|
@ -5,4 +5,4 @@ ADMIN_PASSWORD=admin
|
|||
JWT_COOKIE_SECURE=false
|
||||
ENABLE_HTTPS_REDIRECT=false
|
||||
WEB_PORT=3000
|
||||
CSRF_ALLOWED_ORIGINS=http://192.168.1.204:3000
|
||||
CSRF_ALLOWED_ORIGINS=http://localhost:3000
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ async fn main() -> Result<(), rocket::Error> {
|
|||
|
||||
let rocket = rocket::build()
|
||||
.manage(state)
|
||||
.mount("/", routes![healthz, login, logout, events])
|
||||
.mount("/", routes![healthz, login, logout, events, public_events])
|
||||
.mount("/persons", routes::persons::routes())
|
||||
.mount("/tournament", routes::tournaments::routes());
|
||||
|
||||
|
|
@ -157,3 +157,25 @@ fn events(_user: AuthUser, state: &State<AppState>) -> EventStream![Event + '_]
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/events/public")]
|
||||
fn public_events(state: &State<AppState>) -> EventStream![Event + '_] {
|
||||
let mut receiver = state.event_sender.subscribe();
|
||||
|
||||
EventStream! {
|
||||
loop {
|
||||
match receiver.recv().await {
|
||||
Ok(event) => {
|
||||
match &event {
|
||||
AppEvent::TournamentUpserted { .. } | AppEvent::TournamentDeleted { .. } => {
|
||||
yield Event::json(&event);
|
||||
}
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
Err(RecvError::Closed) => break,
|
||||
Err(RecvError::Lagged(_)) => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ use sqlx::FromRow;
|
|||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub const ATTENDANCE_ID_FIELD_ID: &str = "attendance-id";
|
||||
pub const ATTENDANCE_ID_FIELD_LABEL: &str = "Deltagar-ID";
|
||||
pub const ATTENDANCE_ID_FIELD_PLACEHOLDER: &str = "Ange ditt deltagar-ID från närvarolistan";
|
||||
|
||||
#[derive(Debug, FromRow, Clone)]
|
||||
pub struct TournamentInfo {
|
||||
pub id: i32,
|
||||
|
|
@ -174,6 +178,7 @@ impl TournamentSignupConfig {
|
|||
|
||||
self.entry_fields = normalize_signup_fields(self.entry_fields);
|
||||
self.participant_fields = normalize_signup_fields(self.participant_fields);
|
||||
ensure_attendance_field_for_mode(&mut self);
|
||||
|
||||
self
|
||||
}
|
||||
|
|
@ -213,6 +218,92 @@ fn normalize_signup_fields(mut fields: Vec<TournamentSignupField>) -> Vec<Tourna
|
|||
fields
|
||||
}
|
||||
|
||||
fn remove_attendance_id_field(
|
||||
fields: &mut Vec<TournamentSignupField>,
|
||||
) -> Option<TournamentSignupField> {
|
||||
let mut attendance_index = None;
|
||||
for (index, field) in fields.iter().enumerate() {
|
||||
if field.id == ATTENDANCE_ID_FIELD_ID {
|
||||
attendance_index = Some(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
attendance_index.map(|index| {
|
||||
let mut field = fields.remove(index);
|
||||
sanitize_attendance_id_field(&mut field);
|
||||
field
|
||||
})
|
||||
}
|
||||
|
||||
fn insert_attendance_field_front(
|
||||
fields: &mut Vec<TournamentSignupField>,
|
||||
mut field: TournamentSignupField,
|
||||
) {
|
||||
sanitize_attendance_id_field(&mut field);
|
||||
fields.insert(0, field);
|
||||
}
|
||||
|
||||
fn ensure_attendance_field_for_mode(config: &mut TournamentSignupConfig) {
|
||||
let mut attendance = remove_attendance_id_field(&mut config.entry_fields)
|
||||
.or_else(|| remove_attendance_id_field(&mut config.participant_fields))
|
||||
.unwrap_or_else(default_attendance_id_field);
|
||||
|
||||
if config.mode == "team" {
|
||||
config
|
||||
.entry_fields
|
||||
.retain(|field| field.id != ATTENDANCE_ID_FIELD_ID);
|
||||
config
|
||||
.participant_fields
|
||||
.retain(|field| field.id != ATTENDANCE_ID_FIELD_ID);
|
||||
insert_attendance_field_front(&mut config.participant_fields, attendance);
|
||||
} else {
|
||||
config
|
||||
.entry_fields
|
||||
.retain(|field| field.id != ATTENDANCE_ID_FIELD_ID);
|
||||
config
|
||||
.participant_fields
|
||||
.retain(|field| field.id != ATTENDANCE_ID_FIELD_ID);
|
||||
insert_attendance_field_front(&mut config.entry_fields, attendance);
|
||||
}
|
||||
}
|
||||
|
||||
fn sanitize_attendance_id_field(field: &mut TournamentSignupField) {
|
||||
field.id = ATTENDANCE_ID_FIELD_ID.to_string();
|
||||
field.label = sanitize_attendance_label(&field.label);
|
||||
field.field_type = TournamentFieldType::Text;
|
||||
field.required = true;
|
||||
field.unique = true;
|
||||
field.placeholder = Some(
|
||||
field
|
||||
.placeholder
|
||||
.as_ref()
|
||||
.map(|value| value.trim().to_string())
|
||||
.filter(|value| !value.is_empty())
|
||||
.unwrap_or_else(|| ATTENDANCE_ID_FIELD_PLACEHOLDER.to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
fn sanitize_attendance_label(label: &str) -> String {
|
||||
let trimmed = label.trim();
|
||||
if trimmed.is_empty() {
|
||||
ATTENDANCE_ID_FIELD_LABEL.to_string()
|
||||
} else {
|
||||
trimmed.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn default_attendance_id_field() -> TournamentSignupField {
|
||||
TournamentSignupField {
|
||||
id: ATTENDANCE_ID_FIELD_ID.to_string(),
|
||||
label: ATTENDANCE_ID_FIELD_LABEL.to_string(),
|
||||
field_type: TournamentFieldType::Text,
|
||||
required: true,
|
||||
placeholder: Some(ATTENDANCE_ID_FIELD_PLACEHOLDER.to_string()),
|
||||
unique: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_field_id(input: &str) -> String {
|
||||
let mut slug = input
|
||||
.trim()
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
use crate::auth::AuthUser;
|
||||
use crate::error::ApiError;
|
||||
use crate::models::{
|
||||
AppEvent, CreateTournamentRequest, TournamentFieldType, TournamentInfo, TournamentInfoData,
|
||||
TournamentItemResponse, TournamentListResponse, TournamentParticipantRow,
|
||||
AppEvent, CreateTournamentRequest, Person, TournamentFieldType, TournamentInfo,
|
||||
TournamentInfoData, TournamentItemResponse, TournamentListResponse, TournamentParticipantRow,
|
||||
TournamentParticipantValueRow, TournamentRegistrationDetailResponse,
|
||||
TournamentRegistrationItem, TournamentRegistrationListResponse, TournamentRegistrationResponse,
|
||||
TournamentRegistrationRow, TournamentRegistrationValueRow, TournamentSection,
|
||||
TournamentSectionRecord, TournamentSignupConfig, TournamentSignupField,
|
||||
TournamentSignupFieldRecord, TournamentSignupSubmission, UpdateTournamentRequest,
|
||||
ATTENDANCE_ID_FIELD_ID,
|
||||
};
|
||||
use crate::AppState;
|
||||
use rocket::http::Status;
|
||||
|
|
@ -15,7 +16,7 @@ use rocket::serde::json::Json;
|
|||
use rocket::Route;
|
||||
use serde_json::{Map, Value};
|
||||
use sqlx::{Postgres, Transaction};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
rocket::routes![
|
||||
|
|
@ -107,6 +108,46 @@ fn build_registration_url(slug: &str) -> String {
|
|||
format!("/tournament/{slug}")
|
||||
}
|
||||
|
||||
fn first_non_attendance_entry_value(
|
||||
fields: &[TournamentSignupField],
|
||||
values: &HashMap<String, String>,
|
||||
) -> Option<String> {
|
||||
for field in fields {
|
||||
if field.id == ATTENDANCE_ID_FIELD_ID {
|
||||
continue;
|
||||
}
|
||||
if let Some(value) = values.get(&field.id) {
|
||||
let trimmed = value.trim();
|
||||
if !trimmed.is_empty() {
|
||||
return Some(trimmed.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn build_entry_label(
|
||||
attendance_id: i32,
|
||||
person: &Person,
|
||||
config: &TournamentSignupConfig,
|
||||
entry_values: &HashMap<String, String>,
|
||||
) -> Option<String> {
|
||||
let primary = first_non_attendance_entry_value(&config.entry_fields, entry_values)
|
||||
.unwrap_or_else(|| {
|
||||
let first_name = person.first_name.trim();
|
||||
let last_name = person.last_name.trim();
|
||||
let full = format!("{first_name} {last_name}");
|
||||
full.trim().to_string()
|
||||
});
|
||||
|
||||
let label = format!("{attendance_id} – {primary}").trim().to_string();
|
||||
if label.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(label)
|
||||
}
|
||||
}
|
||||
|
||||
fn signup_fields_equal(left: &[TournamentSignupField], right: &[TournamentSignupField]) -> bool {
|
||||
if left.len() != right.len() {
|
||||
return false;
|
||||
|
|
@ -219,6 +260,7 @@ fn build_signup_config(
|
|||
entry_fields,
|
||||
participant_fields,
|
||||
}
|
||||
.normalized()
|
||||
}
|
||||
|
||||
async fn load_tournament_data(
|
||||
|
|
@ -1062,12 +1104,6 @@ fn validate_submission(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn trimmed(value: Option<&String>) -> Option<String> {
|
||||
value
|
||||
.map(|v| v.trim().to_string())
|
||||
.filter(|v| !v.is_empty())
|
||||
}
|
||||
|
||||
#[rocket::post("/slug/<slug>/signup", data = "<payload>")]
|
||||
pub async fn create_registration_by_slug(
|
||||
state: &rocket::State<AppState>,
|
||||
|
|
@ -1136,42 +1172,129 @@ pub async fn create_registration_by_slug(
|
|||
|
||||
let mut tx = state.db.begin().await?;
|
||||
|
||||
let entry_label = config
|
||||
.entry_fields
|
||||
.first()
|
||||
.and_then(|field| entry_values.get(&field.id))
|
||||
.and_then(|value| trimmed(Some(value)));
|
||||
if !field_map.contains_key(ATTENDANCE_ID_FIELD_ID) {
|
||||
return Err(ApiError::bad_request(
|
||||
"Turneringen är felkonfigurerad och saknar obligatoriskt deltagar-ID-fält.",
|
||||
));
|
||||
}
|
||||
|
||||
let entry_label_requires_unique = config
|
||||
.entry_fields
|
||||
.first()
|
||||
.map(|field| field.unique)
|
||||
.unwrap_or(false);
|
||||
let is_team = config.mode == "team";
|
||||
let mut lead_participant: Option<(i32, Person)> = None;
|
||||
|
||||
if entry_label_requires_unique {
|
||||
if let Some(label) = entry_label.clone() {
|
||||
let is_duplicate = sqlx::query_scalar::<_, bool>(
|
||||
if is_team {
|
||||
entry_values.remove(ATTENDANCE_ID_FIELD_ID);
|
||||
let mut seen_attendance_ids: HashSet<i32> = HashSet::new();
|
||||
|
||||
for (index, values) in participant_values.iter_mut().enumerate() {
|
||||
let attendance_raw = values
|
||||
.get(ATTENDANCE_ID_FIELD_ID)
|
||||
.map(|value| value.trim().to_string())
|
||||
.filter(|value| !value.is_empty())
|
||||
.ok_or_else(|| {
|
||||
ApiError::bad_request(format!(
|
||||
"Spelare #{number}: ange deltagar-ID från närvarolistan.",
|
||||
number = index + 1
|
||||
))
|
||||
})?;
|
||||
|
||||
let attendance_id: i32 = attendance_raw.parse().map_err(|_| {
|
||||
ApiError::bad_request(format!(
|
||||
"Spelare #{number}: deltagar-ID måste vara ett heltal från närvarolistan.",
|
||||
number = index + 1
|
||||
))
|
||||
})?;
|
||||
|
||||
if !seen_attendance_ids.insert(attendance_id) {
|
||||
return Err(ApiError::bad_request(format!(
|
||||
"Spelare #{number}: deltagar-ID används redan av en annan spelare i laget.",
|
||||
number = index + 1
|
||||
)));
|
||||
}
|
||||
|
||||
let person = sqlx::query_as::<_, Person>(
|
||||
r#"
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM tournament_registrations
|
||||
WHERE tournament_id = $1 AND entry_label = $2
|
||||
)
|
||||
SELECT
|
||||
id,
|
||||
first_name,
|
||||
last_name,
|
||||
grade,
|
||||
parent_name,
|
||||
parent_phone_number,
|
||||
checked_in,
|
||||
inside,
|
||||
visitor,
|
||||
sleeping_spot
|
||||
FROM persons
|
||||
WHERE id = $1
|
||||
"#,
|
||||
)
|
||||
.bind(info.id)
|
||||
.bind(&label)
|
||||
.fetch_one(&state.db)
|
||||
.await?;
|
||||
.bind(attendance_id)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::bad_request(format!(
|
||||
"Spelare #{number}: deltagar-ID:t finns inte i närvarolistan.",
|
||||
number = index + 1
|
||||
))
|
||||
})?;
|
||||
|
||||
if is_duplicate {
|
||||
return Err(ApiError::bad_request(
|
||||
"Den här spelaren eller laget är redan anmäld till turneringen.",
|
||||
));
|
||||
values.insert(
|
||||
ATTENDANCE_ID_FIELD_ID.to_string(),
|
||||
attendance_id.to_string(),
|
||||
);
|
||||
|
||||
if lead_participant.is_none() {
|
||||
lead_participant = Some((attendance_id, person.clone()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let attendance_id_value = entry_values
|
||||
.get(ATTENDANCE_ID_FIELD_ID)
|
||||
.map(|value| value.trim().to_string())
|
||||
.filter(|value| !value.is_empty())
|
||||
.ok_or_else(|| ApiError::bad_request("Ange ditt deltagar-ID från närvarolistan."))?;
|
||||
|
||||
let attendance_id: i32 = attendance_id_value.parse().map_err(|_| {
|
||||
ApiError::bad_request("Deltagar-ID måste vara ett heltal från närvarolistan.")
|
||||
})?;
|
||||
|
||||
let person = sqlx::query_as::<_, Person>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
first_name,
|
||||
last_name,
|
||||
grade,
|
||||
parent_name,
|
||||
parent_phone_number,
|
||||
checked_in,
|
||||
inside,
|
||||
visitor,
|
||||
sleeping_spot
|
||||
FROM persons
|
||||
WHERE id = $1
|
||||
"#,
|
||||
)
|
||||
.bind(attendance_id)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::bad_request("Det angivna deltagar-ID:t finns inte i närvarolistan.")
|
||||
})?;
|
||||
|
||||
entry_values.insert(
|
||||
ATTENDANCE_ID_FIELD_ID.to_string(),
|
||||
attendance_id.to_string(),
|
||||
);
|
||||
lead_participant = Some((attendance_id, person));
|
||||
}
|
||||
|
||||
let (lead_attendance_id, lead_person) = lead_participant.ok_or_else(|| {
|
||||
ApiError::bad_request("Minst en deltagare med deltagar-ID krävs för anmälan.")
|
||||
})?;
|
||||
|
||||
let entry_label = build_entry_label(lead_attendance_id, &lead_person, &config, &entry_values);
|
||||
|
||||
for field in &config.entry_fields {
|
||||
if !field.unique {
|
||||
continue;
|
||||
|
|
@ -1192,7 +1315,7 @@ pub async fn create_registration_by_slug(
|
|||
WHERE r.tournament_id = $1
|
||||
AND v.signup_field_id = $2
|
||||
AND v.value = $3
|
||||
)
|
||||
)
|
||||
"#,
|
||||
)
|
||||
.bind(info.id)
|
||||
|
|
@ -1602,45 +1725,129 @@ pub async fn update_registration_by_slug(
|
|||
|
||||
let mut tx = state.db.begin().await?;
|
||||
|
||||
let entry_label = config
|
||||
.entry_fields
|
||||
.first()
|
||||
.and_then(|field| entry_values.get(&field.id))
|
||||
.and_then(|value| trimmed(Some(value)));
|
||||
if !field_map.contains_key(ATTENDANCE_ID_FIELD_ID) {
|
||||
return Err(ApiError::bad_request(
|
||||
"Turneringen är felkonfigurerad och saknar obligatoriskt deltagar-ID-fält.",
|
||||
));
|
||||
}
|
||||
|
||||
let entry_label_requires_unique = config
|
||||
.entry_fields
|
||||
.first()
|
||||
.map(|field| field.unique)
|
||||
.unwrap_or(false);
|
||||
let is_team = config.mode == "team";
|
||||
let mut lead_participant: Option<(i32, Person)> = None;
|
||||
|
||||
if entry_label_requires_unique {
|
||||
if let Some(label) = entry_label.clone() {
|
||||
let is_duplicate = sqlx::query_scalar::<_, bool>(
|
||||
if is_team {
|
||||
entry_values.remove(ATTENDANCE_ID_FIELD_ID);
|
||||
let mut seen_attendance_ids: HashSet<i32> = HashSet::new();
|
||||
|
||||
for (index, values) in participant_values.iter_mut().enumerate() {
|
||||
let attendance_raw = values
|
||||
.get(ATTENDANCE_ID_FIELD_ID)
|
||||
.map(|value| value.trim().to_string())
|
||||
.filter(|value| !value.is_empty())
|
||||
.ok_or_else(|| {
|
||||
ApiError::bad_request(format!(
|
||||
"Spelare #{number}: ange deltagar-ID från närvarolistan.",
|
||||
number = index + 1
|
||||
))
|
||||
})?;
|
||||
|
||||
let attendance_id: i32 = attendance_raw.parse().map_err(|_| {
|
||||
ApiError::bad_request(format!(
|
||||
"Spelare #{number}: deltagar-ID måste vara ett heltal från närvarolistan.",
|
||||
number = index + 1
|
||||
))
|
||||
})?;
|
||||
|
||||
if !seen_attendance_ids.insert(attendance_id) {
|
||||
return Err(ApiError::bad_request(format!(
|
||||
"Spelare #{number}: deltagar-ID används redan av en annan spelare i laget.",
|
||||
number = index + 1
|
||||
)));
|
||||
}
|
||||
|
||||
let person = sqlx::query_as::<_, Person>(
|
||||
r#"
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM tournament_registrations
|
||||
WHERE tournament_id = $1
|
||||
AND entry_label = $2
|
||||
AND id <> $3
|
||||
)
|
||||
SELECT
|
||||
id,
|
||||
first_name,
|
||||
last_name,
|
||||
grade,
|
||||
parent_name,
|
||||
parent_phone_number,
|
||||
checked_in,
|
||||
inside,
|
||||
visitor,
|
||||
sleeping_spot
|
||||
FROM persons
|
||||
WHERE id = $1
|
||||
"#,
|
||||
)
|
||||
.bind(info.id)
|
||||
.bind(&label)
|
||||
.bind(registration.id)
|
||||
.fetch_one(&state.db)
|
||||
.await?;
|
||||
.bind(attendance_id)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::bad_request(format!(
|
||||
"Spelare #{number}: deltagar-ID:t finns inte i närvarolistan.",
|
||||
number = index + 1
|
||||
))
|
||||
})?;
|
||||
|
||||
if is_duplicate {
|
||||
return Err(ApiError::bad_request(
|
||||
"Den här spelaren eller laget är redan anmäld till turneringen.",
|
||||
));
|
||||
values.insert(
|
||||
ATTENDANCE_ID_FIELD_ID.to_string(),
|
||||
attendance_id.to_string(),
|
||||
);
|
||||
|
||||
if lead_participant.is_none() {
|
||||
lead_participant = Some((attendance_id, person.clone()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let attendance_id_value = entry_values
|
||||
.get(ATTENDANCE_ID_FIELD_ID)
|
||||
.map(|value| value.trim().to_string())
|
||||
.filter(|value| !value.is_empty())
|
||||
.ok_or_else(|| ApiError::bad_request("Ange ditt deltagar-ID från närvarolistan."))?;
|
||||
|
||||
let attendance_id: i32 = attendance_id_value.parse().map_err(|_| {
|
||||
ApiError::bad_request("Deltagar-ID måste vara ett heltal från närvarolistan.")
|
||||
})?;
|
||||
|
||||
let person = sqlx::query_as::<_, Person>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
first_name,
|
||||
last_name,
|
||||
grade,
|
||||
parent_name,
|
||||
parent_phone_number,
|
||||
checked_in,
|
||||
inside,
|
||||
visitor,
|
||||
sleeping_spot
|
||||
FROM persons
|
||||
WHERE id = $1
|
||||
"#,
|
||||
)
|
||||
.bind(attendance_id)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::bad_request("Det angivna deltagar-ID:t finns inte i närvarolistan.")
|
||||
})?;
|
||||
|
||||
entry_values.insert(
|
||||
ATTENDANCE_ID_FIELD_ID.to_string(),
|
||||
attendance_id.to_string(),
|
||||
);
|
||||
lead_participant = Some((attendance_id, person));
|
||||
}
|
||||
|
||||
let (lead_attendance_id, lead_person) = lead_participant.ok_or_else(|| {
|
||||
ApiError::bad_request("Minst en deltagare med deltagar-ID krävs för anmälan.")
|
||||
})?;
|
||||
|
||||
let entry_label = build_entry_label(lead_attendance_id, &lead_person, &config, &entry_values);
|
||||
|
||||
for field in &config.entry_fields {
|
||||
if !field.unique {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
"@sveltejs/kit": "^2.22.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^6.0.0",
|
||||
"@tailwindcss/vite": "^4.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"prettier": "^3.4.2",
|
||||
"prettier-plugin-svelte": "^3.3.3",
|
||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||
|
|
@ -210,6 +211,8 @@
|
|||
|
||||
"devalue": ["devalue@5.3.2", "", {}, "sha512-UDsjUbpQn9kvm68slnrs+mfxwFkIflOhkanmyabZ8zOYk8SMEIbJ3TK+88g70hSIeytu4y18f0z/hYHMTrXIWw=="],
|
||||
|
||||
"dotenv": ["dotenv@16.6.1", "", {}, "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow=="],
|
||||
|
||||
"enhanced-resolve": ["enhanced-resolve@5.18.3", "", { "dependencies": { "graceful-fs": "^4.2.4", "tapable": "^2.2.0" } }, "sha512-d4lC8xfavMeBjzGr2vECC3fsGXziXZQyJxD868h2M/mBI3PwAuODxAkLkq5HYuvrPYcUtiLzsTo8U3PgX3Ocww=="],
|
||||
|
||||
"esbuild": ["esbuild@0.25.10", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.25.10", "@esbuild/android-arm": "0.25.10", "@esbuild/android-arm64": "0.25.10", "@esbuild/android-x64": "0.25.10", "@esbuild/darwin-arm64": "0.25.10", "@esbuild/darwin-x64": "0.25.10", "@esbuild/freebsd-arm64": "0.25.10", "@esbuild/freebsd-x64": "0.25.10", "@esbuild/linux-arm": "0.25.10", "@esbuild/linux-arm64": "0.25.10", "@esbuild/linux-ia32": "0.25.10", "@esbuild/linux-loong64": "0.25.10", "@esbuild/linux-mips64el": "0.25.10", "@esbuild/linux-ppc64": "0.25.10", "@esbuild/linux-riscv64": "0.25.10", "@esbuild/linux-s390x": "0.25.10", "@esbuild/linux-x64": "0.25.10", "@esbuild/netbsd-arm64": "0.25.10", "@esbuild/netbsd-x64": "0.25.10", "@esbuild/openbsd-arm64": "0.25.10", "@esbuild/openbsd-x64": "0.25.10", "@esbuild/openharmony-arm64": "0.25.10", "@esbuild/sunos-x64": "0.25.10", "@esbuild/win32-arm64": "0.25.10", "@esbuild/win32-ia32": "0.25.10", "@esbuild/win32-x64": "0.25.10" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-9RiGKvCwaqxO2owP61uQ4BgNborAQskMR6QusfWzQqv7AZOg5oGehdY2pRJMTKuwxd1IDBP4rSbI5lHzU7SMsQ=="],
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ export type AppEvent =
|
|||
| { type: 'tournament_upserted'; tournament: TournamentInfo }
|
||||
| { type: 'tournament_deleted'; tournament_id: number };
|
||||
|
||||
export function listenToEvents(onEvent: (event: AppEvent) => void) {
|
||||
export function listenToEvents(onEvent: (event: AppEvent) => void, endpoint = '/api/events') {
|
||||
let stopped = false;
|
||||
let source: EventSource | null = null;
|
||||
|
||||
function connect() {
|
||||
if (stopped) return;
|
||||
source = new EventSource('/api/events');
|
||||
source = new EventSource(endpoint);
|
||||
source.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data) as AppEvent;
|
||||
|
|
|
|||
|
|
@ -5,10 +5,16 @@ export type TournamentEvent =
|
|||
| { type: 'tournament_upserted'; tournament: TournamentInfo }
|
||||
| { type: 'tournament_deleted'; tournament_id: number };
|
||||
|
||||
type TournamentEventOptions = {
|
||||
endpoint?: string;
|
||||
};
|
||||
|
||||
export function listenToTournamentEvents(
|
||||
onUpsert: (tournament: TournamentInfo) => void,
|
||||
onDelete: (tournamentId: number) => void
|
||||
onDelete: (tournamentId: number) => void,
|
||||
options: TournamentEventOptions = {}
|
||||
) {
|
||||
const endpoint = options.endpoint ?? '/api/events';
|
||||
return listenToEvents((event) => {
|
||||
if (event.type === 'tournament_upserted') {
|
||||
onUpsert(event.tournament);
|
||||
|
|
@ -17,5 +23,5 @@ export function listenToTournamentEvents(
|
|||
if (event.type === 'tournament_deleted') {
|
||||
onDelete(event.tournament_id);
|
||||
}
|
||||
});
|
||||
}, endpoint);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { listenToTournamentEvents } from '$lib/client/tournament-events';
|
||||
|
|
@ -13,96 +12,117 @@
|
|||
let registrations = $state(props.data.registrations ?? []);
|
||||
let refreshing = $state(false);
|
||||
let loadError = $state('');
|
||||
const ATTENDANCE_FIELD_ID = 'attendance-id';
|
||||
|
||||
type RegistrationResponse = {
|
||||
tournament: TournamentRegistrationList['tournament'];
|
||||
registrations: TournamentRegistrationItem[];
|
||||
};
|
||||
|
||||
type RegistrationPayload = RegistrationResponse & { warning?: string };
|
||||
|
||||
function applyResult(result: RegistrationResponse) {
|
||||
tournament = result.tournament;
|
||||
registrations = result.registrations ?? [];
|
||||
}
|
||||
|
||||
async function callEndpoint(
|
||||
endpoint: string,
|
||||
payload: unknown,
|
||||
defaultMessage: string
|
||||
): Promise<RegistrationPayload> {
|
||||
if (!tournament.slug) {
|
||||
throw new Error('Turneringen saknar slug.');
|
||||
function isAttendanceField(field: TournamentSignupField): boolean {
|
||||
return field.id === ATTENDANCE_FIELD_ID;
|
||||
}
|
||||
|
||||
const init: RequestInit = { method: 'POST' };
|
||||
if (payload !== undefined) {
|
||||
init.headers = { 'content-type': 'application/json' };
|
||||
init.body = JSON.stringify(payload);
|
||||
type RegistrationResponse = {
|
||||
tournament: TournamentRegistrationList['tournament'];
|
||||
registrations: TournamentRegistrationItem[];
|
||||
};
|
||||
|
||||
type RegistrationPayload = RegistrationResponse & { warning?: string };
|
||||
|
||||
function applyResult(result: RegistrationResponse) {
|
||||
tournament = result.tournament;
|
||||
registrations = result.registrations ?? [];
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`/admin/tournament/${tournament.slug}/registrations/${endpoint}`,
|
||||
init
|
||||
);
|
||||
const text = await response.text();
|
||||
const trimmed = text.trim();
|
||||
async function callEndpoint(
|
||||
endpoint: string,
|
||||
payload: unknown,
|
||||
defaultMessage: string
|
||||
): Promise<RegistrationPayload> {
|
||||
if (!tournament.slug) {
|
||||
throw new Error('Turneringen saknar slug.');
|
||||
}
|
||||
|
||||
const init: RequestInit = { method: 'POST' };
|
||||
if (payload !== undefined) {
|
||||
init.headers = { 'content-type': 'application/json' };
|
||||
init.body = JSON.stringify(payload);
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`/admin/tournament/${tournament.slug}/registrations/${endpoint}`,
|
||||
init
|
||||
);
|
||||
const text = await response.text();
|
||||
const trimmed = text.trim();
|
||||
|
||||
if (!response.ok) {
|
||||
let message = defaultMessage;
|
||||
try {
|
||||
const parsed = JSON.parse(text);
|
||||
if (parsed?.message) {
|
||||
message = parsed.message;
|
||||
} else if (trimmed) {
|
||||
message = trimmed;
|
||||
}
|
||||
} catch {
|
||||
if (trimmed) {
|
||||
message = trimmed;
|
||||
}
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
if (!trimmed) {
|
||||
throw new Error('Tomt svar från servern.');
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
let message = defaultMessage;
|
||||
try {
|
||||
const parsed = JSON.parse(text);
|
||||
if (parsed?.message) {
|
||||
message = parsed.message;
|
||||
} else if (trimmed) {
|
||||
message = trimmed;
|
||||
const data = JSON.parse(text) as RegistrationPayload;
|
||||
if (
|
||||
!data ||
|
||||
typeof data !== 'object' ||
|
||||
!('tournament' in data) ||
|
||||
!('registrations' in data)
|
||||
) {
|
||||
throw new Error();
|
||||
}
|
||||
return data;
|
||||
} catch {
|
||||
if (trimmed) {
|
||||
message = trimmed;
|
||||
}
|
||||
throw new Error('Kunde inte tolka svaret från servern.');
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
if (!trimmed) {
|
||||
throw new Error('Tomt svar från servern.');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = JSON.parse(text) as RegistrationPayload;
|
||||
if (
|
||||
!data ||
|
||||
typeof data !== 'object' ||
|
||||
!('tournament' in data) ||
|
||||
!('registrations' in data)
|
||||
) {
|
||||
throw new Error();
|
||||
}
|
||||
return data;
|
||||
} catch {
|
||||
throw new Error('Kunde inte tolka svaret från servern.');
|
||||
}
|
||||
}
|
||||
|
||||
let editingId = $state<number | null>(null);
|
||||
let editEntry = $state<Record<string, string>>({});
|
||||
let editParticipants = $state<Record<string, string>[]>([]);
|
||||
let editError = $state('');
|
||||
let editSaving = $state(false);
|
||||
let deletingId = $state<number | null>(null);
|
||||
let deleteError = $state('');
|
||||
let editingId = $state<number | null>(null);
|
||||
let editEntry = $state<Record<string, string>>({});
|
||||
let editParticipants = $state<Record<string, string>[]>([]);
|
||||
let editError = $state('');
|
||||
let editSaving = $state(false);
|
||||
let deletingId = $state<number | null>(null);
|
||||
let deleteError = $state('');
|
||||
|
||||
const entryFields = $derived(() => tournament.signup_config.entry_fields ?? []);
|
||||
const participantFields = $derived(() => tournament.signup_config.participant_fields ?? []);
|
||||
const signupConfig = $derived(() => tournament.signup_config);
|
||||
const minParticipants = $derived(() =>
|
||||
signupConfig().mode === 'team' ? Math.max(1, signupConfig().team_size.min) : 0
|
||||
);
|
||||
const participantFields = $derived(() => tournament.signup_config.participant_fields ?? []);
|
||||
const signupConfig = $derived(() => tournament.signup_config);
|
||||
const minParticipants = $derived(() =>
|
||||
signupConfig().mode === 'team' ? Math.max(1, signupConfig().team_size.min) : 0
|
||||
);
|
||||
const maxParticipants = $derived(() =>
|
||||
signupConfig().mode === 'team' ? Math.max(1, signupConfig().team_size.max) : 0
|
||||
);
|
||||
|
||||
function registrationHeading(registration: TournamentRegistrationItem) {
|
||||
const entry = registration.entry ?? {};
|
||||
for (const field of entryFields()) {
|
||||
if (isAttendanceField(field)) continue;
|
||||
const value = entry[field.id];
|
||||
if (value && value.trim()) {
|
||||
return value.trim();
|
||||
}
|
||||
}
|
||||
const attendanceValue = entry[ATTENDANCE_FIELD_ID];
|
||||
if (attendanceValue && attendanceValue.trim()) {
|
||||
return `Anmälan för ID ${attendanceValue.trim()}`;
|
||||
}
|
||||
return 'Anmälan';
|
||||
}
|
||||
|
||||
function formatDateTime(value: string | null) {
|
||||
if (!value) return null;
|
||||
const date = new Date(value);
|
||||
|
|
@ -130,26 +150,26 @@ const minParticipants = $derived(() =>
|
|||
return map;
|
||||
}
|
||||
|
||||
function blankParticipantMap() {
|
||||
const map: Record<string, string> = {};
|
||||
for (const field of participantFields()) {
|
||||
map[field.id] = '';
|
||||
function blankParticipantMap() {
|
||||
const map: Record<string, string> = {};
|
||||
for (const field of participantFields()) {
|
||||
map[field.id] = '';
|
||||
}
|
||||
return map;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
function fieldInputType(fieldType: string) {
|
||||
switch (fieldType) {
|
||||
case 'email':
|
||||
return 'email';
|
||||
case 'tel':
|
||||
return 'tel';
|
||||
default:
|
||||
return 'text';
|
||||
function fieldInputType(fieldType: string) {
|
||||
switch (fieldType) {
|
||||
case 'email':
|
||||
return 'email';
|
||||
case 'tel':
|
||||
return 'tel';
|
||||
default:
|
||||
return 'text';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ensureParticipantBounds(list: Record<string, string>[]) {
|
||||
function ensureParticipantBounds(list: Record<string, string>[]) {
|
||||
if (signupConfig().mode !== 'team') {
|
||||
return list;
|
||||
}
|
||||
|
|
@ -182,13 +202,13 @@ function ensureParticipantBounds(list: Record<string, string>[]) {
|
|||
editError = '';
|
||||
}
|
||||
|
||||
function cancelEdit() {
|
||||
editingId = null;
|
||||
editEntry = {};
|
||||
editParticipants = [];
|
||||
editError = '';
|
||||
editSaving = false;
|
||||
}
|
||||
function cancelEdit() {
|
||||
editingId = null;
|
||||
editEntry = {};
|
||||
editParticipants = [];
|
||||
editError = '';
|
||||
editSaving = false;
|
||||
}
|
||||
|
||||
function updateEntryField(fieldId: string, value: string) {
|
||||
editEntry = { ...editEntry, [fieldId]: value };
|
||||
|
|
@ -220,74 +240,92 @@ function cancelEdit() {
|
|||
return 'Spelare';
|
||||
}
|
||||
|
||||
async function saveEdit(registration: TournamentRegistrationItem) {
|
||||
if (!tournament.slug || editingId !== registration.id) return;
|
||||
editSaving = true;
|
||||
editError = '';
|
||||
const payload = {
|
||||
entry: { ...editEntry },
|
||||
participants: editParticipants.map((participant) => ({ ...participant }))
|
||||
};
|
||||
try {
|
||||
const result = await callEndpoint(
|
||||
'update',
|
||||
{
|
||||
registration_id: registration.id,
|
||||
entry: payload.entry,
|
||||
participants: payload.participants
|
||||
},
|
||||
'Kunde inte uppdatera anmälan.'
|
||||
);
|
||||
applyResult(result);
|
||||
loadError = result.warning ?? '';
|
||||
cancelEdit();
|
||||
} catch (err) {
|
||||
console.error('Failed to update registration', err);
|
||||
editError = err instanceof Error ? err.message : 'Ett oväntat fel inträffade.';
|
||||
} finally {
|
||||
editSaving = false;
|
||||
async function saveEdit(registration: TournamentRegistrationItem) {
|
||||
if (!tournament.slug || editingId !== registration.id) return;
|
||||
editSaving = true;
|
||||
editError = '';
|
||||
const entry: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(editEntry)) {
|
||||
entry[key] = (value ?? '').trim();
|
||||
}
|
||||
const participants = editParticipants.map((participant) => {
|
||||
const map: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(participant)) {
|
||||
map[key] = (value ?? '').trim();
|
||||
}
|
||||
return map;
|
||||
});
|
||||
const payload = {
|
||||
entry,
|
||||
participants
|
||||
};
|
||||
|
||||
if (entryFields().some(isAttendanceField)) {
|
||||
const attendanceValue = (payload.entry[ATTENDANCE_FIELD_ID] ?? '').trim();
|
||||
if (!attendanceValue) {
|
||||
editSaving = false;
|
||||
editError = 'Ange deltagar-ID från närvarolistan.';
|
||||
return;
|
||||
}
|
||||
if (!/^\d+$/.test(attendanceValue)) {
|
||||
editSaving = false;
|
||||
editError = 'Deltagar-ID får endast innehålla siffror.';
|
||||
return;
|
||||
}
|
||||
const attendanceNumeric = Number.parseInt(attendanceValue, 10);
|
||||
if (!Number.isFinite(attendanceNumeric) || attendanceNumeric <= 0) {
|
||||
editSaving = false;
|
||||
editError = 'Ange ett giltigt deltagar-ID.';
|
||||
return;
|
||||
}
|
||||
payload.entry[ATTENDANCE_FIELD_ID] = String(attendanceNumeric);
|
||||
}
|
||||
try {
|
||||
const result = await callEndpoint(
|
||||
'update',
|
||||
{
|
||||
registration_id: registration.id,
|
||||
entry: payload.entry,
|
||||
participants: payload.participants
|
||||
},
|
||||
'Kunde inte uppdatera anmälan.'
|
||||
);
|
||||
applyResult(result);
|
||||
loadError = result.warning ?? '';
|
||||
cancelEdit();
|
||||
} catch (err) {
|
||||
console.error('Failed to update registration', err);
|
||||
editError = err instanceof Error ? err.message : 'Ett oväntat fel inträffade.';
|
||||
} finally {
|
||||
editSaving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function exportRegistrations() {
|
||||
if (typeof window === 'undefined') return;
|
||||
const lines: string[] = [];
|
||||
const timestamp = formatDateTime(new Date().toISOString()) ?? new Date().toISOString();
|
||||
lines.push(`${tournament.title} – ${registrations.length} anmälningar`);
|
||||
lines.push(`Genererad ${timestamp}`);
|
||||
lines.push('');
|
||||
|
||||
if (registrations.length === 0) {
|
||||
lines.push('Inga anmälningar.');
|
||||
} else {
|
||||
for (const registration of registrations) {
|
||||
lines.push(`Anmälan #${registration.id}`);
|
||||
const created = formatDateTime(registration.created_at) ?? registration.created_at;
|
||||
lines.push(`Skapad: ${created}`);
|
||||
|
||||
if (entryFields().length > 0) {
|
||||
lines.push('Lag / deltagare:');
|
||||
for (const field of entryFields()) {
|
||||
lines.push(` ${field.label}: ${fieldValue(registration.entry, field) || '—'}`);
|
||||
}
|
||||
lines.push(registrationHeading(registration));
|
||||
for (const field of entryFields()) {
|
||||
const value = fieldValue(registration.entry, field).trim();
|
||||
lines.push(`${field.label}: ${value || '—'}`);
|
||||
}
|
||||
|
||||
if (participantFields().length === 0) {
|
||||
if (registration.participants.length > 0) {
|
||||
lines.push(`Spelare: ${registration.participants.length}`);
|
||||
}
|
||||
} else if (registration.participants.length === 0) {
|
||||
lines.push('Spelare: inga angivna');
|
||||
} else {
|
||||
lines.push('Spelare:');
|
||||
if (participantFields().length > 0 && registration.participants.length > 0) {
|
||||
registration.participants.forEach((participant, index) => {
|
||||
lines.push(` Spelare ${index + 1}`);
|
||||
lines.push('');
|
||||
lines.push(`Spelare ${index + 1}`);
|
||||
for (const field of participantFields()) {
|
||||
lines.push(` ${field.label}: ${fieldValue(participant, field) || '—'}`);
|
||||
const value = fieldValue(participant, field).trim();
|
||||
lines.push(`${field.label}: ${value || '—'}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
lines.push('');
|
||||
}
|
||||
}
|
||||
|
|
@ -301,59 +339,62 @@ async function saveEdit(registration: TournamentRegistrationItem) {
|
|||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
}
|
||||
|
||||
async function removeRegistration(registration: TournamentRegistrationItem) {
|
||||
if (!tournament.slug) return;
|
||||
if (!window.confirm('Ta bort denna anmälan? Det går inte att ångra.')) return;
|
||||
deletingId = registration.id;
|
||||
deleteError = '';
|
||||
try {
|
||||
const result = await callEndpoint(
|
||||
'delete',
|
||||
{ registration_id: registration.id },
|
||||
'Kunde inte ta bort anmälan.'
|
||||
async function removeRegistration(registration: TournamentRegistrationItem) {
|
||||
if (!tournament.slug) return;
|
||||
if (!window.confirm('Ta bort denna anmälan? Det går inte att ångra.')) return;
|
||||
deletingId = registration.id;
|
||||
deleteError = '';
|
||||
try {
|
||||
const result = await callEndpoint(
|
||||
'delete',
|
||||
{ registration_id: registration.id },
|
||||
'Kunde inte ta bort anmälan.'
|
||||
);
|
||||
applyResult(result);
|
||||
loadError = result.warning ?? '';
|
||||
if (editingId === registration.id) {
|
||||
cancelEdit();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to delete registration', err);
|
||||
deleteError = err instanceof Error ? err.message : 'Ett oväntat fel inträffade.';
|
||||
} finally {
|
||||
deletingId = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshRegistrations() {
|
||||
if (!tournament.slug) return;
|
||||
refreshing = true;
|
||||
loadError = '';
|
||||
try {
|
||||
const result = await callEndpoint('refresh', undefined, 'Kunde inte hämta anmälningarna.');
|
||||
applyResult(result);
|
||||
loadError = result.warning ?? '';
|
||||
} catch (err) {
|
||||
console.error('Failed to refresh registrations', err);
|
||||
loadError = err instanceof Error ? err.message : 'Ett oväntat fel inträffade.';
|
||||
} finally {
|
||||
refreshing = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const stop = listenToTournamentEvents(
|
||||
(updated) => {
|
||||
if (updated.id === tournament.id && editingId === null) {
|
||||
void refreshRegistrations();
|
||||
}
|
||||
},
|
||||
(deletedId) => {
|
||||
if (deletedId === tournament.id) {
|
||||
registrations = [];
|
||||
loadError = 'Turneringen har tagits bort.';
|
||||
}
|
||||
}
|
||||
);
|
||||
applyResult(result);
|
||||
loadError = result.warning ?? '';
|
||||
if (editingId === registration.id) {
|
||||
cancelEdit();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to delete registration', err);
|
||||
deleteError = err instanceof Error ? err.message : 'Ett oväntat fel inträffade.';
|
||||
} finally {
|
||||
deletingId = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshRegistrations() {
|
||||
if (!tournament.slug) return;
|
||||
refreshing = true;
|
||||
loadError = '';
|
||||
try {
|
||||
const result = await callEndpoint('refresh', undefined, 'Kunde inte hämta anmälningarna.');
|
||||
applyResult(result);
|
||||
loadError = result.warning ?? '';
|
||||
} catch (err) {
|
||||
console.error('Failed to refresh registrations', err);
|
||||
loadError = err instanceof Error ? err.message : 'Ett oväntat fel inträffade.';
|
||||
} finally {
|
||||
refreshing = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const stop = listenToTournamentEvents((updated) => {
|
||||
if (updated.id === tournament.id && editingId === null) {
|
||||
void refreshRegistrations();
|
||||
}
|
||||
}, (deletedId) => {
|
||||
if (deletedId === tournament.id) {
|
||||
registrations = [];
|
||||
loadError = 'Turneringen har tagits bort.';
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
stop();
|
||||
};
|
||||
|
|
@ -366,9 +407,11 @@ onMount(() => {
|
|||
|
||||
<div class="min-h-screen bg-slate-100 text-slate-900">
|
||||
<div class="mx-auto flex min-h-screen max-w-5xl flex-col gap-8 px-3 py-8 sm:px-4">
|
||||
<header class="flex flex-col gap-4 rounded-lg border border-slate-200 bg-white p-6 shadow-sm sm:flex-row sm:items-center sm:justify-between">
|
||||
<header
|
||||
class="flex flex-col gap-4 rounded-lg border border-slate-200 bg-white p-6 shadow-sm sm:flex-row sm:items-center sm:justify-between"
|
||||
>
|
||||
<div class="space-y-1">
|
||||
<p class="text-sm uppercase tracking-[0.4em] text-indigo-500">Admin</p>
|
||||
<p class="text-sm tracking-[0.4em] text-indigo-500 uppercase">Admin</p>
|
||||
<h1 class="text-2xl font-semibold text-slate-900">{tournament.title}</h1>
|
||||
<p class="text-sm text-slate-600">{tournament.game}</p>
|
||||
</div>
|
||||
|
|
@ -392,17 +435,19 @@ onMount(() => {
|
|||
<h2 class="text-lg font-semibold text-slate-900">Sammanfattning</h2>
|
||||
<div class="grid gap-3 sm:grid-cols-3">
|
||||
<div class="rounded-lg border border-slate-200 bg-slate-50 p-4">
|
||||
<p class="text-xs uppercase tracking-wide text-slate-500">Anmälningar</p>
|
||||
<p class="text-xs tracking-wide text-slate-500 uppercase">Anmälningar</p>
|
||||
<p class="mt-1 text-2xl font-semibold text-slate-900">{registrations.length}</p>
|
||||
</div>
|
||||
{#if tournament.start_at}
|
||||
<div class="rounded-lg border border-slate-200 bg-slate-50 p-4">
|
||||
<p class="text-xs uppercase tracking-wide text-slate-500">Start</p>
|
||||
<p class="mt-1 text-sm text-slate-800">{formatDateTime(tournament.start_at) ?? tournament.start_at}</p>
|
||||
<p class="text-xs tracking-wide text-slate-500 uppercase">Start</p>
|
||||
<p class="mt-1 text-sm text-slate-800">
|
||||
{formatDateTime(tournament.start_at) ?? tournament.start_at}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="rounded-lg border border-slate-200 bg-slate-50 p-4">
|
||||
<p class="text-xs uppercase tracking-wide text-slate-500">Format</p>
|
||||
<p class="text-xs tracking-wide text-slate-500 uppercase">Format</p>
|
||||
<p class="mt-1 text-sm text-slate-800">
|
||||
{signupConfig().mode === 'team'
|
||||
? `Lag (${signupConfig().team_size.min}–${signupConfig().team_size.max} spelare)`
|
||||
|
|
@ -412,45 +457,59 @@ onMount(() => {
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<section class="rounded-lg border border-slate-200 bg-white p-6 shadow-sm">
|
||||
<header class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||
<h2 class="text-lg font-semibold text-slate-900">Registreringar</h2>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
{#if registrations.length > 0}
|
||||
<p class="text-sm text-slate-500">Senaste: {formatDateTime(registrations[0].created_at) ?? registrations[0].created_at}</p>
|
||||
{/if}
|
||||
<button
|
||||
type="button"
|
||||
onclick={exportRegistrations}
|
||||
class="rounded-full border border-slate-300 px-4 py-2 text-xs font-semibold uppercase tracking-wide text-slate-600 transition hover:bg-slate-100"
|
||||
>
|
||||
Exportera .txt
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<section class="rounded-lg border border-slate-200 bg-white p-6 shadow-sm">
|
||||
<header class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||
<h2 class="text-lg font-semibold text-slate-900">Registreringar</h2>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
{#if registrations.length > 0}
|
||||
<p class="text-sm text-slate-500">
|
||||
Senaste: {formatDateTime(registrations[0].created_at) ?? registrations[0].created_at}
|
||||
</p>
|
||||
{/if}
|
||||
<button
|
||||
type="button"
|
||||
onclick={exportRegistrations}
|
||||
class="rounded-full border border-slate-300 px-4 py-2 text-xs font-semibold tracking-wide text-slate-600 uppercase transition hover:bg-slate-100"
|
||||
>
|
||||
Exportera .txt
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{#if loadError}
|
||||
<p class="mt-2 rounded-md border border-red-200 bg-red-500/10 px-4 py-2 text-sm text-red-600">{loadError}</p>
|
||||
{/if}
|
||||
{#if deleteError}
|
||||
<p class="mt-2 rounded-md border border-red-200 bg-red-500/10 px-4 py-2 text-sm text-red-600">{deleteError}</p>
|
||||
{/if}
|
||||
{#if refreshing && !loadError}
|
||||
<p class="mt-2 text-xs text-slate-500">Uppdaterar…</p>
|
||||
{/if}
|
||||
{#if loadError}
|
||||
<p
|
||||
class="mt-2 rounded-md border border-red-200 bg-red-500/10 px-4 py-2 text-sm text-red-600"
|
||||
>
|
||||
{loadError}
|
||||
</p>
|
||||
{/if}
|
||||
{#if deleteError}
|
||||
<p
|
||||
class="mt-2 rounded-md border border-red-200 bg-red-500/10 px-4 py-2 text-sm text-red-600"
|
||||
>
|
||||
{deleteError}
|
||||
</p>
|
||||
{/if}
|
||||
{#if refreshing && !loadError}
|
||||
<p class="mt-2 text-xs text-slate-500">Uppdaterar…</p>
|
||||
{/if}
|
||||
|
||||
{#if registrations.length === 0}
|
||||
<p class="mt-4 rounded-md border border-dashed border-slate-300 px-4 py-6 text-center text-sm text-slate-500">
|
||||
<p
|
||||
class="mt-4 rounded-md border border-dashed border-slate-300 px-4 py-6 text-center text-sm text-slate-500"
|
||||
>
|
||||
Inga anmälningar ännu. Dela länken till /tournament/{tournament.slug} för att samla in registreringar.
|
||||
</p>
|
||||
{:else}
|
||||
<div class="mt-6 space-y-5">
|
||||
{#each registrations as registration}
|
||||
{#each registrations as registration}
|
||||
<article class="space-y-4 rounded-lg border border-slate-200 bg-slate-50 p-4">
|
||||
<header class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<h3 class="text-base font-semibold text-slate-900">Anmälan #{registration.id}</h3>
|
||||
<p class="text-xs uppercase tracking-wide text-slate-500">
|
||||
<h3 class="text-base font-semibold text-slate-900">
|
||||
{registrationHeading(registration)}
|
||||
</h3>
|
||||
<p class="text-xs tracking-wide text-slate-500 uppercase">
|
||||
Skapad {formatDateTime(registration.created_at) ?? registration.created_at}
|
||||
</p>
|
||||
</div>
|
||||
|
|
@ -484,25 +543,42 @@ onMount(() => {
|
|||
</header>
|
||||
|
||||
{#if editingId === registration.id}
|
||||
<form class="space-y-4" onsubmit={(event) => {
|
||||
event.preventDefault();
|
||||
saveEdit(registration);
|
||||
}}>
|
||||
<form
|
||||
class="space-y-4"
|
||||
onsubmit={(event) => {
|
||||
event.preventDefault();
|
||||
saveEdit(registration);
|
||||
}}
|
||||
>
|
||||
{#if entryFields().length > 0}
|
||||
<div class="space-y-3">
|
||||
<h4 class="text-sm font-semibold uppercase tracking-wide text-slate-500">Lag / deltagare</h4>
|
||||
<h4 class="text-sm font-semibold tracking-wide text-slate-500 uppercase">
|
||||
Lag / deltagare
|
||||
</h4>
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
{#each entryFields() as field}
|
||||
<label class="flex flex-col gap-1 text-sm font-medium text-slate-700">
|
||||
<span>{field.label}</span>
|
||||
<input
|
||||
type={fieldInputType(field.field_type)}
|
||||
inputmode={isAttendanceField(field) ? 'numeric' : undefined}
|
||||
pattern={isAttendanceField(field) ? '\\d*' : undefined}
|
||||
value={editEntry[field.id] ?? ''}
|
||||
oninput={(event) => updateEntryField(field.id, (event.currentTarget as HTMLInputElement).value)}
|
||||
oninput={(event) =>
|
||||
updateEntryField(
|
||||
field.id,
|
||||
(event.currentTarget as HTMLInputElement).value
|
||||
)}
|
||||
placeholder={field.placeholder ?? ''}
|
||||
disabled={editSaving}
|
||||
class="rounded-md border border-slate-300 px-3 py-2 text-sm text-slate-900 focus:border-indigo-500 focus:outline-none focus:ring focus:ring-indigo-500/40"
|
||||
class="rounded-md border border-slate-300 px-3 py-2 text-sm text-slate-900 focus:border-indigo-500 focus:ring focus:ring-indigo-500/40 focus:outline-none"
|
||||
/>
|
||||
{#if isAttendanceField(field)}
|
||||
<span class="text-xs text-slate-500">
|
||||
Koppla registreringen till en deltagare genom att ange ID från
|
||||
närvarolistan.
|
||||
</span>
|
||||
{/if}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
|
|
@ -511,12 +587,15 @@ onMount(() => {
|
|||
|
||||
<section class="space-y-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<h4 class="text-sm font-semibold uppercase tracking-wide text-slate-500">Spelare</h4>
|
||||
<h4 class="text-sm font-semibold tracking-wide text-slate-500 uppercase">
|
||||
Spelare
|
||||
</h4>
|
||||
{#if signupConfig().mode === 'team'}
|
||||
<button
|
||||
type="button"
|
||||
onclick={addParticipant}
|
||||
disabled={editSaving || (maxParticipants() > 0 && editParticipants.length >= maxParticipants())}
|
||||
disabled={editSaving ||
|
||||
(maxParticipants() > 0 && editParticipants.length >= maxParticipants())}
|
||||
class="rounded-full border border-indigo-300 px-3 py-1 text-xs font-semibold text-indigo-600 transition hover:border-indigo-400 hover:bg-indigo-50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
Lägg till spelare
|
||||
|
|
@ -533,12 +612,17 @@ onMount(() => {
|
|||
{#each editParticipants as participant, index}
|
||||
<div class="space-y-3 rounded-md border border-slate-200 bg-white p-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">{participantLabel(index)}</p>
|
||||
<p
|
||||
class="text-xs font-semibold tracking-wide text-slate-500 uppercase"
|
||||
>
|
||||
{participantLabel(index)}
|
||||
</p>
|
||||
{#if signupConfig().mode === 'team'}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => removeParticipant(index)}
|
||||
disabled={editSaving || editParticipants.length <= Math.max(1, minParticipants())}
|
||||
disabled={editSaving ||
|
||||
editParticipants.length <= Math.max(1, minParticipants())}
|
||||
class="rounded-full border border-red-200 px-3 py-1 text-xs font-semibold text-red-600 transition hover:border-red-400 hover:bg-red-50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
Ta bort
|
||||
|
|
@ -547,27 +631,38 @@ onMount(() => {
|
|||
</div>
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
{#each participantFields() as field}
|
||||
<label class="flex flex-col gap-1 text-sm font-medium text-slate-700">
|
||||
<label
|
||||
class="flex flex-col gap-1 text-sm font-medium text-slate-700"
|
||||
>
|
||||
<span>{field.label}</span>
|
||||
<input
|
||||
type={fieldInputType(field.field_type)}
|
||||
value={participant[field.id] ?? ''}
|
||||
oninput={(event) => updateParticipantField(index, field.id, (event.currentTarget as HTMLInputElement).value)}
|
||||
oninput={(event) =>
|
||||
updateParticipantField(
|
||||
index,
|
||||
field.id,
|
||||
(event.currentTarget as HTMLInputElement).value
|
||||
)}
|
||||
placeholder={field.placeholder ?? ''}
|
||||
disabled={editSaving}
|
||||
class="rounded-md border border-slate-300 px-3 py-2 text-sm text-slate-900 focus:border-indigo-500 focus:outline-none focus:ring focus:ring-indigo-500/40"
|
||||
class="rounded-md border border-slate-300 px-3 py-2 text-sm text-slate-900 focus:border-indigo-500 focus:ring focus:ring-indigo-500/40 focus:outline-none"
|
||||
/>
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
{#if editError}
|
||||
<p class="rounded-md border border-red-200 bg-red-500/10 px-3 py-2 text-sm text-red-600">{editError}</p>
|
||||
<p
|
||||
class="rounded-md border border-red-200 bg-red-500/10 px-3 py-2 text-sm text-red-600"
|
||||
>
|
||||
{editError}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-wrap items-center gap-3 pt-2">
|
||||
|
|
@ -593,28 +688,27 @@ onMount(() => {
|
|||
<div class="grid gap-3 md:grid-cols-2">
|
||||
{#each entryFields() as field}
|
||||
<div class="rounded-md border border-slate-200 bg-white p-3">
|
||||
<p class="text-xs uppercase tracking-wide text-slate-500">{field.label}</p>
|
||||
<p class="mt-1 text-sm text-slate-800">{fieldValue(registration.entry, field) || '—'}</p>
|
||||
<p class="text-xs tracking-wide text-slate-500 uppercase">{field.label}</p>
|
||||
<p class="mt-1 text-sm text-slate-800">
|
||||
{fieldValue(registration.entry, field) || '—'}
|
||||
</p>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<section class="space-y-2">
|
||||
<h4 class="text-sm font-semibold text-slate-800">Spelare</h4>
|
||||
{#if participantFields().length === 0}
|
||||
{#if participantFields().length > 0}
|
||||
<section class="space-y-2">
|
||||
<h4 class="text-sm font-semibold text-slate-800">Spelare</h4>
|
||||
{#if registration.participants.length === 0}
|
||||
<p class="text-xs text-slate-500">Inga spelare angivna.</p>
|
||||
{:else}
|
||||
<p class="text-xs text-slate-500">Antal spelare: {registration.participants.length}</p>
|
||||
{/if}
|
||||
{:else if registration.participants.length === 0}
|
||||
<p class="text-xs text-slate-500">Inga spelare angivna.</p>
|
||||
{:else}
|
||||
{:else}
|
||||
<div class="space-y-3">
|
||||
{#each registration.participants as participant, index}
|
||||
<div class="rounded-md border border-slate-200 bg-white p-3">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Spelare {index + 1}</p>
|
||||
<p class="text-xs font-semibold tracking-wide text-slate-500 uppercase">
|
||||
Spelare {index + 1}
|
||||
</p>
|
||||
<ul class="mt-2 space-y-1 text-sm text-slate-800">
|
||||
{#each participantFields() as field}
|
||||
<li>
|
||||
|
|
@ -624,10 +718,11 @@ onMount(() => {
|
|||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
{/if}
|
||||
{/if}
|
||||
</article>
|
||||
{/each}
|
||||
|
|
|
|||
|
|
@ -63,8 +63,10 @@
|
|||
return `${count} ${count === 1 ? 'spelare' : 'spelare'}`;
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const stop = listenToTournamentEvents(upsertTournament, removeTournament);
|
||||
onMount(() => {
|
||||
const stop = listenToTournamentEvents(upsertTournament, removeTournament, {
|
||||
endpoint: '/api/public-events'
|
||||
});
|
||||
return () => {
|
||||
stop();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
const props = $props<{ data: { tournament: TournamentInfo } }>();
|
||||
const tournament = props.data.tournament;
|
||||
const ATTENDANCE_FIELD_ID = 'attendance-id';
|
||||
|
||||
function pickMode(value: string | null | undefined) {
|
||||
return value === 'team' ? 'team' : 'solo';
|
||||
|
|
@ -24,7 +25,9 @@
|
|||
};
|
||||
}
|
||||
|
||||
function normalizeSignupConfig(config: TournamentSignupConfig | null | undefined): TournamentSignupConfig {
|
||||
function normalizeSignupConfig(
|
||||
config: TournamentSignupConfig | null | undefined
|
||||
): TournamentSignupConfig {
|
||||
if (!config) {
|
||||
return {
|
||||
mode: 'solo',
|
||||
|
|
@ -54,6 +57,7 @@
|
|||
type FieldValueMap = Record<string, string>;
|
||||
|
||||
const signupConfig = normalizeSignupConfig(tournament.signup_config);
|
||||
const entrySectionTitle = signupConfig.mode === 'team' ? 'Lag' : 'Spelare';
|
||||
|
||||
function formatDateTime(value: string | null) {
|
||||
if (!value) return null;
|
||||
|
|
@ -94,6 +98,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
function isAttendanceField(field: TournamentSignupField): boolean {
|
||||
return field.id === ATTENDANCE_FIELD_ID;
|
||||
}
|
||||
|
||||
const minParticipants = signupConfig.mode === 'team' ? signupConfig.team_size.min : 1;
|
||||
const maxParticipants = signupConfig.mode === 'team' ? signupConfig.team_size.max : 1;
|
||||
|
||||
|
|
@ -109,8 +117,6 @@
|
|||
showSuccessModal: false
|
||||
});
|
||||
|
||||
|
||||
|
||||
function initializeParticipants() {
|
||||
const initialCount = Math.max(1, signupConfig.mode === 'team' ? signupConfig.team_size.min : 1);
|
||||
const list: FieldValueMap[] = [];
|
||||
|
|
@ -159,6 +165,13 @@
|
|||
entry[field.id] = (signup.entry[field.id] ?? '').trim();
|
||||
}
|
||||
|
||||
if (entry[ATTENDANCE_FIELD_ID]) {
|
||||
const numeric = Number.parseInt(entry[ATTENDANCE_FIELD_ID], 10);
|
||||
if (Number.isFinite(numeric) && numeric > 0) {
|
||||
entry[ATTENDANCE_FIELD_ID] = String(numeric);
|
||||
}
|
||||
}
|
||||
|
||||
const participants = signup.participants.map((participant) => {
|
||||
const map: Record<string, string> = {};
|
||||
for (const field of signupConfig.participant_fields) {
|
||||
|
|
@ -175,18 +188,58 @@
|
|||
signup.error = '';
|
||||
signup.success = '';
|
||||
|
||||
const isTeam = signupConfig.mode === 'team';
|
||||
|
||||
if (isTeam) {
|
||||
if (signup.participants.length < minParticipants) {
|
||||
signup.error =
|
||||
minParticipants === 1
|
||||
? 'Lägg till minst en spelare.'
|
||||
: `Lägg till minst ${minParticipants} spelare.`;
|
||||
return;
|
||||
}
|
||||
|
||||
for (let index = 0; index < signup.participants.length; index += 1) {
|
||||
const participant = signup.participants[index];
|
||||
const raw = (participant[ATTENDANCE_FIELD_ID] ?? '').trim();
|
||||
if (!raw) {
|
||||
signup.error = `Spelare ${index + 1}: ange deltagar-ID från närvarolistan.`;
|
||||
return;
|
||||
}
|
||||
if (!/^\d+$/.test(raw)) {
|
||||
signup.error = `Spelare ${index + 1}: deltagar-ID får endast innehålla siffror.`;
|
||||
return;
|
||||
}
|
||||
const numeric = Number.parseInt(raw, 10);
|
||||
if (!Number.isFinite(numeric) || numeric <= 0) {
|
||||
signup.error = `Spelare ${index + 1}: ange ett giltigt deltagar-ID.`;
|
||||
return;
|
||||
}
|
||||
participant[ATTENDANCE_FIELD_ID] = String(numeric);
|
||||
}
|
||||
} else {
|
||||
const attendanceValue = (signup.entry[ATTENDANCE_FIELD_ID] ?? '').trim();
|
||||
if (!attendanceValue) {
|
||||
signup.error = 'Ange ditt deltagar-ID från närvarolistan.';
|
||||
return;
|
||||
}
|
||||
if (!/^\d+$/.test(attendanceValue)) {
|
||||
signup.error = 'Deltagar-ID får endast innehålla siffror.';
|
||||
return;
|
||||
}
|
||||
const attendanceNumeric = Number.parseInt(attendanceValue, 10);
|
||||
if (!Number.isFinite(attendanceNumeric) || attendanceNumeric <= 0) {
|
||||
signup.error = 'Ange ett giltigt deltagar-ID.';
|
||||
return;
|
||||
}
|
||||
signup.entry[ATTENDANCE_FIELD_ID] = String(attendanceNumeric);
|
||||
}
|
||||
|
||||
if (signup.participants.length === 0) {
|
||||
signup.error = 'Lägg till minst en spelare.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (signupConfig.mode === 'team') {
|
||||
if (signup.participants.length < minParticipants) {
|
||||
signup.error = `Lägg till minst ${minParticipants} spelare.`;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
signup.submitting = true;
|
||||
try {
|
||||
const payload = buildSignupPayload();
|
||||
|
|
@ -251,12 +304,12 @@
|
|||
<span aria-hidden="true">←</span>
|
||||
<span>Tillbaka till turneringsöversikten</span>
|
||||
</a>
|
||||
<span class="uppercase tracking-[0.4em] text-indigo-300">{tournament.game}</span>
|
||||
<span class="tracking-[0.4em] text-indigo-300 uppercase">{tournament.game}</span>
|
||||
</nav>
|
||||
|
||||
<header class="space-y-4 rounded-2xl bg-slate-900/70 p-6 shadow-lg">
|
||||
<div class="space-y-2">
|
||||
<p class="text-xs uppercase tracking-[0.4em] text-indigo-200">VBytes LAN</p>
|
||||
<p class="text-xs tracking-[0.4em] text-indigo-200 uppercase">VBytes LAN</p>
|
||||
<h1 class="text-3xl font-bold sm:text-4xl">{tournament.title}</h1>
|
||||
{#if tournament.tagline}
|
||||
<p class="text-base text-slate-300">{tournament.tagline}</p>
|
||||
|
|
@ -265,19 +318,19 @@
|
|||
<div class="grid gap-3 sm:grid-cols-2">
|
||||
{#if formattedStart}
|
||||
<div class="rounded-lg border border-slate-800 bg-slate-900/40 p-3">
|
||||
<p class="text-xs uppercase tracking-wide text-indigo-200">Start</p>
|
||||
<p class="text-xs tracking-wide text-indigo-200 uppercase">Start</p>
|
||||
<p class="text-sm text-slate-100">{formattedStart}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{#if tournament.location}
|
||||
<div class="rounded-lg border border-slate-800 bg-slate-900/40 p-3">
|
||||
<p class="text-xs uppercase tracking-wide text-indigo-200">Plats</p>
|
||||
<p class="text-xs tracking-wide text-indigo-200 uppercase">Plats</p>
|
||||
<p class="text-sm text-slate-100">{tournament.location}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{#if tournament.contact}
|
||||
<div class="rounded-lg border border-slate-800 bg-slate-900/40 p-3 sm:col-span-2">
|
||||
<p class="text-xs uppercase tracking-wide text-indigo-200">Kontakt</p>
|
||||
<p class="text-xs tracking-wide text-indigo-200 uppercase">Kontakt</p>
|
||||
<p class="text-sm text-slate-100">{tournament.contact}</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
@ -287,7 +340,9 @@
|
|||
{#if tournament.description}
|
||||
<section class="space-y-3 rounded-2xl border border-slate-800 bg-slate-900/50 p-6">
|
||||
<h2 class="text-lg font-semibold text-slate-100">Beskrivning</h2>
|
||||
<p class="whitespace-pre-line text-sm leading-relaxed text-slate-200">{tournament.description}</p>
|
||||
<p class="text-sm leading-relaxed whitespace-pre-line text-slate-200">
|
||||
{tournament.description}
|
||||
</p>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
|
|
@ -296,7 +351,7 @@
|
|||
{#each tournament.sections as section, index (section.title + index)}
|
||||
<article class="space-y-2 rounded-2xl border border-slate-800 bg-slate-900/50 p-6">
|
||||
<h3 class="text-base font-semibold text-indigo-200">{section.title}</h3>
|
||||
<p class="whitespace-pre-line text-sm leading-relaxed text-slate-200">{section.body}</p>
|
||||
<p class="text-sm leading-relaxed whitespace-pre-line text-slate-200">{section.body}</p>
|
||||
</article>
|
||||
{/each}
|
||||
</section>
|
||||
|
|
@ -306,7 +361,9 @@
|
|||
<header class="space-y-1">
|
||||
<h2 class="text-lg font-semibold text-slate-100">Anmälan</h2>
|
||||
{#if signupConfig.mode === 'team'}
|
||||
<p class="text-sm text-slate-300">Lagstorlek: {signupConfig.team_size.min}–{signupConfig.team_size.max} spelare.</p>
|
||||
<p class="text-sm text-slate-300">
|
||||
Lagstorlek: {signupConfig.team_size.min}–{signupConfig.team_size.max} spelare.
|
||||
</p>
|
||||
{:else}
|
||||
<p class="text-sm text-slate-300">Individuell anmälan.</p>
|
||||
{/if}
|
||||
|
|
@ -315,7 +372,9 @@
|
|||
<form class="space-y-5" onsubmit={handleSignupSubmit}>
|
||||
{#if signupConfig.entry_fields.length > 0}
|
||||
<div class="space-y-3">
|
||||
<h3 class="text-sm font-semibold uppercase tracking-wide text-slate-400">Lag / deltagare</h3>
|
||||
<h3 class="text-sm font-semibold tracking-wide text-slate-400 uppercase">
|
||||
{entrySectionTitle}
|
||||
</h3>
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
{#each signupConfig.entry_fields as field}
|
||||
<label class="flex flex-col gap-1 text-sm font-medium text-slate-200">
|
||||
|
|
@ -324,195 +383,239 @@
|
|||
type={fieldInputType(field.field_type)}
|
||||
required={field.required}
|
||||
placeholder={field.placeholder ?? ''}
|
||||
inputmode={isAttendanceField(field) ? 'numeric' : undefined}
|
||||
pattern={isAttendanceField(field) ? '\\d*' : undefined}
|
||||
autocomplete={isAttendanceField(field) ? 'off' : undefined}
|
||||
value={signup.entry[field.id]}
|
||||
oninput={(event) => (signup.entry[field.id] = (event.currentTarget as HTMLInputElement).value)}
|
||||
class="rounded-md border border-slate-700 bg-slate-900 px-3 py-2 text-sm text-slate-100 focus:border-indigo-500 focus:outline-none focus:ring focus:ring-indigo-500/40"
|
||||
oninput={(event) =>
|
||||
(signup.entry[field.id] = (event.currentTarget as HTMLInputElement).value)}
|
||||
class="rounded-md border border-slate-700 bg-slate-900 px-3 py-2 text-sm text-slate-100 focus:border-indigo-500 focus:ring focus:ring-indigo-500/40 focus:outline-none"
|
||||
/>
|
||||
{#if isAttendanceField(field)}
|
||||
<span class="text-xs text-slate-400"
|
||||
>Ditt deltagar-ID hittar du i närvarolistan eller på ditt kort.</span
|
||||
>
|
||||
{/if}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if signup.showSuccessModal}
|
||||
<div class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/80 px-4">
|
||||
<div
|
||||
class="w-full max-w-2xl space-y-6 rounded-2xl border border-slate-800 bg-slate-900 p-6 shadow-2xl"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="signup-success-title"
|
||||
>
|
||||
<header class="space-y-2 text-center">
|
||||
<p class="text-xs uppercase tracking-[0.4em] text-indigo-300">VBytes LAN</p>
|
||||
<h2 id="signup-success-title" class="text-2xl font-semibold text-slate-100 sm:text-3xl">
|
||||
Anmälan bekräftad
|
||||
</h2>
|
||||
<p class="text-sm text-slate-300">Du är registrerad till {tournament.title}.</p>
|
||||
{#if signup.successRegistrationId}
|
||||
<p class="text-xs uppercase tracking-wide text-indigo-200">Anmälan #{signup.successRegistrationId}</p>
|
||||
{/if}
|
||||
</header>
|
||||
|
||||
<section class="grid gap-4 rounded-2xl border border-slate-800 bg-slate-900/70 p-4 md:grid-cols-2">
|
||||
<div class="space-y-2 text-left">
|
||||
<h3 class="text-sm font-semibold uppercase tracking-wide text-indigo-200">Turnering</h3>
|
||||
<p class="text-sm text-slate-300"><span class="font-medium text-slate-100">Spel:</span> {tournament.game}</p>
|
||||
{#if tournament.start_at}
|
||||
<p class="text-sm text-slate-300">
|
||||
<span class="font-medium text-slate-100">Start:</span>
|
||||
{formatDateTime(tournament.start_at) ?? tournament.start_at}
|
||||
</p>
|
||||
{/if}
|
||||
{#if tournament.location}
|
||||
<p class="text-sm text-slate-300">
|
||||
<span class="font-medium text-slate-100">Plats:</span> {tournament.location}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="space-y-2 text-left">
|
||||
<h3 class="text-sm font-semibold uppercase tracking-wide text-indigo-200">Format</h3>
|
||||
{#if signupConfig.mode === 'team'}
|
||||
<p class="text-sm text-slate-300">
|
||||
Lag {signupConfig.team_size.min}–{signupConfig.team_size.max} spelare
|
||||
</p>
|
||||
{:else}
|
||||
<p class="text-sm text-slate-300">Individuell anmälan</p>
|
||||
{/if}
|
||||
{#if tournament.contact}
|
||||
<p class="text-sm text-slate-300">
|
||||
<span class="font-medium text-slate-100">Kontakt:</span> {tournament.contact}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="space-y-3">
|
||||
<h3 class="text-base font-semibold text-slate-100">Anmälningsuppgifter</h3>
|
||||
{#if signupConfig.entry_fields.length === 0}
|
||||
<p class="rounded-md border border-dashed border-slate-700 px-4 py-3 text-sm text-slate-300">
|
||||
Den här turneringen kräver inga uppgifter utöver spelare.
|
||||
</p>
|
||||
{:else}
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
{#each signupConfig.entry_fields as field}
|
||||
<div class="rounded-md border border-slate-800 bg-slate-900 px-4 py-3">
|
||||
<p class="text-xs uppercase tracking-wide text-indigo-200">{field.label}</p>
|
||||
<p class="mt-1 text-sm text-slate-100">{signup.submittedEntry[field.id] || '—'}</p>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<section class="space-y-3">
|
||||
<h3 class="text-base font-semibold text-slate-100">Spelare</h3>
|
||||
{#if signupConfig.participant_fields.length === 0}
|
||||
{#if signup.submittedParticipants.length === 0}
|
||||
<p class="text-sm text-slate-300">Inga spelare angivna.</p>
|
||||
{:else}
|
||||
<p class="text-sm text-slate-300">Antal spelare: {signup.submittedParticipants.length}</p>
|
||||
{/if}
|
||||
{:else if signup.submittedParticipants.length === 0}
|
||||
<p class="text-sm text-slate-300">Inga spelare angivna.</p>
|
||||
{:else}
|
||||
<div class="space-y-3">
|
||||
{#each signup.submittedParticipants as participant, index}
|
||||
<div class="rounded-md border border-slate-800 bg-slate-900 px-4 py-3">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-indigo-200">Spelare {index + 1}</p>
|
||||
<ul class="mt-2 space-y-1 text-sm text-slate-100">
|
||||
{#each signupConfig.participant_fields as field}
|
||||
<li>
|
||||
<span class="font-medium text-slate-300">{field.label}:</span>
|
||||
<span class="ml-1">{participant[field.id] || '—'}</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<div class="flex justify-center pt-2">
|
||||
<a
|
||||
href="/"
|
||||
class="inline-flex items-center justify-center rounded-full border border-emerald-300 px-5 py-2 text-sm font-semibold text-emerald-200 transition hover:border-emerald-400 hover:bg-emerald-500/10"
|
||||
>
|
||||
Stäng
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{/if}
|
||||
|
||||
<div class="space-y-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<h3 class="text-sm font-semibold uppercase tracking-wide text-slate-400">Spelare</h3>
|
||||
{#if signupConfig.mode === 'team'}
|
||||
<button
|
||||
type="button"
|
||||
onclick={addParticipant}
|
||||
disabled={!canAddParticipant() || signup.submitting}
|
||||
class="rounded-full border border-indigo-300 px-3 py-1 text-xs font-semibold text-indigo-200 transition hover:border-indigo-400 hover:bg-indigo-500/10 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
{#if signup.showSuccessModal}
|
||||
<div class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/80 px-4">
|
||||
<div
|
||||
class="w-full max-w-2xl space-y-6 rounded-2xl border border-slate-800 bg-slate-900 p-6 shadow-2xl"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="signup-success-title"
|
||||
>
|
||||
Lägg till spelare
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
<header class="space-y-2 text-center">
|
||||
<p class="text-xs tracking-[0.4em] text-indigo-300 uppercase">VBytes LAN</p>
|
||||
<h2
|
||||
id="signup-success-title"
|
||||
class="text-2xl font-semibold text-slate-100 sm:text-3xl"
|
||||
>
|
||||
Anmälan bekräftad
|
||||
</h2>
|
||||
<p class="text-sm text-slate-300">Du är registrerad till {tournament.title}.</p>
|
||||
{#if signup.successRegistrationId}
|
||||
<p class="text-xs tracking-wide text-indigo-200 uppercase">
|
||||
Anmälan #{signup.successRegistrationId}
|
||||
</p>
|
||||
{/if}
|
||||
</header>
|
||||
|
||||
{#if signup.participants.length > 0}
|
||||
<div class="space-y-4">
|
||||
{#each signup.participants as participant, index (index)}
|
||||
<div class="space-y-3 rounded-md border border-slate-800 bg-slate-900/60 p-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm font-semibold text-slate-200">{participantDisplayName(index)}</span>
|
||||
{#if signupConfig.mode === 'team' && canRemoveParticipant()}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => removeParticipant(index)}
|
||||
disabled={signup.submitting}
|
||||
class="rounded-full border border-red-300 px-3 py-1 text-xs font-semibold text-red-200 transition hover:border-red-400 hover:bg-red-500/10 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
Ta bort
|
||||
</button>
|
||||
<section
|
||||
class="grid gap-4 rounded-2xl border border-slate-800 bg-slate-900/70 p-4 md:grid-cols-2"
|
||||
>
|
||||
<div class="space-y-2 text-left">
|
||||
<h3 class="text-sm font-semibold tracking-wide text-indigo-200 uppercase">
|
||||
Turnering
|
||||
</h3>
|
||||
<p class="text-sm text-slate-300">
|
||||
<span class="font-medium text-slate-100">Spel:</span>
|
||||
{tournament.game}
|
||||
</p>
|
||||
{#if tournament.start_at}
|
||||
<p class="text-sm text-slate-300">
|
||||
<span class="font-medium text-slate-100">Start:</span>
|
||||
{formatDateTime(tournament.start_at) ?? tournament.start_at}
|
||||
</p>
|
||||
{/if}
|
||||
{#if tournament.location}
|
||||
<p class="text-sm text-slate-300">
|
||||
<span class="font-medium text-slate-100">Plats:</span>
|
||||
{tournament.location}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="space-y-2 text-left">
|
||||
<h3 class="text-sm font-semibold tracking-wide text-indigo-200 uppercase">
|
||||
Format
|
||||
</h3>
|
||||
{#if signupConfig.mode === 'team'}
|
||||
<p class="text-sm text-slate-300">
|
||||
Lag {signupConfig.team_size.min}–{signupConfig.team_size.max} spelare
|
||||
</p>
|
||||
{:else}
|
||||
<p class="text-sm text-slate-300">Individuell anmälan</p>
|
||||
{/if}
|
||||
{#if tournament.contact}
|
||||
<p class="text-sm text-slate-300">
|
||||
<span class="font-medium text-slate-100">Kontakt:</span>
|
||||
{tournament.contact}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{#if signupConfig.participant_fields.length > 0}
|
||||
<section class="space-y-3">
|
||||
<h3 class="text-base font-semibold text-slate-100">Anmälningsuppgifter</h3>
|
||||
{#if signupConfig.entry_fields.length === 0}
|
||||
<p
|
||||
class="rounded-md border border-dashed border-slate-700 px-4 py-3 text-sm text-slate-300"
|
||||
>
|
||||
Den här turneringen kräver inga uppgifter utöver spelare.
|
||||
</p>
|
||||
{:else}
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
{#each signupConfig.participant_fields as field}
|
||||
<label class="flex flex-col gap-1 text-sm font-medium text-slate-200">
|
||||
<span>{field.label}</span>
|
||||
<input
|
||||
type={fieldInputType(field.field_type)}
|
||||
required={field.required}
|
||||
placeholder={field.placeholder ?? ''}
|
||||
value={participant[field.id] ?? ''}
|
||||
oninput={(event) => (participant[field.id] = (event.currentTarget as HTMLInputElement).value)}
|
||||
class="rounded-md border border-slate-700 bg-slate-900 px-3 py-2 text-sm text-slate-100 focus:border-indigo-500 focus:outline-none focus:ring focus:ring-indigo-500/40"
|
||||
/>
|
||||
</label>
|
||||
{#each signupConfig.entry_fields as field}
|
||||
<div class="rounded-md border border-slate-800 bg-slate-900 px-4 py-3">
|
||||
<p class="text-xs tracking-wide text-indigo-200 uppercase">
|
||||
{field.label}
|
||||
</p>
|
||||
<p class="mt-1 text-sm text-slate-100">
|
||||
{signup.submittedEntry[field.id] || '—'}
|
||||
</p>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-xs text-slate-400">Inga spelarspecifika fält krävs.</p>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
{#if signupConfig.mode === 'team'}
|
||||
<section class="space-y-3">
|
||||
<h3 class="text-base font-semibold text-slate-100">Spelare</h3>
|
||||
{#if signupConfig.participant_fields.length === 0}
|
||||
{#if signup.submittedParticipants.length === 0}
|
||||
<p class="text-sm text-slate-300">Inga spelare angivna.</p>
|
||||
{:else}
|
||||
<p class="text-sm text-slate-300">
|
||||
Antal spelare: {signup.submittedParticipants.length}
|
||||
</p>
|
||||
{/if}
|
||||
{:else if signup.submittedParticipants.length === 0}
|
||||
<p class="text-sm text-slate-300">Inga spelare angivna.</p>
|
||||
{:else}
|
||||
<div class="space-y-3">
|
||||
{#each signup.submittedParticipants as participant, index}
|
||||
<div class="rounded-md border border-slate-800 bg-slate-900 px-4 py-3">
|
||||
<p
|
||||
class="text-xs font-semibold tracking-wide text-indigo-200 uppercase"
|
||||
>
|
||||
Spelare {index + 1}
|
||||
</p>
|
||||
<ul class="mt-2 space-y-1 text-sm text-slate-100">
|
||||
{#each signupConfig.participant_fields as field}
|
||||
<li>
|
||||
<span class="font-medium text-slate-300">{field.label}:</span>
|
||||
<span class="ml-1">{participant[field.id] || '—'}</span>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
<div class="flex justify-center pt-2">
|
||||
<a
|
||||
href="/"
|
||||
class="inline-flex items-center justify-center rounded-full border border-emerald-300 px-5 py-2 text-sm font-semibold text-emerald-200 transition hover:border-emerald-400 hover:bg-emerald-500/10"
|
||||
>
|
||||
Stäng
|
||||
</a>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="space-y-2 text-sm">
|
||||
{#if signup.error}
|
||||
<p class="rounded-md border border-red-400 bg-red-500/10 px-4 py-2 text-red-200">{signup.error}</p>
|
||||
{:else if signup.success}
|
||||
<p class="rounded-md border border-emerald-400 bg-emerald-500/10 px-4 py-2 text-emerald-200">{signup.success}</p>
|
||||
{:else}
|
||||
<p class="text-slate-400">Din anmälan skickas direkt till arrangören.</p>
|
||||
{/if}
|
||||
</div>
|
||||
{#if signupConfig.mode === 'team'}
|
||||
<div class="space-y-3">
|
||||
<h3 class="text-sm font-semibold tracking-wide text-slate-400 uppercase">Spelare</h3>
|
||||
|
||||
{#if signup.participants.length > 0}
|
||||
<div class="space-y-4">
|
||||
{#each signup.participants as participant, index (index)}
|
||||
<div class="space-y-3 rounded-md border border-slate-800 bg-slate-900/60 p-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm font-semibold text-slate-200">
|
||||
{participantDisplayName(index)}
|
||||
</span>
|
||||
{#if canRemoveParticipant()}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => removeParticipant(index)}
|
||||
disabled={signup.submitting}
|
||||
class="rounded-full border border-red-300 px-3 py-1 text-xs font-semibold text-red-200 transition hover:border-red-400 hover:bg-red-500/10 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
Ta bort
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if signupConfig.participant_fields.length > 0}
|
||||
<div class="grid gap-3 md:grid-cols-2">
|
||||
{#each signupConfig.participant_fields as field}
|
||||
<label class="flex flex-col gap-1 text-sm font-medium text-slate-200">
|
||||
<span>{field.label}</span>
|
||||
<input
|
||||
type={fieldInputType(field.field_type)}
|
||||
required={field.required}
|
||||
placeholder={field.placeholder ?? ''}
|
||||
value={participant[field.id] ?? ''}
|
||||
oninput={(event) =>
|
||||
(participant[field.id] = (
|
||||
event.currentTarget as HTMLInputElement
|
||||
).value)}
|
||||
class="rounded-md border border-slate-700 bg-slate-900 px-3 py-2 text-sm text-slate-100 focus:border-indigo-500 focus:ring focus:ring-indigo-500/40 focus:outline-none"
|
||||
/>
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-xs text-slate-400">Inga spelarspecifika fält krävs.</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<p class="text-xs text-slate-400">
|
||||
Du kan lägga till upp till {signupConfig.team_size.max} spelare per lag. Minst
|
||||
{signupConfig.team_size.min} krävs.
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="space-y-2 text-sm">
|
||||
{#if signup.error}
|
||||
<p class="rounded-md border border-red-400 bg-red-500/10 px-4 py-2 text-red-200">
|
||||
{signup.error}
|
||||
</p>
|
||||
{:else if signup.success}
|
||||
<p
|
||||
class="rounded-md border border-emerald-400 bg-emerald-500/10 px-4 py-2 text-emerald-200"
|
||||
>
|
||||
{signup.success}
|
||||
</p>
|
||||
{:else}
|
||||
<p class="text-slate-400">Din anmälan skickas direkt till arrangören.</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
|
|
@ -526,7 +629,10 @@
|
|||
|
||||
<footer class="mt-auto flex items-center justify-between text-xs text-slate-500">
|
||||
<p>Senast uppdaterad {formatDateTime(tournament.updated_at) ?? tournament.updated_at}</p>
|
||||
<a href="/admin/tournament" class="rounded-full border border-indigo-300 px-4 py-2 font-semibold text-indigo-300 transition hover:border-indigo-400 hover:bg-indigo-50/5">
|
||||
<a
|
||||
href="/admin/tournament"
|
||||
class="rounded-full border border-indigo-300 px-4 py-2 font-semibold text-indigo-300 transition hover:border-indigo-400 hover:bg-indigo-50/5"
|
||||
>
|
||||
Administrera
|
||||
</a>
|
||||
</footer>
|
||||
|
|
|
|||
26
web/src/routes/api/public-events/+server.ts
Normal file
26
web/src/routes/api/public-events/+server.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import type { RequestHandler } from './$types';
|
||||
import { proxyRequest } from '$lib/server/backend';
|
||||
|
||||
export const GET: RequestHandler = async (event) => {
|
||||
const { response, setCookies } = await proxyRequest(event, '/events/public', {
|
||||
method: 'GET'
|
||||
});
|
||||
|
||||
const headers = new Headers();
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (contentType) {
|
||||
headers.set('content-type', contentType);
|
||||
} else {
|
||||
headers.set('content-type', 'text/event-stream');
|
||||
}
|
||||
for (const cookie of setCookies) {
|
||||
headers.append('set-cookie', cookie);
|
||||
}
|
||||
headers.set('cache-control', 'no-cache');
|
||||
|
||||
return new Response(response.body, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers
|
||||
});
|
||||
};
|
||||
Loading…
Reference in a new issue