Compare commits
8 Commits
ccba9d443b
...
v0.1.5.2
Author | SHA1 | Date | |
---|---|---|---|
c1aeb7c38b | |||
889e110dd9 | |||
a603232ed8 | |||
f0037226a9 | |||
12da9812df | |||
ce019a2bd9 | |||
63384aa209 | |||
ebd9d8a72e |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "quests-template-basic",
|
"name": "quests-template-basic",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.4",
|
"version": "0.1.5.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"check:types": "tsc --noEmit",
|
"check:types": "tsc --noEmit",
|
||||||
|
@@ -3,6 +3,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
|||||||
import { queryClient } from "@/client/rpc-client";
|
import { queryClient } from "@/client/rpc-client";
|
||||||
|
|
||||||
export function AdminBookings() {
|
export function AdminBookings() {
|
||||||
|
const [filterMode, setFilterMode] = useState<"upcoming" | "all" | "date">("upcoming");
|
||||||
const [selectedDate, setSelectedDate] = useState(new Date().toISOString().split('T')[0]);
|
const [selectedDate, setSelectedDate] = useState(new Date().toISOString().split('T')[0]);
|
||||||
const [selectedPhoto, setSelectedPhoto] = useState<string>("");
|
const [selectedPhoto, setSelectedPhoto] = useState<string>("");
|
||||||
const [showPhotoModal, setShowPhotoModal] = useState(false);
|
const [showPhotoModal, setShowPhotoModal] = useState(false);
|
||||||
@@ -64,8 +65,20 @@ export function AdminBookings() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const getTreatmentName = (treatmentId: string) => {
|
const getTreatmentNames = (booking: any) => {
|
||||||
return treatments?.find(t => t.id === treatmentId)?.name || "Unbekannte Behandlung";
|
// Handle new treatments array structure
|
||||||
|
if (booking.treatments && Array.isArray(booking.treatments) && booking.treatments.length > 0) {
|
||||||
|
const names = booking.treatments
|
||||||
|
.map((t: any) => t.name)
|
||||||
|
.filter((name: string) => name && name.trim())
|
||||||
|
.join(", ");
|
||||||
|
return names || "Keine Behandlung";
|
||||||
|
}
|
||||||
|
// Fallback to deprecated treatmentId for backward compatibility
|
||||||
|
if (booking.treatmentId) {
|
||||||
|
return treatments?.find(t => t.id === booking.treatmentId)?.name || "Unbekannte Behandlung";
|
||||||
|
}
|
||||||
|
return "Keine Behandlung";
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStatusColor = (status: string) => {
|
const getStatusColor = (status: string) => {
|
||||||
@@ -127,9 +140,23 @@ export function AdminBookings() {
|
|||||||
return appointmentDate >= today;
|
return appointmentDate >= today;
|
||||||
};
|
};
|
||||||
|
|
||||||
const filteredBookings = bookings?.filter(booking =>
|
// Filter bookings based on selected filter mode
|
||||||
selectedDate ? booking.appointmentDate === selectedDate : true
|
const filteredBookings = bookings?.filter(booking => {
|
||||||
).sort((a, b) => {
|
if (filterMode === "upcoming") {
|
||||||
|
// Show all future bookings (not cancelled)
|
||||||
|
const bookingDate = new Date(booking.appointmentDate);
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
bookingDate.setHours(0, 0, 0, 0);
|
||||||
|
return bookingDate >= today && booking.status !== "cancelled";
|
||||||
|
} else if (filterMode === "date") {
|
||||||
|
// Show bookings for specific date
|
||||||
|
return booking.appointmentDate === selectedDate;
|
||||||
|
} else {
|
||||||
|
// Show all bookings
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}).sort((a, b) => {
|
||||||
if (a.appointmentDate === b.appointmentDate) {
|
if (a.appointmentDate === b.appointmentDate) {
|
||||||
return a.appointmentTime.localeCompare(b.appointmentTime);
|
return a.appointmentTime.localeCompare(b.appointmentTime);
|
||||||
}
|
}
|
||||||
@@ -206,22 +233,54 @@ export function AdminBookings() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Date Filter */}
|
{/* Filter Section */}
|
||||||
<div className="bg-white rounded-lg shadow p-4 mb-6">
|
<div className="bg-white rounded-lg shadow p-4 mb-6">
|
||||||
<div className="flex items-center space-x-4">
|
<div className="flex flex-col space-y-4">
|
||||||
<label className="text-sm font-medium text-gray-700">Filter by date:</label>
|
<div className="flex items-center space-x-2">
|
||||||
|
<label className="text-sm font-medium text-gray-700">Filter:</label>
|
||||||
|
<button
|
||||||
|
onClick={() => setFilterMode("upcoming")}
|
||||||
|
className={`px-4 py-2 rounded-md text-sm font-medium transition-colors ${
|
||||||
|
filterMode === "upcoming"
|
||||||
|
? "bg-pink-600 text-white"
|
||||||
|
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
Zukünftige
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setFilterMode("all")}
|
||||||
|
className={`px-4 py-2 rounded-md text-sm font-medium transition-colors ${
|
||||||
|
filterMode === "all"
|
||||||
|
? "bg-pink-600 text-white"
|
||||||
|
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
Alle
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setFilterMode("date")}
|
||||||
|
className={`px-4 py-2 rounded-md text-sm font-medium transition-colors ${
|
||||||
|
filterMode === "date"
|
||||||
|
? "bg-pink-600 text-white"
|
||||||
|
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
Datum
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{filterMode === "date" && (
|
||||||
|
<div className="flex items-center space-x-4 pl-16">
|
||||||
|
<label className="text-sm font-medium text-gray-700">Wähle Datum:</label>
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
value={selectedDate}
|
value={selectedDate}
|
||||||
onChange={(e) => setSelectedDate(e.target.value)}
|
onChange={(e) => setSelectedDate(e.target.value)}
|
||||||
className="p-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-pink-500 focus:border-pink-500"
|
className="p-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-pink-500 focus:border-pink-500"
|
||||||
/>
|
/>
|
||||||
<button
|
</div>
|
||||||
onClick={() => setSelectedDate("")}
|
)}
|
||||||
className="text-sm text-pink-600 hover:text-pink-800"
|
|
||||||
>
|
|
||||||
Show All
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -260,8 +319,8 @@ export function AdminBookings() {
|
|||||||
<div className="text-sm text-gray-500">{booking.customerPhone || '—'}</div>
|
<div className="text-sm text-gray-500">{booking.customerPhone || '—'}</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="px-6 py-4">
|
||||||
<div className="text-sm text-gray-900">{getTreatmentName(booking.treatmentId)}</div>
|
<div className="text-sm text-gray-900">{getTreatmentNames(booking)}</div>
|
||||||
{booking.notes && (
|
{booking.notes && (
|
||||||
<div className="text-sm text-gray-500">Notizen: {booking.notes}</div>
|
<div className="text-sm text-gray-500">Notizen: {booking.notes}</div>
|
||||||
)}
|
)}
|
||||||
@@ -357,8 +416,10 @@ export function AdminBookings() {
|
|||||||
|
|
||||||
{!filteredBookings?.length && (
|
{!filteredBookings?.length && (
|
||||||
<div className="text-center py-8 text-gray-500">
|
<div className="text-center py-8 text-gray-500">
|
||||||
{selectedDate
|
{filterMode === "date"
|
||||||
? `Keine Buchungen für ${new Date(selectedDate).toLocaleDateString()} gefunden`
|
? `Keine Buchungen für ${new Date(selectedDate).toLocaleDateString()} gefunden`
|
||||||
|
: filterMode === "upcoming"
|
||||||
|
? "Keine zukünftigen Buchungen verfügbar."
|
||||||
: "Keine Buchungen verfügbar."
|
: "Keine Buchungen verfügbar."
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@@ -445,6 +506,15 @@ export function AdminBookings() {
|
|||||||
const booking = bookings?.find(b => b.id === showMessageModal);
|
const booking = bookings?.find(b => b.id === showMessageModal);
|
||||||
if (!booking) return null;
|
if (!booking) return null;
|
||||||
|
|
||||||
|
// Calculate totals for multiple treatments
|
||||||
|
const hasTreatments = booking.treatments && Array.isArray(booking.treatments) && booking.treatments.length > 0;
|
||||||
|
const totalDuration = hasTreatments
|
||||||
|
? booking.treatments.reduce((sum: number, t: any) => sum + (t.duration || 0), 0)
|
||||||
|
: (booking.bookedDurationMinutes || 0);
|
||||||
|
const totalPrice = hasTreatments
|
||||||
|
? booking.treatments.reduce((sum: number, t: any) => sum + (t.price || 0), 0)
|
||||||
|
: 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mb-4 bg-gray-50 p-4 rounded-md">
|
<div className="mb-4 bg-gray-50 p-4 rounded-md">
|
||||||
<p className="text-sm text-gray-700">
|
<p className="text-sm text-gray-700">
|
||||||
@@ -456,9 +526,29 @@ export function AdminBookings() {
|
|||||||
<p className="text-sm text-gray-700">
|
<p className="text-sm text-gray-700">
|
||||||
<strong>Termin:</strong> {new Date(booking.appointmentDate).toLocaleDateString()} um {booking.appointmentTime}
|
<strong>Termin:</strong> {new Date(booking.appointmentDate).toLocaleDateString()} um {booking.appointmentTime}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-gray-700">
|
<div className="text-sm text-gray-700 mt-2">
|
||||||
<strong>Behandlung:</strong> {getTreatmentName(booking.treatmentId)}
|
<strong>Behandlungen:</strong>
|
||||||
</p>
|
{hasTreatments ? (
|
||||||
|
<div className="mt-1 ml-2">
|
||||||
|
{booking.treatments.map((treatment: any, index: number) => (
|
||||||
|
<div key={index} className="mb-1">
|
||||||
|
• {treatment.name} ({treatment.duration} Min., {treatment.price}€)
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{booking.treatments.length > 1 && (
|
||||||
|
<div className="mt-2 pt-2 border-t border-gray-300 font-semibold">
|
||||||
|
Gesamt: {totalDuration} Min., {totalPrice.toFixed(2)}€
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : booking.treatmentId ? (
|
||||||
|
<div className="mt-1 ml-2">
|
||||||
|
• {treatments?.find(t => t.id === booking.treatmentId)?.name || "Unbekannte Behandlung"}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<span className="ml-2 text-gray-500">Keine Behandlung</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})()}
|
})()}
|
||||||
|
@@ -47,7 +47,7 @@ export function AdminCalendar() {
|
|||||||
...queryClient.recurringAvailability.getAvailableTimes.queryOptions({
|
...queryClient.recurringAvailability.getAvailableTimes.queryOptions({
|
||||||
input: {
|
input: {
|
||||||
date: createFormData.appointmentDate,
|
date: createFormData.appointmentDate,
|
||||||
treatmentId: createFormData.treatmentId
|
treatmentIds: createFormData.treatmentId ? [createFormData.treatmentId] : []
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
enabled: !!createFormData.appointmentDate && !!createFormData.treatmentId
|
enabled: !!createFormData.appointmentDate && !!createFormData.treatmentId
|
||||||
@@ -58,7 +58,16 @@ export function AdminCalendar() {
|
|||||||
...queryClient.recurringAvailability.getAvailableTimes.queryOptions({
|
...queryClient.recurringAvailability.getAvailableTimes.queryOptions({
|
||||||
input: {
|
input: {
|
||||||
date: rescheduleFormData.appointmentDate,
|
date: rescheduleFormData.appointmentDate,
|
||||||
treatmentId: (showRescheduleModal ? bookings?.find(b => b.id === showRescheduleModal)?.treatmentId : '') || ''
|
treatmentIds: (() => {
|
||||||
|
const booking = showRescheduleModal ? bookings?.find(b => b.id === showRescheduleModal) : null;
|
||||||
|
if (!booking) return [];
|
||||||
|
// Use new treatments array if available
|
||||||
|
if (booking.treatments && Array.isArray(booking.treatments) && booking.treatments.length > 0) {
|
||||||
|
return booking.treatments.map((t: any) => t.id);
|
||||||
|
}
|
||||||
|
// Fallback to deprecated treatmentId for backward compatibility
|
||||||
|
return booking.treatmentId ? [booking.treatmentId] : [];
|
||||||
|
})()
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
enabled: !!showRescheduleModal && !!rescheduleFormData.appointmentDate
|
enabled: !!showRescheduleModal && !!rescheduleFormData.appointmentDate
|
||||||
@@ -86,8 +95,16 @@ export function AdminCalendar() {
|
|||||||
queryClient.bookings.generateCalDAVToken.mutationOptions()
|
queryClient.bookings.generateCalDAVToken.mutationOptions()
|
||||||
);
|
);
|
||||||
|
|
||||||
const getTreatmentName = (treatmentId: string) => {
|
const getTreatmentNames = (booking: any) => {
|
||||||
return treatments?.find(t => t.id === treatmentId)?.name || "Unbekannte Behandlung";
|
// Handle new treatments array structure
|
||||||
|
if (booking.treatments && Array.isArray(booking.treatments) && booking.treatments.length > 0) {
|
||||||
|
return booking.treatments.map((t: any) => t.name).join(", ");
|
||||||
|
}
|
||||||
|
// Fallback to deprecated treatmentId for backward compatibility
|
||||||
|
if (booking.treatmentId) {
|
||||||
|
return treatments?.find(t => t.id === booking.treatmentId)?.name || "Unbekannte Behandlung";
|
||||||
|
}
|
||||||
|
return "Keine Behandlung";
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStatusColor = (status: string) => {
|
const getStatusColor = (status: string) => {
|
||||||
@@ -219,9 +236,29 @@ export function AdminCalendar() {
|
|||||||
const sessionId = localStorage.getItem('sessionId');
|
const sessionId = localStorage.getItem('sessionId');
|
||||||
if (!sessionId) return;
|
if (!sessionId) return;
|
||||||
|
|
||||||
|
// Convert treatmentId to treatments array
|
||||||
|
const selectedTreatment = treatments?.find(t => t.id === createFormData.treatmentId);
|
||||||
|
if (!selectedTreatment) {
|
||||||
|
setCreateError('Bitte wähle eine Behandlung aus.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const treatmentsArray = [{
|
||||||
|
id: selectedTreatment.id,
|
||||||
|
name: selectedTreatment.name,
|
||||||
|
duration: selectedTreatment.duration,
|
||||||
|
price: selectedTreatment.price
|
||||||
|
}];
|
||||||
|
|
||||||
createManualBooking({
|
createManualBooking({
|
||||||
sessionId,
|
sessionId,
|
||||||
...createFormData
|
treatments: treatmentsArray,
|
||||||
|
customerName: createFormData.customerName,
|
||||||
|
appointmentDate: createFormData.appointmentDate,
|
||||||
|
appointmentTime: createFormData.appointmentTime,
|
||||||
|
customerEmail: createFormData.customerEmail,
|
||||||
|
customerPhone: createFormData.customerPhone,
|
||||||
|
notes: createFormData.notes
|
||||||
}, {
|
}, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
setShowCreateModal(false);
|
setShowCreateModal(false);
|
||||||
@@ -469,7 +506,7 @@ export function AdminCalendar() {
|
|||||||
<div
|
<div
|
||||||
key={booking.id}
|
key={booking.id}
|
||||||
className={`text-xs p-1 rounded border-l-2 ${getStatusColor(booking.status)} truncate`}
|
className={`text-xs p-1 rounded border-l-2 ${getStatusColor(booking.status)} truncate`}
|
||||||
title={`${booking.customerName} - ${getTreatmentName(booking.treatmentId)} (${booking.appointmentTime})`}
|
title={`${booking.customerName} - ${getTreatmentNames(booking)} (${booking.appointmentTime})`}
|
||||||
>
|
>
|
||||||
<div className="font-medium">{booking.appointmentTime}</div>
|
<div className="font-medium">{booking.appointmentTime}</div>
|
||||||
<div className="truncate">{booking.customerName}</div>
|
<div className="truncate">{booking.customerName}</div>
|
||||||
@@ -526,7 +563,7 @@ export function AdminCalendar() {
|
|||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm text-gray-600">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm text-gray-600">
|
||||||
<div>
|
<div>
|
||||||
<strong>Behandlung:</strong> {getTreatmentName(booking.treatmentId)}
|
<strong>Behandlung:</strong> {getTreatmentNames(booking)}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<strong>Uhrzeit:</strong> {booking.appointmentTime}
|
<strong>Uhrzeit:</strong> {booking.appointmentTime}
|
||||||
@@ -842,7 +879,7 @@ export function AdminCalendar() {
|
|||||||
|
|
||||||
{(() => {
|
{(() => {
|
||||||
const booking = bookings?.find(b => b.id === showRescheduleModal);
|
const booking = bookings?.find(b => b.id === showRescheduleModal);
|
||||||
const treatmentName = booking ? getTreatmentName(booking.treatmentId) : '';
|
const treatmentName = booking ? getTreatmentNames(booking) : '';
|
||||||
return booking ? (
|
return booking ? (
|
||||||
<div className="mb-4 text-sm text-gray-700">
|
<div className="mb-4 text-sm text-gray-700">
|
||||||
<div className="mb-2"><strong>Kunde:</strong> {booking.customerName}</div>
|
<div className="mb-2"><strong>Kunde:</strong> {booking.customerName}</div>
|
||||||
|
@@ -3,7 +3,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
|||||||
import { queryClient } from "@/client/rpc-client";
|
import { queryClient } from "@/client/rpc-client";
|
||||||
|
|
||||||
// Feature flag for multi-treatments availability API compatibility
|
// Feature flag for multi-treatments availability API compatibility
|
||||||
const USE_MULTI_TREATMENTS_AVAILABILITY = false;
|
const USE_MULTI_TREATMENTS_AVAILABILITY = true;
|
||||||
|
|
||||||
export function BookingForm() {
|
export function BookingForm() {
|
||||||
const [selectedTreatments, setSelectedTreatments] = useState<Array<{id: string, name: string, duration: number, price: number}>>([]);
|
const [selectedTreatments, setSelectedTreatments] = useState<Array<{id: string, name: string, duration: number, price: number}>>([]);
|
||||||
|
@@ -8,6 +8,50 @@ interface BookingStatusPageProps {
|
|||||||
|
|
||||||
type BookingStatus = "pending" | "confirmed" | "cancelled" | "completed";
|
type BookingStatus = "pending" | "confirmed" | "cancelled" | "completed";
|
||||||
|
|
||||||
|
interface Treatment {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
duration: number;
|
||||||
|
price: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BookingDetails {
|
||||||
|
id: string;
|
||||||
|
customerName: string;
|
||||||
|
customerEmail?: string;
|
||||||
|
customerPhone?: string;
|
||||||
|
appointmentDate: string;
|
||||||
|
appointmentTime: string;
|
||||||
|
treatments: Treatment[];
|
||||||
|
totalDuration: number;
|
||||||
|
totalPrice: number;
|
||||||
|
status: BookingStatus;
|
||||||
|
notes?: string;
|
||||||
|
formattedDate: string;
|
||||||
|
createdAt: string;
|
||||||
|
canCancel: boolean;
|
||||||
|
hoursUntilAppointment: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RescheduleProposalDetails {
|
||||||
|
booking: {
|
||||||
|
id: string;
|
||||||
|
customerName: string;
|
||||||
|
customerEmail?: string;
|
||||||
|
customerPhone?: string;
|
||||||
|
status: BookingStatus;
|
||||||
|
treatments: Treatment[];
|
||||||
|
totalDuration: number;
|
||||||
|
totalPrice: number;
|
||||||
|
};
|
||||||
|
original: { date: string; time: string };
|
||||||
|
proposed: { date?: string; time?: string };
|
||||||
|
expiresAt: string;
|
||||||
|
hoursUntilExpiry: number;
|
||||||
|
isExpired: boolean;
|
||||||
|
canRespond: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
function getStatusInfo(status: BookingStatus) {
|
function getStatusInfo(status: BookingStatus) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case "pending":
|
case "pending":
|
||||||
@@ -57,7 +101,7 @@ export default function BookingStatusPage({ token }: BookingStatusPageProps) {
|
|||||||
const [showCancelConfirm, setShowCancelConfirm] = useState(false);
|
const [showCancelConfirm, setShowCancelConfirm] = useState(false);
|
||||||
const [isCancelling, setIsCancelling] = useState(false);
|
const [isCancelling, setIsCancelling] = useState(false);
|
||||||
const [cancellationResult, setCancellationResult] = useState<{ success: boolean; message: string; formattedDate?: string } | null>(null);
|
const [cancellationResult, setCancellationResult] = useState<{ success: boolean; message: string; formattedDate?: string } | null>(null);
|
||||||
const [rescheduleProposal, setRescheduleProposal] = useState<any | null>(null);
|
const [rescheduleProposal, setRescheduleProposal] = useState<RescheduleProposalDetails | null>(null);
|
||||||
const [rescheduleResult, setRescheduleResult] = useState<{ success: boolean; message: string } | null>(null);
|
const [rescheduleResult, setRescheduleResult] = useState<{ success: boolean; message: string } | null>(null);
|
||||||
const [isAccepting, setIsAccepting] = useState(false);
|
const [isAccepting, setIsAccepting] = useState(false);
|
||||||
const [isDeclining, setIsDeclining] = useState(false);
|
const [isDeclining, setIsDeclining] = useState(false);
|
||||||
@@ -71,7 +115,7 @@ export default function BookingStatusPage({ token }: BookingStatusPageProps) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Try fetching reschedule proposal if booking not found or error
|
// Try fetching reschedule proposal if booking not found or error
|
||||||
const rescheduleQuery = useQuery({
|
const rescheduleQuery = useQuery<RescheduleProposalDetails>({
|
||||||
...queryClient.cancellation.getRescheduleProposal.queryOptions({ input: { token } }),
|
...queryClient.cancellation.getRescheduleProposal.queryOptions({ input: { token } }),
|
||||||
enabled: !!token && (!!bookingError || !booking),
|
enabled: !!token && (!!bookingError || !booking),
|
||||||
});
|
});
|
||||||
@@ -159,7 +203,7 @@ export default function BookingStatusPage({ token }: BookingStatusPageProps) {
|
|||||||
|
|
||||||
if (oneClickAction === 'accept') {
|
if (oneClickAction === 'accept') {
|
||||||
const confirmAccept = window.confirm(
|
const confirmAccept = window.confirm(
|
||||||
`Möchtest du den neuen Termin am ${rescheduleProposal.proposed.date} um ${rescheduleProposal.proposed.time} Uhr akzeptieren?`
|
`Möchtest du den neuen Termin am ${rescheduleProposal.proposed.date || 'TBD'} um ${rescheduleProposal.proposed.time || 'TBD'} Uhr akzeptieren?`
|
||||||
);
|
);
|
||||||
if (confirmAccept) {
|
if (confirmAccept) {
|
||||||
acceptMutation.mutate({ token });
|
acceptMutation.mutate({ token });
|
||||||
@@ -311,12 +355,56 @@ export default function BookingStatusPage({ token }: BookingStatusPageProps) {
|
|||||||
<div className="border rounded-lg p-4 bg-gray-50">
|
<div className="border rounded-lg p-4 bg-gray-50">
|
||||||
<div className="text-sm text-gray-500 font-semibold mb-1">Aktueller Termin</div>
|
<div className="text-sm text-gray-500 font-semibold mb-1">Aktueller Termin</div>
|
||||||
<div className="text-gray-900 font-medium">{rescheduleProposal.original.date} um {rescheduleProposal.original.time} Uhr</div>
|
<div className="text-gray-900 font-medium">{rescheduleProposal.original.date} um {rescheduleProposal.original.time} Uhr</div>
|
||||||
<div className="text-gray-700 text-sm">{rescheduleProposal.booking.treatmentName}</div>
|
<div className="text-gray-700 text-sm mt-2">
|
||||||
|
{rescheduleProposal.booking.treatments && rescheduleProposal.booking.treatments.length > 0 ? (
|
||||||
|
<>
|
||||||
|
{rescheduleProposal.booking.treatments.length <= 2 ? (
|
||||||
|
rescheduleProposal.booking.treatments.map((t, i) => (
|
||||||
|
<div key={i}>{t.name}</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{rescheduleProposal.booking.treatments.slice(0, 2).map((t, i) => (
|
||||||
|
<div key={i}>{t.name}</div>
|
||||||
|
))}
|
||||||
|
<div className="text-gray-500 italic">+{rescheduleProposal.booking.treatments.length - 2} weitere</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<div className="text-gray-600 mt-1 text-xs">
|
||||||
|
{rescheduleProposal.booking.totalDuration} Min
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<span className="text-gray-400 italic">Keine Behandlungen</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="border rounded-lg p-4 bg-orange-50">
|
<div className="border rounded-lg p-4 bg-orange-50">
|
||||||
<div className="text-sm text-orange-700 font-semibold mb-1">Neuer Vorschlag</div>
|
<div className="text-sm text-orange-700 font-semibold mb-1">Neuer Vorschlag</div>
|
||||||
<div className="text-gray-900 font-medium">{rescheduleProposal.proposed.date} um {rescheduleProposal.proposed.time} Uhr</div>
|
<div className="text-gray-900 font-medium">{rescheduleProposal.proposed.date || 'TBD'} um {rescheduleProposal.proposed.time || 'TBD'} Uhr</div>
|
||||||
<div className="text-gray-700 text-sm">{rescheduleProposal.booking.treatmentName}</div>
|
<div className="text-gray-700 text-sm mt-2">
|
||||||
|
{rescheduleProposal.booking.treatments && rescheduleProposal.booking.treatments.length > 0 ? (
|
||||||
|
<>
|
||||||
|
{rescheduleProposal.booking.treatments.length <= 2 ? (
|
||||||
|
rescheduleProposal.booking.treatments.map((t, i) => (
|
||||||
|
<div key={i}>{t.name}</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{rescheduleProposal.booking.treatments.slice(0, 2).map((t, i) => (
|
||||||
|
<div key={i}>{t.name}</div>
|
||||||
|
))}
|
||||||
|
<div className="text-gray-500 italic">+{rescheduleProposal.booking.treatments.length - 2} weitere</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<div className="text-gray-600 mt-1 text-xs">
|
||||||
|
{rescheduleProposal.booking.totalDuration} Min
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<span className="text-gray-400 italic">Keine Behandlungen</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-4 bg-yellow-50 border border-yellow-200 rounded-lg p-3 text-sm text-yellow-800">
|
<div className="mt-4 bg-yellow-50 border border-yellow-200 rounded-lg p-3 text-sm text-yellow-800">
|
||||||
@@ -478,20 +566,44 @@ export default function BookingStatusPage({ token }: BookingStatusPageProps) {
|
|||||||
<span className="text-gray-600">Uhrzeit:</span>
|
<span className="text-gray-600">Uhrzeit:</span>
|
||||||
<span className="font-medium text-gray-900">{booking?.appointmentTime} Uhr</span>
|
<span className="font-medium text-gray-900">{booking?.appointmentTime} Uhr</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between py-2 border-b border-gray-100">
|
|
||||||
<span className="text-gray-600">Behandlung:</span>
|
{/* Treatments List */}
|
||||||
<span className="font-medium text-gray-900">{booking?.treatmentName}</span>
|
<div className="py-2 border-b border-gray-100">
|
||||||
|
<div className="text-gray-600 mb-2">Behandlungen:</div>
|
||||||
|
{booking?.treatments && booking.treatments.length > 0 ? (
|
||||||
|
<div className="bg-gray-50 rounded-lg p-3 space-y-2">
|
||||||
|
{booking.treatments.map((treatment, index) => (
|
||||||
|
<div key={index} className="flex justify-between items-center text-sm">
|
||||||
|
<span className="font-medium text-gray-900">• {treatment.name}</span>
|
||||||
|
<span className="text-gray-600">
|
||||||
|
{treatment.duration} Min - {treatment.price.toFixed(2)} €
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between py-2 border-b border-gray-100">
|
))}
|
||||||
<span className="text-gray-600">Dauer:</span>
|
<div className="flex justify-between items-center pt-2 mt-2 border-t border-gray-200 font-semibold">
|
||||||
<span className="font-medium text-gray-900">{booking?.treatmentDuration} Minuten</span>
|
<span className="text-gray-900">Gesamt:</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{booking.totalDuration} Min - {booking.totalPrice.toFixed(2)} €
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<span className="text-gray-400 text-sm italic">Keine Behandlungen angegeben</span>
|
||||||
|
{((booking?.totalDuration ?? 0) > 0 || (booking?.totalPrice ?? 0) > 0) && (
|
||||||
|
<div className="bg-gray-50 rounded-lg p-3">
|
||||||
|
<div className="flex justify-between items-center font-semibold text-sm">
|
||||||
|
<span className="text-gray-900">Gesamt:</span>
|
||||||
|
<span className="text-gray-900">
|
||||||
|
{booking?.totalDuration ?? 0} Min - {(booking?.totalPrice ?? 0).toFixed(2)} €
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{booking?.treatmentPrice && booking.treatmentPrice > 0 && (
|
|
||||||
<div className="flex justify-between py-2 border-b border-gray-100">
|
|
||||||
<span className="text-gray-600">Preis:</span>
|
|
||||||
<span className="font-medium text-gray-900">{booking.treatmentPrice.toFixed(2)} €</span>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{booking?.hoursUntilAppointment && booking.hoursUntilAppointment > 0 && booking.status !== "cancelled" && booking.status !== "completed" && (
|
{booking?.hoursUntilAppointment && booking.hoursUntilAppointment > 0 && booking.status !== "cancelled" && booking.status !== "completed" && (
|
||||||
<div className="flex justify-between py-2">
|
<div className="flex justify-between py-2">
|
||||||
<span className="text-gray-600">Verbleibende Zeit:</span>
|
<span className="text-gray-600">Verbleibende Zeit:</span>
|
||||||
|
@@ -139,7 +139,11 @@ export default function ReviewSubmissionPage({ token }: ReviewSubmissionPageProp
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between py-2 border-b border-gray-100">
|
<div className="flex justify-between py-2 border-b border-gray-100">
|
||||||
<span className="text-gray-600">Behandlung:</span>
|
<span className="text-gray-600">Behandlung:</span>
|
||||||
<span className="font-medium text-gray-900">{booking.treatmentName}</span>
|
<span className="font-medium text-gray-900">
|
||||||
|
{booking.treatments && booking.treatments.length > 0
|
||||||
|
? booking.treatments.map((t: any) => t.name).join(", ")
|
||||||
|
: "Keine Behandlung"}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between py-2">
|
<div className="flex justify-between py-2">
|
||||||
<span className="text-gray-600">Name:</span>
|
<span className="text-gray-600">Name:</span>
|
||||||
|
@@ -14,12 +14,12 @@ function renderTreatmentList(
|
|||||||
options: { showPrices: boolean } = { showPrices: true }
|
options: { showPrices: boolean } = { showPrices: true }
|
||||||
): string {
|
): string {
|
||||||
const totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0);
|
const totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
const totalPrice = treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
const treatmentItems = treatments.map(t =>
|
const treatmentItems = treatments.map(t =>
|
||||||
options.showPrices
|
options.showPrices
|
||||||
? `<li><strong>${t.name}</strong> - ${t.duration} Min - ${t.price.toFixed(2)} €</li>`
|
? `<li><strong>${t.name}</strong> - ${t.duration} Min - ${(t.price / 100).toFixed(2)} €</li>`
|
||||||
: `<li>${t.name} - ${t.duration} Min - ${t.price.toFixed(2)} €</li>`
|
: `<li>${t.name} - ${t.duration} Min - ${(t.price / 100).toFixed(2)} €</li>`
|
||||||
).join('');
|
).join('');
|
||||||
|
|
||||||
const totalLine = options.showPrices
|
const totalLine = options.showPrices
|
||||||
|
@@ -72,10 +72,10 @@ function createICSFile(params: {
|
|||||||
// Build treatments list for SUMMARY and DESCRIPTION
|
// Build treatments list for SUMMARY and DESCRIPTION
|
||||||
const treatmentNames = icsEscape(treatments.map(t => t.name).join(', '));
|
const treatmentNames = icsEscape(treatments.map(t => t.name).join(', '));
|
||||||
const totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0);
|
const totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
const totalPrice = treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
const treatmentDetails = treatments.map(t =>
|
const treatmentDetails = treatments.map(t =>
|
||||||
`${icsEscape(t.name)} (${t.duration} Min, ${t.price.toFixed(2)} EUR)`
|
`${icsEscape(t.name)} (${t.duration} Min, ${(t.price / 100).toFixed(2)} EUR)`
|
||||||
).join('\\n');
|
).join('\\n');
|
||||||
|
|
||||||
const description = `Behandlungen:\\n${treatmentDetails}\\n\\nGesamt: ${totalDuration} Min, ${totalPrice.toFixed(2)} EUR\\n\\nTermin bei Stargirlnails Kiel`;
|
const description = `Behandlungen:\\n${treatmentDetails}\\n\\nGesamt: ${totalDuration} Min, ${totalPrice.toFixed(2)} EUR\\n\\nTermin bei Stargirlnails Kiel`;
|
||||||
|
@@ -5,7 +5,7 @@ import { assertOwner } from "../lib/auth.js";
|
|||||||
// Types für Buchungen (vereinfacht für CalDAV)
|
// Types für Buchungen (vereinfacht für CalDAV)
|
||||||
type Booking = {
|
type Booking = {
|
||||||
id: string;
|
id: string;
|
||||||
treatmentId: string;
|
treatments?: Array<{id: string, name: string, duration: number, price: number}>;
|
||||||
customerName: string;
|
customerName: string;
|
||||||
customerEmail?: string;
|
customerEmail?: string;
|
||||||
customerPhone?: string;
|
customerPhone?: string;
|
||||||
@@ -13,6 +13,8 @@ type Booking = {
|
|||||||
appointmentTime: string; // HH:MM
|
appointmentTime: string; // HH:MM
|
||||||
status: "pending" | "confirmed" | "cancelled" | "completed";
|
status: "pending" | "confirmed" | "cancelled" | "completed";
|
||||||
notes?: string;
|
notes?: string;
|
||||||
|
// Deprecated fields for backward compatibility
|
||||||
|
treatmentId?: string;
|
||||||
bookedDurationMinutes?: number;
|
bookedDurationMinutes?: number;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
};
|
};
|
||||||
@@ -44,6 +46,14 @@ function formatDateTime(dateStr: string, timeStr: string): string {
|
|||||||
return date.toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
|
return date.toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addMinutesToTime(timeStr: string, minutesToAdd: number): string {
|
||||||
|
const [hours, minutes] = timeStr.split(':').map(Number);
|
||||||
|
const totalMinutes = hours * 60 + minutes + minutesToAdd;
|
||||||
|
const newHours = Math.floor(totalMinutes / 60);
|
||||||
|
const newMinutes = totalMinutes % 60;
|
||||||
|
return `${String(newHours).padStart(2, '0')}:${String(newMinutes).padStart(2, '0')}`;
|
||||||
|
}
|
||||||
|
|
||||||
function generateICSContent(bookings: Booking[], treatments: Treatment[]): string {
|
function generateICSContent(bookings: Booking[], treatments: Treatment[]): string {
|
||||||
const now = new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
|
const now = new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
|
||||||
|
|
||||||
@@ -63,14 +73,41 @@ X-WR-TIMEZONE:Europe/Berlin
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (const booking of activeBookings) {
|
for (const booking of activeBookings) {
|
||||||
const treatment = treatments.find(t => t.id === booking.treatmentId);
|
// Handle new treatments array structure
|
||||||
const treatmentName = treatment?.name || 'Unbekannte Behandlung';
|
let treatmentNames: string;
|
||||||
const duration = booking.bookedDurationMinutes || treatment?.duration || 60;
|
let duration: number;
|
||||||
|
let treatmentDetails: string;
|
||||||
|
let totalPrice = 0;
|
||||||
|
|
||||||
|
if (booking.treatments && Array.isArray(booking.treatments) && booking.treatments.length > 0) {
|
||||||
|
// Use new treatments array
|
||||||
|
treatmentNames = booking.treatments.map(t => t.name).join(', ');
|
||||||
|
|
||||||
|
duration = booking.treatments.reduce((sum, t) => sum + (t.duration || 0), 0);
|
||||||
|
totalPrice = booking.treatments.reduce((sum, t) => sum + ((t.price || 0) / 100), 0);
|
||||||
|
|
||||||
|
// Build detailed treatment list for description
|
||||||
|
treatmentDetails = booking.treatments
|
||||||
|
.map(t => `- ${t.name} (${t.duration} Min., ${(t.price / 100).toFixed(2)}€)`)
|
||||||
|
.join('\\n');
|
||||||
|
|
||||||
|
if (booking.treatments.length > 1) {
|
||||||
|
treatmentDetails += `\\n\\nGesamt: ${duration} Min., ${totalPrice.toFixed(2)}€`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback to deprecated treatmentId for backward compatibility
|
||||||
|
const treatment = booking.treatmentId ? treatments.find(t => t.id === booking.treatmentId) : null;
|
||||||
|
treatmentNames = treatment?.name || 'Unbekannte Behandlung';
|
||||||
|
duration = booking.bookedDurationMinutes || treatment?.duration || 60;
|
||||||
|
treatmentDetails = `Behandlung: ${treatmentNames}`;
|
||||||
|
if (treatment?.price) {
|
||||||
|
treatmentDetails += ` (${duration} Min., ${(treatment.price / 100).toFixed(2)}€)`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const startTime = formatDateTime(booking.appointmentDate, booking.appointmentTime);
|
const startTime = formatDateTime(booking.appointmentDate, booking.appointmentTime);
|
||||||
const endTime = formatDateTime(booking.appointmentDate,
|
const endTimeStr = addMinutesToTime(booking.appointmentTime, duration);
|
||||||
`${String(Math.floor((parseInt(booking.appointmentTime.split(':')[0]) * 60 + parseInt(booking.appointmentTime.split(':')[1]) + duration) / 60)).padStart(2, '0')}:${String((parseInt(booking.appointmentTime.split(':')[0]) * 60 + parseInt(booking.appointmentTime.split(':')[1]) + duration) % 60).padStart(2, '0')}`
|
const endTime = formatDateTime(booking.appointmentDate, endTimeStr);
|
||||||
);
|
|
||||||
|
|
||||||
// UID für jeden Termin (eindeutig)
|
// UID für jeden Termin (eindeutig)
|
||||||
const uid = `booking-${booking.id}@stargirlnails.de`;
|
const uid = `booking-${booking.id}@stargirlnails.de`;
|
||||||
@@ -83,8 +120,8 @@ UID:${uid}
|
|||||||
DTSTAMP:${now}
|
DTSTAMP:${now}
|
||||||
DTSTART:${startTime}
|
DTSTART:${startTime}
|
||||||
DTEND:${endTime}
|
DTEND:${endTime}
|
||||||
SUMMARY:${treatmentName} - ${booking.customerName}
|
SUMMARY:${treatmentNames} - ${booking.customerName}
|
||||||
DESCRIPTION:Behandlung: ${treatmentName}\\nKunde: ${booking.customerName}${booking.customerPhone ? `\\nTelefon: ${booking.customerPhone}` : ''}${booking.notes ? `\\nNotizen: ${booking.notes}` : ''}
|
DESCRIPTION:${treatmentDetails}\\n\\nKunde: ${booking.customerName}${booking.customerPhone ? `\\nTelefon: ${booking.customerPhone}` : ''}${booking.notes ? `\\nNotizen: ${booking.notes}` : ''}
|
||||||
STATUS:${status}
|
STATUS:${status}
|
||||||
TRANSP:OPAQUE
|
TRANSP:OPAQUE
|
||||||
END:VEVENT
|
END:VEVENT
|
||||||
|
@@ -367,9 +367,9 @@ const create = os
|
|||||||
treatments: input.treatments
|
treatments: input.treatments
|
||||||
});
|
});
|
||||||
|
|
||||||
const treatmentsText = input.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n');
|
const treatmentsText = input.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n');
|
||||||
const totalDuration = input.treatments.reduce((sum, t) => sum + t.duration, 0);
|
const totalDuration = input.treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
const totalPrice = input.treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = input.treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
await sendEmail({
|
await sendEmail({
|
||||||
to: input.customerEmail,
|
to: input.customerEmail,
|
||||||
@@ -394,9 +394,9 @@ const create = os
|
|||||||
});
|
});
|
||||||
|
|
||||||
const homepageUrl = generateUrl();
|
const homepageUrl = generateUrl();
|
||||||
const treatmentsText = input.treatments.map(t => ` - ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n');
|
const treatmentsText = input.treatments.map(t => ` - ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n');
|
||||||
const totalDuration = input.treatments.reduce((sum, t) => sum + t.duration, 0);
|
const totalDuration = input.treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
const totalPrice = input.treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = input.treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
const adminText = `Neue Buchungsanfrage eingegangen:\n\n` +
|
const adminText = `Neue Buchungsanfrage eingegangen:\n\n` +
|
||||||
`Name: ${input.customerName}\n` +
|
`Name: ${input.customerName}\n` +
|
||||||
@@ -483,9 +483,9 @@ const updateStatus = os
|
|||||||
treatments: booking.treatments
|
treatments: booking.treatments
|
||||||
});
|
});
|
||||||
|
|
||||||
const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n');
|
const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n');
|
||||||
const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0);
|
const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
const totalPrice = booking.treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = booking.treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
if (booking.customerEmail) {
|
if (booking.customerEmail) {
|
||||||
await sendEmailWithAGBAndCalendar({
|
await sendEmailWithAGBAndCalendar({
|
||||||
@@ -512,9 +512,9 @@ const updateStatus = os
|
|||||||
treatments: booking.treatments
|
treatments: booking.treatments
|
||||||
});
|
});
|
||||||
|
|
||||||
const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n');
|
const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n');
|
||||||
const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0);
|
const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
const totalPrice = booking.treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = booking.treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
if (booking.customerEmail) {
|
if (booking.customerEmail) {
|
||||||
await sendEmail({
|
await sendEmail({
|
||||||
@@ -571,9 +571,9 @@ const remove = os
|
|||||||
treatments: booking.treatments
|
treatments: booking.treatments
|
||||||
});
|
});
|
||||||
|
|
||||||
const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n');
|
const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n');
|
||||||
const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0);
|
const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
const totalPrice = booking.treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = booking.treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
await sendEmail({
|
await sendEmail({
|
||||||
to: booking.customerEmail,
|
to: booking.customerEmail,
|
||||||
@@ -693,8 +693,8 @@ const createManual = os
|
|||||||
treatments: input.treatments
|
treatments: input.treatments
|
||||||
});
|
});
|
||||||
|
|
||||||
const treatmentsText = input.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n');
|
const treatmentsText = input.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n');
|
||||||
const totalPrice = input.treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = input.treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
await sendEmailWithAGBAndCalendar({
|
await sendEmailWithAGBAndCalendar({
|
||||||
to: input.customerEmail!,
|
to: input.customerEmail!,
|
||||||
@@ -874,8 +874,8 @@ export const router = {
|
|||||||
treatments: updated.treatments,
|
treatments: updated.treatments,
|
||||||
});
|
});
|
||||||
|
|
||||||
const treatmentsText = updated.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n');
|
const treatmentsText = updated.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n');
|
||||||
const totalPrice = updated.treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = updated.treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
await sendEmailWithAGBAndCalendar({
|
await sendEmailWithAGBAndCalendar({
|
||||||
to: updated.customerEmail,
|
to: updated.customerEmail,
|
||||||
@@ -929,9 +929,9 @@ export const router = {
|
|||||||
if (booking.customerEmail) {
|
if (booking.customerEmail) {
|
||||||
const bookingAccessToken = await queryClient.cancellation.createToken({ bookingId: booking.id });
|
const bookingAccessToken = await queryClient.cancellation.createToken({ bookingId: booking.id });
|
||||||
|
|
||||||
const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n');
|
const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n');
|
||||||
const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0);
|
const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
const totalPrice = booking.treatments.reduce((sum, t) => sum + t.price, 0);
|
const totalPrice = booking.treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
|
||||||
await sendEmail({
|
await sendEmail({
|
||||||
to: booking.customerEmail,
|
to: booking.customerEmail,
|
||||||
|
@@ -28,7 +28,15 @@ const cancellationKV = createKV<BookingAccessToken>("cancellation_tokens");
|
|||||||
// Types for booking and availability
|
// Types for booking and availability
|
||||||
type Booking = {
|
type Booking = {
|
||||||
id: string;
|
id: string;
|
||||||
treatmentId: string;
|
treatments: Array<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
duration: number;
|
||||||
|
price: number;
|
||||||
|
}>;
|
||||||
|
// Deprecated fields for backward compatibility
|
||||||
|
treatmentId?: string;
|
||||||
|
bookedDurationMinutes?: number;
|
||||||
customerName: string;
|
customerName: string;
|
||||||
customerEmail?: string;
|
customerEmail?: string;
|
||||||
customerPhone?: string;
|
customerPhone?: string;
|
||||||
@@ -120,10 +128,43 @@ const getBookingByToken = os
|
|||||||
throw new Error("Booking not found");
|
throw new Error("Booking not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get treatment details
|
// Handle treatments array
|
||||||
|
let treatments: Array<{id: string; name: string; duration: number; price: number}>;
|
||||||
|
let totalDuration: number;
|
||||||
|
let totalPrice: number;
|
||||||
|
|
||||||
|
if (booking.treatments && booking.treatments.length > 0) {
|
||||||
|
// New bookings with treatments array
|
||||||
|
treatments = booking.treatments;
|
||||||
|
totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
|
totalPrice = treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
} else if (booking.treatmentId) {
|
||||||
|
// Old bookings with single treatmentId (backward compatibility)
|
||||||
const treatmentsKV = createKV<any>("treatments");
|
const treatmentsKV = createKV<any>("treatments");
|
||||||
const treatment = await treatmentsKV.getItem(booking.treatmentId);
|
const treatment = await treatmentsKV.getItem(booking.treatmentId);
|
||||||
|
|
||||||
|
if (treatment) {
|
||||||
|
treatments = [{
|
||||||
|
id: treatment.id,
|
||||||
|
name: treatment.name,
|
||||||
|
duration: treatment.duration,
|
||||||
|
price: treatment.price,
|
||||||
|
}];
|
||||||
|
totalDuration = treatment.duration;
|
||||||
|
totalPrice = treatment.price / 100;
|
||||||
|
} else {
|
||||||
|
// Fallback if treatment not found
|
||||||
|
treatments = [];
|
||||||
|
totalDuration = booking.bookedDurationMinutes || 60;
|
||||||
|
totalPrice = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Edge case: no treatments and no treatmentId
|
||||||
|
treatments = [];
|
||||||
|
totalDuration = 0;
|
||||||
|
totalPrice = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate if cancellation is still possible
|
// Calculate if cancellation is still possible
|
||||||
const minStornoTimespan = parseInt(process.env.MIN_STORNO_TIMESPAN || "24");
|
const minStornoTimespan = parseInt(process.env.MIN_STORNO_TIMESPAN || "24");
|
||||||
const appointmentDateTime = new Date(`${booking.appointmentDate}T${booking.appointmentTime}:00`);
|
const appointmentDateTime = new Date(`${booking.appointmentDate}T${booking.appointmentTime}:00`);
|
||||||
@@ -140,10 +181,9 @@ const getBookingByToken = os
|
|||||||
customerPhone: booking.customerPhone,
|
customerPhone: booking.customerPhone,
|
||||||
appointmentDate: booking.appointmentDate,
|
appointmentDate: booking.appointmentDate,
|
||||||
appointmentTime: booking.appointmentTime,
|
appointmentTime: booking.appointmentTime,
|
||||||
treatmentId: booking.treatmentId,
|
treatments,
|
||||||
treatmentName: treatment?.name || "Unbekannte Behandlung",
|
totalDuration,
|
||||||
treatmentDuration: treatment?.duration || 60,
|
totalPrice,
|
||||||
treatmentPrice: treatment?.price || 0,
|
|
||||||
status: booking.status,
|
status: booking.status,
|
||||||
notes: booking.notes,
|
notes: booking.notes,
|
||||||
formattedDate: formatDateGerman(booking.appointmentDate),
|
formattedDate: formatDateGerman(booking.appointmentDate),
|
||||||
@@ -284,9 +324,43 @@ export const router = {
|
|||||||
throw new Error("Booking not found");
|
throw new Error("Booking not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle treatments array
|
||||||
|
let treatments: Array<{id: string; name: string; duration: number; price: number}>;
|
||||||
|
let totalDuration: number;
|
||||||
|
let totalPrice: number;
|
||||||
|
|
||||||
|
if (booking.treatments && booking.treatments.length > 0) {
|
||||||
|
// New bookings with treatments array
|
||||||
|
treatments = booking.treatments;
|
||||||
|
totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0);
|
||||||
|
totalPrice = treatments.reduce((sum, t) => sum + (t.price / 100), 0);
|
||||||
|
} else if (booking.treatmentId) {
|
||||||
|
// Old bookings with single treatmentId (backward compatibility)
|
||||||
const treatmentsKV = createKV<any>("treatments");
|
const treatmentsKV = createKV<any>("treatments");
|
||||||
const treatment = await treatmentsKV.getItem(booking.treatmentId);
|
const treatment = await treatmentsKV.getItem(booking.treatmentId);
|
||||||
|
|
||||||
|
if (treatment) {
|
||||||
|
treatments = [{
|
||||||
|
id: treatment.id,
|
||||||
|
name: treatment.name,
|
||||||
|
duration: treatment.duration,
|
||||||
|
price: treatment.price,
|
||||||
|
}];
|
||||||
|
totalDuration = treatment.duration;
|
||||||
|
totalPrice = treatment.price / 100;
|
||||||
|
} else {
|
||||||
|
// Fallback if treatment not found
|
||||||
|
treatments = [];
|
||||||
|
totalDuration = booking.bookedDurationMinutes || 60;
|
||||||
|
totalPrice = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Edge case: no treatments and no treatmentId
|
||||||
|
treatments = [];
|
||||||
|
totalDuration = 0;
|
||||||
|
totalPrice = 0;
|
||||||
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const isExpired = new Date(proposal.expiresAt) <= now;
|
const isExpired = new Date(proposal.expiresAt) <= now;
|
||||||
const hoursUntilExpiry = isExpired ? 0 : Math.max(0, Math.round((new Date(proposal.expiresAt).getTime() - now.getTime()) / (1000 * 60 * 60)));
|
const hoursUntilExpiry = isExpired ? 0 : Math.max(0, Math.round((new Date(proposal.expiresAt).getTime() - now.getTime()) / (1000 * 60 * 60)));
|
||||||
@@ -298,8 +372,9 @@ export const router = {
|
|||||||
customerEmail: booking.customerEmail,
|
customerEmail: booking.customerEmail,
|
||||||
customerPhone: booking.customerPhone,
|
customerPhone: booking.customerPhone,
|
||||||
status: booking.status,
|
status: booking.status,
|
||||||
treatmentId: booking.treatmentId,
|
treatments,
|
||||||
treatmentName: treatment?.name || "Unbekannte Behandlung",
|
totalDuration,
|
||||||
|
totalPrice,
|
||||||
},
|
},
|
||||||
original: {
|
original: {
|
||||||
date: proposal.originalDate || booking.appointmentDate,
|
date: proposal.originalDate || booking.appointmentDate,
|
||||||
@@ -358,14 +433,22 @@ export const router = {
|
|||||||
const booking = await bookingsKV.getItem(proposal.bookingId);
|
const booking = await bookingsKV.getItem(proposal.bookingId);
|
||||||
if (booking) {
|
if (booking) {
|
||||||
const treatmentsKV = createKV<any>("treatments");
|
const treatmentsKV = createKV<any>("treatments");
|
||||||
|
// Get treatment name(s) from new treatments array or fallback to deprecated treatmentId
|
||||||
|
let treatmentName = "Unbekannte Behandlung";
|
||||||
|
if (booking.treatments && Array.isArray(booking.treatments) && booking.treatments.length > 0) {
|
||||||
|
treatmentName = booking.treatments.map((t: any) => t.name).join(", ");
|
||||||
|
} else if (booking.treatmentId) {
|
||||||
const treatment = await treatmentsKV.getItem(booking.treatmentId);
|
const treatment = await treatmentsKV.getItem(booking.treatmentId);
|
||||||
|
treatmentName = treatment?.name || "Unbekannte Behandlung";
|
||||||
|
}
|
||||||
|
|
||||||
expiredDetails.push({
|
expiredDetails.push({
|
||||||
customerName: booking.customerName,
|
customerName: booking.customerName,
|
||||||
originalDate: proposal.originalDate || booking.appointmentDate,
|
originalDate: proposal.originalDate || booking.appointmentDate,
|
||||||
originalTime: proposal.originalTime || booking.appointmentTime,
|
originalTime: proposal.originalTime || booking.appointmentTime,
|
||||||
proposedDate: proposal.proposedDate!,
|
proposedDate: proposal.proposedDate!,
|
||||||
proposedTime: proposal.proposedTime!,
|
proposedTime: proposal.proposedTime!,
|
||||||
treatmentName: treatment?.name || "Unbekannte Behandlung",
|
treatmentName: treatmentName,
|
||||||
customerEmail: booking.customerEmail,
|
customerEmail: booking.customerEmail,
|
||||||
customerPhone: booking.customerPhone,
|
customerPhone: booking.customerPhone,
|
||||||
expiredAt: proposal.expiresAt,
|
expiredAt: proposal.expiresAt,
|
||||||
|
Reference in New Issue
Block a user