Implement complete calendar creation functionality

Add full end-to-end calendar creation feature including:
- Create Calendar button in sidebar footer
- Modal form with name, description, and color picker (16 predefined colors in 4x4 grid)
- Form validation and error handling with loading states
- Backend API endpoint for calendar creation with authentication
- CalDAV MKCALENDAR protocol implementation with proper XML generation
- Real-time calendar list refresh after successful creation
- Responsive design for mobile and desktop

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Connor Johnstone
2025-08-28 21:21:30 -04:00
parent f94d057f81
commit f9c87369e5
10 changed files with 748 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ use serde::Deserialize;
use std::sync::Arc;
use chrono::Datelike;
use crate::{AppState, models::{CalDAVLoginRequest, AuthResponse, ApiError, UserInfo, CalendarInfo}};
use crate::{AppState, models::{CalDAVLoginRequest, AuthResponse, ApiError, UserInfo, CalendarInfo, CreateCalendarRequest, CreateCalendarResponse}};
use crate::calendar::{CalDAVClient, CalendarEvent};
#[derive(Deserialize)]
@@ -252,4 +252,44 @@ fn extract_password_header(headers: &HeaderMap) -> Result<String, ApiError> {
} else {
Err(ApiError::BadRequest("X-CalDAV-Password header required".to_string()))
}
}
pub async fn create_calendar(
State(state): State<Arc<AppState>>,
headers: HeaderMap,
Json(request): Json<CreateCalendarRequest>,
) -> Result<Json<CreateCalendarResponse>, ApiError> {
println!("📝 Create calendar request received: name='{}', description={:?}, color={:?}",
request.name, request.description, request.color);
// Extract and verify token
let token = extract_bearer_token(&headers)?;
let password = extract_password_header(&headers)?;
// Validate request
if request.name.trim().is_empty() {
return Err(ApiError::BadRequest("Calendar name is required".to_string()));
}
if request.name.len() > 100 {
return Err(ApiError::BadRequest("Calendar name too long (max 100 characters)".to_string()));
}
// Create CalDAV config from token and password
let config = state.auth_service.caldav_config_from_token(&token, &password)?;
let client = CalDAVClient::new(config);
// Create the calendar
client.create_calendar(
&request.name,
request.description.as_deref(),
request.color.as_deref()
)
.await
.map_err(|e| ApiError::Internal(format!("Failed to create calendar: {}", e)))?;
Ok(Json(CreateCalendarResponse {
success: true,
message: "Calendar created successfully".to_string(),
}))
}