feat: add email, scheduler, and Zulip integration services
- Add email service for sending meeting invites with ICS attachments - Add scheduler for background calendar sync jobs - Add Zulip service for meeting notifications - Make ics_url optional for participants - Add /api/schedule endpoint with 2-hour lead time validation - Update frontend to support scheduling flow Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
18
frontend/package-lock.json
generated
18
frontend/package-lock.json
generated
@@ -2859,7 +2859,6 @@
|
||||
"integrity": "sha512-bJFoMATwIGaxxx8VJPeM8TonI8t579oRvgAuT8zFugJsJZgzqv0Fu8Mhp68iecjzG7cnN3mO2dJQ5uUM2EFrgQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"undici-types": "~6.21.0"
|
||||
}
|
||||
@@ -2877,7 +2876,6 @@
|
||||
"integrity": "sha512-/LDXMQh55EzZQ0uVAZmKKhfENivEvWz6E+EYzh+/MCjMhNsotd+ZHhBGIjFDTi6+fz0OhQQQLbTgdQIxxCsC0w==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/prop-types": "*",
|
||||
"csstype": "^3.0.2"
|
||||
@@ -2889,7 +2887,6 @@
|
||||
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"peerDependencies": {
|
||||
"@types/react": "^18.0.0"
|
||||
}
|
||||
@@ -2940,7 +2937,6 @@
|
||||
"integrity": "sha512-Zhy8HCvBUEfBECzIl1PKqF4p11+d0aUJS1GeUiuqK9WmOug8YCmC4h4bjyBvMyAMI9sbRczmrYL5lKg/YMbrcQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "8.38.0",
|
||||
"@typescript-eslint/types": "8.38.0",
|
||||
@@ -3173,7 +3169,6 @@
|
||||
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@@ -3378,7 +3373,6 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"caniuse-lite": "^1.0.30001726",
|
||||
"electron-to-chromium": "^1.5.173",
|
||||
@@ -3712,7 +3706,6 @@
|
||||
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.6.0.tgz",
|
||||
"integrity": "sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/kossnocorp"
|
||||
@@ -3794,8 +3787,7 @@
|
||||
"version": "8.6.0",
|
||||
"resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.6.0.tgz",
|
||||
"integrity": "sha512-SjWyZBHJPbqxHOzckOfo8lHisEaJWmwd23XppYFYVh10bU66/Pn5tkVkbkCMZVdbUE5eTCI2nD8OyIP4Z+uwkA==",
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/embla-carousel-react": {
|
||||
"version": "8.6.0",
|
||||
@@ -3893,7 +3885,6 @@
|
||||
"integrity": "sha512-LSehfdpgMeWcTZkWZVIJl+tkZ2nuSkyyB9C27MZqFWXuph7DvaowgcTvKqxvpLW1JZIk8PN7hFY3Rj9LQ7m7lg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.12.1",
|
||||
@@ -5415,7 +5406,6 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"nanoid": "^3.3.11",
|
||||
"picocolors": "^1.1.1",
|
||||
@@ -5602,7 +5592,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
|
||||
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"loose-envify": "^1.1.0"
|
||||
},
|
||||
@@ -5629,7 +5618,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
|
||||
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"loose-envify": "^1.1.0",
|
||||
"scheduler": "^0.23.2"
|
||||
@@ -5643,7 +5631,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.61.1.tgz",
|
||||
"integrity": "sha512-2vbXUFDYgqEgM2RcXcAT2PwDW/80QARi+PKmHy5q2KhuKvOlG8iIYgf7eIlIANR5trW9fJbP4r5aub3a4egsew==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
@@ -6197,7 +6184,6 @@
|
||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz",
|
||||
"integrity": "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@alloc/quick-lru": "^5.2.0",
|
||||
"arg": "^5.0.2",
|
||||
@@ -6322,7 +6308,6 @@
|
||||
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
@@ -6502,7 +6487,6 @@
|
||||
"integrity": "sha512-qO3aKv3HoQC8QKiNSTuUM1l9o/XX3+c+VTgLHbJWHZGeTPVAg2XwazI9UWzoxjIJCGCV2zU60uqMzjeLZuULqA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.21.3",
|
||||
"postcss": "^8.4.43",
|
||||
|
||||
@@ -4,7 +4,7 @@ export interface ParticipantAPI {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
ics_url: string;
|
||||
ics_url: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ export interface TimeSlotAPI {
|
||||
export interface CreateParticipantRequest {
|
||||
name: string;
|
||||
email: string;
|
||||
ics_url: string;
|
||||
ics_url?: string;
|
||||
}
|
||||
|
||||
async function handleResponse<T>(response: Response): Promise<T> {
|
||||
@@ -76,3 +76,24 @@ export async function syncParticipant(id: string): Promise<void> {
|
||||
throw new Error('Failed to sync participant calendar');
|
||||
}
|
||||
}
|
||||
|
||||
export async function scheduleMeeting(
|
||||
participantIds: string[],
|
||||
title: string,
|
||||
description: string,
|
||||
startTime: string,
|
||||
endTime: string,
|
||||
): Promise<{ email_sent: boolean; zulip_sent: boolean }> {
|
||||
const response = await fetch(`${API_URL}/api/schedule`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
participant_ids: participantIds,
|
||||
title,
|
||||
description,
|
||||
start_time: startTime,
|
||||
end_time: endTime,
|
||||
}),
|
||||
});
|
||||
return handleResponse(response);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,23 @@ import {
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Check, X, Loader2 } from 'lucide-react';
|
||||
|
||||
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
|
||||
const dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
|
||||
const hours = [9, 10, 11, 12, 13, 14, 15, 16, 17];
|
||||
|
||||
// Get the dates for Mon-Fri of the current week
|
||||
const getWeekDates = () => {
|
||||
const now = new Date();
|
||||
const monday = new Date(now);
|
||||
monday.setDate(now.getDate() - now.getDay() + 1);
|
||||
monday.setHours(0, 0, 0, 0);
|
||||
|
||||
return dayNames.map((_, i) => {
|
||||
const date = new Date(monday);
|
||||
date.setDate(monday.getDate() + i);
|
||||
return date.toISOString().split('T')[0]; // "YYYY-MM-DD"
|
||||
});
|
||||
};
|
||||
|
||||
interface AvailabilityHeatmapProps {
|
||||
slots: TimeSlot[];
|
||||
selectedParticipants: Participant[];
|
||||
@@ -26,8 +40,10 @@ export const AvailabilityHeatmap = ({
|
||||
showPartialAvailability = false,
|
||||
isLoading = false,
|
||||
}: AvailabilityHeatmapProps) => {
|
||||
const getSlot = (day: string, hour: number) => {
|
||||
return slots.find((s) => s.day === day && s.hour === hour);
|
||||
const weekDates = getWeekDates();
|
||||
|
||||
const getSlot = (dateStr: string, hour: number) => {
|
||||
return slots.find((s) => s.day === dateStr && s.hour === hour);
|
||||
};
|
||||
|
||||
const getEffectiveAvailability = (slot: TimeSlot) => {
|
||||
@@ -41,6 +57,13 @@ export const AvailabilityHeatmap = ({
|
||||
return `${hour.toString().padStart(2, '0')}:00`;
|
||||
};
|
||||
|
||||
const isSlotTooSoon = (dateStr: string, hour: number) => {
|
||||
const slotTime = new Date(`${dateStr}T${formatHour(hour)}:00Z`);
|
||||
const now = new Date();
|
||||
const twoHoursFromNow = new Date(now.getTime() + 2 * 60 * 60 * 1000);
|
||||
return slotTime < twoHoursFromNow;
|
||||
};
|
||||
|
||||
const getWeekDateRange = () => {
|
||||
const now = new Date();
|
||||
const monday = new Date(now);
|
||||
@@ -87,12 +110,12 @@ export const AvailabilityHeatmap = ({
|
||||
<div className="min-w-[600px]">
|
||||
<div className="grid grid-cols-[60px_repeat(5,1fr)] gap-1 mb-2">
|
||||
<div></div>
|
||||
{days.map((day) => (
|
||||
{dayNames.map((dayName) => (
|
||||
<div
|
||||
key={day}
|
||||
key={dayName}
|
||||
className="text-center text-sm font-medium text-muted-foreground py-2"
|
||||
>
|
||||
{day}
|
||||
{dayName}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -103,18 +126,22 @@ export const AvailabilityHeatmap = ({
|
||||
<div className="text-xs text-muted-foreground flex items-center justify-end pr-3">
|
||||
{formatHour(hour)}
|
||||
</div>
|
||||
{days.map((day) => {
|
||||
const slot = getSlot(day, hour);
|
||||
if (!slot) return <div key={`${day}-${hour}`} className="h-12 bg-muted rounded" />;
|
||||
{weekDates.map((dateStr, dayIndex) => {
|
||||
const slot = getSlot(dateStr, hour);
|
||||
const dayName = dayNames[dayIndex];
|
||||
const tooSoon = isSlotTooSoon(dateStr, hour);
|
||||
if (!slot) return <div key={`${dateStr}-${hour}`} className="h-12 bg-muted rounded" />;
|
||||
|
||||
const effectiveAvailability = getEffectiveAvailability(slot);
|
||||
|
||||
return (
|
||||
<Popover key={`${day}-${hour}`}>
|
||||
<Popover key={`${dateStr}-${hour}`}>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
className={cn(
|
||||
"h-12 rounded-md transition-all duration-200 hover:scale-105 hover:shadow-md focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
||||
"h-12 rounded-md transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
||||
tooSoon && "opacity-40 cursor-not-allowed",
|
||||
!tooSoon && "hover:scale-105 hover:shadow-md",
|
||||
effectiveAvailability === 'full' && "bg-availability-full hover:bg-availability-full/90",
|
||||
effectiveAvailability === 'partial' && "bg-availability-partial hover:bg-availability-partial/90",
|
||||
effectiveAvailability === 'none' && "bg-availability-none hover:bg-availability-none/90"
|
||||
@@ -124,8 +151,13 @@ export const AvailabilityHeatmap = ({
|
||||
<PopoverContent className="w-64 p-4 animate-scale-in" align="center">
|
||||
<div className="space-y-3">
|
||||
<div className="font-semibold text-foreground">
|
||||
{day} {formatHour(hour)}–{formatHour(hour + 1)}
|
||||
{dayName} {formatHour(hour)}–{formatHour(hour + 1)}
|
||||
</div>
|
||||
{tooSoon && (
|
||||
<div className="text-sm text-muted-foreground italic">
|
||||
This time slot has passed or is too soon to schedule
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-2">
|
||||
{selectedParticipants.map((participant) => {
|
||||
const isAvailable = slot.availableParticipants.includes(participant.name);
|
||||
@@ -148,7 +180,7 @@ export const AvailabilityHeatmap = ({
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{effectiveAvailability !== 'none' && (
|
||||
{effectiveAvailability !== 'none' && !tooSoon && (
|
||||
<Button
|
||||
variant="schedule"
|
||||
className="w-full mt-2"
|
||||
|
||||
@@ -25,16 +25,16 @@ export const ParticipantManager = ({
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!name.trim() || !email.trim() || !icsLink.trim()) {
|
||||
if (!name.trim() || !email.trim()) {
|
||||
toast({
|
||||
title: "Missing fields",
|
||||
description: "Please fill in all fields",
|
||||
description: "Please fill in name and email",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
onAddParticipant({ name: name.trim(), email: email.trim(), icsLink: icsLink.trim() });
|
||||
onAddParticipant({ name: name.trim(), email: email.trim(), icsLink: icsLink.trim() || '' });
|
||||
setName('');
|
||||
setEmail('');
|
||||
setIcsLink('');
|
||||
@@ -89,7 +89,7 @@ export const ParticipantManager = ({
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="icsLink">Calendar ICS Link</Label>
|
||||
<Label htmlFor="icsLink">Calendar ICS Link (optional)</Label>
|
||||
<Input
|
||||
id="icsLink"
|
||||
placeholder="https://calendar.google.com/..."
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { TimeSlot, Participant } from '@/types/calendar';
|
||||
import { scheduleMeeting } from '@/api/client';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -11,7 +12,7 @@ import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { Calendar, Clock, Users, Send } from 'lucide-react';
|
||||
import { Calendar, Clock, Users, Send, AlertCircle } from 'lucide-react';
|
||||
|
||||
interface ScheduleModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -34,7 +35,23 @@ export const ScheduleModal = ({
|
||||
return `${hour.toString().padStart(2, '0')}:00`;
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
const formatDate = (dateStr: string) => {
|
||||
const date = new Date(dateStr + 'T00:00:00');
|
||||
return date.toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric' });
|
||||
};
|
||||
|
||||
const isTooSoon = () => {
|
||||
if (!slot) return false;
|
||||
// Use UTC to match backend timezone
|
||||
const startDateTime = new Date(`${slot.day}T${formatHour(slot.hour)}:00Z`);
|
||||
const now = new Date();
|
||||
const twoHoursFromNow = new Date(now.getTime() + 2 * 60 * 60 * 1000);
|
||||
return startDateTime < twoHoursFromNow;
|
||||
};
|
||||
|
||||
const tooSoon = isTooSoon();
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!title.trim()) {
|
||||
toast({
|
||||
title: "Please enter a meeting title",
|
||||
@@ -43,19 +60,41 @@ export const ScheduleModal = ({
|
||||
return;
|
||||
}
|
||||
|
||||
if (!slot) return;
|
||||
|
||||
setIsSubmitting(true);
|
||||
|
||||
// Simulate API call
|
||||
setTimeout(() => {
|
||||
setIsSubmitting(false);
|
||||
try {
|
||||
// Calculate start and end times
|
||||
// slot.day is YYYY-MM-DD
|
||||
const startDateTime = new Date(`${slot.day}T${formatHour(slot.hour)}:00Z`);
|
||||
const endDateTime = new Date(`${slot.day}T${formatHour(slot.hour + 1)}:00Z`);
|
||||
|
||||
await scheduleMeeting(
|
||||
participants.map(p => p.id),
|
||||
title,
|
||||
notes,
|
||||
startDateTime.toISOString(),
|
||||
endDateTime.toISOString()
|
||||
);
|
||||
|
||||
toast({
|
||||
title: "Meeting scheduled",
|
||||
description: "Invitations sent to all participants",
|
||||
description: "Invitations sent via Email and Zulip",
|
||||
});
|
||||
|
||||
setTitle('');
|
||||
setNotes('');
|
||||
onClose();
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: "Scheduling failed",
|
||||
description: error instanceof Error ? error.message : "Unknown error",
|
||||
variant: "destructive",
|
||||
});
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!slot) return null;
|
||||
@@ -72,7 +111,7 @@ export const ScheduleModal = ({
|
||||
<div className="bg-accent/50 rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<Calendar className="w-4 h-4 text-primary" />
|
||||
<span className="font-medium">{slot.day}</span>
|
||||
<span className="font-medium">{formatDate(slot.day)}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<Clock className="w-4 h-4 text-primary" />
|
||||
@@ -109,12 +148,20 @@ export const ScheduleModal = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Lead Time Warning */}
|
||||
{tooSoon && (
|
||||
<div className="flex items-center gap-2 p-3 bg-destructive/10 border border-destructive/20 rounded-lg text-sm text-destructive">
|
||||
<AlertCircle className="w-4 h-4 flex-shrink-0" />
|
||||
<span>Meetings must be scheduled at least 2 hours in advance</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Actions */}
|
||||
<Button
|
||||
variant="schedule"
|
||||
className="w-full h-12"
|
||||
onClick={handleSubmit}
|
||||
disabled={isSubmitting}
|
||||
disabled={isSubmitting || tooSoon}
|
||||
>
|
||||
{isSubmitting ? (
|
||||
<span className="animate-pulse">Sending...</span>
|
||||
|
||||
@@ -118,7 +118,7 @@ const Index = () => {
|
||||
const created = await createParticipant({
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
ics_url: data.icsLink,
|
||||
ics_url: data.icsLink || undefined,
|
||||
});
|
||||
setParticipants((prev) => [...prev, apiToParticipant(created)]);
|
||||
toast({
|
||||
|
||||
Reference in New Issue
Block a user