* feat(companion): add native iOS UI components for modals and pickers - Add LogoutConfirmModal.ios.tsx using native Alert.alert() - Add BookingModals.ios.tsx using native Alert.prompt() for reject modal - Add RescheduleScreen.ios.tsx using @expo/ui/swift-ui DateTimePicker These iOS-specific implementations provide native glass UI experience instead of custom React Native modals. * fix(companion): use correct DatePicker API from @expo/ui/swift-ui - Change import from DateTimePicker to DatePicker - Use onDateChange instead of onDateSelected - Use displayedComponents as array instead of string - Use selection instead of initialDate * feat(companion): add native Android DateTimePicker for RescheduleScreen - Use @expo/ui/jetpack-compose DateTimePicker for native Android date/time selection - Use variant='picker' with showVariantToggle=false for consistent UI - Use displayedComponents='date' for date picker and 'hourAndMinute' for time picker - Use is24Hour=true for 24-hour time format * Revert "feat(companion): add native Android DateTimePicker for RescheduleScreen" This reverts commit 95677679c2e86889b935e658fac011ae9669fa10. * adjust date and time picker for ios, and use native ios ui for delete event type * feat(companion): add native Android DateTimePicker and web HTML inputs for RescheduleScreen - Add RescheduleScreen.android.tsx using @react-native-community/datetimepicker for native Android date/time pickers - Update RescheduleScreen.tsx to use native HTML date/time inputs on web/extension - Install @react-native-community/datetimepicker package * fix lint errors * use expos date and time picker for android * address cubics comments * remove dependancy causing android build fail * fix versions * custom date and time picker for android * fix react compiler memo issue * address cubics commments * feat(companion): convert booking action pages to native iOS bottom sheets (#26366) * feat(companion): add native iOS bottom sheet for meeting session details * move file to correct location, remove bg and use glass ui bg * feat(companion): convert booking action pages to iOS bottom sheets - Add iOS-specific bottom sheet implementations for: - edit-location (detents: 0.5, 0.7) - mark-no-show (detents: 0.4, 0.6) - view-recordings (detents: 0.7, 0.9) - add-guests (detents: 0.6, 0.8) - reschedule (detents: 0.8, 0.95) - Move route files from (tabs)/(bookings)/ to root app/ level - Register screens in root _layout.tsx with platform-specific options - Update navigation paths from nested to root level - Remove migrated screens from bookings _layout.tsx * updated booking actions pages to use glass ui bottom sheet * new ui for booking actions ready * add biome file * fix event type detail react compiler issue * update button style * fix black flash ui * use glass ui buttons for Availability and event type detail page * fix lint issue * address cubics comments * make booking actions ui transparent * remove black flash and keep transparent ui --------- Co-authored-by: Volnei Munhoz <[email protected]>
442 lines
12 KiB
TypeScript
442 lines
12 KiB
TypeScript
import type { useRouter } from "expo-router";
|
|
import { useState } from "react";
|
|
import { Alert } from "react-native";
|
|
import type { Booking } from "@/services/calcom";
|
|
import { showErrorAlert } from "@/utils/alerts";
|
|
|
|
interface UseBookingActionsParams {
|
|
router: ReturnType<typeof useRouter>;
|
|
cancelMutation: (
|
|
params: { uid: string; reason: string },
|
|
options?: {
|
|
onSuccess?: () => void;
|
|
onError?: (error: Error) => void;
|
|
}
|
|
) => void;
|
|
confirmMutation: (
|
|
params: { uid: string },
|
|
options?: {
|
|
onSuccess?: () => void;
|
|
onError?: (error: Error) => void;
|
|
}
|
|
) => void;
|
|
declineMutation: (
|
|
params: { uid: string; reason?: string },
|
|
options?: {
|
|
onSuccess?: () => void;
|
|
onError?: (error: Error) => void;
|
|
}
|
|
) => void;
|
|
rescheduleMutation: (
|
|
params: { uid: string; start: string; reschedulingReason?: string },
|
|
options?: {
|
|
onSuccess?: () => void;
|
|
onError?: (error: Error) => void;
|
|
}
|
|
) => void;
|
|
isConfirming: boolean;
|
|
isDeclining: boolean;
|
|
isRescheduling: boolean;
|
|
}
|
|
|
|
export const useBookingActions = ({
|
|
router,
|
|
cancelMutation,
|
|
confirmMutation,
|
|
declineMutation,
|
|
rescheduleMutation,
|
|
isConfirming,
|
|
isDeclining,
|
|
isRescheduling,
|
|
}: UseBookingActionsParams) => {
|
|
// Reschedule modal state
|
|
const [showRescheduleModal, setShowRescheduleModal] = useState(false);
|
|
const [rescheduleBooking, setRescheduleBooking] = useState<Booking | null>(null);
|
|
const [rescheduleDate, setRescheduleDate] = useState("");
|
|
const [rescheduleTime, setRescheduleTime] = useState("");
|
|
const [rescheduleReason, setRescheduleReason] = useState("");
|
|
|
|
// Reject modal state
|
|
const [showRejectModal, setShowRejectModal] = useState(false);
|
|
const [rejectBooking, setRejectBooking] = useState<Booking | null>(null);
|
|
const [rejectReason, setRejectReason] = useState("");
|
|
|
|
// Selected booking for actions modal
|
|
const [selectedBooking, setSelectedBooking] = useState<Booking | null>(null);
|
|
|
|
/**
|
|
* Navigate to booking detail page
|
|
*/
|
|
const handleBookingPress = (booking: Booking) => {
|
|
router.push({
|
|
pathname: "/(tabs)/(bookings)/booking-detail",
|
|
params: { uid: booking.uid },
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Open reschedule modal with pre-filled data
|
|
*/
|
|
const handleRescheduleBooking = (booking: Booking) => {
|
|
// Get the start time from booking (prefer startTime, fallback to start)
|
|
const startTimeValue = booking.startTime || booking.start;
|
|
|
|
// Validate we have a valid date
|
|
if (!startTimeValue) {
|
|
showErrorAlert("Error", "Unable to reschedule: booking has no start time");
|
|
return;
|
|
}
|
|
|
|
const currentDate = new Date(startTimeValue);
|
|
|
|
// Check if the date is valid
|
|
if (Number.isNaN(currentDate.getTime())) {
|
|
showErrorAlert("Error", "Unable to reschedule: invalid booking date");
|
|
return;
|
|
}
|
|
|
|
// Use local timezone consistently (not UTC) to avoid date/time mismatch
|
|
const year = currentDate.getFullYear();
|
|
const month = String(currentDate.getMonth() + 1).padStart(2, "0");
|
|
const day = String(currentDate.getDate()).padStart(2, "0");
|
|
const hours = String(currentDate.getHours()).padStart(2, "0");
|
|
const minutes = String(currentDate.getMinutes()).padStart(2, "0");
|
|
|
|
const dateStr = `${year}-${month}-${day}`;
|
|
const timeStr = `${hours}:${minutes}`;
|
|
|
|
setRescheduleBooking(booking);
|
|
setRescheduleDate(dateStr);
|
|
setRescheduleTime(timeStr);
|
|
setRescheduleReason("");
|
|
setShowRescheduleModal(true);
|
|
};
|
|
|
|
/**
|
|
* Validate and submit reschedule request (uses internal state)
|
|
*/
|
|
const handleSubmitReschedule = () => {
|
|
if (!rescheduleBooking || !rescheduleDate || !rescheduleTime) {
|
|
showErrorAlert("Error", "Please enter both date and time");
|
|
return;
|
|
}
|
|
|
|
// Parse the date and time
|
|
const dateTimeStr = `${rescheduleDate}T${rescheduleTime}:00`;
|
|
const newDateTime = new Date(dateTimeStr);
|
|
|
|
// Validate the date
|
|
if (Number.isNaN(newDateTime.getTime())) {
|
|
showErrorAlert(
|
|
"Error",
|
|
"Invalid date or time format. Please use YYYY-MM-DD for date and HH:MM for time."
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Check if the new time is in the future
|
|
if (newDateTime <= new Date()) {
|
|
showErrorAlert("Error", "Please select a future date and time");
|
|
return;
|
|
}
|
|
|
|
// Convert to UTC ISO string
|
|
const startUtc = newDateTime.toISOString();
|
|
|
|
rescheduleMutation(
|
|
{
|
|
uid: rescheduleBooking.uid,
|
|
start: startUtc,
|
|
reschedulingReason: rescheduleReason || undefined,
|
|
},
|
|
{
|
|
onSuccess: () => {
|
|
setShowRescheduleModal(false);
|
|
setRescheduleBooking(null);
|
|
Alert.alert("Success", "Booking rescheduled successfully");
|
|
},
|
|
onError: (error) => {
|
|
showErrorAlert("Error", error.message || "Failed to reschedule booking");
|
|
},
|
|
}
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Submit reschedule with provided values (used by RescheduleModal component)
|
|
*/
|
|
const handleRescheduleWithValues = async (
|
|
date: string,
|
|
time: string,
|
|
reason?: string
|
|
): Promise<void> => {
|
|
if (!rescheduleBooking) {
|
|
throw new Error("No booking selected");
|
|
}
|
|
|
|
// Parse the date and time
|
|
const dateTimeStr = `${date}T${time}:00`;
|
|
const newDateTime = new Date(dateTimeStr);
|
|
|
|
// Validate the date
|
|
if (Number.isNaN(newDateTime.getTime())) {
|
|
throw new Error(
|
|
"Invalid date or time format. Please use YYYY-MM-DD for date and HH:MM for time."
|
|
);
|
|
}
|
|
|
|
// Check if the new time is in the future
|
|
if (newDateTime <= new Date()) {
|
|
throw new Error("Please select a future date and time");
|
|
}
|
|
|
|
// Convert to UTC ISO string
|
|
const startUtc = newDateTime.toISOString();
|
|
|
|
return new Promise((resolve, reject) => {
|
|
rescheduleMutation(
|
|
{
|
|
uid: rescheduleBooking.uid,
|
|
start: startUtc,
|
|
reschedulingReason: reason || undefined,
|
|
},
|
|
{
|
|
onSuccess: () => {
|
|
setShowRescheduleModal(false);
|
|
setRescheduleBooking(null);
|
|
Alert.alert("Success", "Booking rescheduled successfully");
|
|
resolve();
|
|
},
|
|
onError: (error) => {
|
|
reject(new Error(error.message || "Failed to reschedule booking"));
|
|
},
|
|
}
|
|
);
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Close reschedule modal and reset state
|
|
*/
|
|
const handleCloseRescheduleModal = () => {
|
|
setShowRescheduleModal(false);
|
|
setRescheduleBooking(null);
|
|
};
|
|
|
|
/**
|
|
* Show alert and cancel booking (iOS Alert.prompt pattern)
|
|
*/
|
|
const handleCancelBooking = (booking: Booking) => {
|
|
Alert.alert("Cancel Event", `Are you sure you want to cancel "${booking.title}"?`, [
|
|
{ text: "Cancel", style: "cancel" },
|
|
{
|
|
text: "Cancel Event",
|
|
style: "destructive",
|
|
onPress: () => {
|
|
// Prompt for cancellation reason
|
|
Alert.prompt(
|
|
"Cancellation Reason",
|
|
"Please provide a reason for cancelling this booking:",
|
|
[
|
|
{ text: "Cancel", style: "cancel" },
|
|
{
|
|
text: "Cancel Event",
|
|
style: "destructive",
|
|
onPress: (reason?: string) => {
|
|
const cancellationReason = reason?.trim() || "Event cancelled by host";
|
|
cancelMutation(
|
|
{ uid: booking.uid, reason: cancellationReason },
|
|
{
|
|
onSuccess: () => {
|
|
Alert.alert("Success", "Event cancelled successfully");
|
|
},
|
|
onError: (_error) => {
|
|
console.error("Failed to cancel booking");
|
|
showErrorAlert("Error", "Failed to cancel event. Please try again.");
|
|
},
|
|
}
|
|
);
|
|
},
|
|
},
|
|
],
|
|
"plain-text",
|
|
"",
|
|
"default"
|
|
);
|
|
},
|
|
},
|
|
]);
|
|
};
|
|
|
|
/**
|
|
* Show alert and confirm booking
|
|
*/
|
|
const handleConfirmBooking = (booking: Booking) => {
|
|
Alert.alert("Confirm Booking", `Are you sure you want to confirm "${booking.title}"?`, [
|
|
{ text: "Cancel", style: "cancel" },
|
|
{
|
|
text: "Confirm",
|
|
onPress: () => {
|
|
confirmMutation(
|
|
{ uid: booking.uid },
|
|
{
|
|
onSuccess: () => {
|
|
Alert.alert("Success", "Booking confirmed successfully");
|
|
},
|
|
onError: (error) => {
|
|
showErrorAlert("Error", error.message || "Failed to confirm booking");
|
|
},
|
|
}
|
|
);
|
|
},
|
|
},
|
|
]);
|
|
};
|
|
|
|
/**
|
|
* Open reject modal (used by iOS for custom modal UI)
|
|
*/
|
|
const handleOpenRejectModal = (booking: Booking) => {
|
|
setRejectBooking(booking);
|
|
setRejectReason("");
|
|
setShowRejectModal(true);
|
|
};
|
|
|
|
/**
|
|
* Show alert and reject booking (Android Alert.prompt pattern)
|
|
*/
|
|
const handleRejectBooking = (booking: Booking) => {
|
|
Alert.alert("Decline Booking", `Are you sure you want to decline "${booking.title}"?`, [
|
|
{ text: "Cancel", style: "cancel" },
|
|
{
|
|
text: "Decline",
|
|
style: "destructive",
|
|
onPress: () => {
|
|
// Show optional reason input
|
|
Alert.prompt(
|
|
"Decline Reason",
|
|
"Optionally provide a reason for declining (press OK to skip)",
|
|
[
|
|
{ text: "Cancel", style: "cancel" },
|
|
{
|
|
text: "OK",
|
|
onPress: (reason?: string) => {
|
|
declineMutation(
|
|
{ uid: booking.uid, reason: reason || undefined },
|
|
{
|
|
onSuccess: () => {
|
|
Alert.alert("Success", "Booking declined successfully");
|
|
},
|
|
onError: (error) => {
|
|
showErrorAlert("Error", error.message || "Failed to decline booking");
|
|
},
|
|
}
|
|
);
|
|
},
|
|
},
|
|
],
|
|
"plain-text",
|
|
"",
|
|
"default"
|
|
);
|
|
},
|
|
},
|
|
]);
|
|
};
|
|
|
|
/**
|
|
* Submit rejection with reason (used by iOS custom modal)
|
|
* @param reasonOverride - Optional reason passed directly to avoid race condition with state updates
|
|
*/
|
|
const handleSubmitReject = (reasonOverride?: string) => {
|
|
if (!rejectBooking) return;
|
|
|
|
// Use passed reason if provided, otherwise fall back to state
|
|
const reason = reasonOverride !== undefined ? reasonOverride : rejectReason;
|
|
|
|
declineMutation(
|
|
{ uid: rejectBooking.uid, reason: reason || undefined },
|
|
{
|
|
onSuccess: () => {
|
|
setShowRejectModal(false);
|
|
setRejectBooking(null);
|
|
setRejectReason("");
|
|
Alert.alert("Success", "Booking rejected successfully");
|
|
},
|
|
onError: (_error) => {
|
|
showErrorAlert("Error", "Failed to reject booking. Please try again.");
|
|
},
|
|
}
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Close reject modal and reset state
|
|
*/
|
|
const handleCloseRejectModal = () => {
|
|
setShowRejectModal(false);
|
|
setRejectBooking(null);
|
|
setRejectReason("");
|
|
};
|
|
|
|
/**
|
|
* Inline confirm handler (for use directly in JSX)
|
|
*/
|
|
const handleInlineConfirm = (booking: Booking) => {
|
|
confirmMutation(
|
|
{ uid: booking.uid },
|
|
{
|
|
onSuccess: () => {
|
|
Alert.alert("Success", "Booking confirmed successfully");
|
|
},
|
|
onError: (_error) => {
|
|
showErrorAlert("Error", "Failed to confirm booking. Please try again.");
|
|
},
|
|
}
|
|
);
|
|
};
|
|
|
|
return {
|
|
// Reschedule state
|
|
showRescheduleModal,
|
|
setShowRescheduleModal,
|
|
rescheduleBooking,
|
|
rescheduleDate,
|
|
setRescheduleDate,
|
|
rescheduleTime,
|
|
setRescheduleTime,
|
|
rescheduleReason,
|
|
setRescheduleReason,
|
|
|
|
// Reject state
|
|
showRejectModal,
|
|
setShowRejectModal,
|
|
rejectBooking,
|
|
rejectReason,
|
|
setRejectReason,
|
|
|
|
// Selected booking state
|
|
selectedBooking,
|
|
setSelectedBooking,
|
|
|
|
// Handlers
|
|
handleBookingPress,
|
|
handleRescheduleBooking,
|
|
handleSubmitReschedule,
|
|
handleRescheduleWithValues,
|
|
handleCloseRescheduleModal,
|
|
handleCancelBooking,
|
|
handleConfirmBooking,
|
|
handleOpenRejectModal,
|
|
handleRejectBooking,
|
|
handleSubmitReject,
|
|
handleCloseRejectModal,
|
|
handleInlineConfirm,
|
|
|
|
// Loading states (pass through)
|
|
isConfirming,
|
|
isDeclining,
|
|
isRescheduling,
|
|
};
|
|
};
|