Scheduling infrastructure for absolutely everyone.
refactor(companion): extract AvailabilityDetailScreen with AppPressable migration (#26106)
Dhairyashil Shinde6650fdb9ef23
diff --git a/companion/api/server.ts b/companion/api/server.tsindex f4b79bd865e..294b2110771 100644--- a/companion/api/server.ts+++ b/companion/api/server.ts@@ -55,7 +55,12 @@ const sendFile = (res: ServerResponse, filePath: string) => {const stream = createReadStream(filePath);stream.on("error", (error) => {- console.error("Failed to read file:", error);+ console.error("Failed to read file");+ if (process.env.NODE_ENV !== "production") {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[companion/api] Failed to read file", { message, stack });+ }res.statusCode = 500;res.end("Internal Server Error");});@@ -76,7 +81,12 @@ export default async function handler(req: IncomingMessage, res: ServerResponse)const filePath = await resolveFilePath(safePath);sendFile(res, filePath);} catch (error) {- console.error("Server render error:", error);+ console.error("Server render error");+ if (process.env.NODE_ENV !== "production") {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[companion/api] Server render error", { message, stack });+ }res.statusCode = 500;res.end("Internal Server Error");}diff --git a/companion/app/(tabs)/(availability)/index.tsx b/companion/app/(tabs)/(availability)/index.tsxindex 462015b486a..95444e6d91d 100644--- a/companion/app/(tabs)/(availability)/index.tsx+++ b/companion/app/(tabs)/(availability)/index.tsx@@ -1,306 +1,22 @@-import { Ionicons } from "@expo/vector-icons";-import { Stack, useRouter } from "expo-router";-import React, { useState, useMemo, Activity } from "react";-import {- View,- Text,- FlatList,- RefreshControl,- TouchableOpacity,- ActionSheetIOS,- Alert,- Platform,- TextInput,- ScrollView,-} from "react-native";--import { CalComAPIService, Schedule } from "../../../services/calcom";-import { Header } from "../../../components/Header";-import { FullScreenModal } from "../../../components/FullScreenModal";-import { LoadingSpinner } from "../../../components/LoadingSpinner";-import { EmptyScreen } from "../../../components/EmptyScreen";-import { showErrorAlert } from "../../../utils/alerts";-import { offlineAwareRefresh } from "../../../utils/network";-import { shadows } from "../../../utils/shadows";-import {- useSchedules,- useCreateSchedule,- useDeleteSchedule,- useDuplicateSchedule,- useSetScheduleAsDefault,-} from "../../../hooks";+import { AvailabilityListScreen } from "../../../components/screens/AvailabilityListScreen";import { isLiquidGlassAvailable } from "expo-glass-effect";-import { AvailabilityListItem } from "../../../components/availability-list-item/AvailabilityListItem";+import { Stack } from "expo-router";+import React, { useState } from "react";+import { Platform } from "react-native";export default function Availability() {- const router = useRouter();const [searchQuery, setSearchQuery] = useState("");const [showCreateModal, setShowCreateModal] = useState(false);- const [newScheduleName, setNewScheduleName] = useState("");- const [showActionsModal, setShowActionsModal] = useState(false);- const [selectedSchedule, setSelectedSchedule] = useState<Schedule | null>(null);- const [showDeleteModal, setShowDeleteModal] = useState(false);-- // Use React Query hooks- const {- data: schedules = [],- isLoading: loading,- isFetching,- error: queryError,- refetch,- } = useSchedules();-- // Show refresh indicator when fetching- const refreshing = isFetching && !loading;-- const { mutate: createScheduleMutation, isPending: creating } = useCreateSchedule();- const { mutate: deleteScheduleMutation, isPending: deleting } = useDeleteSchedule();- const { mutate: duplicateScheduleMutation } = useDuplicateSchedule();- const { mutate: setAsDefaultMutation } = useSetScheduleAsDefault();-- // Convert query error to string- // Don't show error UI for authentication errors (user will be redirected to login)- // Only show error UI in development mode for other errors- const isAuthError =- queryError?.message?.includes("Authentication") ||- queryError?.message?.includes("sign in") ||- queryError?.message?.includes("401");- const error = queryError && !isAuthError && __DEV__ ? "Failed to load availability." : null;-- // Filter schedules based on search query- const filteredSchedules = useMemo(() => {- if (searchQuery.trim() === "") {- return schedules;- }- const searchLower = searchQuery.toLowerCase();- return schedules.filter((schedule) => schedule.name.toLowerCase().includes(searchLower));- }, [schedules, searchQuery]);-- // Note: We don't use useFocusEffect here because schedules have Infinity stale time.- // Data only refreshes on mutations (create/update/delete) or manual pull-to-refresh.-- // Handle pull-to-refresh (offline-aware)- const onRefresh = () => offlineAwareRefresh(refetch);-- const handleSearch = (query: string) => {- setSearchQuery(query);- };-- const handleScheduleLongPress = (schedule: Schedule) => {- if (Platform.OS !== "ios") {- // Fallback for non-iOS platforms (Android Alert supports max 3 buttons)- const options = [];- if (!schedule.isDefault) {- options.push({ text: "β Set as default", onPress: () => handleSetAsDefault(schedule) });- }- options.push(- { text: "π Duplicate", onPress: () => handleDuplicate(schedule) },- { text: "ποΈ Delete", style: "destructive", onPress: () => handleDelete(schedule) }- );- // Android Alert automatically adds cancel, so we don't need to include it explicitly- Alert.alert(schedule.name, "", options);- return;- }-- const options = ["Cancel"];- if (!schedule.isDefault) {- options.push("β Set as default");- }- options.push("π Duplicate", "ποΈ Delete");-- const destructiveButtonIndex = options.length - 1; // Delete button- const cancelButtonIndex = 0;-- ActionSheetIOS.showActionSheetWithOptions(- {- options,- destructiveButtonIndex,- cancelButtonIndex,- title: schedule.name,- },- (buttonIndex) => {- if (buttonIndex === cancelButtonIndex) {- return;- }-- if (!schedule.isDefault) {- // Options: ["Cancel", "β Set as default", "π Duplicate", "ποΈ Delete"]- if (buttonIndex === 1) {- handleSetAsDefault(schedule);- } else if (buttonIndex === 2) {- handleDuplicate(schedule);- } else if (buttonIndex === 3) {- handleDelete(schedule);- }- } else {- // Options: ["Cancel", "π Duplicate", "ποΈ Delete"]- if (buttonIndex === 1) {- handleDuplicate(schedule);- } else if (buttonIndex === 2) {- handleDelete(schedule);- }- }- }- );- };-- const handleSetAsDefault = (schedule: Schedule) => {- setAsDefaultMutation(schedule.id, {- onError: () => {- showErrorAlert("Error", "Failed to set schedule as default. Please try again.");- },- });- };-- const handleDuplicate = (schedule: Schedule) => {- duplicateScheduleMutation(schedule.id, {- onError: () => {- showErrorAlert("Error", "Failed to duplicate schedule. Please try again.");- },- });- };-- const handleDelete = (schedule: Schedule) => {- if (Platform.OS === "web") {- // Use custom modal for web- setShowDeleteModal(true);- } else {- // Use native Alert for iOS/Android- Alert.alert("Delete Schedule", `Are you sure you want to delete "${schedule.name}"?`, [- { text: "Cancel", style: "cancel" },- {- text: "Delete",- style: "destructive",- onPress: () => {- deleteScheduleMutation(schedule.id, {- onError: () => {- showErrorAlert("Error", "Failed to delete schedule. Please try again.");- },- });- },- },- ]);- }- };-- const confirmDelete = () => {- if (!selectedSchedule) return;-- deleteScheduleMutation(selectedSchedule.id, {- onSuccess: () => {- setShowDeleteModal(false);- setSelectedSchedule(null);- },- onError: () => {- showErrorAlert("Error", "Failed to delete schedule. Please try again.");- },- });- };-- const handleSchedulePress = (schedule: Schedule) => {- router.push({- pathname: "/availability-detail",- params: { id: schedule.id.toString() },- });- };const handleCreateNew = () => {- setNewScheduleName("");setShowCreateModal(true);};- const handleCreateSchedule = async () => {- if (!newScheduleName.trim()) {- Alert.alert("Error", "Please enter a schedule name");- return;- }-- // Get user's timezone (default to America/New_York if not available)- let userTimezone = "America/New_York";- try {- const userProfile = await CalComAPIService.getUserProfile();- if (userProfile.timeZone) {- userTimezone = userProfile.timeZone;- }- } catch (error) {- console.log("Could not get user timezone, using default");- }-- // Create schedule with Monday-Friday 9 AM - 5 PM default- createScheduleMutation(- {- name: newScheduleName.trim(),- timeZone: userTimezone,- isDefault: false,- availability: [- {- days: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],- startTime: "09:00",- endTime: "17:00",- },- ],- },- {- onSuccess: (newSchedule) => {- setShowCreateModal(false);- setNewScheduleName("");-- // Navigate to edit the newly created schedule- router.push({- pathname: "/availability-detail",- params: {- id: newSchedule.id.toString(),- },- });- },- onError: (error) => {- console.error("Failed to create schedule:", error);- showErrorAlert("Error", "Failed to create schedule. Please try again.");- },- }- );- };-- if (loading) {- return (- <View className="flex-1 bg-[#f8f9fa]">- <Header />- <View className="flex-1 items-center justify-center p-5">- <LoadingSpinner size="large" />- </View>- </View>- );- }-- if (error) {- return (- <View className="flex-1 bg-[#f8f9fa]">- <Header />- <View className="flex-1 items-center justify-center p-5">- <Ionicons name="alert-circle" size={64} color="#FF3B30" />- <Text className="mb-2 mt-4 text-center text-xl font-bold text-[#333]">- Unable to load availability- </Text>- <Text className="mb-6 text-center text-base text-[#666]">{error}</Text>- <TouchableOpacity className="rounded-lg bg-black px-6 py-3" onPress={() => refetch()}>- <Text className="text-base font-semibold text-white">Retry</Text>- </TouchableOpacity>- </View>- </View>- );- }-- // Determine what content to show- const showEmptyState = schedules.length === 0 && !loading;- const showSearchEmptyState =- filteredSchedules.length === 0 && searchQuery.trim() !== "" && !showEmptyState;- const showList = !showEmptyState && !showSearchEmptyState;-return (<><Stack.Headerstyle={{ backgroundColor: "transparent", shadowColor: "transparent" }}- blurEffect={isLiquidGlassAvailable() ? undefined : "light"} // Only looks cool on iOS 18 and below+ blurEffect={isLiquidGlassAvailable() ? undefined : "light"}hidden={Platform.OS === "android"}><Stack.Header.Title large>Availability</Stack.Header.Title>@@ -311,322 +27,18 @@ export default function Availability() {</Stack.Header.Right><Stack.Header.SearchBarplaceholder="Search schedules"- onChangeText={(e) => handleSearch(e.nativeEvent.text)}+ onChangeText={(e) => setSearchQuery(e.nativeEvent.text)}obscureBackground={false}barTintColor="#fff"/></Stack.Header>- <Activity mode={Platform.OS !== "ios" ? "visible" : "hidden"}>- <Header />- <View className="flex-row items-center gap-3 border-b border-gray-300 bg-gray-100 px-4 py-2">- <TextInput- className="flex-1 rounded-lg border border-gray-200 bg-white px-3 py-2 text-[17px] text-black focus:border-black focus:ring-2 focus:ring-black"- placeholder="Search schedules"- placeholderTextColor="#9CA3AF"- value={searchQuery}- onChangeText={handleSearch}- autoCapitalize="none"- autoCorrect={false}- clearButtonMode="while-editing"- />- <TouchableOpacity- className="min-w-[60px] flex-row items-center justify-center gap-1 rounded-lg bg-black px-2.5 py-2"- onPress={handleCreateNew}- >- <Ionicons name="add" size={18} color="#fff" />- <Text className="text-base font-semibold text-white">New</Text>- </TouchableOpacity>- </View>- </Activity>-- {/* Empty state - no schedules */}- <Activity mode={showEmptyState ? "visible" : "hidden"}>- <ScrollView- style={{ backgroundColor: "white" }}- contentContainerStyle={{- flexGrow: 1,- justifyContent: "center",- alignItems: "center",- padding: 20,- paddingBottom: 90,- }}- refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}- contentInsetAdjustmentBehavior="automatic"- >- <EmptyScreen- icon="time-outline"- headline="Create an availability schedule"- description="Creating availability schedules allows you to manage availability across event types. They can be applied to one or more event types."- buttonText="New"- onButtonPress={handleCreateNew}- />- </ScrollView>- </Activity>-- {/* Search bar and content for non-empty states */}- <Activity mode={!showEmptyState ? "visible" : "hidden"}>- {/* Search empty state */}- <Activity mode={showSearchEmptyState ? "visible" : "hidden"}>- <ScrollView- style={{ backgroundColor: "white" }}- contentContainerStyle={{- flexGrow: 1,- justifyContent: "center",- alignItems: "center",- padding: 20,- paddingBottom: 90,- }}- refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}- >- <EmptyScreen- icon="search-outline"- headline={`No results found for "${searchQuery}"`}- description="Try searching with different keywords"- />- </ScrollView>- </Activity>-- {/* Schedules list */}- <Activity mode={showList ? "visible" : "hidden"}>- <FlatList- className="flex-1 rounded-lg border border-[#E5E5EA] bg-white"- contentContainerStyle={{- paddingBottom: 90,- paddingHorizontal: 8,- paddingVertical: 4,- }}- data={filteredSchedules}- keyExtractor={(item) => item.id.toString()}- renderItem={({ item, index }) => (- <AvailabilityListItem- item={item}- index={index}- handleSchedulePress={handleSchedulePress}- handleScheduleLongPress={handleScheduleLongPress}- setSelectedSchedule={setSelectedSchedule}- setShowActionsModal={setShowActionsModal}- onDuplicate={handleDuplicate}- onDelete={handleDelete}- onSetAsDefault={handleSetAsDefault}- />- )}- refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}- showsVerticalScrollIndicator={false}- contentInsetAdjustmentBehavior="automatic"- />- </Activity>- </Activity>-- {/* Create Schedule Modal */}- <FullScreenModal- visible={showCreateModal}- animationType="fade"- onRequestClose={() => setShowCreateModal(false)}- >- <TouchableOpacity- className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"- activeOpacity={1}- onPress={() => setShowCreateModal(false)}- >- <TouchableOpacity- className="w-[90%] max-w-[500px] rounded-2xl bg-white"- activeOpacity={1}- onPress={(e) => e.stopPropagation()}- style={shadows.xl()}- >- {/* Header */}- <View className="px-8 pb-4 pt-6">- <Text className="text-2xl font-semibold text-[#111827]">Add a new schedule</Text>- </View>-- {/* Content */}- <View className="px-8 pb-6">- <View className="mb-1">- <Text className="mb-2 text-sm font-medium text-[#374151]">Name</Text>- <TextInput- className="rounded-md border border-[#D1D5DB] bg-white px-3 py-2.5 text-base text-[#111827]"- placeholder="Working Hours"- placeholderTextColor="#9CA3AF"- value={newScheduleName}- onChangeText={setNewScheduleName}- autoFocus- autoCapitalize="words"- returnKeyType="done"- onSubmitEditing={handleCreateSchedule}- />- </View>- </View>-- {/* Footer */}- <View className="rounded-b-2xl border-t border-[#E5E7EB] bg-[#F9FAFB] px-8 py-4">- <View className="flex-row justify-end gap-2 space-x-2">- <TouchableOpacity- className="rounded-xl border border-[#D1D5DB] bg-white px-2 py-2 md:px-4"- onPress={() => {- setShowCreateModal(false);- setNewScheduleName("");- }}- disabled={creating}- >- <Text className="text-base font-medium text-[#374151]">Close</Text>- </TouchableOpacity>- <TouchableOpacity- className={`rounded-xl bg-[#111827] px-2 py-2 md:px-4 ${creating ? "opacity-60" : ""}`}- onPress={handleCreateSchedule}- disabled={creating}- >- <Text className="text-base font-medium text-white">Continue</Text>- </TouchableOpacity>- </View>- </View>- </TouchableOpacity>- </TouchableOpacity>- </FullScreenModal>-- {/* Schedule Actions Modal */}- <FullScreenModal- visible={showActionsModal}- animationType="fade"- onRequestClose={() => setShowActionsModal(false)}- >- <TouchableOpacity- className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"- activeOpacity={1}- onPress={() => setShowActionsModal(false)}- >- <TouchableOpacity- className="mx-4 w-full max-w-sm rounded-2xl bg-white"- activeOpacity={1}- onPress={(e) => e.stopPropagation()}- >- {/* Header */}- <View className="border-b border-gray-200 p-6">- <Text className="text-center text-xl font-semibold text-gray-900">- Schedule Actions- </Text>- </View>-- {/* Actions List */}- <View className="p-2">- {/* Set as Default - only show if not already default */}- <Activity- mode={selectedSchedule && !selectedSchedule.isDefault ? "visible" : "hidden"}- >- <>- <TouchableOpacity- onPress={() => {- setShowActionsModal(false);- if (selectedSchedule) {- handleSetAsDefault(selectedSchedule);- }- }}- className="flex-row items-center p-2 hover:bg-gray-50 md:p-4"- >- <Ionicons name="star-outline" size={20} color="#6B7280" />- <Text className="ml-3 text-base text-gray-900">Set as Default</Text>- </TouchableOpacity>-- <View className="mx-4 my-2 h-px bg-gray-200" />- </>- </Activity>-- {/* Duplicate */}- <TouchableOpacity- onPress={() => {- setShowActionsModal(false);- if (selectedSchedule) {- setTimeout(() => {- handleDuplicate(selectedSchedule);- }, 100);- }- }}- className="flex-row items-center p-2 hover:bg-gray-50 md:p-4"- >- <Ionicons name="copy-outline" size={20} color="#6B7280" />- <Text className="ml-3 text-base text-gray-900">Duplicate</Text>- </TouchableOpacity>-- {/* Separator */}- <View className="mx-4 my-2 h-px bg-gray-200" />-- {/* Delete */}- <TouchableOpacity- onPress={() => {- setShowActionsModal(false);- if (selectedSchedule) {- // Small delay to ensure modal closes before alert shows- setTimeout(() => {- handleDelete(selectedSchedule);- }, 100);- }- }}- className="flex-row items-center p-2 hover:bg-gray-50 md:p-4"- >- <Ionicons name="trash-outline" size={20} color="#800000" />- <Text className="ml-3 text-base text-[#800000]">Delete</Text>- </TouchableOpacity>- </View>-- {/* Cancel button */}- <View className="border-t border-gray-200 p-2 md:p-4">- <TouchableOpacity- className="w-full rounded-lg bg-gray-100 p-3"- onPress={() => setShowActionsModal(false)}- >- <Text className="text-center text-base font-medium text-gray-700">Cancel</Text>- </TouchableOpacity>- </View>- </TouchableOpacity>- </TouchableOpacity>- </FullScreenModal>-- {/* Delete Confirmation Modal */}- <FullScreenModal- visible={showDeleteModal}- animationType="fade"- onRequestClose={() => !deleting && setShowDeleteModal(false)}- >- <View className="flex-1 items-center justify-center bg-black/50 p-4">- <View className="w-full max-w-sm rounded-2xl bg-white p-6">- {/* Icon */}- <View className="mb-4 items-center">- <View className="h-12 w-12 items-center justify-center rounded-full bg-red-100">- <Ionicons name="trash-outline" size={24} color="#800000" />- </View>- </View>-- {/* Title */}- <Text className="mb-2 text-center text-xl font-semibold text-gray-900">- Delete Schedule- </Text>-- {/* Description */}- <Text className="mb-6 text-center text-base text-gray-600">- Are you sure you want to delete "{selectedSchedule?.name}"? This action cannot be- undone.- </Text>-- {/* Buttons */}- <View className="flex-row gap-3">- <TouchableOpacity- className="flex-1 rounded-lg bg-gray-100 px-4 py-3"- onPress={() => setShowDeleteModal(false)}- disabled={deleting}- >- <Text className="text-center text-base font-semibold text-gray-700">Cancel</Text>- </TouchableOpacity>- <TouchableOpacity- className={`flex-1 rounded-lg bg-gray-900 px-4 py-3 ${deleting ? "opacity-50" : ""}`}- onPress={confirmDelete}- disabled={deleting}- >- <Text className="text-center text-base font-semibold text-white">Delete</Text>- </TouchableOpacity>- </View>- </View>- </View>- </FullScreenModal>+ <AvailabilityListScreen+ searchQuery={searchQuery}+ onSearchChange={setSearchQuery}+ showCreateModal={showCreateModal}+ onShowCreateModalChange={setShowCreateModal}+ /></>);}diff --git a/companion/app/(tabs)/(event-types)/index.tsx b/companion/app/(tabs)/(event-types)/index.tsxindex 5a82fdea978..0533e6c46de 100644--- a/companion/app/(tabs)/(event-types)/index.tsx+++ b/companion/app/(tabs)/(event-types)/index.tsx@@ -243,7 +243,12 @@ export default function EventTypes() {}},onError: (error) => {- console.error("Failed to delete event type:", error);+ const message = error instanceof Error ? error.message : String(error);+ console.error("Failed to delete event type", message);+ if (__DEV__) {+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[EventTypes] deleteEventType failed", { message, stack });+ }if (Platform.OS === "web") {showToastMessage("Failed to delete event type");} else {@@ -283,7 +288,12 @@ export default function EventTypes() {});},onError: (error) => {- console.error("Failed to duplicate event type:", error);+ const message = error instanceof Error ? error.message : String(error);+ console.error("Failed to duplicate event type", message);+ if (__DEV__) {+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[EventTypes] duplicateEventType failed", { message, stack });+ }if (Platform.OS === "web") {showToastMessage("Failed to duplicate event type");} else {@@ -305,7 +315,7 @@ export default function EventTypes() {await openInAppBrowser(link, "event type preview");}} catch (error) {- console.error("Failed to open preview:", error);+ console.error("Failed to open preview");if (Platform.OS === "web") {showToastMessage("Failed to open preview");} else {@@ -373,7 +383,12 @@ export default function EventTypes() {});},onError: (error) => {- console.error("Failed to create event type:", error);+ const message = error instanceof Error ? error.message : String(error);+ console.error("Failed to create event type", message);+ if (__DEV__) {+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[EventTypes] createEventType failed", { message, stack });+ }showErrorAlert("Error", "Failed to create event type. Please try again.");},}diff --git a/companion/app/(tabs)/more.tsx b/companion/app/(tabs)/more.tsxindex 31da2a6c644..71032856e43 100644--- a/companion/app/(tabs)/more.tsx+++ b/companion/app/(tabs)/more.tsx@@ -25,7 +25,12 @@ export default function More() {try {await logout();} catch (error) {- console.error("Logout error:", error);+ const message = error instanceof Error ? error.message : String(error);+ console.error("Logout error", message);+ if (__DEV__) {+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[More] logout failed", { message, stack });+ }showErrorAlert("Error", "Failed to sign out. Please try again.");}};diff --git a/companion/app/availability-detail.tsx b/companion/app/availability-detail.tsxindex 42aa63d0fbf..65bd0629bec 100644--- a/companion/app/availability-detail.tsx+++ b/companion/app/availability-detail.tsx@@ -1,995 +1,18 @@-import { Ionicons } from "@expo/vector-icons";-import { GlassView } from "expo-glass-effect";-import { useRouter, useLocalSearchParams, Stack } from "expo-router";-import React, { useState, useEffect } from "react";-import {- View,- Text,- ScrollView,- TouchableOpacity,- TextInput,- Alert,- ActivityIndicator,- Switch,-} from "react-native";-import { useSafeAreaInsets } from "react-native-safe-area-context";--import { CalComAPIService, Schedule } from "../services/calcom";-import { ScheduleAvailability } from "../services/types";-import { FullScreenModal } from "../components/FullScreenModal";-import { showErrorAlert } from "../utils/alerts";--const DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];-const DAY_ABBREVIATIONS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];--// Convert 24-hour time to 12-hour format with AM/PM-const formatTime12Hour = (time24: string): string => {- const [hours, minutes] = time24.split(":");- const hour = parseInt(hours, 10);- const min = minutes || "00";- const period = hour >= 12 ? "PM" : "AM";- const hour12 = hour === 0 ? 12 : hour > 12 ? hour - 12 : hour;- // Pad single-digit hours with leading zero for consistent width- const hour12Padded = hour12.toString().padStart(2, "0");- return `${hour12Padded}:${min} ${period}`;-};--// Format availability for display-const formatAvailabilityDisplay = (- availability: Record<number, ScheduleAvailability[]>-): string[] => {- // Group slots by time range- const timeRangeMap: Record<string, number[]> = {};-- Object.keys(availability).forEach((dayIndexStr) => {- const dayIndex = Number(dayIndexStr);- const slots = availability[dayIndex];- if (slots && slots.length > 0) {- slots.forEach((slot) => {- const timeKey = `${slot.startTime}-${slot.endTime}`;- if (!timeRangeMap[timeKey]) {- timeRangeMap[timeKey] = [];- }- timeRangeMap[timeKey].push(dayIndex);- });- }- });-- // Format each time range group- const formatted: string[] = [];- Object.keys(timeRangeMap).forEach((timeKey) => {- const days = timeRangeMap[timeKey].sort((a, b) => a - b);- const [startTime, endTime] = timeKey.split("-");- const dayNames = days.map((day) => DAY_ABBREVIATIONS[day]).join(", ");- const timeRange = `${formatTime12Hour(startTime)} - ${formatTime12Hour(endTime)}`;- formatted.push(`${dayNames}, ${timeRange}`);- });-- return formatted;-};--// Generate time options (15-minute intervals)-const generateTimeOptions = () => {- const options: string[] = [];- for (let hour = 0; hour < 24; hour++) {- for (let minute = 0; minute < 60; minute += 15) {- const h = hour.toString().padStart(2, "0");- const m = minute.toString().padStart(2, "0");- options.push(`${h}:${m}`);- }- }- return options;-};--const TIME_OPTIONS = generateTimeOptions();+import { AvailabilityDetailScreen } from "../components/screens/AvailabilityDetailScreen";+import { useLocalSearchParams, Stack } from "expo-router";+import React from "react";export default function AvailabilityDetail() {- const router = useRouter();const { id } = useLocalSearchParams<{ id: string }>();- const insets = useSafeAreaInsets();-- const [loading, setLoading] = useState(true);- const [saving, setSaving] = useState(false);- const [schedule, setSchedule] = useState<Schedule | null>(null);- const [scheduleName, setScheduleName] = useState("");- const [timeZone, setTimeZone] = useState("");- const [isDefault, setIsDefault] = useState(false);- const [availability, setAvailability] = useState<Record<number, ScheduleAvailability[]>>({});- const [showTimezoneModal, setShowTimezoneModal] = useState(false);- const [showTimePicker, setShowTimePicker] = useState<{- dayIndex: number;- slotIndex: number;- type: "start" | "end";- } | null>(null);- const [overrides, setOverrides] = useState<- Array<{- date: string; // Format: "2024-05-20"- startTime: string; // Format: "12:00" or "00:00" for unavailable- endTime: string; // Format: "14:00" or "00:00" for unavailable- }>- >([]);- const [showOverrideModal, setShowOverrideModal] = useState(false);- const [editingOverride, setEditingOverride] = useState<number | null>(null);- const [overrideDate, setOverrideDate] = useState("");- const [overrideStartTime, setOverrideStartTime] = useState("09:00");- const [overrideEndTime, setOverrideEndTime] = useState("17:00");- const [isUnavailable, setIsUnavailable] = useState(false);- const [showOverrideTimePicker, setShowOverrideTimePicker] = useState<{- type: "start" | "end";- } | null>(null);-- // Common timezones- const timezones = [- "America/New_York",- "America/Chicago",- "America/Denver",- "America/Los_Angeles",- "Europe/London",- "Europe/Paris",- "Europe/Berlin",- "Asia/Tokyo",- "Asia/Shanghai",- "Asia/Kolkata",- "Australia/Sydney",- "UTC",- ];-- useEffect(() => {- if (id) {- fetchSchedule();- }- }, [id]);-- const fetchSchedule = async () => {- try {- setLoading(true);- const scheduleData = await CalComAPIService.getScheduleById(Number(id));-- if (scheduleData) {- setSchedule(scheduleData);- setScheduleName(scheduleData.name || "");- setTimeZone(scheduleData.timeZone || "UTC");- setIsDefault(scheduleData.isDefault || false);-- // Convert availability array to day-indexed object- const availabilityMap: Record<number, ScheduleAvailability[]> = {};-- // Map day names to numbers- const dayNameToNumber: Record<string, number> = {- Sunday: 0,- Monday: 1,- Tuesday: 2,- Wednesday: 3,- Thursday: 4,- Friday: 5,- Saturday: 6,- };-- if (scheduleData.availability && Array.isArray(scheduleData.availability)) {- scheduleData.availability.forEach((slot) => {- // Handle both string day names and number day formats- let days: number[] = [];- if (Array.isArray(slot.days)) {- days = slot.days- .map((day) => {- // If it's a day name string (e.g., "Sunday", "Monday")- if (typeof day === "string" && dayNameToNumber[day] !== undefined) {- return dayNameToNumber[day];- }- // If it's a number string (e.g., "0", "1")- if (typeof day === "string") {- const parsed = parseInt(day, 10);- if (!isNaN(parsed) && parsed >= 0 && parsed <= 6) {- return parsed;- }- }- // If it's already a number- if (typeof day === "number" && day >= 0 && day <= 6) {- return day;- }- return null;- })- .filter((day): day is number => day !== null);- }-- days.forEach((day) => {- if (!availabilityMap[day]) {- availabilityMap[day] = [];- }- availabilityMap[day].push({- days: [day.toString()],- startTime: slot.startTime || "09:00:00",- endTime: slot.endTime || "17:00:00",- });- });- });- }-- setAvailability(availabilityMap);-- // Load overrides if they exist- if (scheduleData.overrides && Array.isArray(scheduleData.overrides)) {- const formattedOverrides = scheduleData.overrides.map((override) => ({- date: override.date || "",- startTime: override.startTime || "00:00",- endTime: override.endTime || "00:00",- }));- setOverrides(formattedOverrides);- } else {- setOverrides([]);- }- }- } catch (error) {- console.error("Error fetching schedule:", error);- showErrorAlert("Error", "Failed to load schedule. Please try again.");- router.back();- } finally {- setLoading(false);- }- };-- const toggleDay = (dayIndex: number) => {- setAvailability((prev) => {- const newAvailability = { ...prev };- if (newAvailability[dayIndex] && newAvailability[dayIndex].length > 0) {- // Disable day - remove availability- delete newAvailability[dayIndex];- } else {- // Enable day - add default time slot (9 AM - 5 PM)- newAvailability[dayIndex] = [- {- days: [dayIndex.toString()],- startTime: "09:00:00",- endTime: "17:00:00",- },- ];- }- return newAvailability;- });- };-- const addTimeSlot = (dayIndex: number) => {- setAvailability((prev) => {- const newAvailability = { ...prev };- if (!newAvailability[dayIndex]) {- newAvailability[dayIndex] = [];- }- newAvailability[dayIndex].push({- days: [dayIndex.toString()],- startTime: "09:00:00",- endTime: "17:00:00",- });- return newAvailability;- });- };-- const removeTimeSlot = (dayIndex: number, slotIndex: number) => {- setAvailability((prev) => {- const newAvailability = { ...prev };- if (newAvailability[dayIndex]) {- newAvailability[dayIndex] = newAvailability[dayIndex].filter((_, i) => i !== slotIndex);- if (newAvailability[dayIndex].length === 0) {- delete newAvailability[dayIndex];- }- }- return newAvailability;- });- };-- const updateTimeSlot = (- dayIndex: number,- slotIndex: number,- type: "start" | "end",- time: string- ) => {- setAvailability((prev) => {- const newAvailability = { ...prev };- if (newAvailability[dayIndex] && newAvailability[dayIndex][slotIndex]) {- const slot = { ...newAvailability[dayIndex][slotIndex] };- if (type === "start") {- slot.startTime = `${time}:00`;- } else {- slot.endTime = `${time}:00`;- }- newAvailability[dayIndex][slotIndex] = slot;- }- return newAvailability;- });- };-- const handleSave = async () => {- try {- setSaving(true);-- // Convert availability object back to array format with day names- const availabilityArray: Array<{- days: string[]; // Day names like "Monday", "Tuesday"- startTime: string; // Format: "09:00"- endTime: string; // Format: "10:00"- }> = [];-- Object.keys(availability).forEach((dayIndexStr) => {- const dayIndex = Number(dayIndexStr);- const slots = availability[dayIndex];- if (slots && slots.length > 0) {- slots.forEach((slot) => {- // Convert day number to day name- const dayName = DAYS[dayIndex];-- // Format time from "09:00:00" to "09:00" (remove seconds)- const formatTimeForAPI = (time: string): string => {- return time.substring(0, 5); // Take only HH:MM- };-- availabilityArray.push({- days: [dayName],- startTime: formatTimeForAPI(slot.startTime),- endTime: formatTimeForAPI(slot.endTime),- });- });- }- });-- // Format overrides for API (ensure times are in HH:MM format)- const formattedOverrides = overrides.map((override) => ({- date: override.date,- startTime: override.startTime.substring(0, 5), // Ensure HH:MM format- endTime: override.endTime.substring(0, 5), // Ensure HH:MM format- }));- await CalComAPIService.updateSchedule(Number(id), {- name: scheduleName,- timeZone,- availability: availabilityArray,- isDefault: isDefault,- overrides: formattedOverrides,- });-- Alert.alert("Success", "Schedule updated successfully", [- { text: "OK", onPress: () => router.back() },- ]);- } catch (error) {- showErrorAlert("Error", "Failed to update schedule. Please try again.");- } finally {- setSaving(false);- }- };-- const handleSetAsDefault = async () => {- try {- await CalComAPIService.updateSchedule(Number(id), {- isDefault: true,- });- setIsDefault(true);- Alert.alert("Success", "Schedule set as default successfully");- } catch (error) {- showErrorAlert("Error", "Failed to set schedule as default. Please try again.");- }- };-- const handleDelete = () => {- Alert.alert("Delete Schedule", `Are you sure you want to delete "${scheduleName}"?`, [- { text: "Cancel", style: "cancel" },- {- text: "Delete",- style: "destructive",- onPress: async () => {- try {- await CalComAPIService.deleteSchedule(Number(id));- Alert.alert("Success", "Schedule deleted successfully", [- { text: "OK", onPress: () => router.back() },- ]);- } catch (error) {- showErrorAlert("Error", "Failed to delete schedule. Please try again.");- }- },- },- ]);- };-- const handleAddOverride = () => {- setEditingOverride(null);- setOverrideDate("");- setOverrideStartTime("09:00");- setOverrideEndTime("17:00");- setIsUnavailable(false);- setShowOverrideModal(true);- };-- const handleEditOverride = (index: number) => {- const override = overrides[index];- setEditingOverride(index);- setOverrideDate(override.date);- setOverrideStartTime(override.startTime);- setOverrideEndTime(override.endTime);- setIsUnavailable(override.startTime === "00:00" && override.endTime === "00:00");- setShowOverrideModal(true);- };-- const handleDeleteOverride = (index: number) => {- Alert.alert("Delete Override", "Are you sure you want to delete this date override?", [- { text: "Cancel", style: "cancel" },- {- text: "Delete",- style: "destructive",- onPress: () => {- setOverrides(overrides.filter((_, i) => i !== index));- },- },- ]);- };-- const handleSaveOverride = () => {- if (!overrideDate) {- Alert.alert("Error", "Please select a date");- return;- }-- const newOverride = {- date: overrideDate,- startTime: isUnavailable ? "00:00" : overrideStartTime,- endTime: isUnavailable ? "00:00" : overrideEndTime,- };-- if (editingOverride !== null) {- // Update existing override- const updated = [...overrides];- updated[editingOverride] = newOverride;- setOverrides(updated);- } else {- // Add new override- setOverrides([...overrides, newOverride]);- }-- setShowOverrideModal(false);- };-- const formatDateForDisplay = (dateStr: string): string => {- if (!dateStr) return "";- const date = new Date(dateStr + "T00:00:00");- return date.toLocaleDateString("en-US", {- month: "short",- day: "numeric",- year: "numeric",- });- };-- if (loading) {- return (- <View className="flex-1 items-center justify-center bg-[#f8f9fa]">- <ActivityIndicator size="large" color="#000000" />- <Text className="mt-4 text-base text-[#666]">Loading schedule...</Text>- </View>- );+ if (!id) {+ return null;}return (<>- <Stack.Screen- options={{- headerShown: true,- headerTitle: () => (- <Text style={{ fontSize: 20, fontWeight: "700" }}>Edit Availability</Text>- ),- headerLeft: () => (- <TouchableOpacity onPress={() => router.back()} className="ml-4">- <Ionicons name="chevron-back" size={24} color="#000" />- </TouchableOpacity>- ),- headerRight: () => (- <TouchableOpacity- className={`mr-4 min-w-[60px] items-center rounded-[10px] bg-black px-2 py-2 md:px-4 ${saving ? "opacity-60" : ""}`}- onPress={handleSave}- disabled={saving}- >- <Text className="text-base font-semibold text-white">Save</Text>- </TouchableOpacity>- ),- }}- />- <View className="flex-1">- <ScrollView- className="flex-1 bg-[#f8f9fa]"- contentContainerStyle={{ padding: 16, paddingBottom: 200 }}- >- <View className="gap-4">- {/* Schedule Name and Working Hours Display */}- <View className="rounded-2xl bg-white p-6">- <Text className="mb-3 text-xl font-bold text-[#333]">{scheduleName}</Text>- {Object.keys(availability).length > 0 ? (- <View>- {formatAvailabilityDisplay(availability).map((line, index) => (- <Text key={index} className="mb-1 text-base text-[#666]">- {line}- </Text>- ))}- </View>- ) : (- <Text className="text-base text-[#999]">No availability set</Text>- )}- </View>-- {/* Availability Schedule */}- <View className="rounded-2xl bg-white p-6">- <Text className="mb-4 text-xl font-bold text-[#333]">Availability</Text>- {DAYS.map((day, dayIndex) => {- const daySlots = availability[dayIndex] || [];- const isEnabled = daySlots.length > 0;- const firstSlot = daySlots[0];-- return (- <View- key={dayIndex}- className={`mb-3 border-b border-[#E5E5EA] pb-3 ${dayIndex === DAYS.length - 1 ? "mb-0 border-b-0 pb-0" : ""}`}- >- <View className="flex-row items-center">- <View className="flex-1 flex-row items-center">- <Switch- value={isEnabled}- onValueChange={() => toggleDay(dayIndex)}- trackColor={{ false: "#E5E5EA", true: "#34C759" }}- thumbColor="#fff"- style={{ transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }] }}- />- <Text- className="ml-1 text-base font-medium text-[#333]"- style={{ width: 40 }}- >- {DAY_ABBREVIATIONS[dayIndex]}- </Text>- {isEnabled && firstSlot ? (- <View className="flex-row items-center gap-2">- <TouchableOpacity- onPress={() =>- setShowTimePicker({ dayIndex, slotIndex: 0, type: "start" })- }- className="rounded-lg border border-[#E5E5EA] bg-white px-2 py-1"- style={{ width: 85 }}- >- <Text className="text-center text-base text-[#333]">- {formatTime12Hour(firstSlot.startTime)}- </Text>- </TouchableOpacity>- <Text className="text-base text-[#666]">-</Text>- <TouchableOpacity- onPress={() =>- setShowTimePicker({ dayIndex, slotIndex: 0, type: "end" })- }- className="rounded-lg border border-[#E5E5EA] bg-white px-2 py-1"- style={{ width: 85 }}- >- <Text className="text-center text-base text-[#333]">- {formatTime12Hour(firstSlot.endTime)}- </Text>- </TouchableOpacity>- </View>- ) : null}- </View>- {isEnabled ? (- <TouchableOpacity onPress={() => addTimeSlot(dayIndex)} className="p-1">- <Ionicons name="add-circle-outline" size={20} color="#007AFF" />- </TouchableOpacity>- ) : null}- </View>-- {isEnabled && daySlots.length > 1 ? (- <View className="mt-2" style={{ marginLeft: 108 }}>- {daySlots.slice(1).map((slot, slotIndex) => (- <View key={slotIndex + 1} className="mb-2 flex-row items-center gap-2">- <TouchableOpacity- onPress={() =>- setShowTimePicker({- dayIndex,- slotIndex: slotIndex + 1,- type: "start",- })- }- className="rounded-lg border border-[#E5E5EA] bg-white px-2 py-1"- style={{ width: 85 }}- >- <Text className="text-center text-base text-[#333]">- {formatTime12Hour(slot.startTime)}- </Text>- </TouchableOpacity>- <Text className="text-base text-[#666]">-</Text>- <TouchableOpacity- onPress={() =>- setShowTimePicker({- dayIndex,- slotIndex: slotIndex + 1,- type: "end",- })- }- className="rounded-lg border border-[#E5E5EA] bg-white px-2 py-1"- style={{ width: 85 }}- >- <Text className="text-center text-base text-[#333]">- {formatTime12Hour(slot.endTime)}- </Text>- </TouchableOpacity>- <TouchableOpacity- onPress={() => removeTimeSlot(dayIndex, slotIndex + 1)}- className="p-1"- >- <Ionicons name="trash-outline" size={20} color="#FF3B30" />- </TouchableOpacity>- </View>- ))}- </View>- ) : null}- </View>- );- })}- </View>-- {/* Timezone */}- <View className="rounded-2xl bg-white p-6">- <Text className="mb-3 text-xl font-bold text-[#333]">Timezone</Text>- <TouchableOpacity- onPress={() => setShowTimezoneModal(true)}- className="flex-row items-center justify-between rounded-lg border border-[#E5E5EA] bg-[#F8F9FA] px-3 py-3"- >- <Text className="text-base text-[#333]">{timeZone}</Text>- <Ionicons name="chevron-down" size={20} color="#666" />- </TouchableOpacity>- </View>-- {/* Date Overrides */}- <View className="rounded-2xl bg-white p-6">- <Text className="mb-2 text-xl font-bold text-[#333]">Date overrides</Text>- <Text className="mb-4 text-base text-[#666]">- Add dates when your availability changes from your daily hours.- </Text>-- {overrides.length > 0 ? (- <View className="mb-4">- {overrides.map((override, index) => (- <View- key={index}- className="mb-2 flex-row items-center justify-between rounded-lg border border-[#E5E5EA] bg-[#F8F9FA] p-3"- >- <View className="flex-1">- <Text className="mb-1 text-base font-medium text-[#333]">- {formatDateForDisplay(override.date)}- </Text>- {override.startTime === "00:00" && override.endTime === "00:00" ? (- <Text className="text-sm text-[#666]">Unavailable (All day)</Text>- ) : (- <Text className="text-sm text-[#666]">- {formatTime12Hour(override.startTime + ":00")} -{" "}- {formatTime12Hour(override.endTime + ":00")}- </Text>- )}- </View>- <View className="flex-row items-center gap-2">- <TouchableOpacity onPress={() => handleEditOverride(index)} className="p-2">- <Ionicons name="pencil-outline" size={20} color="#007AFF" />- </TouchableOpacity>- <TouchableOpacity- onPress={() => handleDeleteOverride(index)}- className="p-2"- >- <Ionicons name="trash-outline" size={20} color="#FF3B30" />- </TouchableOpacity>- </View>- </View>- ))}- </View>- ) : null}-- <TouchableOpacity- onPress={handleAddOverride}- className="flex-row items-center justify-center rounded-lg border border-dashed border-[#E5E5EA] py-3"- >- <Ionicons name="add-circle-outline" size={20} color="#007AFF" />- <Text className="ml-2 text-base font-medium text-[#007AFF]">Add an override</Text>- </TouchableOpacity>- </View>- </View>- </ScrollView>-- {/* Bottom Action Bar */}- <GlassView- style={{- position: "absolute",- bottom: 0,- left: 0,- right: 0,- paddingTop: 16,- paddingHorizontal: 20,- backgroundColor: "#f8f9fa",- borderTopWidth: 0.5,- borderTopColor: "#E5E5EA",- paddingBottom: insets.bottom + 12,- }}- glassEffectStyle="clear"- >- <View className="flex-row items-center justify-between">- <View className="flex-row items-center gap-2">- <Text className="text-base font-medium text-[#333]">Set as Default</Text>- <Switch- value={isDefault}- onValueChange={handleSetAsDefault}- disabled={isDefault}- trackColor={{ false: "#E5E5EA", true: "#34C759" }}- thumbColor="#FFFFFF"- />- </View>-- <View className="flex-row items-center gap-3">- <GlassView- className="overflow-hidden rounded-full bg-[rgba(255,255,255,0.1)]"- glassEffectStyle="clear"- >- <TouchableOpacity- className="h-11 w-11 items-center justify-center"- onPress={handleDelete}- >- <Ionicons name="trash-outline" size={20} color="#FF3B30" />- </TouchableOpacity>- </GlassView>- </View>- </View>- </GlassView>- </View>-- {/* Timezone Modal */}- <FullScreenModal- visible={showTimezoneModal}- animationType="fade"- onRequestClose={() => setShowTimezoneModal(false)}- >- <TouchableOpacity- className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"- activeOpacity={1}- onPress={() => setShowTimezoneModal(false)}- >- <TouchableOpacity- className="max-h-[80%] w-[90%] max-w-[500px] rounded-2xl bg-white p-4"- activeOpacity={1}- onPress={(e) => e.stopPropagation()}- >- <View className="mb-4 flex-row items-center justify-between">- <Text className="text-xl font-bold text-[#333]">Select Timezone</Text>- <TouchableOpacity onPress={() => setShowTimezoneModal(false)}>- <Ionicons name="close" size={24} color="#666" />- </TouchableOpacity>- </View>- <ScrollView>- {timezones.map((tz) => (- <TouchableOpacity- key={tz}- onPress={() => {- setTimeZone(tz);- setShowTimezoneModal(false);- }}- className="border-b border-[#E5E5EA] py-3"- >- <Text className="text-base text-[#333]">{tz}</Text>- </TouchableOpacity>- ))}- </ScrollView>- </TouchableOpacity>- </TouchableOpacity>- </FullScreenModal>-- {/* Time Picker Modal */}- <FullScreenModal- visible={!!showTimePicker}- animationType="fade"- onRequestClose={() => setShowTimePicker(null)}- >- <TouchableOpacity- className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"- activeOpacity={1}- onPress={() => setShowTimePicker(null)}- >- <TouchableOpacity- className="max-h-[80%] w-[90%] max-w-[500px] rounded-2xl bg-white p-4"- activeOpacity={1}- onPress={(e) => e.stopPropagation()}- >- <View className="mb-4 flex-row items-center justify-between">- <Text className="text-xl font-bold text-[#333]">- Select {showTimePicker?.type === "start" ? "Start" : "End"} Time- </Text>- <TouchableOpacity onPress={() => setShowTimePicker(null)}>- <Ionicons name="close" size={24} color="#666" />- </TouchableOpacity>- </View>- <ScrollView>- {TIME_OPTIONS.map((time) => {- const currentTime =- showTimePicker?.type === "start"- ? availability[showTimePicker.dayIndex]?.[- showTimePicker.slotIndex- ]?.startTime.substring(0, 5)- : availability[showTimePicker?.dayIndex || 0]?.[- showTimePicker?.slotIndex || 0- ]?.endTime.substring(0, 5);- const isSelected = currentTime === time;-- return (- <TouchableOpacity- key={time}- onPress={() => {- if (showTimePicker) {- updateTimeSlot(- showTimePicker.dayIndex,- showTimePicker.slotIndex,- showTimePicker.type,- time- );- setShowTimePicker(null);- }- }}- className={`border-b border-[#E5E5EA] py-3 ${isSelected ? "bg-[#E3F2FD]" : ""}`}- >- <Text- className={`text-base ${isSelected ? "font-semibold text-[#007AFF]" : "text-[#333]"}`}- >- {time}- </Text>- </TouchableOpacity>- );- })}- </ScrollView>- </TouchableOpacity>- </TouchableOpacity>- </FullScreenModal>-- {/* Override Modal */}- <FullScreenModal- visible={showOverrideModal}- animationType="fade"- onRequestClose={() => setShowOverrideModal(false)}- >- <TouchableOpacity- className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"- activeOpacity={1}- onPress={() => setShowOverrideModal(false)}- >- <TouchableOpacity- className="max-h-[90%] w-[90%] max-w-[500px] rounded-2xl bg-white p-6"- activeOpacity={1}- onPress={(e) => e.stopPropagation()}- >- <View className="mb-4 flex-row items-center justify-between">- <Text className="text-xl font-bold text-[#333]">- {editingOverride !== null ? "Edit Override" : "Add Override"}- </Text>- <TouchableOpacity onPress={() => setShowOverrideModal(false)}>- <Ionicons name="close" size={24} color="#666" />- </TouchableOpacity>- </View>-- <ScrollView>- <View className="gap-4">- {/* Date Picker */}- <View>- <Text className="mb-2 text-base font-semibold text-[#333]">- Select the dates to override- </Text>- <TextInput- value={overrideDate}- onChangeText={setOverrideDate}- placeholder="YYYY-MM-DD (e.g., 2024-05-20)"- placeholderTextColor="#999"- className="rounded-lg border border-[#E5E5EA] bg-[#F8F9FA] px-3 py-3 text-base text-[#333]"- />- <Text className="mt-1 text-sm text-[#666]">Enter date in YYYY-MM-DD format</Text>- </View>-- {/* Unavailable Toggle */}- <View className="flex-row items-center justify-between">- <Text className="text-base font-semibold text-[#333]">- Mark unavailable (All day)- </Text>- <Switch- value={isUnavailable}- onValueChange={setIsUnavailable}- trackColor={{ false: "#E5E5EA", true: "#34C759" }}- thumbColor="#FFFFFF"- />- </View>-- {/* Time Picker (only if not unavailable) */}- {!isUnavailable ? (- <View>- <Text className="mb-3 text-base font-semibold text-[#333]">- Which hours are you free?- </Text>- <View className="flex-row items-center gap-2">- <TouchableOpacity- onPress={() => setShowOverrideTimePicker({ type: "start" })}- className="flex-1 rounded-lg border border-[#E5E5EA] bg-white px-3 py-3"- >- <Text className="text-center text-base text-[#333]">- {formatTime12Hour(overrideStartTime + ":00")}- </Text>- </TouchableOpacity>- <Text className="text-base text-[#666]">-</Text>- <TouchableOpacity- onPress={() => setShowOverrideTimePicker({ type: "end" })}- className="flex-1 rounded-lg border border-[#E5E5EA] bg-white px-3 py-3"- >- <Text className="text-center text-base text-[#333]">- {formatTime12Hour(overrideEndTime + ":00")}- </Text>- </TouchableOpacity>- </View>- </View>- ) : null}-- {/* Save Button */}- <TouchableOpacity- onPress={handleSaveOverride}- className="mt-4 rounded-lg bg-black py-3"- >- <Text className="text-center text-base font-semibold text-white">- Save Override- </Text>- </TouchableOpacity>- </View>- </ScrollView>- </TouchableOpacity>- </TouchableOpacity>- </FullScreenModal>-- {/* Override Time Picker Modal */}- <FullScreenModal- visible={!!showOverrideTimePicker}- animationType="fade"- onRequestClose={() => setShowOverrideTimePicker(null)}- >- <TouchableOpacity- className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"- activeOpacity={1}- onPress={() => setShowOverrideTimePicker(null)}- >- <TouchableOpacity- className="max-h-[60%] w-[90%] max-w-[500px] rounded-2xl bg-white p-6"- activeOpacity={1}- onPress={(e) => e.stopPropagation()}- >- <View className="mb-4 flex-row items-center justify-between">- <Text className="text-xl font-bold text-[#333]">- Select {showOverrideTimePicker?.type === "start" ? "Start" : "End"} Time- </Text>- <TouchableOpacity onPress={() => setShowOverrideTimePicker(null)}>- <Ionicons name="close" size={24} color="#666" />- </TouchableOpacity>- </View>- <ScrollView>- {TIME_OPTIONS.map((time) => {- const currentTime =- showOverrideTimePicker?.type === "start" ? overrideStartTime : overrideEndTime;- const isSelected = currentTime === time;- return (- <TouchableOpacity- key={time}- onPress={() => {- if (showOverrideTimePicker?.type === "start") {- setOverrideStartTime(time);- } else {- setOverrideEndTime(time);- }- setShowOverrideTimePicker(null);- }}- className={`border-b border-[#E5E5EA] py-3 ${isSelected ? "bg-[#F0F9FF]" : ""}`}- >- <Text- className={`text-base ${isSelected ? "font-semibold text-[#007AFF]" : "text-[#333]"}`}- >- {formatTime12Hour(time + ":00")}- </Text>- </TouchableOpacity>- );- })}- </ScrollView>- </TouchableOpacity>- </TouchableOpacity>- </FullScreenModal>+ <Stack.Screen options={{ headerShown: false }} />+ <AvailabilityDetailScreen id={id} /></>);}diff --git a/companion/app/booking-detail.tsx b/companion/app/booking-detail.tsxindex 0425bf6351a..146b2c3c5fa 100644--- a/companion/app/booking-detail.tsx+++ b/companion/app/booking-detail.tsx@@ -1,683 +1,18 @@-import { Ionicons } from "@expo/vector-icons";-import { useRouter, useLocalSearchParams, Stack } from "expo-router";-import React, { useState, useEffect } from "react";-import {- View,- Text,- ScrollView,- TouchableOpacity,- Alert,- ActivityIndicator,- TextInput,- Platform,-} from "react-native";-import { useSafeAreaInsets } from "react-native-safe-area-context";-import { CalComAPIService, Booking } from "../services/calcom";-import { showErrorAlert } from "../utils/alerts";-import { openInAppBrowser } from "../utils/browser";-import { shadows } from "../utils/shadows";-import { SvgImage } from "../components/SvgImage";-import { FullScreenModal } from "../components/FullScreenModal";-import { BookingActionsModal } from "../components/BookingActionsModal";-import { getAppIconUrl } from "../utils/getAppIconUrl";-import { getDefaultLocationIconUrl, defaultLocations } from "../utils/defaultLocations";-import { formatAppIdToDisplayName } from "../utils/formatters";--// Format date: "Tuesday, November 25, 2025"-const formatDateFull = (dateString: string): string => {- if (!dateString) return "";- try {- const date = new Date(dateString);- return date.toLocaleDateString("en-US", {- weekday: "long",- month: "long",- day: "numeric",- year: "numeric",- });- } catch (error) {- return "";- }-};--// Format time: "9:40pm - 10:00pm"-const formatTime12Hour = (dateString: string): string => {- if (!dateString) return "";- try {- const date = new Date(dateString);- const hours = date.getHours();- const minutes = date.getMinutes();- const period = hours >= 12 ? "pm" : "am";- const hour12 = hours === 0 ? 12 : hours > 12 ? hours - 12 : hours;- const minStr = minutes.toString().padStart(2, "0");- return `${hour12}:${minStr}${period}`;- } catch (error) {- return "";- }-};--// Get timezone from date string-const getTimezone = (dateString: string): string => {- if (!dateString) return "";- try {- const date = new Date(dateString);- const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;- return timeZone;- } catch (error) {- return "";- }-};--// Get initials from a name (e.g., "Keith Williams" -> "KW", "Dhairyashil Shinde" -> "DS")-const getInitials = (name: string): string => {- if (!name) return "";- const parts = name.trim().split(/\s+/);- if (parts.length === 0) return "";- if (parts.length === 1) {- return parts[0].charAt(0).toUpperCase();- }- // Get first letter of first name and first letter of last name- return (parts[0].charAt(0) + parts[parts.length - 1].charAt(0)).toUpperCase();-};--// Get location provider info-const getLocationProvider = (location: string | undefined, metadata?: Record<string, any>) => {- // Check metadata for videoCallUrl first- const videoCallUrl = metadata?.videoCallUrl;- const locationToCheck = videoCallUrl || location;-- if (!locationToCheck) return null;-- // Check if it's a video call URL- if (typeof locationToCheck === "string" && locationToCheck.startsWith("http")) {- // Try to detect provider from URL- if (locationToCheck.includes("cal.com/video") || locationToCheck.includes("cal-video")) {- const iconUrl = getAppIconUrl("daily_video", "cal-video");- return {- label: "Cal Video",- iconUrl: iconUrl || "https://app.cal.com/app-store/dailyvideo/icon.svg",- url: locationToCheck,- };- }- // Check for other video providers by URL pattern- const videoProviders = [- { pattern: /zoom\.us/, label: "Zoom", type: "zoom_video", appId: "zoom" },- {- pattern: /meet\.google\.com/,- label: "Google Meet",- type: "google_video",- appId: "google-meet",- },- {- pattern: /teams\.microsoft\.com/,- label: "Microsoft Teams",- type: "office365_video",- appId: "msteams",- },- ];-- for (const provider of videoProviders) {- if (provider.pattern.test(locationToCheck)) {- const iconUrl = getAppIconUrl(provider.type, provider.appId);- return {- label: provider.label,- iconUrl: iconUrl,- url: locationToCheck,- };- }- }-- // Generic link meeting- const linkIconUrl = getDefaultLocationIconUrl("link") || "https://app.cal.com/link.svg";- return {- label: "Link Meeting",- iconUrl: linkIconUrl,- url: locationToCheck,- };- }-- // Check if it's an integration location (e.g., "integrations:zoom", "integrations:cal-video")- if (typeof locationToCheck === "string" && locationToCheck.startsWith("integrations:")) {- const appId = locationToCheck.replace("integrations:", "");- const iconUrl = getAppIconUrl("", appId);-- if (iconUrl) {- return {- label: formatAppIdToDisplayName(appId),- iconUrl: iconUrl,- url: null,- };- }- }-- // Check if it's a default location type- const defaultLocation = defaultLocations.find((loc) => loc.type === locationToCheck);- if (defaultLocation) {- return {- label: defaultLocation.label,- iconUrl: defaultLocation.iconUrl,- url: null,- };- }-- // Fallback: return as plain text location- return {- label: locationToCheck,- iconUrl: null,- url: null,- };-};+import { BookingDetailScreen } from "../components/screens/BookingDetailScreen";+import { useLocalSearchParams, Stack } from "expo-router";+import React from "react";export default function BookingDetail() {- const router = useRouter();const { uid } = useLocalSearchParams<{ uid: string }>();- const insets = useSafeAreaInsets();-- const [loading, setLoading] = useState(true);- const [booking, setBooking] = useState<Booking | null>(null);- const [error, setError] = useState<string | null>(null);- const [showActionsModal, setShowActionsModal] = useState(false);- const [showRescheduleModal, setShowRescheduleModal] = useState(false);- const [rescheduleDate, setRescheduleDate] = useState("");- const [rescheduleTime, setRescheduleTime] = useState("");- const [rescheduleReason, setRescheduleReason] = useState("");- const [rescheduling, setRescheduling] = useState(false);-- useEffect(() => {- if (uid) {- fetchBooking();- }- }, [uid]);-- const fetchBooking = async () => {- try {- setLoading(true);- setError(null);- const bookingData = await CalComAPIService.getBookingByUid(uid);- console.log("Booking data received:", JSON.stringify(bookingData, null, 2));- console.log("User:", bookingData.user);- console.log("Hosts:", bookingData.hosts);- console.log("Attendees:", bookingData.attendees);- console.log("Recurring fields:", {- recurringEventId: bookingData.recurringEventId,- recurringBookingUid: (bookingData as any).recurringBookingUid,- metadata: (bookingData as any).metadata,- });- setBooking(bookingData);- } catch (err) {- console.error("Error fetching booking:", err);- setError("Failed to load booking. Please try again.");- if (__DEV__) {- Alert.alert("Error", "Failed to load booking. Please try again.", [- { text: "OK", onPress: () => router.back() },- ]);- } else {- router.back();- }- } finally {- setLoading(false);- }- };-- const handleJoinMeeting = () => {- if (!booking?.location) return;-- const provider = getLocationProvider(booking.location);- if (provider?.url) {- openInAppBrowser(provider.url, "meeting link");- }- };- const openRescheduleModal = () => {- if (!booking) return;-- // Pre-fill with the current booking date/time (using local timezone consistently)- const currentDate = new Date(booking.startTime);- const dateStr = `${currentDate.getFullYear()}-${String(currentDate.getMonth() + 1).padStart(2, "0")}-${String(currentDate.getDate()).padStart(2, "0")}`;- const timeStr = `${String(currentDate.getHours()).padStart(2, "0")}:${String(currentDate.getMinutes()).padStart(2, "0")}`;-- setRescheduleDate(dateStr);- setRescheduleTime(timeStr);- setRescheduleReason("");- setShowRescheduleModal(true);- };-- const handleReschedule = async () => {- if (!booking || !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 (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();-- setRescheduling(true);- try {- await CalComAPIService.rescheduleBooking(booking.uid, {- start: startUtc,- reschedulingReason: rescheduleReason.trim() || undefined,- });-- Alert.alert("Success", "Booking rescheduled successfully");- setShowRescheduleModal(false);- setRescheduleDate("");- setRescheduleTime("");- setRescheduleReason("");-- // Refresh booking data- await fetchBooking();- } catch (error) {- console.error("Failed to reschedule booking:", error);- showErrorAlert("Error", "Failed to reschedule booking. Please try again.");- } finally {- setRescheduling(false);- }- };-- if (loading) {- return (- <View className="flex-1 items-center justify-center bg-[#f8f9fa]">- <ActivityIndicator size="large" color="#000000" />- <Text className="mt-4 text-base text-gray-500">Loading booking...</Text>- </View>- );- }-- if (error || !booking) {- return (- <View className="flex-1 items-center justify-center bg-[#f8f9fa] p-5">- <Ionicons name="alert-circle" size={64} color="#FF3B30" />- <Text className="mb-2 mt-4 text-center text-xl font-bold text-gray-800">- {error || "Booking not found"}- </Text>- <TouchableOpacity- className="mt-6 rounded-lg bg-black px-6 py-3"- onPress={() => router.back()}- >- <Text className="text-base font-semibold text-white">Go Back</Text>- </TouchableOpacity>- </View>- );+ if (!uid) {+ return null;}- const startTime = booking.start || booking.startTime || "";- const endTime = booking.end || booking.endTime || "";- const dateFormatted = formatDateFull(startTime);- const timeFormatted = `${formatTime12Hour(startTime)} - ${formatTime12Hour(endTime)}`;- const timezone = getTimezone(startTime);- const locationProvider = getLocationProvider(booking.location, booking.responses);-return (<>- <Stack.Screen- options={{- headerShown: true,- headerTitle: booking?.title || "Booking Details",- headerLeft: () => (- <TouchableOpacity- onPress={() => router.back()}- className="items-center justify-center rounded-full"- style={{ width: 40, height: 40, backgroundColor: "#F0F0F0" }}- >- <Ionicons name="chevron-back" size={24} color="#000" />- </TouchableOpacity>- ),- headerRight: () => (- <TouchableOpacity- onPress={() => setShowActionsModal(true)}- className="items-center justify-center rounded-full"- style={{ width: 40, height: 40, backgroundColor: "#F0F0F0" }}- >- <Ionicons name="ellipsis-horizontal" size={24} color="#000" />- </TouchableOpacity>- ),- }}- />- <View className="flex-1 bg-[#f8f9fa]">- <ScrollView className="flex-1" contentContainerStyle={{ padding: 16, paddingBottom: 100 }}>- {/* Title */}- <View className="mb-3">- <Text className="mb-2 text-2xl font-semibold text-[#333]">{booking.title}</Text>- <Text className="text-base text-[#666]">- {dateFormatted} {timeFormatted} ({timezone})- </Text>- </View>-- {/* Who Section */}- <View className="mb-2 rounded-2xl bg-white p-6">- <Text className="mb-4 text-base font-medium text-[#666]">Who</Text>- {/* Show host from user field or hosts array */}- {booking.user || (booking.hosts && booking.hosts.length > 0) ? (- <View className="mb-4">- {booking.user ? (- <View className="flex-row items-start">- <View className="mr-3 h-12 w-12 items-center justify-center rounded-full bg-black">- <Text className="text-base font-semibold text-white">- {getInitials(booking.user.name)}- </Text>- </View>- <View className="flex-1">- <View className="mb-1 flex-row flex-wrap items-center">- <Text className="text-base font-medium text-[#333]">- {booking.user.name}- </Text>- <View className="ml-2 rounded bg-[#007AFF] px-2 py-0.5">- <Text className="text-xs font-medium text-white">host</Text>- </View>- </View>- <Text className="text-sm text-[#666]">{booking.user.email}</Text>- </View>- </View>- ) : booking.hosts && booking.hosts.length > 0 ? (- booking.hosts.map((host, hostIndex) => (- <View- key={hostIndex}- className={`flex-row items-start ${hostIndex > 0 ? "mt-4" : ""}`}- >- <View className="mr-3 h-12 w-12 items-center justify-center rounded-full bg-black">- <Text className="text-base font-semibold text-white">- {getInitials(host.name || "Host")}- </Text>- </View>- <View className="flex-1">- <View className="mb-1 flex-row flex-wrap items-center">- <Text className="text-base font-medium text-[#333]">- {host.name || "Host"}- </Text>- <View className="ml-2 rounded bg-[#007AFF] px-2 py-0.5">- <Text className="text-xs font-medium text-white">host</Text>- </View>- </View>- {host.email && <Text className="text-sm text-[#666]">{host.email}</Text>}- </View>- </View>- ))- ) : null}- </View>- ) : null}- {booking.attendees && booking.attendees.length > 0 ? (- <View>- {booking.attendees.map((attendee, index) => (- <View key={index} className={`flex-row items-start ${index > 0 ? "mt-4" : ""}`}>- <View className="mr-3 h-12 w-12 items-center justify-center rounded-full bg-black">- <Text className="text-base font-semibold text-white">- {getInitials(attendee.name)}- </Text>- </View>- <View className="flex-1">- <Text className="mb-1 text-base font-medium text-[#333]">- {attendee.name}- </Text>- <Text className="text-sm text-[#666]">{attendee.email}</Text>- </View>- </View>- ))}- </View>- ) : null}- </View>-- {/* Where Section */}- {locationProvider ? (- <View className="mb-2 rounded-2xl bg-white p-6">- <Text className="mb-4 text-base font-medium text-[#666]">Where</Text>- {locationProvider.url ? (- <TouchableOpacity- onPress={handleJoinMeeting}- className="flex-row flex-wrap items-center"- >- {locationProvider.iconUrl ? (- <SvgImage- uri={locationProvider.iconUrl}- width={20}- height={20}- style={{ marginRight: 8 }}- />- ) : null}- <Text className="text-base text-[#007AFF]">{locationProvider.label}: </Text>- <Text className="flex-1 text-base text-[#007AFF]" numberOfLines={1}>- {locationProvider.url}- </Text>- </TouchableOpacity>- ) : (- <View className="flex-row items-center">- {locationProvider.iconUrl ? (- <SvgImage- uri={locationProvider.iconUrl}- width={20}- height={20}- style={{ marginRight: 8 }}- />- ) : null}- <Text className="text-base text-[#333]">{locationProvider.label}</Text>- </View>- )}- </View>- ) : null}-- {/* Recurring Event Section */}- {booking.recurringEventId || booking.recurringBookingUid ? (- <View className="mb-2 rounded-2xl bg-white p-6">- <Text className="mb-2 text-base font-medium text-[#666]">Recurring Event</Text>- <Text className="text-base text-[#666]">Every 2 weeks for 6 occurrences</Text>- </View>- ) : null}-- {/* Description Section */}- {booking.description ? (- <View className="mb-2 rounded-2xl bg-white p-6">- <Text className="mb-2 text-base font-medium text-[#666]">Description</Text>- <Text className="text-base leading-6 text-[#666]">{booking.description}</Text>- </View>- ) : null}-- {/* Join Meeting Button */}- {locationProvider?.url ? (- <TouchableOpacity- onPress={handleJoinMeeting}- className="mb-2 flex-row items-center justify-center rounded-lg bg-black px-6 py-4"- >- {locationProvider.iconUrl ? (- <SvgImage- uri={locationProvider.iconUrl}- width={20}- height={20}- style={{ marginRight: 8 }}- />- ) : null}- <Text className="text-base font-semibold text-white">- Join {locationProvider.label}- </Text>- </TouchableOpacity>- ) : null}- </ScrollView>- </View>-- {/* Booking Actions Modal */}- <BookingActionsModal- visible={showActionsModal}- onClose={() => setShowActionsModal(false)}- booking={booking}- hasLocationUrl={!!locationProvider?.url}- isUpcoming={booking ? new Date(booking.startTime) > new Date() : false}- isPast={booking ? new Date(booking.startTime) <= new Date() : false}- isCancelled={booking?.status?.toUpperCase() === "CANCELLED"}- isUnconfirmed={booking?.status?.toUpperCase() === "PENDING"}- onReschedule={openRescheduleModal}- onEditLocation={() => {- Alert.alert("Edit Location", "Edit location functionality coming soon");- }}- onAddGuests={() => {- Alert.alert("Add Guests", "Add guests functionality coming soon");- }}- onViewRecordings={() => {- Alert.alert("View Recordings", "View recordings functionality coming soon");- }}- onMeetingSessionDetails={() => {- Alert.alert(- "Meeting Session Details",- "Meeting session details functionality coming soon"- );- }}- onMarkNoShow={() => {- Alert.alert("Mark as No-Show", "Mark as no-show functionality coming soon");- }}- onReportBooking={() => {- Alert.alert("Report Booking", "Report booking functionality coming soon");- }}- onCancelBooking={() => {- Alert.alert("Cancel Booking", "Are you sure you want to cancel this booking?", [- { text: "No", style: "cancel" },- {- text: "Yes, Cancel",- style: "destructive",- onPress: () => {- // TODO: Implement cancel booking- console.log("Cancel booking");- },- },- ]);- }}- />-- {/* Reschedule Modal */}- <FullScreenModal- visible={showRescheduleModal}- animationType="fade"- onRequestClose={() => setShowRescheduleModal(false)}- >- <TouchableOpacity- className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"- activeOpacity={1}- onPress={() => setShowRescheduleModal(false)}- >- <TouchableOpacity- className="w-[90%] max-w-[500px] rounded-2xl bg-white"- activeOpacity={1}- onPress={(e) => e.stopPropagation()}- style={shadows.xl()}- >- {/* Header */}- <View className="px-8 pb-4 pt-6">- <View className="flex-row items-start space-x-3">- <View className="h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-[#F3F4F6]">- <Ionicons name="calendar-outline" size={24} color="#111827" />- </View>- <View className="flex-1 pt-1">- <Text className="mb-2 text-2xl font-semibold text-[#111827]">- Reschedule Booking- </Text>- <Text className="text-sm text-[#6B7280]">- Select a new date and time for this booking.- </Text>- </View>- </View>- </View>-- {/* Content */}- <ScrollView className="max-h-[400px] px-8 pb-6">- {/* Date Input */}- <View className="mb-4">- <Text className="mb-2 text-sm font-bold text-[#111827]">- New Date- <Text className="font-normal text-[#6B7280]"> (YYYY-MM-DD)</Text>- </Text>- <TextInput- className="rounded-md border border-[#D1D5DB] bg-white px-3 py-3 text-base text-[#111827]"- placeholder="2024-12-25"- placeholderTextColor="#9CA3AF"- value={rescheduleDate}- onChangeText={setRescheduleDate}- editable={!rescheduling}- keyboardType="default"- />- </View>-- {/* Time Input */}- <View className="mb-4">- <Text className="mb-2 text-sm font-bold text-[#111827]">- New Time- <Text className="font-normal text-[#6B7280]"> (HH:MM, 24-hour)</Text>- </Text>- <TextInput- className="rounded-md border border-[#D1D5DB] bg-white px-3 py-3 text-base text-[#111827]"- placeholder="14:30"- placeholderTextColor="#9CA3AF"- value={rescheduleTime}- onChangeText={setRescheduleTime}- editable={!rescheduling}- keyboardType="default"- />- </View>-- {/* Reason Input */}- <View className="mb-2">- <Text className="mb-2 text-sm font-bold text-[#111827]">- Reason- <Text className="font-normal text-[#6B7280]"> (Optional)</Text>- </Text>- <TextInput- className="min-h-[80px] rounded-md border border-[#D1D5DB] bg-white px-3 py-3 text-base text-[#111827]"- placeholder="Enter reason for rescheduling..."- placeholderTextColor="#9CA3AF"- value={rescheduleReason}- onChangeText={setRescheduleReason}- multiline- numberOfLines={3}- textAlignVertical="top"- editable={!rescheduling}- />- </View>- </ScrollView>-- {/* Footer */}- <View className="rounded-b-2xl border-t border-[#E5E7EB] bg-[#F9FAFB] px-8 py-4">- <View className="flex-row justify-end gap-2 space-x-2">- <TouchableOpacity- className="rounded-xl border border-[#D1D5DB] bg-white px-2 py-2 md:px-4"- onPress={() => {- setShowRescheduleModal(false);- setRescheduleDate("");- setRescheduleTime("");- setRescheduleReason("");- }}- disabled={rescheduling}- >- <Text className="text-base font-medium text-[#374151]">Cancel</Text>- </TouchableOpacity>- <TouchableOpacity- className={`rounded-xl bg-[#111827] px-2 py-2 md:px-4 ${rescheduling ? "opacity-60" : ""}`}- onPress={handleReschedule}- disabled={rescheduling}- >- {rescheduling ? (- <ActivityIndicator size="small" color="white" />- ) : (- <Text className="text-base font-medium text-white">Reschedule</Text>- )}- </TouchableOpacity>- </View>- </View>- </TouchableOpacity>- </TouchableOpacity>- </FullScreenModal>+ <Stack.Screen options={{ headerShown: false }} />+ <BookingDetailScreen uid={uid} /></>);}diff --git a/companion/app/event-type-detail.tsx b/companion/app/event-type-detail.tsxindex edafbfc3fc5..9fe8dd4dcb7 100644--- a/companion/app/event-type-detail.tsx+++ b/companion/app/event-type-detail.tsx@@ -1678,7 +1678,7 @@ export default function EventTypeDetail() {schedulesLoading={schedulesLoading}scheduleDetailsLoading={scheduleDetailsLoading}selectedScheduleDetails={selectedScheduleDetails}- getDaySchedule={getDaySchedule}+ getDaySchedules={getDaySchedule}formatTime={formatTime}selectedTimezone={selectedTimezone}/>diff --git a/companion/components/AppPressable.tsx b/companion/components/AppPressable.tsxnew file mode 100644index 00000000000..923ddcf01aa--- /dev/null+++ b/companion/components/AppPressable.tsx@@ -0,0 +1,16 @@+import React from "react";+import { TouchableOpacity } from "react-native";+import type { TouchableOpacityProps } from "react-native";++type AppPressableProps = TouchableOpacityProps & {+ className?: string;+};++export const AppPressable = React.forwardRef<+ React.ElementRef<typeof TouchableOpacity>,+ AppPressableProps+>(({ className, ...props }, ref) => {+ return <TouchableOpacity ref={ref} className={className} {...props} />;+});++AppPressable.displayName = "AppPressable";diff --git a/companion/components/AuthTokenProvider.tsx b/companion/components/AuthTokenProvider.tsxindex b6d6f0f261f..28e77e4f493 100644--- a/companion/components/AuthTokenProvider.tsx+++ b/companion/components/AuthTokenProvider.tsx@@ -1,6 +1,6 @@import { useEffect } from "react";import { useAuth } from "../contexts/AuthContext";-import { setAuthToken, setWebSession } from "../services/calcom";+import { CalComAPIService } from "../services/calcom";export function AuthTokenProvider({ children }: { children: React.ReactNode }) {const { accessToken, isAuthenticated, isWebSession } = useAuth();@@ -8,12 +8,10 @@ export function AuthTokenProvider({ children }: { children: React.ReactNode }) {useEffect(() => {if (isAuthenticated) {if (accessToken) {- setAuthToken(accessToken);+ CalComAPIService.setAccessToken(accessToken);}- setWebSession(isWebSession);} else {- setAuthToken(null);- setWebSession(false);+ CalComAPIService.clearAuth();}}, [isAuthenticated, accessToken, isWebSession]);diff --git a/companion/components/FullScreenModal.d.ts b/companion/components/FullScreenModal.d.tsnew file mode 100644index 00000000000..a64aae387de--- /dev/null+++ b/companion/components/FullScreenModal.d.ts@@ -0,0 +1,10 @@+import type React from "react";+import type { ModalProps } from "react-native";++export interface FullScreenModalProps extends ModalProps {+ visible: boolean;+ onRequestClose: () => void;+ children: React.ReactNode;+}++export declare function FullScreenModal(props: FullScreenModalProps): JSX.Element;diff --git a/companion/components/Header.tsx b/companion/components/Header.tsxindex 1c967229b84..2064949a966 100644--- a/companion/components/Header.tsx+++ b/companion/components/Header.tsx@@ -34,7 +34,12 @@ export function Header() {const profile = await CalComAPIService.getUserProfile();setUserProfile(profile);} catch (error) {- console.error("Failed to fetch user profile:", error);+ console.error("Failed to fetch user profile");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[Header] fetchUserProfile failed", { message, stack });+ }} finally {setLoading(false);}@@ -55,7 +60,12 @@ export function Header() {await Clipboard.setStringAsync(publicPageUrl);Alert.alert("Link Copied!", "Your public page link has been copied to clipboard.");} catch (error) {- console.error("Failed to copy public page link:", error);+ console.error("Failed to copy public page link");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[Header] copyPublicPageLink failed", { message, stack });+ }Alert.alert("Error", "Failed to copy link. Please try again.");}};diff --git a/companion/components/LoginScreen.tsx b/companion/components/LoginScreen.tsxindex 3e3c2cbc757..218ab798877 100644--- a/companion/components/LoginScreen.tsx+++ b/companion/components/LoginScreen.tsx@@ -14,7 +14,7 @@ export function LoginScreen() {try {await loginWithOAuth();} catch (error) {- console.error("OAuth login error:", error);+ console.error("OAuth login error");showErrorAlert("Login Failed",error instanceof Errordiff --git a/companion/components/LogoutButton.tsx b/companion/components/LogoutButton.tsxindex 14defc4fa30..5dc50e213bb 100644--- a/companion/components/LogoutButton.tsx+++ b/companion/components/LogoutButton.tsx@@ -35,7 +35,12 @@ export function LogoutButton({ className = "" }: LogoutButtonProps) {try {await logout();} catch (error) {- console.error("Logout error:", error);+ const message = error instanceof Error ? error.message : String(error);+ console.error("Logout error", message);+ if (__DEV__) {+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[LogoutButton] logout failed", { message, stack });+ }if (Platform.OS === "web") {window.alert("Failed to sign out. Please try again.");} else {diff --git a/companion/components/event-type-detail/tabs/AvailabilityTab.tsx b/companion/components/event-type-detail/tabs/AvailabilityTab.tsxindex 6b04c069a9a..0202c63bc3c 100644--- a/companion/components/event-type-detail/tabs/AvailabilityTab.tsx+++ b/companion/components/event-type-detail/tabs/AvailabilityTab.tsx@@ -16,7 +16,7 @@ interface AvailabilityTabProps {schedulesLoading: boolean;scheduleDetailsLoading: boolean;selectedScheduleDetails: any;- getDaySchedule: () => DaySchedule[];+ getDaySchedules: () => DaySchedule[];formatTime: (time: string) => string;selectedTimezone: string;}@@ -60,7 +60,7 @@ export function AvailabilityTab(props: AvailabilityTabProps) {<Text className="text-sm italic text-[#8E8E93]">Loading schedule details...</Text></View>) : props.selectedScheduleDetails ? (- props.getDaySchedule().map((dayInfo, index) => (+ props.getDaySchedules().map((dayInfo, index) => (<View key={index} className="flex-row items-center justify-between py-4"><TextclassName={`ml-2 flex-1 text-[15px] font-medium text-[#333] ${diff --git a/companion/components/screens/AvailabilityDetailScreen.tsx b/companion/components/screens/AvailabilityDetailScreen.tsxnew file mode 100644index 00000000000..f7b72a7b739--- /dev/null+++ b/companion/components/screens/AvailabilityDetailScreen.tsx@@ -0,0 +1,1017 @@+import { CalComAPIService, Schedule } from "../../services/calcom";+import { ScheduleAvailability } from "../../services/types";+import { showErrorAlert } from "../../utils/alerts";+import { AppPressable } from "../AppPressable";+import { FullScreenModal } from "../FullScreenModal";+import { Ionicons } from "@expo/vector-icons";+import { GlassView } from "expo-glass-effect";+import { useRouter } from "expo-router";+import React, { useState, useEffect } from "react";+import { View, Text, ScrollView, TextInput, Alert, ActivityIndicator, Switch } from "react-native";+import { useSafeAreaInsets } from "react-native-safe-area-context";++const DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];+const DAY_ABBREVIATIONS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];++// Convert 24-hour time to 12-hour format with AM/PM+const formatTime12Hour = (time24: string): string => {+ const [hours, minutes] = time24.split(":");+ const hour = parseInt(hours, 10);+ const min = minutes || "00";+ const period = hour >= 12 ? "PM" : "AM";+ const hour12 = hour === 0 ? 12 : hour > 12 ? hour - 12 : hour;+ // Pad single-digit hours with leading zero for consistent width+ const hour12Padded = hour12.toString().padStart(2, "0");+ return `${hour12Padded}:${min} ${period}`;+};++// Format availability for display+const formatAvailabilityDisplay = (+ availability: Record<number, ScheduleAvailability[]>+): string[] => {+ // Group slots by time range+ const timeRangeMap: Record<string, number[]> = {};++ Object.keys(availability).forEach((dayIndexStr) => {+ const dayIndex = Number(dayIndexStr);+ const slots = availability[dayIndex];+ if (slots && slots.length > 0) {+ slots.forEach((slot) => {+ const timeKey = `${slot.startTime}-${slot.endTime}`;+ if (!timeRangeMap[timeKey]) {+ timeRangeMap[timeKey] = [];+ }+ timeRangeMap[timeKey].push(dayIndex);+ });+ }+ });++ // Format each time range group+ const formatted: string[] = [];+ Object.keys(timeRangeMap).forEach((timeKey) => {+ const days = timeRangeMap[timeKey].sort((a, b) => a - b);+ const [startTime, endTime] = timeKey.split("-");+ const dayNames = days.map((day) => DAY_ABBREVIATIONS[day]).join(", ");+ const timeRange = `${formatTime12Hour(startTime)} - ${formatTime12Hour(endTime)}`;+ formatted.push(`${dayNames}, ${timeRange}`);+ });++ return formatted;+};++// Generate time options (15-minute intervals)+const generateTimeOptions = () => {+ const options: string[] = [];+ for (let hour = 0; hour < 24; hour++) {+ for (let minute = 0; minute < 60; minute += 15) {+ const h = hour.toString().padStart(2, "0");+ const m = minute.toString().padStart(2, "0");+ options.push(`${h}:${m}`);+ }+ }+ return options;+};++const TIME_OPTIONS = generateTimeOptions();++export interface AvailabilityDetailScreenProps {+ id: string;+}++export function AvailabilityDetailScreen({ id }: AvailabilityDetailScreenProps) {+ const router = useRouter();+ const insets = useSafeAreaInsets();++ const [loading, setLoading] = useState(true);+ const [saving, setSaving] = useState(false);+ const [schedule, setSchedule] = useState<Schedule | null>(null);+ const [scheduleName, setScheduleName] = useState("");+ const [timeZone, setTimeZone] = useState("");+ const [isDefault, setIsDefault] = useState(false);+ const [availability, setAvailability] = useState<Record<number, ScheduleAvailability[]>>({});+ const [showTimezoneModal, setShowTimezoneModal] = useState(false);+ const [showTimePicker, setShowTimePicker] = useState<{+ dayIndex: number;+ slotIndex: number;+ type: "start" | "end";+ } | null>(null);+ const [overrides, setOverrides] = useState<+ Array<{+ date: string; // Format: "2024-05-20"+ startTime: string; // Format: "12:00" or "00:00" for unavailable+ endTime: string; // Format: "14:00" or "00:00" for unavailable+ }>+ >([]);+ const [showOverrideModal, setShowOverrideModal] = useState(false);+ const [editingOverride, setEditingOverride] = useState<number | null>(null);+ const [overrideDate, setOverrideDate] = useState("");+ const [overrideStartTime, setOverrideStartTime] = useState("09:00");+ const [overrideEndTime, setOverrideEndTime] = useState("17:00");+ const [isUnavailable, setIsUnavailable] = useState(false);+ const [showOverrideTimePicker, setShowOverrideTimePicker] = useState<{+ type: "start" | "end";+ } | null>(null);++ // Common timezones+ const timezones = [+ "America/New_York",+ "America/Chicago",+ "America/Denver",+ "America/Los_Angeles",+ "Europe/London",+ "Europe/Paris",+ "Europe/Berlin",+ "Asia/Tokyo",+ "Asia/Shanghai",+ "Asia/Kolkata",+ "Australia/Sydney",+ "UTC",+ ];++ useEffect(() => {+ if (id) {+ fetchSchedule();+ }+ }, [id]);++ const fetchSchedule = async () => {+ try {+ setLoading(true);+ const scheduleData = await CalComAPIService.getScheduleById(Number(id));++ if (scheduleData) {+ setSchedule(scheduleData);+ setScheduleName(scheduleData.name || "");+ setTimeZone(scheduleData.timeZone || "UTC");+ setIsDefault(scheduleData.isDefault || false);++ // Convert availability array to day-indexed object+ const availabilityMap: Record<number, ScheduleAvailability[]> = {};++ // Map day names to numbers+ const dayNameToNumber: Record<string, number> = {+ Sunday: 0,+ Monday: 1,+ Tuesday: 2,+ Wednesday: 3,+ Thursday: 4,+ Friday: 5,+ Saturday: 6,+ };++ if (scheduleData.availability && Array.isArray(scheduleData.availability)) {+ scheduleData.availability.forEach((slot) => {+ // Handle both string day names and number day formats+ let days: number[] = [];+ if (Array.isArray(slot.days)) {+ days = slot.days+ .map((day) => {+ // If it's a day name string (e.g., "Sunday", "Monday")+ if (typeof day === "string" && dayNameToNumber[day] !== undefined) {+ return dayNameToNumber[day];+ }+ // If it's a number string (e.g., "0", "1")+ if (typeof day === "string") {+ const parsed = parseInt(day, 10);+ if (!isNaN(parsed) && parsed >= 0 && parsed <= 6) {+ return parsed;+ }+ }+ // If it's already a number+ if (typeof day === "number" && day >= 0 && day <= 6) {+ return day;+ }+ return null;+ })+ .filter((day): day is number => day !== null);+ }++ days.forEach((day) => {+ if (!availabilityMap[day]) {+ availabilityMap[day] = [];+ }+ availabilityMap[day].push({+ days: [day.toString()],+ startTime: slot.startTime || "09:00:00",+ endTime: slot.endTime || "17:00:00",+ });+ });+ });+ }++ setAvailability(availabilityMap);++ // Load overrides if they exist+ if (scheduleData.overrides && Array.isArray(scheduleData.overrides)) {+ const formattedOverrides = scheduleData.overrides.map((override) => ({+ date: override.date || "",+ startTime: override.startTime || "00:00",+ endTime: override.endTime || "00:00",+ }));+ setOverrides(formattedOverrides);+ } else {+ setOverrides([]);+ }+ }+ } catch (error) {+ // Avoid logging raw error objects from API calls (may contain sensitive response data).+ console.error("Error fetching schedule");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ console.debug("[AvailabilityDetailScreen] fetchSchedule failed", { message });+ }+ showErrorAlert("Error", "Failed to load schedule. Please try again.");+ router.back();+ } finally {+ setLoading(false);+ }+ };++ const toggleDay = (dayIndex: number) => {+ setAvailability((prev) => {+ const newAvailability = { ...prev };+ if (newAvailability[dayIndex] && newAvailability[dayIndex].length > 0) {+ // Disable day - remove availability+ delete newAvailability[dayIndex];+ } else {+ // Enable day - add default time slot (9 AM - 5 PM)+ newAvailability[dayIndex] = [+ {+ days: [dayIndex.toString()],+ startTime: "09:00:00",+ endTime: "17:00:00",+ },+ ];+ }+ return newAvailability;+ });+ };++ const addTimeSlot = (dayIndex: number) => {+ setAvailability((prev) => {+ const newAvailability = { ...prev };+ if (!newAvailability[dayIndex]) {+ newAvailability[dayIndex] = [];+ }+ newAvailability[dayIndex].push({+ days: [dayIndex.toString()],+ startTime: "09:00:00",+ endTime: "17:00:00",+ });+ return newAvailability;+ });+ };++ const removeTimeSlot = (dayIndex: number, slotIndex: number) => {+ setAvailability((prev) => {+ const newAvailability = { ...prev };+ if (newAvailability[dayIndex]) {+ newAvailability[dayIndex] = newAvailability[dayIndex].filter((_, i) => i !== slotIndex);+ if (newAvailability[dayIndex].length === 0) {+ delete newAvailability[dayIndex];+ }+ }+ return newAvailability;+ });+ };++ const updateTimeSlot = (+ dayIndex: number,+ slotIndex: number,+ type: "start" | "end",+ time: string+ ) => {+ setAvailability((prev) => {+ const newAvailability = { ...prev };+ if (newAvailability[dayIndex] && newAvailability[dayIndex][slotIndex]) {+ const slot = { ...newAvailability[dayIndex][slotIndex] };+ if (type === "start") {+ slot.startTime = `${time}:00`;+ } else {+ slot.endTime = `${time}:00`;+ }+ newAvailability[dayIndex][slotIndex] = slot;+ }+ return newAvailability;+ });+ };++ const handleSave = async () => {+ try {+ setSaving(true);++ // Convert availability object back to array format with day names+ const availabilityArray: Array<{+ days: string[]; // Day names like "Monday", "Tuesday"+ startTime: string; // Format: "09:00"+ endTime: string; // Format: "10:00"+ }> = [];++ Object.keys(availability).forEach((dayIndexStr) => {+ const dayIndex = Number(dayIndexStr);+ const slots = availability[dayIndex];+ if (slots && slots.length > 0) {+ slots.forEach((slot) => {+ // Convert day number to day name+ const dayName = DAYS[dayIndex];++ // Format time from "09:00:00" to "09:00" (remove seconds)+ const formatTimeForAPI = (time: string): string => {+ return time.substring(0, 5); // Take only HH:MM+ };++ availabilityArray.push({+ days: [dayName],+ startTime: formatTimeForAPI(slot.startTime),+ endTime: formatTimeForAPI(slot.endTime),+ });+ });+ }+ });++ // Format overrides for API (ensure times are in HH:MM format)+ const formattedOverrides = overrides.map((override) => ({+ date: override.date,+ startTime: override.startTime.substring(0, 5), // Ensure HH:MM format+ endTime: override.endTime.substring(0, 5), // Ensure HH:MM format+ }));++ await CalComAPIService.updateSchedule(Number(id), {+ name: scheduleName,+ timeZone,+ availability: availabilityArray,+ isDefault: isDefault,+ overrides: formattedOverrides,+ });++ Alert.alert("Success", "Schedule updated successfully", [+ { text: "OK", onPress: () => router.back() },+ ]);+ } catch (error) {+ showErrorAlert("Error", "Failed to update schedule. Please try again.");+ } finally {+ setSaving(false);+ }+ };++ const handleSetAsDefault = async () => {+ try {+ await CalComAPIService.updateSchedule(Number(id), {+ isDefault: true,+ });+ setIsDefault(true);+ Alert.alert("Success", "Schedule set as default successfully");+ } catch (error) {+ showErrorAlert("Error", "Failed to set schedule as default. Please try again.");+ }+ };++ const handleDelete = () => {+ Alert.alert("Delete Schedule", `Are you sure you want to delete "${scheduleName}"?`, [+ { text: "Cancel", style: "cancel" },+ {+ text: "Delete",+ style: "destructive",+ onPress: async () => {+ try {+ await CalComAPIService.deleteSchedule(Number(id));+ Alert.alert("Success", "Schedule deleted successfully", [+ { text: "OK", onPress: () => router.back() },+ ]);+ } catch (error) {+ showErrorAlert("Error", "Failed to delete schedule. Please try again.");+ }+ },+ },+ ]);+ };++ const handleAddOverride = () => {+ setEditingOverride(null);+ setOverrideDate("");+ setOverrideStartTime("09:00");+ setOverrideEndTime("17:00");+ setIsUnavailable(false);+ setShowOverrideModal(true);+ };++ const handleEditOverride = (index: number) => {+ const override = overrides[index];+ setEditingOverride(index);+ setOverrideDate(override.date);+ setOverrideStartTime(override.startTime);+ setOverrideEndTime(override.endTime);+ setIsUnavailable(override.startTime === "00:00" && override.endTime === "00:00");+ setShowOverrideModal(true);+ };++ const handleDeleteOverride = (index: number) => {+ Alert.alert("Delete Override", "Are you sure you want to delete this date override?", [+ { text: "Cancel", style: "cancel" },+ {+ text: "Delete",+ style: "destructive",+ onPress: () => {+ setOverrides(overrides.filter((_, i) => i !== index));+ },+ },+ ]);+ };++ const handleSaveOverride = () => {+ if (!overrideDate) {+ Alert.alert("Error", "Please select a date");+ return;+ }++ const newOverride = {+ date: overrideDate,+ startTime: isUnavailable ? "00:00" : overrideStartTime,+ endTime: isUnavailable ? "00:00" : overrideEndTime,+ };++ if (editingOverride !== null) {+ // Update existing override+ const updated = [...overrides];+ updated[editingOverride] = newOverride;+ setOverrides(updated);+ } else {+ // Add new override+ setOverrides([...overrides, newOverride]);+ }++ setShowOverrideModal(false);+ };++ const formatDateForDisplay = (dateStr: string): string => {+ if (!dateStr) return "";+ const date = new Date(dateStr + "T00:00:00");+ return date.toLocaleDateString("en-US", {+ month: "short",+ day: "numeric",+ year: "numeric",+ });+ };++ if (loading) {+ return (+ <View className="flex-1 items-center justify-center bg-[#f8f9fa]">+ <ActivityIndicator size="large" color="#000000" />+ <Text className="mt-4 text-base text-[#666]">Loading schedule...</Text>+ </View>+ );+ }++ return (+ <View className="flex-1 bg-[#f8f9fa]">+ {/* Glass Header */}+ <GlassView+ style={[+ {+ position: "absolute",+ top: 0,+ left: 0,+ right: 0,+ zIndex: 1000,+ paddingHorizontal: 16,+ paddingBottom: 12,+ paddingTop: insets.top + 8,+ },+ ]}+ glassEffectStyle="clear"+ >+ <View className="min-h-[44px] flex-row items-center justify-between">+ <AppPressable+ className="h-10 w-10 items-start justify-center"+ onPress={() => router.back()}+ >+ <Ionicons name="chevron-back" size={24} color="#000" />+ </AppPressable>++ <Text+ className="mx-2.5 flex-1 text-center text-lg font-semibold text-black"+ numberOfLines={1}+ >+ Edit Availability+ </Text>++ <AppPressable+ className={`min-w-[60px] items-center rounded-[10px] bg-black px-2 py-2 md:px-4 ${+ saving ? "opacity-60" : ""+ }`}+ onPress={handleSave}+ disabled={saving}+ >+ <Text className="text-base font-semibold text-white">Save</Text>+ </AppPressable>+ </View>+ </GlassView>++ <ScrollView+ className="flex-1"+ style={{ paddingTop: insets.top + 70 }}+ contentContainerStyle={{ padding: 16, paddingBottom: 200 }}+ >+ <View className="gap-4">+ {/* Schedule Name and Working Hours Display */}+ <View className="rounded-2xl bg-white p-6">+ <Text className="mb-3 text-xl font-bold text-[#333]">{scheduleName}</Text>+ {Object.keys(availability).length > 0 ? (+ <View>+ {formatAvailabilityDisplay(availability).map((line, index) => (+ <Text key={index} className="mb-1 text-base text-[#666]">+ {line}+ </Text>+ ))}+ </View>+ ) : (+ <Text className="text-base text-[#999]">No availability set</Text>+ )}+ </View>++ {/* Availability Schedule */}+ <View className="rounded-2xl bg-white p-6">+ <Text className="mb-4 text-xl font-bold text-[#333]">Availability</Text>+ {DAYS.map((day, dayIndex) => {+ const daySlots = availability[dayIndex] || [];+ const isEnabled = daySlots.length > 0;+ const firstSlot = daySlots[0];++ return (+ <View+ key={dayIndex}+ className={`mb-3 border-b border-[#E5E5EA] pb-3 ${+ dayIndex === DAYS.length - 1 ? "mb-0 border-b-0 pb-0" : ""+ }`}+ >+ <View className="flex-row items-center">+ <View className="flex-1 flex-row items-center">+ <Switch+ value={isEnabled}+ onValueChange={() => toggleDay(dayIndex)}+ trackColor={{ false: "#E5E5EA", true: "#34C759" }}+ thumbColor="#fff"+ style={{ transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }] }}+ />+ <Text+ className="ml-1 text-base font-medium text-[#333]"+ style={{ width: 40 }}+ >+ {DAY_ABBREVIATIONS[dayIndex]}+ </Text>+ {isEnabled && firstSlot ? (+ <View className="flex-row items-center gap-2">+ <AppPressable+ onPress={() =>+ setShowTimePicker({ dayIndex, slotIndex: 0, type: "start" })+ }+ className="rounded-lg border border-[#E5E5EA] bg-white px-2 py-1"+ style={{ width: 85 }}+ >+ <Text className="text-center text-base text-[#333]">+ {formatTime12Hour(firstSlot.startTime)}+ </Text>+ </AppPressable>+ <Text className="text-base text-[#666]">-</Text>+ <AppPressable+ onPress={() =>+ setShowTimePicker({ dayIndex, slotIndex: 0, type: "end" })+ }+ className="rounded-lg border border-[#E5E5EA] bg-white px-2 py-1"+ style={{ width: 85 }}+ >+ <Text className="text-center text-base text-[#333]">+ {formatTime12Hour(firstSlot.endTime)}+ </Text>+ </AppPressable>+ </View>+ ) : null}+ </View>+ {isEnabled ? (+ <AppPressable onPress={() => addTimeSlot(dayIndex)} className="p-1">+ <Ionicons name="add-circle-outline" size={20} color="#007AFF" />+ </AppPressable>+ ) : null}+ </View>++ {isEnabled && daySlots.length > 1 ? (+ <View className="mt-2" style={{ marginLeft: 108 }}>+ {daySlots.slice(1).map((slot, slotIndex) => (+ <View key={slotIndex + 1} className="mb-2 flex-row items-center gap-2">+ <AppPressable+ onPress={() =>+ setShowTimePicker({+ dayIndex,+ slotIndex: slotIndex + 1,+ type: "start",+ })+ }+ className="rounded-lg border border-[#E5E5EA] bg-white px-2 py-1"+ style={{ width: 85 }}+ >+ <Text className="text-center text-base text-[#333]">+ {formatTime12Hour(slot.startTime)}+ </Text>+ </AppPressable>+ <Text className="text-base text-[#666]">-</Text>+ <AppPressable+ onPress={() =>+ setShowTimePicker({+ dayIndex,+ slotIndex: slotIndex + 1,+ type: "end",+ })+ }+ className="rounded-lg border border-[#E5E5EA] bg-white px-2 py-1"+ style={{ width: 85 }}+ >+ <Text className="text-center text-base text-[#333]">+ {formatTime12Hour(slot.endTime)}+ </Text>+ </AppPressable>+ <AppPressable+ onPress={() => removeTimeSlot(dayIndex, slotIndex + 1)}+ className="p-1"+ >+ <Ionicons name="trash-outline" size={20} color="#FF3B30" />+ </AppPressable>+ </View>+ ))}+ </View>+ ) : null}+ </View>+ );+ })}+ </View>++ {/* Timezone */}+ <View className="rounded-2xl bg-white p-6">+ <Text className="mb-3 text-xl font-bold text-[#333]">Timezone</Text>+ <AppPressable+ onPress={() => setShowTimezoneModal(true)}+ className="flex-row items-center justify-between rounded-lg border border-[#E5E5EA] bg-[#F8F9FA] px-3 py-3"+ >+ <Text className="text-base text-[#333]">{timeZone}</Text>+ <Ionicons name="chevron-down" size={20} color="#666" />+ </AppPressable>+ </View>++ {/* Date Overrides */}+ <View className="rounded-2xl bg-white p-6">+ <Text className="mb-2 text-xl font-bold text-[#333]">Date overrides</Text>+ <Text className="mb-4 text-base text-[#666]">+ Add dates when your availability changes from your daily hours.+ </Text>++ {overrides.length > 0 ? (+ <View className="mb-4">+ {overrides.map((override, index) => (+ <View+ key={index}+ className="mb-2 flex-row items-center justify-between rounded-lg border border-[#E5E5EA] bg-[#F8F9FA] p-3"+ >+ <View className="flex-1">+ <Text className="mb-1 text-base font-medium text-[#333]">+ {formatDateForDisplay(override.date)}+ </Text>+ {override.startTime === "00:00" && override.endTime === "00:00" ? (+ <Text className="text-sm text-[#666]">Unavailable (All day)</Text>+ ) : (+ <Text className="text-sm text-[#666]">+ {formatTime12Hour(override.startTime + ":00")} -{" "}+ {formatTime12Hour(override.endTime + ":00")}+ </Text>+ )}+ </View>+ <View className="flex-row items-center gap-2">+ <AppPressable onPress={() => handleEditOverride(index)} className="p-2">+ <Ionicons name="pencil-outline" size={20} color="#007AFF" />+ </AppPressable>+ <AppPressable onPress={() => handleDeleteOverride(index)} className="p-2">+ <Ionicons name="trash-outline" size={20} color="#FF3B30" />+ </AppPressable>+ </View>+ </View>+ ))}+ </View>+ ) : null}++ <AppPressable+ onPress={handleAddOverride}+ className="flex-row items-center justify-center rounded-lg border border-dashed border-[#E5E5EA] py-3"+ >+ <Ionicons name="add-circle-outline" size={20} color="#007AFF" />+ <Text className="ml-2 text-base font-medium text-[#007AFF]">Add an override</Text>+ </AppPressable>+ </View>+ </View>+ </ScrollView>++ {/* Bottom Action Bar */}+ <GlassView+ style={{+ position: "absolute",+ bottom: 0,+ left: 0,+ right: 0,+ paddingTop: 16,+ paddingHorizontal: 20,+ backgroundColor: "#f8f9fa",+ borderTopWidth: 0.5,+ borderTopColor: "#E5E5EA",+ paddingBottom: insets.bottom + 12,+ }}+ glassEffectStyle="clear"+ >+ <View className="flex-row items-center justify-between">+ <View className="flex-row items-center gap-2">+ <Text className="text-base font-medium text-[#333]">Set as Default</Text>+ <Switch+ value={isDefault}+ onValueChange={handleSetAsDefault}+ disabled={isDefault}+ trackColor={{ false: "#E5E5EA", true: "#34C759" }}+ thumbColor="#FFFFFF"+ />+ </View>++ <View className="flex-row items-center gap-3">+ <GlassView+ className="overflow-hidden rounded-full bg-[rgba(255,255,255,0.1)]"+ glassEffectStyle="clear"+ >+ <AppPressable+ className="h-11 w-11 items-center justify-center"+ onPress={handleDelete}+ >+ <Ionicons name="trash-outline" size={20} color="#FF3B30" />+ </AppPressable>+ </GlassView>+ </View>+ </View>+ </GlassView>++ {/* Timezone Modal */}+ <FullScreenModal+ visible={showTimezoneModal}+ animationType="fade"+ onRequestClose={() => setShowTimezoneModal(false)}+ >+ <AppPressable+ className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"+ activeOpacity={1}+ onPress={() => setShowTimezoneModal(false)}+ >+ <AppPressable+ className="max-h-[80%] w-[90%] max-w-[500px] rounded-2xl bg-white p-4"+ activeOpacity={1}+ onPress={(e) => e.stopPropagation()}+ >+ <View className="mb-4 flex-row items-center justify-between">+ <Text className="text-xl font-bold text-[#333]">Select Timezone</Text>+ <AppPressable onPress={() => setShowTimezoneModal(false)}>+ <Ionicons name="close" size={24} color="#666" />+ </AppPressable>+ </View>+ <ScrollView>+ {timezones.map((tz) => (+ <AppPressable+ key={tz}+ onPress={() => {+ setTimeZone(tz);+ setShowTimezoneModal(false);+ }}+ className="border-b border-[#E5E5EA] py-3"+ >+ <Text className="text-base text-[#333]">{tz}</Text>+ </AppPressable>+ ))}+ </ScrollView>+ </AppPressable>+ </AppPressable>+ </FullScreenModal>++ {/* Time Picker Modal */}+ <FullScreenModal+ visible={!!showTimePicker}+ animationType="fade"+ onRequestClose={() => setShowTimePicker(null)}+ >+ <AppPressable+ className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"+ activeOpacity={1}+ onPress={() => setShowTimePicker(null)}+ >+ <AppPressable+ className="max-h-[80%] w-[90%] max-w-[500px] rounded-2xl bg-white p-4"+ activeOpacity={1}+ onPress={(e) => e.stopPropagation()}+ >+ <View className="mb-4 flex-row items-center justify-between">+ <Text className="text-xl font-bold text-[#333]">+ Select {showTimePicker?.type === "start" ? "Start" : "End"} Time+ </Text>+ <AppPressable onPress={() => setShowTimePicker(null)}>+ <Ionicons name="close" size={24} color="#666" />+ </AppPressable>+ </View>+ <ScrollView>+ {TIME_OPTIONS.map((time) => {+ const currentTime =+ showTimePicker?.type === "start"+ ? availability[showTimePicker.dayIndex]?.[+ showTimePicker.slotIndex+ ]?.startTime.substring(0, 5)+ : availability[showTimePicker?.dayIndex || 0]?.[+ showTimePicker?.slotIndex || 0+ ]?.endTime.substring(0, 5);+ const isSelected = currentTime === time;++ return (+ <AppPressable+ key={time}+ onPress={() => {+ if (showTimePicker) {+ updateTimeSlot(+ showTimePicker.dayIndex,+ showTimePicker.slotIndex,+ showTimePicker.type,+ time+ );+ setShowTimePicker(null);+ }+ }}+ className={`border-b border-[#E5E5EA] py-3 ${isSelected ? "bg-[#E3F2FD]" : ""}`}+ >+ <Text+ className={`text-base ${+ isSelected ? "font-semibold text-[#007AFF]" : "text-[#333]"+ }`}+ >+ {time}+ </Text>+ </AppPressable>+ );+ })}+ </ScrollView>+ </AppPressable>+ </AppPressable>+ </FullScreenModal>++ {/* Override Modal */}+ <FullScreenModal+ visible={showOverrideModal}+ animationType="fade"+ onRequestClose={() => setShowOverrideModal(false)}+ >+ <AppPressable+ className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"+ activeOpacity={1}+ onPress={() => setShowOverrideModal(false)}+ >+ <AppPressable+ className="max-h-[90%] w-[90%] max-w-[500px] rounded-2xl bg-white p-6"+ activeOpacity={1}+ onPress={(e) => e.stopPropagation()}+ >+ <View className="mb-4 flex-row items-center justify-between">+ <Text className="text-xl font-bold text-[#333]">+ {editingOverride !== null ? "Edit Override" : "Add Override"}+ </Text>+ <AppPressable onPress={() => setShowOverrideModal(false)}>+ <Ionicons name="close" size={24} color="#666" />+ </AppPressable>+ </View>++ <ScrollView>+ <View className="gap-4">+ {/* Date Picker */}+ <View>+ <Text className="mb-2 text-base font-semibold text-[#333]">+ Select the dates to override+ </Text>+ <TextInput+ value={overrideDate}+ onChangeText={setOverrideDate}+ placeholder="YYYY-MM-DD (e.g., 2024-05-20)"+ placeholderTextColor="#999"+ className="rounded-lg border border-[#E5E5EA] bg-[#F8F9FA] px-3 py-3 text-base text-[#333]"+ />+ <Text className="mt-1 text-sm text-[#666]">Enter date in YYYY-MM-DD format</Text>+ </View>++ {/* Unavailable Toggle */}+ <View className="flex-row items-center justify-between">+ <Text className="text-base font-semibold text-[#333]">+ Mark unavailable (All day)+ </Text>+ <Switch+ value={isUnavailable}+ onValueChange={setIsUnavailable}+ trackColor={{ false: "#E5E5EA", true: "#34C759" }}+ thumbColor="#FFFFFF"+ />+ </View>++ {/* Time Picker (only if not unavailable) */}+ {!isUnavailable ? (+ <View>+ <Text className="mb-3 text-base font-semibold text-[#333]">+ Which hours are you free?+ </Text>+ <View className="flex-row items-center gap-2">+ <AppPressable+ onPress={() => setShowOverrideTimePicker({ type: "start" })}+ className="flex-1 rounded-lg border border-[#E5E5EA] bg-white px-3 py-3"+ >+ <Text className="text-center text-base text-[#333]">+ {formatTime12Hour(overrideStartTime + ":00")}+ </Text>+ </AppPressable>+ <Text className="text-base text-[#666]">-</Text>+ <AppPressable+ onPress={() => setShowOverrideTimePicker({ type: "end" })}+ className="flex-1 rounded-lg border border-[#E5E5EA] bg-white px-3 py-3"+ >+ <Text className="text-center text-base text-[#333]">+ {formatTime12Hour(overrideEndTime + ":00")}+ </Text>+ </AppPressable>+ </View>+ </View>+ ) : null}++ {/* Save Button */}+ <AppPressable+ onPress={handleSaveOverride}+ className="mt-4 rounded-lg bg-black py-3"+ >+ <Text className="text-center text-base font-semibold text-white">+ Save Override+ </Text>+ </AppPressable>+ </View>+ </ScrollView>+ </AppPressable>+ </AppPressable>+ </FullScreenModal>++ {/* Override Time Picker Modal */}+ <FullScreenModal+ visible={!!showOverrideTimePicker}+ animationType="fade"+ onRequestClose={() => setShowOverrideTimePicker(null)}+ >+ <AppPressable+ className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"+ activeOpacity={1}+ onPress={() => setShowOverrideTimePicker(null)}+ >+ <AppPressable+ className="max-h-[60%] w-[90%] max-w-[500px] rounded-2xl bg-white p-6"+ activeOpacity={1}+ onPress={(e) => e.stopPropagation()}+ >+ <View className="mb-4 flex-row items-center justify-between">+ <Text className="text-xl font-bold text-[#333]">+ Select {showOverrideTimePicker?.type === "start" ? "Start" : "End"} Time+ </Text>+ <AppPressable onPress={() => setShowOverrideTimePicker(null)}>+ <Ionicons name="close" size={24} color="#666" />+ </AppPressable>+ </View>+ <ScrollView>+ {TIME_OPTIONS.map((time) => {+ const currentTime =+ showOverrideTimePicker?.type === "start" ? overrideStartTime : overrideEndTime;+ const isSelected = currentTime === time;+ return (+ <AppPressable+ key={time}+ onPress={() => {+ if (showOverrideTimePicker?.type === "start") {+ setOverrideStartTime(time);+ } else {+ setOverrideEndTime(time);+ }+ setShowOverrideTimePicker(null);+ }}+ className={`border-b border-[#E5E5EA] py-3 ${isSelected ? "bg-[#F0F9FF]" : ""}`}+ >+ <Text+ className={`text-base ${+ isSelected ? "font-semibold text-[#007AFF]" : "text-[#333]"+ }`}+ >+ {formatTime12Hour(time + ":00")}+ </Text>+ </AppPressable>+ );+ })}+ </ScrollView>+ </AppPressable>+ </AppPressable>+ </FullScreenModal>+ </View>+ );+}diff --git a/companion/components/screens/AvailabilityListScreen.tsx b/companion/components/screens/AvailabilityListScreen.tsxnew file mode 100644index 00000000000..4780f175575--- /dev/null+++ b/companion/components/screens/AvailabilityListScreen.tsx@@ -0,0 +1,631 @@+import { AppPressable } from "../../components/AppPressable";+import { EmptyScreen } from "../../components/EmptyScreen";+import { FullScreenModal } from "../../components/FullScreenModal";+import { Header } from "../../components/Header";+import { LoadingSpinner } from "../../components/LoadingSpinner";+import { AvailabilityListItem } from "../../components/availability-list-item/AvailabilityListItem";+import {+ useSchedules,+ useCreateSchedule,+ useDeleteSchedule,+ useDuplicateSchedule,+ useSetScheduleAsDefault,+} from "../../hooks";+import { CalComAPIService, Schedule } from "../../services/calcom";+import { showErrorAlert } from "../../utils/alerts";+import { offlineAwareRefresh } from "../../utils/network";+import { shadows } from "../../utils/shadows";+import { Ionicons } from "@expo/vector-icons";+import { useRouter } from "expo-router";+import React, { useState, useMemo, Activity } from "react";+import {+ View,+ Text,+ FlatList,+ RefreshControl,+ ActionSheetIOS,+ Alert,+ Platform,+ TextInput,+ ScrollView,+} from "react-native";++export interface AvailabilityListScreenProps {+ searchQuery: string;+ onSearchChange: (query: string) => void;+ showCreateModal: boolean;+ onShowCreateModalChange: (show: boolean) => void;+}++export function AvailabilityListScreen({+ searchQuery,+ onSearchChange,+ showCreateModal,+ onShowCreateModalChange,+}: AvailabilityListScreenProps) {+ const router = useRouter();+ const [newScheduleName, setNewScheduleName] = useState("");+ const [showActionsModal, setShowActionsModal] = useState(false);+ const [selectedSchedule, setSelectedSchedule] = useState<Schedule | null>(null);+ const [showDeleteModal, setShowDeleteModal] = useState(false);++ // Use React Query hooks+ const {+ data: schedules = [],+ isLoading: loading,+ isFetching,+ error: queryError,+ refetch,+ } = useSchedules();++ // Show refresh indicator when fetching+ const refreshing = isFetching && !loading;++ const { mutate: createScheduleMutation, isPending: creating } = useCreateSchedule();+ const { mutate: deleteScheduleMutation, isPending: deleting } = useDeleteSchedule();+ const { mutate: duplicateScheduleMutation } = useDuplicateSchedule();+ const { mutate: setAsDefaultMutation } = useSetScheduleAsDefault();++ // Convert query error to string+ // Don't show error UI for authentication errors (user will be redirected to login)+ // Only show error UI in development mode for other errors+ const isAuthError =+ queryError?.message?.includes("Authentication") ||+ queryError?.message?.includes("sign in") ||+ queryError?.message?.includes("401");+ const error = queryError && !isAuthError && __DEV__ ? "Failed to load availability." : null;++ // Filter schedules based on search query+ const filteredSchedules = useMemo(() => {+ if (searchQuery.trim() === "") {+ return schedules;+ }+ const searchLower = searchQuery.toLowerCase();+ return schedules.filter((schedule) => schedule.name.toLowerCase().includes(searchLower));+ }, [schedules, searchQuery]);++ // Note: We don't use useFocusEffect here because schedules have Infinity stale time.+ // Data only refreshes on mutations (create/update/delete) or manual pull-to-refresh.++ // Handle pull-to-refresh (offline-aware)+ const onRefresh = () => offlineAwareRefresh(refetch);++ const handleSearch = (query: string) => {+ onSearchChange(query);+ };++ const handleScheduleLongPress = (schedule: Schedule) => {+ if (Platform.OS !== "ios") {+ // Fallback for non-iOS platforms (Android Alert supports max 3 buttons)+ const options = [];+ if (!schedule.isDefault) {+ options.push({ text: "Set as default", onPress: () => handleSetAsDefault(schedule) });+ }+ options.push(+ { text: "Duplicate", onPress: () => handleDuplicate(schedule) },+ { text: "Delete", style: "destructive" as const, onPress: () => handleDelete(schedule) }+ );+ // Android Alert automatically adds cancel, so we don't need to include it explicitly+ Alert.alert(schedule.name, "", options);+ return;+ }++ const options = ["Cancel"];+ if (!schedule.isDefault) {+ options.push("Set as default");+ }+ options.push("Duplicate", "Delete");++ const destructiveButtonIndex = options.length - 1; // Delete button+ const cancelButtonIndex = 0;++ ActionSheetIOS.showActionSheetWithOptions(+ {+ options,+ destructiveButtonIndex,+ cancelButtonIndex,+ title: schedule.name,+ },+ (buttonIndex) => {+ if (buttonIndex === cancelButtonIndex) {+ return;+ }++ if (!schedule.isDefault) {+ // Options: ["Cancel", "Set as default", "Duplicate", "Delete"]+ if (buttonIndex === 1) {+ handleSetAsDefault(schedule);+ } else if (buttonIndex === 2) {+ handleDuplicate(schedule);+ } else if (buttonIndex === 3) {+ handleDelete(schedule);+ }+ } else {+ // Options: ["Cancel", "Duplicate", "Delete"]+ if (buttonIndex === 1) {+ handleDuplicate(schedule);+ } else if (buttonIndex === 2) {+ handleDelete(schedule);+ }+ }+ }+ );+ };++ const handleSetAsDefault = (schedule: Schedule) => {+ setAsDefaultMutation(schedule.id, {+ onError: () => {+ showErrorAlert("Error", "Failed to set schedule as default. Please try again.");+ },+ });+ };++ const handleDuplicate = (schedule: Schedule) => {+ duplicateScheduleMutation(schedule.id, {+ onError: () => {+ showErrorAlert("Error", "Failed to duplicate schedule. Please try again.");+ },+ });+ };++ const handleDelete = (schedule: Schedule) => {+ if (Platform.OS === "web") {+ // Use custom modal for web+ setShowDeleteModal(true);+ } else {+ // Use native Alert for iOS/Android+ Alert.alert("Delete Schedule", `Are you sure you want to delete "${schedule.name}"?`, [+ { text: "Cancel", style: "cancel" },+ {+ text: "Delete",+ style: "destructive",+ onPress: () => {+ deleteScheduleMutation(schedule.id, {+ onError: () => {+ showErrorAlert("Error", "Failed to delete schedule. Please try again.");+ },+ });+ },+ },+ ]);+ }+ };++ const confirmDelete = () => {+ if (!selectedSchedule) return;++ deleteScheduleMutation(selectedSchedule.id, {+ onSuccess: () => {+ setShowDeleteModal(false);+ setSelectedSchedule(null);+ },+ onError: () => {+ showErrorAlert("Error", "Failed to delete schedule. Please try again.");+ },+ });+ };++ const handleSchedulePress = (schedule: Schedule) => {+ router.push({+ pathname: "/availability-detail",+ params: { id: schedule.id.toString() },+ });+ };++ const handleCreateNew = () => {+ setNewScheduleName("");+ onShowCreateModalChange(true);+ };++ const handleCreateSchedule = async () => {+ if (!newScheduleName.trim()) {+ Alert.alert("Error", "Please enter a schedule name");+ return;+ }++ // Get user's timezone (default to America/New_York if not available)+ let userTimezone = "America/New_York";+ try {+ const userProfile = await CalComAPIService.getUserProfile();+ if (userProfile.timeZone) {+ userTimezone = userProfile.timeZone;+ }+ } catch (error) {+ console.log("Could not get user timezone, using default");+ }++ // Create schedule with Monday-Friday 9 AM - 5 PM default+ createScheduleMutation(+ {+ name: newScheduleName.trim(),+ timeZone: userTimezone,+ isDefault: false,+ availability: [+ {+ days: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],+ startTime: "09:00",+ endTime: "17:00",+ },+ ],+ },+ {+ onSuccess: (newSchedule) => {+ onShowCreateModalChange(false);+ setNewScheduleName("");++ // Navigate to edit the newly created schedule+ router.push({+ pathname: "/availability-detail",+ params: {+ id: newSchedule.id.toString(),+ },+ });+ },+ onError: (error) => {+ const message = error instanceof Error ? error.message : String(error);+ console.error("Failed to create schedule", message);+ if (__DEV__) {+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[AvailabilityListScreen] createSchedule failed", { message, stack });+ }+ showErrorAlert("Error", "Failed to create schedule. Please try again.");+ },+ }+ );+ };++ if (loading) {+ return (+ <View className="flex-1 bg-[#f8f9fa]">+ <Header />+ <View className="flex-1 items-center justify-center p-5">+ <LoadingSpinner size="large" />+ </View>+ </View>+ );+ }++ if (error) {+ return (+ <View className="flex-1 bg-[#f8f9fa]">+ <Header />+ <View className="flex-1 items-center justify-center p-5">+ <Ionicons name="alert-circle" size={64} color="#FF3B30" />+ <Text className="mb-2 mt-4 text-center text-xl font-bold text-[#333]">+ Unable to load availability+ </Text>+ <Text className="mb-6 text-center text-base text-[#666]">{error}</Text>+ <AppPressable className="rounded-lg bg-black px-6 py-3" onPress={() => refetch()}>+ <Text className="text-base font-semibold text-white">Retry</Text>+ </AppPressable>+ </View>+ </View>+ );+ }++ // Determine what content to show+ const showEmptyState = schedules.length === 0 && !loading;+ const showSearchEmptyState =+ filteredSchedules.length === 0 && searchQuery.trim() !== "" && !showEmptyState;+ const showList = !showEmptyState && !showSearchEmptyState;++ return (+ <>+ {/* Non-iOS header with search */}+ <Activity mode={Platform.OS !== "ios" ? "visible" : "hidden"}>+ <Header />+ <View className="flex-row items-center gap-3 border-b border-gray-300 bg-gray-100 px-4 py-2">+ <TextInput+ className="flex-1 rounded-lg border border-gray-200 bg-white px-3 py-2 text-[17px] text-black focus:border-black focus:ring-2 focus:ring-black"+ placeholder="Search schedules"+ placeholderTextColor="#9CA3AF"+ value={searchQuery}+ onChangeText={handleSearch}+ autoCapitalize="none"+ autoCorrect={false}+ clearButtonMode="while-editing"+ />+ <AppPressable+ className="min-w-[60px] flex-row items-center justify-center gap-1 rounded-lg bg-black px-2.5 py-2"+ onPress={handleCreateNew}+ >+ <Ionicons name="add" size={18} color="#fff" />+ <Text className="text-base font-semibold text-white">New</Text>+ </AppPressable>+ </View>+ </Activity>++ {/* Empty state - no schedules */}+ <Activity mode={showEmptyState ? "visible" : "hidden"}>+ <ScrollView+ style={{ backgroundColor: "white" }}+ contentContainerStyle={{+ flexGrow: 1,+ justifyContent: "center",+ alignItems: "center",+ padding: 20,+ paddingBottom: 90,+ }}+ refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}+ contentInsetAdjustmentBehavior="automatic"+ >+ <EmptyScreen+ icon="time-outline"+ headline="Create an availability schedule"+ description="Creating availability schedules allows you to manage availability across event types. They can be applied to one or more event types."+ buttonText="New"+ onButtonPress={handleCreateNew}+ />+ </ScrollView>+ </Activity>++ {/* Search bar and content for non-empty states */}+ <Activity mode={!showEmptyState ? "visible" : "hidden"}>+ {/* Search empty state */}+ <Activity mode={showSearchEmptyState ? "visible" : "hidden"}>+ <ScrollView+ style={{ backgroundColor: "white" }}+ contentContainerStyle={{+ flexGrow: 1,+ justifyContent: "center",+ alignItems: "center",+ padding: 20,+ paddingBottom: 90,+ }}+ refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}+ >+ <EmptyScreen+ icon="search-outline"+ headline={`No results found for "${searchQuery}"`}+ description="Try searching with different keywords"+ />+ </ScrollView>+ </Activity>++ {/* Schedules list */}+ <Activity mode={showList ? "visible" : "hidden"}>+ <FlatList+ className="flex-1 rounded-lg border border-[#E5E5EA] bg-white"+ contentContainerStyle={{+ paddingBottom: 90,+ paddingHorizontal: 8,+ paddingVertical: 4,+ }}+ data={filteredSchedules}+ keyExtractor={(item) => item.id.toString()}+ renderItem={({ item, index }) => (+ <AvailabilityListItem+ item={item}+ index={index}+ handleSchedulePress={handleSchedulePress}+ handleScheduleLongPress={handleScheduleLongPress}+ setSelectedSchedule={setSelectedSchedule}+ setShowActionsModal={setShowActionsModal}+ onDuplicate={handleDuplicate}+ onDelete={handleDelete}+ onSetAsDefault={handleSetAsDefault}+ />+ )}+ refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}+ showsVerticalScrollIndicator={false}+ contentInsetAdjustmentBehavior="automatic"+ />+ </Activity>+ </Activity>++ {/* Create Schedule Modal */}+ <FullScreenModal+ visible={showCreateModal}+ animationType="fade"+ onRequestClose={() => onShowCreateModalChange(false)}+ >+ <AppPressable+ className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"+ activeOpacity={1}+ onPress={() => onShowCreateModalChange(false)}+ >+ <AppPressable+ className="w-[90%] max-w-[500px] rounded-2xl bg-white"+ activeOpacity={1}+ onPress={(e) => e.stopPropagation()}+ style={shadows.xl()}+ >+ {/* Header */}+ <View className="px-8 pb-4 pt-6">+ <Text className="text-2xl font-semibold text-[#111827]">Add a new schedule</Text>+ </View>++ {/* Content */}+ <View className="px-8 pb-6">+ <View className="mb-1">+ <Text className="mb-2 text-sm font-medium text-[#374151]">Name</Text>+ <TextInput+ className="rounded-md border border-[#D1D5DB] bg-white px-3 py-2.5 text-base text-[#111827]"+ placeholder="Working Hours"+ placeholderTextColor="#9CA3AF"+ value={newScheduleName}+ onChangeText={setNewScheduleName}+ autoFocus+ autoCapitalize="words"+ returnKeyType="done"+ onSubmitEditing={handleCreateSchedule}+ />+ </View>+ </View>++ {/* Footer */}+ <View className="rounded-b-2xl border-t border-[#E5E7EB] bg-[#F9FAFB] px-8 py-4">+ <View className="flex-row justify-end gap-2 space-x-2">+ <AppPressable+ className="rounded-xl border border-[#D1D5DB] bg-white px-2 py-2 md:px-4"+ onPress={() => {+ onShowCreateModalChange(false);+ setNewScheduleName("");+ }}+ disabled={creating}+ >+ <Text className="text-base font-medium text-[#374151]">Close</Text>+ </AppPressable>+ <AppPressable+ className={`rounded-xl bg-[#111827] px-2 py-2 md:px-4 ${+ creating ? "opacity-60" : ""+ }`}+ onPress={handleCreateSchedule}+ disabled={creating}+ >+ <Text className="text-base font-medium text-white">Continue</Text>+ </AppPressable>+ </View>+ </View>+ </AppPressable>+ </AppPressable>+ </FullScreenModal>++ {/* Schedule Actions Modal */}+ <FullScreenModal+ visible={showActionsModal}+ animationType="fade"+ onRequestClose={() => setShowActionsModal(false)}+ >+ <AppPressable+ className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"+ activeOpacity={1}+ onPress={() => setShowActionsModal(false)}+ >+ <AppPressable+ className="mx-4 w-full max-w-sm rounded-2xl bg-white"+ activeOpacity={1}+ onPress={(e) => e.stopPropagation()}+ >+ {/* Header */}+ <View className="border-b border-gray-200 p-6">+ <Text className="text-center text-xl font-semibold text-gray-900">+ Schedule Actions+ </Text>+ </View>++ {/* Actions List */}+ <View className="p-2">+ {/* Set as Default - only show if not already default */}+ <Activity+ mode={selectedSchedule && !selectedSchedule.isDefault ? "visible" : "hidden"}+ >+ <>+ <AppPressable+ onPress={() => {+ setShowActionsModal(false);+ if (selectedSchedule) {+ handleSetAsDefault(selectedSchedule);+ }+ }}+ className="flex-row items-center p-2 hover:bg-gray-50 md:p-4"+ >+ <Ionicons name="star-outline" size={20} color="#6B7280" />+ <Text className="ml-3 text-base text-gray-900">Set as Default</Text>+ </AppPressable>++ <View className="mx-4 my-2 h-px bg-gray-200" />+ </>+ </Activity>++ {/* Duplicate */}+ <AppPressable+ onPress={() => {+ setShowActionsModal(false);+ if (selectedSchedule) {+ setTimeout(() => {+ handleDuplicate(selectedSchedule);+ }, 100);+ }+ }}+ className="flex-row items-center p-2 hover:bg-gray-50 md:p-4"+ >+ <Ionicons name="copy-outline" size={20} color="#6B7280" />+ <Text className="ml-3 text-base text-gray-900">Duplicate</Text>+ </AppPressable>++ {/* Separator */}+ <View className="mx-4 my-2 h-px bg-gray-200" />++ {/* Delete */}+ <AppPressable+ onPress={() => {+ setShowActionsModal(false);+ if (selectedSchedule) {+ // Small delay to ensure modal closes before alert shows+ setTimeout(() => {+ handleDelete(selectedSchedule);+ }, 100);+ }+ }}+ className="flex-row items-center p-2 hover:bg-gray-50 md:p-4"+ >+ <Ionicons name="trash-outline" size={20} color="#800000" />+ <Text className="ml-3 text-base text-[#800000]">Delete</Text>+ </AppPressable>+ </View>++ {/* Cancel button */}+ <View className="border-t border-gray-200 p-2 md:p-4">+ <AppPressable+ className="w-full rounded-lg bg-gray-100 p-3"+ onPress={() => setShowActionsModal(false)}+ >+ <Text className="text-center text-base font-medium text-gray-700">Cancel</Text>+ </AppPressable>+ </View>+ </AppPressable>+ </AppPressable>+ </FullScreenModal>++ {/* Delete Confirmation Modal */}+ <FullScreenModal+ visible={showDeleteModal}+ animationType="fade"+ onRequestClose={() => !deleting && setShowDeleteModal(false)}+ >+ <View className="flex-1 items-center justify-center bg-black/50 p-4">+ <View className="w-full max-w-sm rounded-2xl bg-white p-6">+ {/* Icon */}+ <View className="mb-4 items-center">+ <View className="h-12 w-12 items-center justify-center rounded-full bg-red-100">+ <Ionicons name="trash-outline" size={24} color="#800000" />+ </View>+ </View>++ {/* Title */}+ <Text className="mb-2 text-center text-xl font-semibold text-gray-900">+ Delete Schedule+ </Text>++ {/* Description */}+ <Text className="mb-6 text-center text-base text-gray-600">+ Are you sure you want to delete "{selectedSchedule?.name}"? This action cannot be+ undone.+ </Text>++ {/* Buttons */}+ <View className="flex-row gap-3">+ <AppPressable+ className="flex-1 rounded-lg bg-gray-100 px-4 py-3"+ onPress={() => setShowDeleteModal(false)}+ disabled={deleting}+ >+ <Text className="text-center text-base font-semibold text-gray-700">Cancel</Text>+ </AppPressable>+ <AppPressable+ className={`flex-1 rounded-lg bg-gray-900 px-4 py-3 ${+ deleting ? "opacity-50" : ""+ }`}+ onPress={confirmDelete}+ disabled={deleting}+ >+ <Text className="text-center text-base font-semibold text-white">Delete</Text>+ </AppPressable>+ </View>+ </View>+ </View>+ </FullScreenModal>+ </>+ );+}diff --git a/companion/components/screens/BookingDetailScreen.tsx b/companion/components/screens/BookingDetailScreen.tsxnew file mode 100644index 00000000000..40fbc431020--- /dev/null+++ b/companion/components/screens/BookingDetailScreen.tsx@@ -0,0 +1,704 @@+import { CalComAPIService, Booking } from "../../services/calcom";+import { showErrorAlert } from "../../utils/alerts";+import { openInAppBrowser } from "../../utils/browser";+import { getDefaultLocationIconUrl, defaultLocations } from "../../utils/defaultLocations";+import { formatAppIdToDisplayName } from "../../utils/formatters";+import { getAppIconUrl } from "../../utils/getAppIconUrl";+import { shadows } from "../../utils/shadows";+import { AppPressable } from "../AppPressable";+import { BookingActionsModal } from "../BookingActionsModal";+import { FullScreenModal } from "../FullScreenModal";+import { SvgImage } from "../SvgImage";+import { Ionicons } from "@expo/vector-icons";+import { GlassView } from "expo-glass-effect";+import { useRouter } from "expo-router";+import React, { useState, useEffect } from "react";+import { View, Text, ScrollView, Alert, ActivityIndicator, TextInput } from "react-native";+import { useSafeAreaInsets } from "react-native-safe-area-context";++// Format date: "Tuesday, November 25, 2025"+const formatDateFull = (dateString: string): string => {+ if (!dateString) return "";+ try {+ const date = new Date(dateString);+ return date.toLocaleDateString("en-US", {+ weekday: "long",+ month: "long",+ day: "numeric",+ year: "numeric",+ });+ } catch (error) {+ return "";+ }+};++// Format time: "9:40pm - 10:00pm"+const formatTime12Hour = (dateString: string): string => {+ if (!dateString) return "";+ try {+ const date = new Date(dateString);+ const hours = date.getHours();+ const minutes = date.getMinutes();+ const period = hours >= 12 ? "pm" : "am";+ const hour12 = hours === 0 ? 12 : hours > 12 ? hours - 12 : hours;+ const minStr = minutes.toString().padStart(2, "0");+ return `${hour12}:${minStr}${period}`;+ } catch (error) {+ return "";+ }+};++// Get timezone from date string+const getTimezone = (dateString: string): string => {+ if (!dateString) return "";+ try {+ const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;+ return timeZone;+ } catch (error) {+ return "";+ }+};++// Get initials from a name (e.g., "Keith Williams" -> "KW", "Dhairyashil Shinde" -> "DS")+const getInitials = (name: string): string => {+ if (!name) return "";+ const parts = name.trim().split(/\s+/);+ if (parts.length === 0) return "";+ if (parts.length === 1) {+ return parts[0].charAt(0).toUpperCase();+ }+ // Get first letter of first name and first letter of last name+ return (parts[0].charAt(0) + parts[parts.length - 1].charAt(0)).toUpperCase();+};++// Get location provider info+const getLocationProvider = (location: string | undefined, metadata?: Record<string, unknown>) => {+ // Check metadata for videoCallUrl first+ const videoCallUrl = metadata?.videoCallUrl;+ const locationToCheck = videoCallUrl || location;++ if (!locationToCheck) return null;++ // Check if it's a video call URL+ if (typeof locationToCheck === "string" && locationToCheck.startsWith("http")) {+ // Try to detect provider from URL+ if (locationToCheck.includes("cal.com/video") || locationToCheck.includes("cal-video")) {+ const iconUrl = getAppIconUrl("daily_video", "cal-video");+ return {+ label: "Cal Video",+ iconUrl: iconUrl || "https://app.cal.com/app-store/dailyvideo/icon.svg",+ url: locationToCheck,+ };+ }+ // Check for other video providers by URL pattern+ const videoProviders = [+ { pattern: /zoom\.us/, label: "Zoom", type: "zoom_video", appId: "zoom" },+ {+ pattern: /meet\.google\.com/,+ label: "Google Meet",+ type: "google_video",+ appId: "google-meet",+ },+ {+ pattern: /teams\.microsoft\.com/,+ label: "Microsoft Teams",+ type: "office365_video",+ appId: "msteams",+ },+ ];++ for (const provider of videoProviders) {+ if (provider.pattern.test(locationToCheck)) {+ const iconUrl = getAppIconUrl(provider.type, provider.appId);+ return {+ label: provider.label,+ iconUrl: iconUrl,+ url: locationToCheck,+ };+ }+ }++ // Generic link meeting+ const linkIconUrl = getDefaultLocationIconUrl("link") || "https://app.cal.com/link.svg";+ return {+ label: "Link Meeting",+ iconUrl: linkIconUrl,+ url: locationToCheck,+ };+ }++ // Check if it's an integration location (e.g., "integrations:zoom", "integrations:cal-video")+ if (typeof locationToCheck === "string" && locationToCheck.startsWith("integrations:")) {+ const appId = locationToCheck.replace("integrations:", "");+ const iconUrl = getAppIconUrl("", appId);++ if (iconUrl) {+ return {+ label: formatAppIdToDisplayName(appId),+ iconUrl: iconUrl,+ url: null,+ };+ }+ }++ // Check if it's a default location type+ const defaultLocation = defaultLocations.find((loc) => loc.type === locationToCheck);+ if (defaultLocation) {+ return {+ label: defaultLocation.label,+ iconUrl: defaultLocation.iconUrl,+ url: null,+ };+ }++ // Fallback: return as plain text location+ return {+ label: locationToCheck as string,+ iconUrl: null,+ url: null,+ };+};++export interface BookingDetailScreenProps {+ uid: string;+}++export function BookingDetailScreen({ uid }: BookingDetailScreenProps) {+ const router = useRouter();+ const insets = useSafeAreaInsets();++ const [loading, setLoading] = useState(true);+ const [booking, setBooking] = useState<Booking | null>(null);+ const [error, setError] = useState<string | null>(null);+ const [showActionsModal, setShowActionsModal] = useState(false);+ const [showRescheduleModal, setShowRescheduleModal] = useState(false);+ const [rescheduleDate, setRescheduleDate] = useState("");+ const [rescheduleTime, setRescheduleTime] = useState("");+ const [rescheduleReason, setRescheduleReason] = useState("");+ const [rescheduling, setRescheduling] = useState(false);++ useEffect(() => {+ if (uid) {+ fetchBooking();+ }+ }, [uid]);++ const fetchBooking = async () => {+ try {+ setLoading(true);+ setError(null);+ const bookingData = await CalComAPIService.getBookingByUid(uid);+ // Avoid logging booking payloads: they may contain PII (names/emails/notes).+ if (__DEV__) {+ console.debug("[BookingDetailScreen] booking fetched", {+ uid: bookingData.uid,+ status: bookingData.status,+ hostCount: bookingData.hosts?.length ?? (bookingData.user ? 1 : 0),+ attendeeCount: bookingData.attendees?.length ?? 0,+ hasRecurringEventId: Boolean(bookingData.recurringEventId),+ });+ }+ setBooking(bookingData);+ } catch (err) {+ console.error("Error fetching booking");+ if (__DEV__) {+ const message = err instanceof Error ? err.message : String(err);+ const stack = err instanceof Error ? err.stack : undefined;+ console.debug("[BookingDetailScreen] fetchBooking failed", { message, stack });+ }+ setError("Failed to load booking. Please try again.");+ if (__DEV__) {+ Alert.alert("Error", "Failed to load booking. Please try again.", [+ { text: "OK", onPress: () => router.back() },+ ]);+ } else {+ router.back();+ }+ } finally {+ setLoading(false);+ }+ };++ const handleJoinMeeting = () => {+ if (!booking?.location) return;++ const provider = getLocationProvider(booking.location);+ if (provider?.url) {+ openInAppBrowser(provider.url, "meeting link");+ }+ };++ const openRescheduleModal = () => {+ if (!booking) return;++ // Pre-fill with the current booking date/time (using local timezone consistently)+ const currentDate = new Date(booking.startTime);+ const dateStr = `${currentDate.getFullYear()}-${String(currentDate.getMonth() + 1).padStart(+ 2,+ "0"+ )}-${String(currentDate.getDate()).padStart(2, "0")}`;+ const timeStr = `${String(currentDate.getHours()).padStart(2, "0")}:${String(+ currentDate.getMinutes()+ ).padStart(2, "0")}`;++ setRescheduleDate(dateStr);+ setRescheduleTime(timeStr);+ setRescheduleReason("");+ setShowRescheduleModal(true);+ };++ const handleReschedule = async () => {+ if (!booking || !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 (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();++ setRescheduling(true);+ try {+ await CalComAPIService.rescheduleBooking(booking.uid, {+ start: startUtc,+ reschedulingReason: rescheduleReason.trim() || undefined,+ });++ Alert.alert("Success", "Booking rescheduled successfully");+ setShowRescheduleModal(false);+ setRescheduleDate("");+ setRescheduleTime("");+ setRescheduleReason("");++ // Refresh booking data+ await fetchBooking();+ } catch (error) {+ console.error("Failed to reschedule booking");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[BookingDetailScreen] rescheduleBooking failed", { message, stack });+ }+ showErrorAlert("Error", "Failed to reschedule booking. Please try again.");+ } finally {+ setRescheduling(false);+ }+ };++ if (loading) {+ return (+ <View className="flex-1 items-center justify-center bg-[#f8f9fa]">+ <ActivityIndicator size="large" color="#000000" />+ <Text className="mt-4 text-base text-gray-500">Loading booking...</Text>+ </View>+ );+ }++ if (error || !booking) {+ return (+ <View className="flex-1 items-center justify-center bg-[#f8f9fa] p-5">+ <Ionicons name="alert-circle" size={64} color="#FF3B30" />+ <Text className="mb-2 mt-4 text-center text-xl font-bold text-gray-800">+ {error || "Booking not found"}+ </Text>+ <AppPressable className="mt-6 rounded-lg bg-black px-6 py-3" onPress={() => router.back()}>+ <Text className="text-base font-semibold text-white">Go Back</Text>+ </AppPressable>+ </View>+ );+ }++ const startTime = booking.start || booking.startTime || "";+ const endTime = booking.end || booking.endTime || "";+ const dateFormatted = formatDateFull(startTime);+ const timeFormatted = `${formatTime12Hour(startTime)} - ${formatTime12Hour(endTime)}`;+ const timezone = getTimezone(startTime);+ const locationProvider = getLocationProvider(booking.location, booking.responses);++ return (+ <View className="flex-1 bg-[#f8f9fa]">+ {/* Glass Header */}+ <GlassView+ style={[+ {+ position: "absolute",+ top: 0,+ left: 0,+ right: 0,+ zIndex: 1000,+ paddingHorizontal: 16,+ paddingBottom: 12,+ paddingTop: insets.top + 8,+ },+ ]}+ glassEffectStyle="clear"+ >+ <View className="min-h-[44px] flex-row items-center justify-between">+ <AppPressable+ className="h-10 w-10 items-center justify-center rounded-full bg-[#F0F0F0]"+ onPress={() => router.back()}+ >+ <Ionicons name="chevron-back" size={24} color="#000" />+ </AppPressable>++ <Text+ className="mx-2.5 flex-1 text-center text-lg font-semibold text-black"+ numberOfLines={1}+ >+ {booking?.title || "Booking Details"}+ </Text>++ <AppPressable+ className="h-10 w-10 items-center justify-center rounded-full bg-[#F0F0F0]"+ onPress={() => setShowActionsModal(true)}+ >+ <Ionicons name="ellipsis-horizontal" size={24} color="#000" />+ </AppPressable>+ </View>+ </GlassView>++ <ScrollView+ className="flex-1"+ style={{ paddingTop: insets.top + 70 }}+ contentContainerStyle={{ padding: 16, paddingBottom: 100 }}+ >+ {/* Title */}+ <View className="mb-3">+ <Text className="mb-2 text-2xl font-semibold text-[#333]">{booking.title}</Text>+ <Text className="text-base text-[#666]">+ {dateFormatted} {timeFormatted} ({timezone})+ </Text>+ </View>++ {/* Who Section */}+ <View className="mb-2 rounded-2xl bg-white p-6">+ <Text className="mb-4 text-base font-medium text-[#666]">Who</Text>+ {/* Show host from user field or hosts array */}+ {booking.user || (booking.hosts && booking.hosts.length > 0) ? (+ <View className="mb-4">+ {booking.user ? (+ <View className="flex-row items-start">+ <View className="mr-3 h-12 w-12 items-center justify-center rounded-full bg-black">+ <Text className="text-base font-semibold text-white">+ {getInitials(booking.user.name)}+ </Text>+ </View>+ <View className="flex-1">+ <View className="mb-1 flex-row flex-wrap items-center">+ <Text className="text-base font-medium text-[#333]">{booking.user.name}</Text>+ <View className="ml-2 rounded bg-[#007AFF] px-2 py-0.5">+ <Text className="text-xs font-medium text-white">host</Text>+ </View>+ </View>+ <Text className="text-sm text-[#666]">{booking.user.email}</Text>+ </View>+ </View>+ ) : booking.hosts && booking.hosts.length > 0 ? (+ booking.hosts.map((host, hostIndex) => (+ <View+ key={hostIndex}+ className={`flex-row items-start ${hostIndex > 0 ? "mt-4" : ""}`}+ >+ <View className="mr-3 h-12 w-12 items-center justify-center rounded-full bg-black">+ <Text className="text-base font-semibold text-white">+ {getInitials(host.name || "Host")}+ </Text>+ </View>+ <View className="flex-1">+ <View className="mb-1 flex-row flex-wrap items-center">+ <Text className="text-base font-medium text-[#333]">+ {host.name || "Host"}+ </Text>+ <View className="ml-2 rounded bg-[#007AFF] px-2 py-0.5">+ <Text className="text-xs font-medium text-white">host</Text>+ </View>+ </View>+ {host.email && <Text className="text-sm text-[#666]">{host.email}</Text>}+ </View>+ </View>+ ))+ ) : null}+ </View>+ ) : null}+ {booking.attendees && booking.attendees.length > 0 ? (+ <View>+ {booking.attendees.map((attendee, index) => (+ <View key={index} className={`flex-row items-start ${index > 0 ? "mt-4" : ""}`}>+ <View className="mr-3 h-12 w-12 items-center justify-center rounded-full bg-black">+ <Text className="text-base font-semibold text-white">+ {getInitials(attendee.name)}+ </Text>+ </View>+ <View className="flex-1">+ <Text className="mb-1 text-base font-medium text-[#333]">{attendee.name}</Text>+ <Text className="text-sm text-[#666]">{attendee.email}</Text>+ </View>+ </View>+ ))}+ </View>+ ) : null}+ </View>++ {/* Where Section */}+ {locationProvider ? (+ <View className="mb-2 rounded-2xl bg-white p-6">+ <Text className="mb-4 text-base font-medium text-[#666]">Where</Text>+ {locationProvider.url ? (+ <AppPressable onPress={handleJoinMeeting} className="flex-row flex-wrap items-center">+ {locationProvider.iconUrl ? (+ <SvgImage+ uri={locationProvider.iconUrl}+ width={20}+ height={20}+ style={{ marginRight: 8 }}+ />+ ) : null}+ <Text className="text-base text-[#007AFF]">{locationProvider.label}: </Text>+ <Text className="flex-1 text-base text-[#007AFF]" numberOfLines={1}>+ {locationProvider.url}+ </Text>+ </AppPressable>+ ) : (+ <View className="flex-row items-center">+ {locationProvider.iconUrl ? (+ <SvgImage+ uri={locationProvider.iconUrl}+ width={20}+ height={20}+ style={{ marginRight: 8 }}+ />+ ) : null}+ <Text className="text-base text-[#333]">{locationProvider.label}</Text>+ </View>+ )}+ </View>+ ) : null}++ {/* Recurring Event Section */}+ {booking.recurringEventId ||+ (booking as { recurringBookingUid?: string }).recurringBookingUid ? (+ <View className="mb-2 rounded-2xl bg-white p-6">+ <Text className="mb-2 text-base font-medium text-[#666]">Recurring Event</Text>+ <Text className="text-base text-[#666]">Every 2 weeks for 6 occurrences</Text>+ </View>+ ) : null}++ {/* Description Section */}+ {booking.description ? (+ <View className="mb-2 rounded-2xl bg-white p-6">+ <Text className="mb-2 text-base font-medium text-[#666]">Description</Text>+ <Text className="text-base leading-6 text-[#666]">{booking.description}</Text>+ </View>+ ) : null}++ {/* Join Meeting Button */}+ {locationProvider?.url ? (+ <AppPressable+ onPress={handleJoinMeeting}+ className="mb-2 flex-row items-center justify-center rounded-lg bg-black px-6 py-4"+ >+ {locationProvider.iconUrl ? (+ <SvgImage+ uri={locationProvider.iconUrl}+ width={20}+ height={20}+ style={{ marginRight: 8 }}+ />+ ) : null}+ <Text className="text-base font-semibold text-white">+ Join {locationProvider.label}+ </Text>+ </AppPressable>+ ) : null}+ </ScrollView>++ {/* Booking Actions Modal */}+ <BookingActionsModal+ visible={showActionsModal}+ onClose={() => setShowActionsModal(false)}+ booking={booking}+ hasLocationUrl={!!locationProvider?.url}+ isUpcoming={booking ? new Date(booking.startTime) > new Date() : false}+ isPast={booking ? new Date(booking.startTime) <= new Date() : false}+ isCancelled={booking?.status?.toUpperCase() === "CANCELLED"}+ isUnconfirmed={booking?.status?.toUpperCase() === "PENDING"}+ onReschedule={openRescheduleModal}+ onEditLocation={() => {+ Alert.alert("Edit Location", "Edit location functionality coming soon");+ }}+ onAddGuests={() => {+ Alert.alert("Add Guests", "Add guests functionality coming soon");+ }}+ onViewRecordings={() => {+ Alert.alert("View Recordings", "View recordings functionality coming soon");+ }}+ onMeetingSessionDetails={() => {+ Alert.alert(+ "Meeting Session Details",+ "Meeting session details functionality coming soon"+ );+ }}+ onMarkNoShow={() => {+ Alert.alert("Mark as No-Show", "Mark as no-show functionality coming soon");+ }}+ onReportBooking={() => {+ Alert.alert("Report Booking", "Report booking functionality coming soon");+ }}+ onCancelBooking={() => {+ Alert.alert("Cancel Booking", "Are you sure you want to cancel this booking?", [+ { text: "No", style: "cancel" },+ {+ text: "Yes, Cancel",+ style: "destructive",+ onPress: () => {+ // TODO: Implement cancel booking+ if (__DEV__)+ console.debug("[BookingDetailScreen] cancel booking (not implemented yet)");+ },+ },+ ]);+ }}+ />++ {/* Reschedule Modal */}+ <FullScreenModal+ visible={showRescheduleModal}+ animationType="fade"+ onRequestClose={() => setShowRescheduleModal(false)}+ >+ <AppPressable+ className="flex-1 items-center justify-center bg-black/50 p-2 md:p-4"+ onPress={() => setShowRescheduleModal(false)}+ >+ <AppPressable+ className="w-[90%] max-w-[500px] rounded-2xl bg-white"+ onPress={(e) => e.stopPropagation()}+ style={shadows.xl()}+ >+ {/* Header */}+ <View className="px-8 pb-4 pt-6">+ <View className="flex-row items-start space-x-3">+ <View className="h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-[#F3F4F6]">+ <Ionicons name="calendar-outline" size={24} color="#111827" />+ </View>+ <View className="flex-1 pt-1">+ <Text className="mb-2 text-2xl font-semibold text-[#111827]">+ Reschedule Booking+ </Text>+ <Text className="text-sm text-[#6B7280]">+ Select a new date and time for this booking.+ </Text>+ </View>+ </View>+ </View>++ {/* Content */}+ <ScrollView className="max-h-[400px] px-8 pb-6">+ {/* Date Input */}+ <View className="mb-4">+ <Text className="mb-2 text-sm font-bold text-[#111827]">+ New Date+ <Text className="font-normal text-[#6B7280]"> (YYYY-MM-DD)</Text>+ </Text>+ <TextInput+ className="rounded-md border border-[#D1D5DB] bg-white px-3 py-3 text-base text-[#111827]"+ placeholder="2024-12-25"+ placeholderTextColor="#9CA3AF"+ value={rescheduleDate}+ onChangeText={setRescheduleDate}+ editable={!rescheduling}+ keyboardType="default"+ />+ </View>++ {/* Time Input */}+ <View className="mb-4">+ <Text className="mb-2 text-sm font-bold text-[#111827]">+ New Time+ <Text className="font-normal text-[#6B7280]"> (HH:MM, 24-hour)</Text>+ </Text>+ <TextInput+ className="rounded-md border border-[#D1D5DB] bg-white px-3 py-3 text-base text-[#111827]"+ placeholder="14:30"+ placeholderTextColor="#9CA3AF"+ value={rescheduleTime}+ onChangeText={setRescheduleTime}+ editable={!rescheduling}+ keyboardType="default"+ />+ </View>++ {/* Reason Input */}+ <View className="mb-2">+ <Text className="mb-2 text-sm font-bold text-[#111827]">+ Reason+ <Text className="font-normal text-[#6B7280]"> (Optional)</Text>+ </Text>+ <TextInput+ className="min-h-[80px] rounded-md border border-[#D1D5DB] bg-white px-3 py-3 text-base text-[#111827]"+ placeholder="Enter reason for rescheduling..."+ placeholderTextColor="#9CA3AF"+ value={rescheduleReason}+ onChangeText={setRescheduleReason}+ multiline+ numberOfLines={3}+ textAlignVertical="top"+ editable={!rescheduling}+ />+ </View>+ </ScrollView>++ {/* Footer */}+ <View className="rounded-b-2xl border-t border-[#E5E7EB] bg-[#F9FAFB] px-8 py-4">+ <View className="flex-row justify-end gap-2 space-x-2">+ <AppPressable+ className="rounded-xl border border-[#D1D5DB] bg-white px-2 py-2 md:px-4"+ onPress={() => {+ setShowRescheduleModal(false);+ setRescheduleDate("");+ setRescheduleTime("");+ setRescheduleReason("");+ }}+ disabled={rescheduling}+ >+ <Text className="text-base font-medium text-[#374151]">Cancel</Text>+ </AppPressable>+ <AppPressable+ className={`rounded-xl bg-[#111827] px-2 py-2 md:px-4 ${+ rescheduling ? "opacity-60" : ""+ }`}+ onPress={handleReschedule}+ disabled={rescheduling}+ >+ {rescheduling ? (+ <ActivityIndicator size="small" color="white" />+ ) : (+ <Text className="text-base font-medium text-white">Reschedule</Text>+ )}+ </AppPressable>+ </View>+ </View>+ </AppPressable>+ </AppPressable>+ </FullScreenModal>+ </View>+ );+}diff --git a/companion/contexts/AuthContext.tsx b/companion/contexts/AuthContext.tsxindex 0bfd077a9e2..e6e273bd414 100644--- a/companion/contexts/AuthContext.tsx+++ b/companion/contexts/AuthContext.tsx@@ -36,6 +36,10 @@ interface AuthProviderProps {// Use the shared secure storage adapterconst storage = secureStorage;+const getErrorMessage = (error: unknown) =>+ error instanceof Error ? error.message : String(error);+const getErrorStack = (error: unknown) => (error instanceof Error ? error.stack : undefined);+export function AuthProvider({ children }: AuthProviderProps) {const [isAuthenticated, setIsAuthenticated] = useState(false);const [accessToken, setAccessToken] = useState<string | null>(null);@@ -143,7 +147,14 @@ export function AuthProvider({ children }: AuthProviderProps) {newRefreshToken || refreshToken || undefined);} catch (error) {- console.error("Failed to handle token refresh:", error);+ const message = getErrorMessage(error);+ console.error("Failed to handle token refresh", message);+ if (__DEV__) {+ console.debug("[AuthContext] token refresh handler failed", {+ message,+ stack: getErrorStack(error),+ });+ }await logout();}};@@ -213,7 +224,14 @@ export function AuthProvider({ children }: AuthProviderProps) {handleWebSessionAuth();}} catch (error) {- console.error("Failed to check auth state:", error);+ const message = getErrorMessage(error);+ console.error("Failed to check auth state", message);+ if (__DEV__) {+ console.debug("[AuthContext] checkAuthState failed", {+ message,+ stack: getErrorStack(error),+ });+ }} finally {setLoading(false);}@@ -234,7 +252,14 @@ export function AuthProvider({ children }: AuthProviderProps) {await setupAfterLogin(tokens.accessToken, tokens.refreshToken);}} catch (error) {- console.error("Failed to login from web session:", error);+ const message = getErrorMessage(error);+ console.error("Failed to login from web session", message);+ if (__DEV__) {+ console.debug("[AuthContext] loginFromWebSession failed", {+ message,+ stack: getErrorStack(error),+ });+ }throw error;}};@@ -267,7 +292,14 @@ export function AuthProvider({ children }: AuthProviderProps) {// Clear PKCE parametersoauthService.clearPKCEParams();} catch (error) {- console.error("OAuth login failed:", error);+ const message = getErrorMessage(error);+ console.error("OAuth login failed", message);+ if (__DEV__) {+ console.debug("[AuthContext] loginWithOAuth failed", {+ message,+ stack: getErrorStack(error),+ });+ }throw error;} finally {setLoading(false);@@ -279,7 +311,11 @@ export function AuthProvider({ children }: AuthProviderProps) {await clearAuth();resetAuthState();} catch (error) {- console.error("Failed to logout:", error);+ const message = getErrorMessage(error);+ console.error("Failed to logout", message);+ if (__DEV__) {+ console.debug("[AuthContext] logout failed", { message, stack: getErrorStack(error) });+ }}};diff --git a/companion/extension/entrypoints/content.ts b/companion/extension/entrypoints/content.tsindex 36c825dcb3a..69951a2d800 100644--- a/companion/extension/entrypoints/content.ts+++ b/companion/extension/entrypoints/content.ts@@ -17,7 +17,7 @@ export default defineContentScript({console.log("Cal.com: Gmail integration initialized successfully");} catch (error) {// Fail silently - don't break Gmail UI- console.error("Cal.com: Failed to initialize Gmail integration:", error);+ console.error("Cal.com: Failed to initialize Gmail integration");}}@@ -29,7 +29,7 @@ export default defineContentScript({console.log("Cal.com: Google Calendar integration initialized successfully");} catch (error) {// Fail silently - don't break Google Calendar UI- console.error("Cal.com: Failed to initialize Google Calendar integration:", error);+ console.error("Cal.com: Failed to initialize Google Calendar integration");}}@@ -1536,8 +1536,8 @@ export default defineContentScript({${datesHTML}<div style="margin-top: 13px;"><a href="https://cal.com/${username}/${eventType.slug}?cal.tz=${encodeURIComponent(- timezone- )}" style="text-decoration: none; cursor: pointer; color: #0B57D0; font-size: 14px;">+ timezone+ )}" style="text-decoration: none; cursor: pointer; color: #0B57D0; font-size: 14px;">See all available times β</a></div>@@ -1642,7 +1642,7 @@ export default defineContentScript({return false;}} catch (error) {- console.error("Cal.com: Critical error inserting HTML:", error);+ console.error("Cal.com: Critical error inserting HTML");return false;}}@@ -1871,7 +1871,7 @@ export default defineContentScript({}, 1000);} catch (error) {// Critical failure - log but don't break Gmail- console.error("Cal.com: Failed to initialize chip watcher:", error);+ console.error("Cal.com: Failed to initialize chip watcher");}}@@ -2203,7 +2203,7 @@ export default defineContentScript({embedButton.style.opacity = "1";embedButton.style.cursor = "pointer";} catch (error) {- console.error("Cal.com: Failed to insert embed:", error);+ console.error("Cal.com: Failed to insert embed");// Check if this is the "Extension context invalidated" errorconst isContextInvalidated =@@ -2371,7 +2371,7 @@ export default defineContentScript({window.removeEventListener("resize", updatePosition);};} catch (error) {- console.error("Cal.com: Failed to create or insert action bar:", error);+ console.error("Cal.com: Failed to create or insert action bar");// Clean up if something failedtry {actionBar.remove();@@ -2381,7 +2381,7 @@ export default defineContentScript({}} catch (error) {// Catch-all to prevent breaking Gmail UI- console.error("Cal.com: Error handling Google chip:", error);+ console.error("Cal.com: Error handling Google chip");return;}}@@ -2458,8 +2458,8 @@ export default defineContentScript({<div style="font-size: 13px; color: #666; margin-top: 4px;">${parsedData.slots.length} time slot${parsedData.slots.length > 1 ? "s" : ""} β’ ${- parsedData.detectedDuration- }min each</div>+ parsedData.detectedDuration+ }min each</div></div><button class="close-menu" style="background: none; border: none; cursor: pointer; font-size: 28px; color: #666; line-height: 1; padding: 0; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 50%; transition: background 0.2s ease;">Γ</button>`;@@ -2912,7 +2912,7 @@ export default defineContentScript({});});} catch (error) {- console.error("Error showing Cal.com suggestion menu:", error);+ console.error("Error showing Cal.com suggestion menu");loadingDiv.remove();const errorMessage = error instanceof Error ? error.message : "";diff --git a/companion/extension/lib/google-calendar.ts b/companion/extension/lib/google-calendar.tsindex 9e0c563f441..9e56ed5e731 100644--- a/companion/extension/lib/google-calendar.ts+++ b/companion/extension/lib/google-calendar.ts@@ -543,7 +543,7 @@ function parseAttendees(eventPopup: Element): AttendeeInfo[] {const whoSection = allText.match(/Who:([\s\S]*?)(?:Where:|When:|$)/i);if (whoSection) {const whoText = whoSection[1];- const whoEmails = whoText.match(emailRegex) || [];+ const whoEmails: string[] = whoText.match(emailRegex) ?? [];whoEmails.forEach((email) => {const emailLower = email.toLowerCase();@@ -584,7 +584,7 @@ function parseAttendees(eventPopup: Element): AttendeeInfo[] {guestListContainers.forEach((container) => {const containerText = container.textContent || "";- const emails = containerText.match(emailRegex) || [];+ const emails: string[] = containerText.match(emailRegex) ?? [];emails.forEach((email) => {const emailLower = email.toLowerCase();diff --git a/companion/hooks/useBookingActions.ts b/companion/hooks/useBookingActions.tsindex 4ec9a615349..703f28d7264 100644--- a/companion/hooks/useBookingActions.ts+++ b/companion/hooks/useBookingActions.ts@@ -176,7 +176,7 @@ export const useBookingActions = ({Alert.alert("Success", "Event cancelled successfully");},onError: (error) => {- console.error("Failed to cancel booking:", error);+ console.error("Failed to cancel booking");showErrorAlert("Error", "Failed to cancel event. Please try again.");},}diff --git a/companion/hooks/useBookings.ts b/companion/hooks/useBookings.tsindex 2221b86b033..c074187f06b 100644--- a/companion/hooks/useBookings.ts+++ b/companion/hooks/useBookings.ts@@ -108,7 +108,7 @@ export function useCancelBooking() {});},onError: (error) => {- console.error("Failed to cancel booking:", error);+ console.error("Failed to cancel booking");},});}@@ -152,7 +152,7 @@ export function useRescheduleBooking() {});},onError: (error) => {- console.error("Failed to reschedule booking:", error);+ console.error("Failed to reschedule booking");},});}@@ -184,7 +184,7 @@ export function useConfirmBooking() {});},onError: (error) => {- console.error("Failed to confirm booking:", error);+ console.error("Failed to confirm booking");},});}@@ -217,7 +217,7 @@ export function useDeclineBooking() {});},onError: (error) => {- console.error("Failed to decline booking:", error);+ console.error("Failed to decline booking");},});}diff --git a/companion/hooks/useEventTypes.ts b/companion/hooks/useEventTypes.tsindex edcf9fe6520..08f2fee9e00 100644--- a/companion/hooks/useEventTypes.ts+++ b/companion/hooks/useEventTypes.ts@@ -93,7 +93,12 @@ export function useCreateEventType() {queryClient.setQueryData(queryKeys.eventTypes.detail(newEventType.id), newEventType);},onError: (error) => {- console.error("Failed to create event type:", error);+ console.error("Failed to create event type");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[useCreateEventType] failed", { message, stack });+ }},});}@@ -127,7 +132,12 @@ export function useUpdateEventType() {queryClient.setQueryData(queryKeys.eventTypes.detail(variables.id), updatedEventType);},onError: (error) => {- console.error("Failed to update event type:", error);+ console.error("Failed to update event type");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[useUpdateEventType] failed", { message, stack });+ }},});}@@ -173,7 +183,12 @@ export function useDeleteEventType() {if (context?.previousEventTypes) {queryClient.setQueryData(queryKeys.eventTypes.lists(), context.previousEventTypes);}- console.error("Failed to delete event type:", error);+ console.error("Failed to delete event type");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[useDeleteEventType] failed", { message, stack });+ }},onSettled: () => {// Always refetch after error or success@@ -233,7 +248,12 @@ export function useDuplicateEventType() {queryClient.invalidateQueries({ queryKey: queryKeys.eventTypes.lists() });},onError: (error) => {- console.error("Failed to duplicate event type:", error);+ console.error("Failed to duplicate event type");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[useDuplicateEventType] failed", { message, stack });+ }},});}diff --git a/companion/hooks/useSchedules.ts b/companion/hooks/useSchedules.tsindex f2746bbb96b..f73a401cf9f 100644--- a/companion/hooks/useSchedules.ts+++ b/companion/hooks/useSchedules.ts@@ -147,7 +147,7 @@ export function useCreateSchedule() {queryClient.setQueryData(queryKeys.schedules.detail(newSchedule.id), newSchedule);},onError: (error) => {- console.error("Failed to create schedule:", error);+ console.error("Failed to create schedule");},});}@@ -181,7 +181,7 @@ export function useUpdateSchedule() {queryClient.setQueryData(queryKeys.schedules.detail(variables.id), updatedSchedule);},onError: (error) => {- console.error("Failed to update schedule:", error);+ console.error("Failed to update schedule");},});}@@ -208,7 +208,7 @@ export function useSetScheduleAsDefault() {queryClient.invalidateQueries({ queryKey: queryKeys.schedules.all });},onError: (error) => {- console.error("Failed to set schedule as default:", error);+ console.error("Failed to set schedule as default");},});}@@ -252,7 +252,7 @@ export function useDeleteSchedule() {if (context?.previousSchedules) {queryClient.setQueryData(queryKeys.schedules.lists(), context.previousSchedules);}- console.error("Failed to delete schedule:", error);+ console.error("Failed to delete schedule");},onSettled: () => {// Always refetch after error or success@@ -283,7 +283,7 @@ export function useDuplicateSchedule() {queryClient.invalidateQueries({ queryKey: queryKeys.schedules.lists() });},onError: (error) => {- console.error("Failed to duplicate schedule:", error);+ console.error("Failed to duplicate schedule");},});}diff --git a/companion/hooks/useUserProfile.ts b/companion/hooks/useUserProfile.tsindex 944aa9c885d..3934edf7510 100644--- a/companion/hooks/useUserProfile.ts+++ b/companion/hooks/useUserProfile.ts@@ -114,7 +114,12 @@ export function useUpdateUserProfile() {if (context?.previousProfile) {queryClient.setQueryData(queryKeys.userProfile.current(), context.previousProfile);}- console.error("Failed to update user profile:", error);+ console.error("Failed to update user profile");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[useUpdateUserProfile] failed", { message, stack });+ }},onSettled: () => {// Always refetch after error or successdiff --git a/companion/package.json b/companion/package.jsonindex ae717510f49..6ca6cadeeea 100644--- a/companion/package.json+++ b/companion/package.json@@ -1,13 +1,14 @@{"name": "cal-companion","displayName": "Cal.com Companion",- "version": "1.7.4",+ "version": "1.7.5","main": "index.js","scripts": {"start": "expo start","android": "expo run:android","ios": "expo run:ios","web": "expo start --web",+ "typecheck": "tsc -p tsconfig.json --noEmit","ext": "wxt","ext:build": "wxt build","ext:build-prod": "BUILD_FOR_STORE=true wxt build",diff --git a/companion/services/calcom.ts b/companion/services/calcom.tsindex a0760e35224..cf44ab1f0ff 100644--- a/companion/services/calcom.ts+++ b/companion/services/calcom.ts@@ -191,7 +191,7 @@ export class CalComAPIService {throw new Error("Invalid response from update user profile API");} catch (error) {- console.error("updateUserProfile error:", error);+ console.error("updateUserProfile error");throw error;}}@@ -321,7 +321,7 @@ export class CalComAPIService {"2024-06-14");} catch (error) {- console.error("Delete API error:", error);+ console.error("Delete API error");throw error;}}@@ -349,7 +349,7 @@ export class CalComAPIService {throw new Error("Invalid response from create event type API");} catch (error) {- console.error("createEventType error:", error);+ console.error("createEventType error");throw error;}}@@ -406,7 +406,7 @@ export class CalComAPIService {throw new Error("Invalid response from reschedule booking API");} catch (error) {- console.error("rescheduleBooking error:", error);+ console.error("rescheduleBooking error");throw error;}}@@ -431,7 +431,7 @@ export class CalComAPIService {throw new Error("Invalid response from confirm booking API");} catch (error) {- console.error("confirmBooking error:", error);+ console.error("confirmBooking error");throw error;}}@@ -462,7 +462,7 @@ export class CalComAPIService {throw new Error("Invalid response from decline booking API");} catch (error) {- console.error("declineBooking error:", error);+ console.error("declineBooking error");throw error;}}@@ -502,7 +502,7 @@ export class CalComAPIService {throw new Error("Invalid response from mark absent API");} catch (error) {- console.error("markAbsent error:", error);+ console.error("markAbsent error");throw error;}}@@ -589,7 +589,7 @@ export class CalComAPIService {}throw new Error("Invalid response from get booking API");} catch (error) {- console.error("getBookingByUid error:", error);+ console.error("getBookingByUid error");throw error;}}@@ -775,7 +775,7 @@ export class CalComAPIService {throw new Error("Invalid response from create schedule API");} catch (error) {- console.error("createSchedule error:", error);+ console.error("createSchedule error");throw error;}}@@ -802,7 +802,7 @@ export class CalComAPIService {return null;} catch (error) {- console.error("getScheduleById error:", error);+ console.error("getScheduleById error");throw error;}}@@ -820,7 +820,7 @@ export class CalComAPIService {return [];} catch (error) {- console.error("getConferencingOptions error:", error);+ console.error("getConferencingOptions error");throw error;}}@@ -849,7 +849,7 @@ export class CalComAPIService {return null;}}- console.error("getEventTypeById error:", error);+ console.error("getEventTypeById error");throw error;}}@@ -946,7 +946,7 @@ export class CalComAPIService {throw new Error("Invalid response from update event type API");} catch (error) {- console.error("updateEventType error:", error);+ console.error("updateEventType error");throw error;}}@@ -992,7 +992,7 @@ export class CalComAPIService {throw new Error("Invalid response from update schedule API");} catch (error) {- console.error("updateSchedule error:", error);+ console.error("updateSchedule error");throw error;}}@@ -1017,7 +1017,7 @@ export class CalComAPIService {throw new Error("Invalid response from duplicate schedule API");} catch (error) {- console.error("duplicateSchedule error:", error);+ console.error("duplicateSchedule error");throw error;}}@@ -1036,7 +1036,7 @@ export class CalComAPIService {"2024-06-11");} catch (error) {- console.error("deleteSchedule error:", error);+ console.error("deleteSchedule error");throw error;}}@@ -1056,7 +1056,7 @@ export class CalComAPIService {return [];} catch (error) {- console.error("getWebhooks error:", error);+ console.error("getWebhooks error");throw error;}}@@ -1079,7 +1079,7 @@ export class CalComAPIService {throw new Error("Invalid response from create webhook API");} catch (error) {- console.error("createWebhook error:", error);+ console.error("createWebhook error");throw error;}}@@ -1105,7 +1105,7 @@ export class CalComAPIService {throw new Error("Invalid response from update webhook API");} catch (error) {- console.error("updateWebhook error:", error);+ console.error("updateWebhook error");throw error;}}@@ -1117,7 +1117,7 @@ export class CalComAPIService {method: "DELETE",});} catch (error) {- console.error("deleteWebhook error:", error);+ console.error("deleteWebhook error");throw error;}}@@ -1135,7 +1135,7 @@ export class CalComAPIService {return [];} catch (error) {- console.error("getEventTypeWebhooks error:", error);+ console.error("getEventTypeWebhooks error");throw error;}}@@ -1164,7 +1164,7 @@ export class CalComAPIService {throw new Error("Invalid response from create event type webhook API");} catch (error) {- console.error("createEventTypeWebhook error:", error);+ console.error("createEventTypeWebhook error");throw error;}}@@ -1194,7 +1194,7 @@ export class CalComAPIService {throw new Error("Invalid response from update event type webhook API");} catch (error) {- console.error("updateEventTypeWebhook error:", error);+ console.error("updateEventTypeWebhook error");throw error;}}@@ -1206,7 +1206,7 @@ export class CalComAPIService {method: "DELETE",});} catch (error) {- console.error("deleteEventTypeWebhook error:", error);+ console.error("deleteEventTypeWebhook error");throw error;}}@@ -1228,7 +1228,7 @@ export class CalComAPIService {return [];} catch (error) {- console.error("getEventTypePrivateLinks error:", error);+ console.error("getEventTypePrivateLinks error");throw error;}}@@ -1257,7 +1257,7 @@ export class CalComAPIService {throw new Error("Invalid response from create private link API");} catch (error) {- console.error("createEventTypePrivateLink error:", error);+ console.error("createEventTypePrivateLink error");throw error;}}@@ -1287,7 +1287,7 @@ export class CalComAPIService {throw new Error("Invalid response from update private link API");} catch (error) {- console.error("updateEventTypePrivateLink error:", error);+ console.error("updateEventTypePrivateLink error");throw error;}}@@ -1299,7 +1299,7 @@ export class CalComAPIService {method: "DELETE",});} catch (error) {- console.error("deleteEventTypePrivateLink error:", error);+ console.error("deleteEventTypePrivateLink error");throw error;}}diff --git a/companion/utils/browser.ts b/companion/utils/browser.tsindex 33d09817835..eecfddff973 100644--- a/companion/utils/browser.ts+++ b/companion/utils/browser.ts@@ -57,7 +57,12 @@ export const openInAppBrowser = async (await WebBrowser.openBrowserAsync(url, browserOptions);} catch (error) {- console.error(`Failed to open ${url}:`, error);+ console.error("Failed to open link");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[openInAppBrowser] failed", { message, stack, fallbackMessage });+ }showErrorAlert("Error", `Failed to open ${fallbackMessage || "link"}. Please try again.`);}};diff --git a/companion/utils/gmailGoogleChipParser.ts b/companion/utils/gmailGoogleChipParser.tsindex 1989103b80e..7d550cbfcec 100644--- a/companion/utils/gmailGoogleChipParser.ts+++ b/companion/utils/gmailGoogleChipParser.ts@@ -149,7 +149,12 @@ export function parseGoogleChip(chipElement: HTMLElement): ParsedGoogleChip | nudetectedDuration,};} catch (error) {- console.error("Error parsing Google chip:", error);+ console.error("Error parsing Google chip");+ if (__DEV__) {+ const message = error instanceof Error ? error.message : String(error);+ const stack = error instanceof Error ? error.stack : undefined;+ console.debug("[gmailGoogleChipParser] parse failed", { message, stack });+ }return null;}}diff --git a/companion/utils/index.ts b/companion/utils/index.tsindex 2376dad4fb0..224349c17d8 100644--- a/companion/utils/index.ts+++ b/companion/utils/index.ts@@ -31,7 +31,7 @@ export { showErrorAlert } from "./alerts";export { openInAppBrowser } from "./browser";// Network utilities-export { isOnline, subscribeToNetworkChanges } from "./network";+export { isOnline } from "./network";// Slug utilitiesexport { slugify } from "./slugify";diff --git a/companion/wxt.config.ts b/companion/wxt.config.tsindex 05aaffdb9b3..34597802826 100644--- a/companion/wxt.config.ts+++ b/companion/wxt.config.ts@@ -58,7 +58,7 @@ export default defineConfig({outDir: ".output",manifest: {name: "Cal.com Companion",- version: "1.7.4",+ version: "1.7.5",description: "Your calendar companion for quick booking and scheduling",permissions: ["activeTab", "storage", "identity"],host_permissions: [@@ -68,7 +68,7 @@ export default defineConfig({"https://mail.google.com/*","https://calendar.google.com/*",// Include localhost permission for dev builds (needed for iframe to load)- ...(!isBuildForStore ? ["http://localhost:*/*"] : []),+ // ...(!isBuildForStore ? ["http://localhost:*/*"] : []),],content_security_policy: {extension_pages: !isBuildForStore