Create event creation structuring and polishing
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
export const load = async ({ locals }: { locals: any }) => {
|
|
||||||
const { session } = await locals.safeGetSession();
|
|
||||||
|
|
||||||
return {
|
|
||||||
session
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -2,6 +2,15 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import type { GoogleSheet } from '$lib/sheets.js';
|
import type { GoogleSheet } from '$lib/sheets.js';
|
||||||
import { isTokenValid, refreshAccessToken } from '$lib/google.js';
|
import { isTokenValid, refreshAccessToken } from '$lib/google.js';
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
|
// Import Components
|
||||||
|
import GoogleAuthStep from './components/GoogleAuthStep.svelte';
|
||||||
|
import EventDetailsStep from './components/EventDetailsStep.svelte';
|
||||||
|
import GoogleSheetsStep from './components/GoogleSheetsStep.svelte';
|
||||||
|
import EmailSettingsStep from './components/EmailSettingsStep.svelte';
|
||||||
|
import StepNavigator from './components/StepNavigator.svelte';
|
||||||
|
import StepNavigation from './components/StepNavigation.svelte';
|
||||||
|
|
||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
|
|
||||||
@@ -16,7 +25,8 @@
|
|||||||
connecting: false,
|
connecting: false,
|
||||||
showCancelOption: false,
|
showCancelOption: false,
|
||||||
token: null as string | null,
|
token: null as string | null,
|
||||||
error: null as string | null
|
error: null as string | null,
|
||||||
|
userEmail: null as string | null
|
||||||
});
|
});
|
||||||
|
|
||||||
// Step 1: Event Details
|
// Step 1: Event Details
|
||||||
@@ -71,13 +81,20 @@
|
|||||||
const isValid = await isTokenValid(accessToken);
|
const isValid = await isTokenValid(accessToken);
|
||||||
authData.isConnected = isValid;
|
authData.isConnected = isValid;
|
||||||
authData.token = accessToken;
|
authData.token = accessToken;
|
||||||
|
|
||||||
|
if (isValid) {
|
||||||
|
// Fetch user info
|
||||||
|
await fetchUserInfo(accessToken);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
authData.isConnected = false;
|
authData.isConnected = false;
|
||||||
|
authData.userEmail = null;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error checking Google auth:', error);
|
console.error('Error checking Google auth:', error);
|
||||||
authData.isConnected = false;
|
authData.isConnected = false;
|
||||||
authData.error = 'Error checking Google connection';
|
authData.error = 'Error checking Google connection';
|
||||||
|
authData.userEmail = null;
|
||||||
} finally {
|
} finally {
|
||||||
authData.checking = false;
|
authData.checking = false;
|
||||||
}
|
}
|
||||||
@@ -170,6 +187,59 @@
|
|||||||
authData.connecting = false;
|
authData.connecting = false;
|
||||||
authData.showCancelOption = false;
|
authData.showCancelOption = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchUserInfo(accessToken: string) {
|
||||||
|
try {
|
||||||
|
const response = await fetch('https://www.googleapis.com/oauth2/v2/userinfo', {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessToken}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const userData = await response.json();
|
||||||
|
authData.userEmail = userData.email;
|
||||||
|
} else {
|
||||||
|
console.error('Failed to fetch user info:', await response.text());
|
||||||
|
authData.userEmail = null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching user info:', error);
|
||||||
|
authData.userEmail = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function disconnectGoogle() {
|
||||||
|
try {
|
||||||
|
// First revoke the token at Google
|
||||||
|
const accessToken = localStorage.getItem('google_access_token');
|
||||||
|
if (accessToken) {
|
||||||
|
await fetch(`https://accounts.google.com/o/oauth2/revoke?token=${accessToken}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove tokens from local storage
|
||||||
|
localStorage.removeItem('google_access_token');
|
||||||
|
localStorage.removeItem('google_refresh_token');
|
||||||
|
|
||||||
|
// Update auth state
|
||||||
|
authData.isConnected = false;
|
||||||
|
authData.token = null;
|
||||||
|
authData.userEmail = null;
|
||||||
|
|
||||||
|
// Clear any selected sheets data
|
||||||
|
sheetsData.availableSheets = [];
|
||||||
|
sheetsData.selectedSheet = null;
|
||||||
|
sheetsData.sheetData = [];
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error disconnecting from Google:', error);
|
||||||
|
authData.error = 'Failed to disconnect from Google';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Step navigation
|
// Step navigation
|
||||||
function nextStep() {
|
function nextStep() {
|
||||||
@@ -300,7 +370,6 @@
|
|||||||
|
|
||||||
loading = true;
|
loading = true;
|
||||||
try {
|
try {
|
||||||
// TODO: Replace with actual Supabase function call
|
|
||||||
const { error } = await data.supabase.rpc('create_event', {
|
const { error } = await data.supabase.rpc('create_event', {
|
||||||
p_name: eventData.name,
|
p_name: eventData.name,
|
||||||
p_date: eventData.date,
|
p_date: eventData.date,
|
||||||
@@ -316,7 +385,7 @@
|
|||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
|
|
||||||
// Redirect to events list or show success message
|
// Redirect to events list or show success message
|
||||||
window.location.href = '/private/events';
|
goto('/private/events');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating event:', error);
|
console.error('Error creating event:', error);
|
||||||
errors.submit = 'Failed to create event. Please try again.';
|
errors.submit = 'Failed to create event. Please try again.';
|
||||||
@@ -336,423 +405,22 @@
|
|||||||
if (currentStep === 3) return emailData.subject && emailData.body;
|
if (currentStep === 3) return emailData.subject && emailData.body;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
let stepTitle = $derived(() => {
|
|
||||||
if (currentStep === 0) return 'Connect Google Account';
|
|
||||||
if (currentStep === 1) return 'Event Details';
|
|
||||||
if (currentStep === 2) return 'Connect Google Sheets';
|
|
||||||
if (currentStep === 3) return 'Email Settings';
|
|
||||||
return '';
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="max-w-4xl mx-auto p-6">
|
<div class="max-w-4xl mx-auto p-6">
|
||||||
<!-- Header -->
|
<!-- Header -->
|
||||||
<div class="mb-8">
|
<StepNavigator {currentStep} {totalSteps} />
|
||||||
<h1 class="text-2xl font-bold text-gray-900 mb-2">Create New Event</h1>
|
|
||||||
<div class="flex items-center gap-4">
|
|
||||||
{#each Array(totalSteps) as _, index}
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<div class="w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium {
|
|
||||||
index === currentStep ? 'bg-blue-600 text-white' :
|
|
||||||
index < currentStep ? 'bg-green-600 text-white' :
|
|
||||||
'bg-gray-200 text-gray-600'
|
|
||||||
}">
|
|
||||||
{index + 1}
|
|
||||||
</div>
|
|
||||||
{#if index < totalSteps - 1}
|
|
||||||
<div class="w-8 h-1 {
|
|
||||||
index < currentStep ? 'bg-green-600' : 'bg-gray-200'
|
|
||||||
}"></div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
<p class="text-gray-600 mt-2">Step {currentStep + 1} of {totalSteps}: {stepTitle}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Step Content -->
|
<!-- Step Content -->
|
||||||
<div class="rounded-lg border border-gray-300 bg-white p-6 mb-6">
|
<div class="rounded-lg border border-gray-300 bg-white p-6 mb-6">
|
||||||
{#if currentStep === 0}
|
{#if currentStep === 0}
|
||||||
<!-- Step 0: Google Authentication -->
|
<GoogleAuthStep {authData} {errors} {connectToGoogle} {cancelGoogleAuth} {disconnectGoogle} />
|
||||||
<div class="space-y-6">
|
|
||||||
<div class="text-center">
|
|
||||||
<h3 class="text-lg font-medium text-gray-900 mb-4">Connect Your Google Account</h3>
|
|
||||||
<p class="text-gray-600 mb-6">
|
|
||||||
To create events and import participants from Google Sheets, you need to connect your Google account.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
{#if authData.checking}
|
|
||||||
<div class="flex justify-center items-center space-x-2">
|
|
||||||
<div class="animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"></div>
|
|
||||||
<span class="text-gray-600">Checking connection...</span>
|
|
||||||
</div>
|
|
||||||
{:else if authData.isConnected}
|
|
||||||
<div class="rounded-lg bg-green-50 border border-green-200 p-4 mb-4">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<div class="flex-shrink-0">
|
|
||||||
<svg class="h-5 w-5 text-green-400" viewBox="0 0 20 20" fill="currentColor">
|
|
||||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div class="ml-3">
|
|
||||||
<p class="text-sm font-medium text-green-800">
|
|
||||||
Google account connected successfully!
|
|
||||||
</p>
|
|
||||||
<p class="text-sm text-green-700 mt-1">
|
|
||||||
You can now access Google Sheets and Gmail features.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="rounded-lg bg-yellow-50 border border-yellow-200 p-4 mb-4">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<div class="flex-shrink-0">
|
|
||||||
<svg class="h-5 w-5 text-yellow-400" viewBox="0 0 20 20" fill="currentColor">
|
|
||||||
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div class="ml-3">
|
|
||||||
<p class="text-sm font-medium text-yellow-800">
|
|
||||||
Google account not connected
|
|
||||||
</p>
|
|
||||||
<p class="text-sm text-yellow-700 mt-1">
|
|
||||||
Please connect your Google account to continue with event creation.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex flex-col gap-3">
|
|
||||||
<button
|
|
||||||
onclick={connectToGoogle}
|
|
||||||
disabled={authData.connecting}
|
|
||||||
class="inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition disabled:opacity-50 disabled:cursor-not-allowed"
|
|
||||||
aria-label="Connect to Google account"
|
|
||||||
>
|
|
||||||
{#if authData.connecting}
|
|
||||||
<div class="w-5 h-5 mr-2 animate-spin rounded-full border-2 border-white border-t-transparent"></div>
|
|
||||||
Connecting...
|
|
||||||
{:else}
|
|
||||||
<svg class="w-5 h-5 mr-2" viewBox="0 0 24 24">
|
|
||||||
<path fill="currentColor" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
|
|
||||||
<path fill="currentColor" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
|
|
||||||
<path fill="currentColor" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"/>
|
|
||||||
<path fill="currentColor" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"/>
|
|
||||||
</svg>
|
|
||||||
Connect to Google
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{#if authData.connecting && authData.showCancelOption}
|
|
||||||
<button
|
|
||||||
onclick={cancelGoogleAuth}
|
|
||||||
class="text-sm text-gray-600 hover:text-gray-900"
|
|
||||||
aria-label="Cancel Google authentication"
|
|
||||||
>
|
|
||||||
Cancel connection
|
|
||||||
</button>
|
|
||||||
<p class="text-xs text-gray-500 mt-1">
|
|
||||||
Taking too long? You can cancel and try again.
|
|
||||||
</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if authData.error}
|
|
||||||
<div class="mt-4 rounded-lg bg-red-50 border border-red-200 p-4">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<div class="flex-shrink-0">
|
|
||||||
<svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor">
|
|
||||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div class="ml-3">
|
|
||||||
<p class="text-sm font-medium text-red-800">
|
|
||||||
Connection Error
|
|
||||||
</p>
|
|
||||||
<p class="text-sm text-red-700 mt-1">
|
|
||||||
{authData.error}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if errors.auth}
|
|
||||||
<p class="mt-2 text-sm text-red-600">{errors.auth}</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{:else if currentStep === 1}
|
{:else if currentStep === 1}
|
||||||
<!-- Step 1: Event Details -->
|
<EventDetailsStep {eventData} {errors} />
|
||||||
<div class="space-y-6">
|
|
||||||
<div>
|
|
||||||
<label for="eventName" class="block text-sm font-medium text-gray-700 mb-2">
|
|
||||||
Event Name *
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
id="eventName"
|
|
||||||
type="text"
|
|
||||||
bind:value={eventData.name}
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
||||||
placeholder="Enter event name"
|
|
||||||
/>
|
|
||||||
{#if errors.name}
|
|
||||||
<p class="mt-1 text-sm text-red-600">{errors.name}</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label for="eventDate" class="block text-sm font-medium text-gray-700 mb-2">
|
|
||||||
Event Date *
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
id="eventDate"
|
|
||||||
type="date"
|
|
||||||
bind:value={eventData.date}
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
||||||
/>
|
|
||||||
{#if errors.date}
|
|
||||||
<p class="mt-1 text-sm text-red-600">{errors.date}</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{:else if currentStep === 2}
|
{:else if currentStep === 2}
|
||||||
<!-- Step 2: Google Sheets -->
|
<GoogleSheetsStep {sheetsData} {errors} {loadRecentSheets} {selectSheet} {toggleSheetList} />
|
||||||
<div class="space-y-6">
|
|
||||||
<div>
|
|
||||||
<h3 class="text-lg font-medium text-gray-900 mb-4">Select Google Sheet</h3>
|
|
||||||
|
|
||||||
{#if sheetsData.loading && sheetsData.availableSheets.length === 0}
|
|
||||||
<div class="space-y-3">
|
|
||||||
{#each Array(5) as _}
|
|
||||||
<div class="p-4 border border-gray-200 rounded animate-pulse">
|
|
||||||
<div class="h-4 bg-gray-200 rounded w-3/4 mb-2"></div>
|
|
||||||
<div class="h-3 bg-gray-100 rounded w-1/2"></div>
|
|
||||||
</div>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{:else if sheetsData.availableSheets.length === 0}
|
|
||||||
<div class="text-center py-8">
|
|
||||||
<p class="text-gray-500">No Google Sheets found.</p>
|
|
||||||
<button
|
|
||||||
onclick={loadRecentSheets}
|
|
||||||
class="mt-2 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition"
|
|
||||||
>
|
|
||||||
Refresh
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="space-y-3">
|
|
||||||
{#if !sheetsData.expandedSheetList && sheetsData.selectedSheet}
|
|
||||||
<!-- Selected sheet only (collapsed view) -->
|
|
||||||
<div class="flex items-center justify-between p-4 border border-blue-500 bg-blue-50 rounded">
|
|
||||||
<div>
|
|
||||||
<div class="font-medium text-gray-900">{sheetsData.selectedSheet.name}</div>
|
|
||||||
<div class="text-sm text-gray-500">
|
|
||||||
Modified: {new Date(sheetsData.selectedSheet.modifiedTime).toLocaleDateString()}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onclick={toggleSheetList}
|
|
||||||
class="text-blue-600 hover:text-blue-800 flex items-center"
|
|
||||||
aria-label="Show all sheets"
|
|
||||||
>
|
|
||||||
<span class="text-sm mr-1">Change</span>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor">
|
|
||||||
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<!-- All sheets (expanded view) -->
|
|
||||||
<div class="flex justify-between items-center mb-2">
|
|
||||||
<h4 class="text-sm font-medium text-gray-700">Available Sheets</h4>
|
|
||||||
{#if sheetsData.selectedSheet}
|
|
||||||
<button
|
|
||||||
onclick={toggleSheetList}
|
|
||||||
class="text-sm text-blue-600 hover:text-blue-800"
|
|
||||||
aria-label="Hide sheet list"
|
|
||||||
>
|
|
||||||
Collapse list
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<div class="grid gap-3">
|
|
||||||
{#each sheetsData.availableSheets as sheet}
|
|
||||||
<button
|
|
||||||
onclick={() => selectSheet(sheet)}
|
|
||||||
class="p-4 text-left border border-gray-200 rounded hover:border-blue-500 transition {
|
|
||||||
sheetsData.selectedSheet?.id === sheet.id ? 'border-blue-500 bg-blue-50' : ''
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
<div class="font-medium text-gray-900">{sheet.name}</div>
|
|
||||||
<div class="text-sm text-gray-500">
|
|
||||||
Modified: {new Date(sheet.modifiedTime).toLocaleDateString()}
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if errors.sheet}
|
|
||||||
<p class="mt-2 text-sm text-red-600">{errors.sheet}</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if sheetsData.selectedSheet && sheetsData.sheetData.length > 0}
|
|
||||||
<div>
|
|
||||||
<h4 class="text-md font-medium text-gray-900 mb-3">Column Mapping</h4>
|
|
||||||
|
|
||||||
<!-- Instructions for column mapping -->
|
|
||||||
<div class="bg-blue-50 p-4 rounded-md border border-blue-200 mb-4">
|
|
||||||
<p class="text-sm text-blue-800 mb-2 font-medium">Column Mapping Instructions:</p>
|
|
||||||
<p class="text-sm text-blue-700">
|
|
||||||
Select what each column represents by using the dropdown in each column header.
|
|
||||||
Make sure to assign Name, Surname, Email, and Confirmation columns.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="overflow-x-auto">
|
|
||||||
<table class="w-full border border-gray-200 rounded">
|
|
||||||
<thead>
|
|
||||||
<tr class="bg-gray-50">
|
|
||||||
{#each sheetsData.sheetData[0] || [] as header, index}
|
|
||||||
<th class="px-3 py-2 border-b border-gray-200 text-left">
|
|
||||||
<div class="flex flex-col gap-2">
|
|
||||||
<div class="font-medium text-gray-900">
|
|
||||||
Column {index + 1}
|
|
||||||
<span class="text-xs text-gray-500">({header || 'Empty'})</span>
|
|
||||||
</div>
|
|
||||||
<select
|
|
||||||
class="text-sm normal-case font-normal px-2 py-1 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
||||||
aria-label={`Select data type for column ${index + 1}`}
|
|
||||||
onclick={(e) => e.stopPropagation()}
|
|
||||||
onchange={(e) => {
|
|
||||||
const value = e.target.value;
|
|
||||||
if (value === "none") return;
|
|
||||||
|
|
||||||
// Reset previous selection if this column was already mapped
|
|
||||||
if (sheetsData.columnMapping.name === index + 1) sheetsData.columnMapping.name = 0;
|
|
||||||
if (sheetsData.columnMapping.surname === index + 1) sheetsData.columnMapping.surname = 0;
|
|
||||||
if (sheetsData.columnMapping.email === index + 1) sheetsData.columnMapping.email = 0;
|
|
||||||
if (sheetsData.columnMapping.confirmation === index + 1) sheetsData.columnMapping.confirmation = 0;
|
|
||||||
|
|
||||||
// Set new mapping
|
|
||||||
if (value === "name") sheetsData.columnMapping.name = index + 1;
|
|
||||||
else if (value === "surname") sheetsData.columnMapping.surname = index + 1;
|
|
||||||
else if (value === "email") sheetsData.columnMapping.email = index + 1;
|
|
||||||
else if (value === "confirmation") sheetsData.columnMapping.confirmation = index + 1;
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<option value="none">Select data type</option>
|
|
||||||
<option value="name" selected={sheetsData.columnMapping.name === index + 1}>Name</option>
|
|
||||||
<option value="surname" selected={sheetsData.columnMapping.surname === index + 1}>Surname</option>
|
|
||||||
<option value="email" selected={sheetsData.columnMapping.email === index + 1}>Email</option>
|
|
||||||
<option value="confirmation" selected={sheetsData.columnMapping.confirmation === index + 1}>Confirmation</option>
|
|
||||||
</select>
|
|
||||||
{#if sheetsData.columnMapping.name === index + 1}
|
|
||||||
<span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded">Name Column</span>
|
|
||||||
{:else if sheetsData.columnMapping.surname === index + 1}
|
|
||||||
<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">Surname Column</span>
|
|
||||||
{:else if sheetsData.columnMapping.email === index + 1}
|
|
||||||
<span class="bg-purple-100 text-purple-800 text-xs px-2 py-1 rounded">Email Column</span>
|
|
||||||
{:else if sheetsData.columnMapping.confirmation === index + 1}
|
|
||||||
<span class="bg-amber-100 text-amber-800 text-xs px-2 py-1 rounded">Confirmation Column</span>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</th>
|
|
||||||
{/each}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{#each sheetsData.sheetData.slice(0, 10) as row, rowIndex}
|
|
||||||
<tr class="hover:bg-gray-50">
|
|
||||||
{#each row as cell, cellIndex}
|
|
||||||
<td class="px-3 py-2 border-b border-gray-100 text-sm">
|
|
||||||
<span
|
|
||||||
class={
|
|
||||||
sheetsData.columnMapping.name === cellIndex + 1 ? 'font-medium text-green-700' :
|
|
||||||
sheetsData.columnMapping.surname === cellIndex + 1 ? 'font-medium text-blue-700' :
|
|
||||||
sheetsData.columnMapping.email === cellIndex + 1 ? 'font-medium text-purple-700' :
|
|
||||||
sheetsData.columnMapping.confirmation === cellIndex + 1 ? 'font-medium text-amber-700' :
|
|
||||||
'text-gray-700'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{cell || ''}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
{/each}
|
|
||||||
</tr>
|
|
||||||
{/each}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<p class="mt-2 text-sm text-gray-500">Showing first 10 rows</p>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if sheetsData.loading && sheetsData.selectedSheet}
|
|
||||||
<div class="text-center py-4">
|
|
||||||
<div class="text-gray-600">Loading sheet data...</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if errors.sheetData}
|
|
||||||
<p class="text-sm text-red-600">{errors.sheetData}</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{:else if currentStep === 3}
|
{:else if currentStep === 3}
|
||||||
<!-- Step 3: Email Settings -->
|
<EmailSettingsStep {emailData} {errors} />
|
||||||
<div class="space-y-6">
|
|
||||||
<div>
|
|
||||||
<label for="emailSubject" class="block text-sm font-medium text-gray-700 mb-2">
|
|
||||||
Email Subject *
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
id="emailSubject"
|
|
||||||
type="text"
|
|
||||||
bind:value={emailData.subject}
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
||||||
placeholder="Event invitation subject"
|
|
||||||
/>
|
|
||||||
{#if errors.subject}
|
|
||||||
<p class="mt-1 text-sm text-red-600">{errors.subject}</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label for="emailBody" class="block text-sm font-medium text-gray-700 mb-2">
|
|
||||||
Email Body *
|
|
||||||
</label>
|
|
||||||
<textarea
|
|
||||||
id="emailBody"
|
|
||||||
bind:value={emailData.body}
|
|
||||||
rows="8"
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
|
||||||
placeholder="Email message content..."
|
|
||||||
></textarea>
|
|
||||||
{#if errors.body}
|
|
||||||
<p class="mt-1 text-sm text-red-600">{errors.body}</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Preview -->
|
|
||||||
<div class="border-t border-gray-200 pt-6">
|
|
||||||
<h4 class="text-md font-medium text-gray-900 mb-3">Preview</h4>
|
|
||||||
<div class="border border-gray-200 rounded p-4 bg-gray-50">
|
|
||||||
<div class="font-medium text-gray-900 mb-2">Subject: {emailData.subject || 'No subject'}</div>
|
|
||||||
<div class="text-gray-700 whitespace-pre-line">{emailData.body || 'No content'}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if errors.submit}
|
{#if errors.submit}
|
||||||
@@ -763,33 +431,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Navigation -->
|
<!-- Navigation -->
|
||||||
<div class="flex items-center justify-between">
|
<StepNavigation
|
||||||
<button
|
{currentStep}
|
||||||
onclick={prevStep}
|
{totalSteps}
|
||||||
disabled={currentStep === 0}
|
{canProceed}
|
||||||
class="px-4 py-2 text-gray-700 bg-gray-100 hover:bg-gray-200 rounded transition disabled:opacity-50 disabled:cursor-not-allowed"
|
{loading}
|
||||||
>
|
{prevStep}
|
||||||
Previous
|
{nextStep}
|
||||||
</button>
|
{createEvent}
|
||||||
|
/>
|
||||||
<div class="flex gap-2">
|
|
||||||
{#if currentStep < totalSteps - 1}
|
|
||||||
<button
|
|
||||||
onclick={nextStep}
|
|
||||||
disabled={currentStep === 0 ? !authData.isConnected : !canProceed}
|
|
||||||
class="px-6 py-2 bg-blue-600 text-white font-semibold rounded hover:bg-blue-700 transition disabled:opacity-50 disabled:cursor-not-allowed"
|
|
||||||
>
|
|
||||||
Next
|
|
||||||
</button>
|
|
||||||
{:else}
|
|
||||||
<button
|
|
||||||
onclick={createEvent}
|
|
||||||
disabled={!canProceed || loading}
|
|
||||||
class="px-6 py-2 bg-green-600 text-white font-semibold rounded hover:bg-green-700 transition disabled:opacity-50 disabled:cursor-not-allowed"
|
|
||||||
>
|
|
||||||
{loading ? 'Creating...' : 'Create Event'}
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let { emailData, errors } = $props<{
|
||||||
|
emailData: {
|
||||||
|
subject: string;
|
||||||
|
body: string;
|
||||||
|
};
|
||||||
|
errors: Record<string, string>;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="space-y-6">
|
||||||
|
<div>
|
||||||
|
<label for="emailSubject" class="block text-sm font-medium text-gray-700 mb-2">
|
||||||
|
Email Subject *
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="emailSubject"
|
||||||
|
type="text"
|
||||||
|
bind:value={emailData.subject}
|
||||||
|
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||||
|
placeholder="Event invitation subject"
|
||||||
|
/>
|
||||||
|
{#if errors.subject}
|
||||||
|
<p class="mt-1 text-sm text-red-600">{errors.subject}</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="emailBody" class="block text-sm font-medium text-gray-700 mb-2">
|
||||||
|
Email Body *
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
id="emailBody"
|
||||||
|
bind:value={emailData.body}
|
||||||
|
rows="8"
|
||||||
|
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||||
|
placeholder="Email message content..."
|
||||||
|
></textarea>
|
||||||
|
{#if errors.body}
|
||||||
|
<p class="mt-1 text-sm text-red-600">{errors.body}</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let { eventData, errors } = $props<{
|
||||||
|
eventData: {
|
||||||
|
name: string;
|
||||||
|
date: string;
|
||||||
|
};
|
||||||
|
errors: Record<string, string>;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="space-y-6">
|
||||||
|
<div>
|
||||||
|
<h3 class="text-lg font-medium text-gray-900 mb-4">Event details</h3>
|
||||||
|
|
||||||
|
<label for="eventName" class="block text-sm font-medium text-gray-700 mb-2">
|
||||||
|
Event Name *
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="eventName"
|
||||||
|
type="text"
|
||||||
|
bind:value={eventData.name}
|
||||||
|
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||||
|
placeholder="Enter event name"
|
||||||
|
/>
|
||||||
|
{#if errors.name}
|
||||||
|
<p class="mt-1 text-sm text-red-600">{errors.name}</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="eventDate" class="block text-sm font-medium text-gray-700 mb-2">
|
||||||
|
Event Date *
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="eventDate"
|
||||||
|
type="date"
|
||||||
|
bind:value={eventData.date}
|
||||||
|
class="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||||
|
/>
|
||||||
|
{#if errors.date}
|
||||||
|
<p class="mt-1 text-sm text-red-600">{errors.date}</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
// Props
|
||||||
|
let { authData, errors, connectToGoogle, cancelGoogleAuth, disconnectGoogle } = $props<{
|
||||||
|
authData: {
|
||||||
|
isConnected: boolean;
|
||||||
|
checking: boolean;
|
||||||
|
connecting: boolean;
|
||||||
|
showCancelOption: boolean;
|
||||||
|
token: string | null;
|
||||||
|
error: string | null;
|
||||||
|
userEmail: string | null;
|
||||||
|
};
|
||||||
|
errors: Record<string, string>;
|
||||||
|
connectToGoogle: () => Promise<void>;
|
||||||
|
cancelGoogleAuth: () => void;
|
||||||
|
disconnectGoogle: () => Promise<void>;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="space-y-6">
|
||||||
|
<div class="text-center">
|
||||||
|
<h3 class="text-lg font-medium text-gray-900 mb-4">Connect Your Google Account</h3>
|
||||||
|
<p class="text-gray-600 mb-6">
|
||||||
|
To create events and import participants from Google Sheets, you need to connect your Google account.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{#if authData.checking}
|
||||||
|
<div class="flex justify-center items-center space-x-2">
|
||||||
|
<div class="animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"></div>
|
||||||
|
<span class="text-gray-600">Checking connection...</span>
|
||||||
|
</div>
|
||||||
|
{:else if authData.isConnected}
|
||||||
|
<div class="rounded-lg bg-green-50 border border-green-200 p-4 mb-4">
|
||||||
|
<div class="flex items-center justify-start">
|
||||||
|
<div class="justify-start flex flex-col items-start">
|
||||||
|
<p class="text-sm font-medium text-green-800">
|
||||||
|
Google account connected successfully!
|
||||||
|
</p>
|
||||||
|
{#if authData.userEmail}
|
||||||
|
<div class="flex items-center mt-2 bg-white rounded-full px-3 py-1 border border-green-300">
|
||||||
|
<p class="text-sm font-medium text-gray-700">
|
||||||
|
{authData.userEmail}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
<p class="text-sm text-green-700 mt-2">
|
||||||
|
You can now access Google Sheets and Gmail features.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4 flex justify-end">
|
||||||
|
<button
|
||||||
|
onclick={disconnectGoogle}
|
||||||
|
class="text-sm text-red-600 hover:text-red-800 flex items-center"
|
||||||
|
aria-label="Disconnect Google account"
|
||||||
|
>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" />
|
||||||
|
</svg>
|
||||||
|
Disconnect
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="rounded-lg bg-yellow-50 border border-yellow-200 p-4 mb-4">
|
||||||
|
<div class="flex items-center justify-start">
|
||||||
|
<div class="flex-shrink-0">
|
||||||
|
<svg class="h-5 w-5 text-yellow-400" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="ml-3 justify-start flex flex-col items-start">
|
||||||
|
<p class="text-sm font-medium text-yellow-800">
|
||||||
|
Google account not connected
|
||||||
|
</p>
|
||||||
|
<p class="text-sm text-yellow-700 mt-1">
|
||||||
|
Please connect your Google account to continue with event creation.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-3">
|
||||||
|
<button
|
||||||
|
onclick={connectToGoogle}
|
||||||
|
disabled={authData.connecting}
|
||||||
|
class="inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
aria-label="Connect to Google account"
|
||||||
|
>
|
||||||
|
{#if authData.connecting}
|
||||||
|
<div class="w-5 h-5 mr-2 animate-spin rounded-full border-2 border-white border-t-transparent"></div>
|
||||||
|
Connecting...
|
||||||
|
{:else}
|
||||||
|
<svg class="w-5 h-5 mr-2" viewBox="0 0 24 24">
|
||||||
|
<path fill="currentColor" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
|
||||||
|
<path fill="currentColor" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
|
||||||
|
<path fill="currentColor" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"/>
|
||||||
|
<path fill="currentColor" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"/>
|
||||||
|
</svg>
|
||||||
|
Connect to Google
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{#if authData.connecting && authData.showCancelOption}
|
||||||
|
<button
|
||||||
|
onclick={cancelGoogleAuth}
|
||||||
|
class="text-sm text-gray-600 hover:text-gray-900"
|
||||||
|
aria-label="Cancel Google authentication"
|
||||||
|
>
|
||||||
|
Cancel connection
|
||||||
|
</button>
|
||||||
|
<p class="text-xs text-gray-500 mt-1">
|
||||||
|
Taking too long? You can cancel and try again.
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if authData.error}
|
||||||
|
<div class="mt-4 rounded-lg bg-red-50 border border-red-200 p-4">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<div class="flex-shrink-0">
|
||||||
|
<svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="ml-3">
|
||||||
|
<p class="text-sm font-medium text-red-800">
|
||||||
|
Connection Error
|
||||||
|
</p>
|
||||||
|
<p class="text-sm text-red-700 mt-1">
|
||||||
|
{authData.error}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if errors.auth}
|
||||||
|
<p class="mt-2 text-sm text-red-600">{errors.auth}</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { GoogleSheet } from '$lib/sheets.js';
|
||||||
|
|
||||||
|
// Props
|
||||||
|
let { sheetsData, errors, loadRecentSheets, selectSheet, toggleSheetList } = $props<{
|
||||||
|
sheetsData: {
|
||||||
|
availableSheets: GoogleSheet[];
|
||||||
|
selectedSheet: GoogleSheet | null;
|
||||||
|
sheetData: string[][];
|
||||||
|
columnMapping: {
|
||||||
|
name: number;
|
||||||
|
surname: number;
|
||||||
|
email: number;
|
||||||
|
confirmation: number;
|
||||||
|
};
|
||||||
|
loading: boolean;
|
||||||
|
expandedSheetList: boolean;
|
||||||
|
};
|
||||||
|
errors: Record<string, string>;
|
||||||
|
loadRecentSheets: () => Promise<void>;
|
||||||
|
selectSheet: (sheet: GoogleSheet) => Promise<void>;
|
||||||
|
toggleSheetList: () => void;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="space-y-6">
|
||||||
|
<div>
|
||||||
|
<h3 class="text-lg font-medium text-gray-900 mb-4">Select Google Sheet</h3>
|
||||||
|
|
||||||
|
{#if sheetsData.loading && sheetsData.availableSheets.length === 0}
|
||||||
|
<div class="space-y-3">
|
||||||
|
{#each Array(5) as _}
|
||||||
|
<div class="p-4 border border-gray-200 rounded animate-pulse">
|
||||||
|
<div class="h-4 bg-gray-200 rounded w-3/4 mb-2"></div>
|
||||||
|
<div class="h-3 bg-gray-100 rounded w-1/2"></div>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{:else if sheetsData.availableSheets.length === 0}
|
||||||
|
<div class="text-center py-8">
|
||||||
|
<p class="text-gray-500">No Google Sheets found.</p>
|
||||||
|
<button
|
||||||
|
onclick={loadRecentSheets}
|
||||||
|
class="mt-2 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition"
|
||||||
|
>
|
||||||
|
Refresh
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="space-y-3">
|
||||||
|
{#if !sheetsData.expandedSheetList && sheetsData.selectedSheet}
|
||||||
|
<!-- Selected sheet only (collapsed view) -->
|
||||||
|
<div class="flex items-center justify-between p-4 border border-blue-500 bg-blue-50 rounded">
|
||||||
|
<div>
|
||||||
|
<div class="font-medium text-gray-900">{sheetsData.selectedSheet.name}</div>
|
||||||
|
<div class="text-sm text-gray-500">
|
||||||
|
Modified: {new Date(sheetsData.selectedSheet.modifiedTime).toLocaleDateString()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onclick={toggleSheetList}
|
||||||
|
class="text-blue-600 hover:text-blue-800 flex items-center"
|
||||||
|
aria-label="Show all sheets"
|
||||||
|
>
|
||||||
|
<span class="text-sm mr-1">Change</span>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<!-- All sheets (expanded view) -->
|
||||||
|
<div class="flex justify-between items-center mb-2">
|
||||||
|
<h4 class="text-sm font-medium text-gray-700">Available Sheets</h4>
|
||||||
|
{#if sheetsData.selectedSheet}
|
||||||
|
<button
|
||||||
|
onclick={toggleSheetList}
|
||||||
|
class="text-sm text-blue-600 hover:text-blue-800"
|
||||||
|
aria-label="Hide sheet list"
|
||||||
|
>
|
||||||
|
Collapse list
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="grid gap-3">
|
||||||
|
{#each sheetsData.availableSheets as sheet}
|
||||||
|
<button
|
||||||
|
onclick={() => selectSheet(sheet)}
|
||||||
|
class="p-4 text-left border border-gray-200 rounded hover:border-blue-500 transition {
|
||||||
|
sheetsData.selectedSheet?.id === sheet.id ? 'border-blue-500 bg-blue-50' : ''
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<div class="font-medium text-gray-900">{sheet.name}</div>
|
||||||
|
<div class="text-sm text-gray-500">
|
||||||
|
Modified: {new Date(sheet.modifiedTime).toLocaleDateString()}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if errors.sheet}
|
||||||
|
<p class="mt-2 text-sm text-red-600">{errors.sheet}</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if sheetsData.selectedSheet && sheetsData.sheetData.length > 0}
|
||||||
|
<div>
|
||||||
|
<h3 class="text-lg font-medium text-gray-900 mb-4">Column Mapping</h3>
|
||||||
|
|
||||||
|
<!-- Instructions for column mapping -->
|
||||||
|
<div class="bg-white p-4 rounded-md border border-gray-300 mb-4">
|
||||||
|
<p class="text-sm text-black-800 mb-2 font-medium">Column Mapping Instructions:</p>
|
||||||
|
<p class="text-sm text-black-700">
|
||||||
|
Select what each column represents by using the dropdown in each column header.
|
||||||
|
Make sure to assign Name, Surname, Email, and Confirmation columns.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="w-full border border-gray-200 rounded">
|
||||||
|
<thead>
|
||||||
|
<tr class="bg-gray-50">
|
||||||
|
{#each sheetsData.sheetData[0] || [] as header, index}
|
||||||
|
<th class="px-3 py-2 border-b border-gray-200 text-left">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<div class="font-medium text-gray-900">
|
||||||
|
{header || `Empty Column ${index + 1}`}
|
||||||
|
</div>
|
||||||
|
<select
|
||||||
|
class="text-sm normal-case font-normal px-2 py-1 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||||
|
aria-label={`Select data type for column ${index + 1}`}
|
||||||
|
onclick={(e) => e.stopPropagation()}
|
||||||
|
onchange={(e) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
if (value === "none") return;
|
||||||
|
|
||||||
|
// Reset previous selection if this column was already mapped
|
||||||
|
if (sheetsData.columnMapping.name === index + 1) sheetsData.columnMapping.name = 0;
|
||||||
|
if (sheetsData.columnMapping.surname === index + 1) sheetsData.columnMapping.surname = 0;
|
||||||
|
if (sheetsData.columnMapping.email === index + 1) sheetsData.columnMapping.email = 0;
|
||||||
|
if (sheetsData.columnMapping.confirmation === index + 1) sheetsData.columnMapping.confirmation = 0;
|
||||||
|
|
||||||
|
// Set new mapping
|
||||||
|
if (value === "name") sheetsData.columnMapping.name = index + 1;
|
||||||
|
else if (value === "surname") sheetsData.columnMapping.surname = index + 1;
|
||||||
|
else if (value === "email") sheetsData.columnMapping.email = index + 1;
|
||||||
|
else if (value === "confirmation") sheetsData.columnMapping.confirmation = index + 1;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="none">Select data type</option>
|
||||||
|
<option value="name" selected={sheetsData.columnMapping.name === index + 1}>Name</option>
|
||||||
|
<option value="surname" selected={sheetsData.columnMapping.surname === index + 1}>Surname</option>
|
||||||
|
<option value="email" selected={sheetsData.columnMapping.email === index + 1}>Email</option>
|
||||||
|
<option value="confirmation" selected={sheetsData.columnMapping.confirmation === index + 1}>Confirmation</option>
|
||||||
|
</select>
|
||||||
|
<div class="h-7 mt-1"> <!-- Fixed height container to prevent layout shift -->
|
||||||
|
{#if sheetsData.columnMapping.name === index + 1}
|
||||||
|
<span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded">Name Column</span>
|
||||||
|
{:else if sheetsData.columnMapping.surname === index + 1}
|
||||||
|
<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">Surname Column</span>
|
||||||
|
{:else if sheetsData.columnMapping.email === index + 1}
|
||||||
|
<span class="bg-purple-100 text-purple-800 text-xs px-2 py-1 rounded">Email Column</span>
|
||||||
|
{:else if sheetsData.columnMapping.confirmation === index + 1}
|
||||||
|
<span class="bg-amber-100 text-amber-800 text-xs px-2 py-1 rounded">Confirmation Column</span>
|
||||||
|
{:else}
|
||||||
|
<span class="bg-gray-100 text-gray-400 text-xs px-2 py-1 rounded">Not Mapped</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
{/each}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each sheetsData.sheetData.slice(0, 10) as row, rowIndex}
|
||||||
|
<tr class="hover:bg-gray-50">
|
||||||
|
{#each row as cell, cellIndex}
|
||||||
|
<td class="px-3 py-2 border-b border-gray-100 text-sm">
|
||||||
|
<span
|
||||||
|
class={
|
||||||
|
sheetsData.columnMapping.name === cellIndex + 1 ? 'font-medium text-green-700' :
|
||||||
|
sheetsData.columnMapping.surname === cellIndex + 1 ? 'font-medium text-blue-700' :
|
||||||
|
sheetsData.columnMapping.email === cellIndex + 1 ? 'font-medium text-purple-700' :
|
||||||
|
sheetsData.columnMapping.confirmation === cellIndex + 1 ? 'font-medium text-amber-700' :
|
||||||
|
'text-gray-700'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{cell || ''}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
{/each}
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<p class="mt-2 text-sm text-gray-500">Showing first 10 rows</p>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if sheetsData.loading && sheetsData.selectedSheet}
|
||||||
|
<div class="text-center py-4">
|
||||||
|
<div class="text-gray-600">Loading sheet data...</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if errors.sheetData}
|
||||||
|
<p class="text-sm text-red-600">{errors.sheetData}</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
// Props
|
||||||
|
let { currentStep, totalSteps, canProceed, loading, prevStep, nextStep, createEvent } = $props<{
|
||||||
|
currentStep: number;
|
||||||
|
totalSteps: number;
|
||||||
|
canProceed: boolean;
|
||||||
|
loading: boolean;
|
||||||
|
prevStep: () => void;
|
||||||
|
nextStep: () => void;
|
||||||
|
createEvent: () => Promise<void>;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<button
|
||||||
|
onclick={prevStep}
|
||||||
|
disabled={currentStep === 0}
|
||||||
|
class="px-4 py-2 text-gray-700 bg-gray-100 hover:bg-gray-200 rounded transition disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
Previous
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="flex gap-2">
|
||||||
|
{#if currentStep < totalSteps - 1}
|
||||||
|
<button
|
||||||
|
onclick={nextStep}
|
||||||
|
disabled={!canProceed}
|
||||||
|
class="px-6 py-2 bg-blue-600 text-white font-semibold rounded hover:bg-blue-700 transition disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</button>
|
||||||
|
{:else}
|
||||||
|
<button
|
||||||
|
onclick={createEvent}
|
||||||
|
disabled={!canProceed || loading}
|
||||||
|
class="px-6 py-2 bg-green-600 text-white font-semibold rounded hover:bg-green-700 transition disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
{loading ? 'Creating...' : 'Create Event'}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
// Props
|
||||||
|
let { currentStep, totalSteps, stepTitle } = $props<{
|
||||||
|
currentStep: number;
|
||||||
|
totalSteps: number;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="mb-8">
|
||||||
|
<div class="flex items-center justify-center gap-4 w-full">
|
||||||
|
{#each Array(totalSteps) as _, index}
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div class="w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium {
|
||||||
|
index === currentStep ? 'bg-blue-600 text-white' :
|
||||||
|
index < currentStep ? 'bg-green-600 text-white' :
|
||||||
|
'bg-gray-200 text-gray-600'
|
||||||
|
}">
|
||||||
|
{index + 1}
|
||||||
|
</div>
|
||||||
|
{#if index < totalSteps - 1}
|
||||||
|
<div class="w-10 h-1 rounded {
|
||||||
|
index < currentStep ? 'bg-green-600' : 'bg-gray-200'
|
||||||
|
}"></div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user