Files
cal.diy/companion/components/screens/AddGuestsScreen.tsx
T
Dhairyashil Shinde 9e84f59216 feat(companion): UI Enhancements for Android and Extension (#26434)
* feat: companion-android-ui-upgrade version 1

* recurrings and unconfirmed booking filter and page implementation

* add badge and links to event type list page

* address cubics comments

* feat(companion): unify dropdown menu for Android and extension (#26486)

* feat(companion): unify dropdown menu for Android and extension

- Merge Android-specific dropdown implementations into base component files
- EventTypeListItem: Add DropdownMenu with Preview, Copy link, Edit, Duplicate, Delete actions
- BookingListItem: Add DropdownMenu with booking actions (reschedule, edit location, add guests, etc.)
- RecurringBookingListItem: Add DropdownMenu with recurring booking actions
- AvailabilityListItem: Add DropdownMenu with Set as Default, Duplicate, Delete actions
- BookingDetailScreen: Add DropdownMenu in header for Android with AlertDialog for cancel confirmation
- Delete all .android.tsx files as implementations are now unified

* fix(companion): fix typecheck errors after dropdown unification

- Remove unused props from EventTypeListItem.ios.tsx (copiedEventTypeId, handleEventTypeLongPress)
- Remove unused onActionsPress prop from BookingListItem.ios.tsx
- Remove copiedEventTypeId and handleEventTypeLongPress props from index.ios.tsx and index.tsx
- Remove onLongPress and onActionsPress props from BookingListScreen.tsx
- Remove handleScheduleLongPress, setSelectedSchedule, setShowActionsModal props from AvailabilityListScreen.tsx
- Fix BookingDetailScreen.tsx to use correct action property names (reschedule.visible instead of canReschedule, etc.)

* fix(companion): remove unused code after dropdown unification

- Remove unused handleEventTypeLongPress function and ActionSheetIOS import from index.ios.tsx
- Remove unused copiedEventTypeId state, handleEventTypeLongPress function, and ActionSheetIOS import from index.tsx
- Prefix unused setSelectedBooking with underscore in BookingListScreen.tsx
- Remove unused handleScheduleLongPress function and ActionSheetIOS import from AvailabilityListScreen.tsx

* feat(companion): unify booking filter UI for Android and extension

- Remove SegmentedControl from web/extension booking list page
- Use Header dropdown for booking status filter on both Android and web
- Use unified event type filter dropdown for both platforms
- Remove unused showFilterModal state and related code
- Pass filterOptions, activeFilter, and onFilterChange to Header for all platforms

* fix(companion): add header padding for web/extension to prevent button clipping

- Add headerLeftContainerStyle and headerRightContainerStyle with 12px padding for web platform
- Applied to root Stack and all nested tab Stack layouts
- Fixes issue where header buttons were touching edges and getting chopped off on extension/web
- Android remains unaffected as the fix is web-only

* fix(companion): add HeaderButtonWrapper for web-only header padding

- Create HeaderButtonWrapper component that adds 12px margin on web only
- Wrap all header buttons with HeaderButtonWrapper to prevent clipping
- Revert invalid screenOptions changes that caused typecheck errors
- Apply fix to all screens with native header buttons:
  - reschedule.tsx, edit-location.tsx, add-guests.tsx
  - mark-no-show.tsx, view-recordings.tsx, meeting-session-details.tsx
  - event-type-detail.tsx, BookingDetailScreen.tsx, profile-sheet.tsx
  - edit-availability-day.tsx, edit-availability-name.tsx, edit-availability-override.tsx

* update more ui-ux

* address cubics comments

* address cubics comments & open event type list page first for inttial render of app
2026-01-07 07:19:07 -03:00

264 lines
8.7 KiB
TypeScript

/**
* AddGuestsScreen Component
*
* Screen content for adding guests to a booking.
* Used with the add-guests route that has native Stack.Header.
*/
import { Ionicons } from "@expo/vector-icons";
import { forwardRef, useCallback, useEffect, useImperativeHandle, useState } from "react";
import {
Alert,
KeyboardAvoidingView,
Platform,
ScrollView,
Text,
TextInput,
TouchableOpacity,
View,
} from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useAddGuests } from "@/hooks/useBookings";
import type { Booking } from "@/services/calcom";
import { safeLogError } from "@/utils/safeLogger";
export interface AddGuestsScreenProps {
booking: Booking | null;
onSuccess: () => void;
onSavingChange?: (isSaving: boolean) => void;
onGuestCountChange?: (count: number) => void;
transparentBackground?: boolean;
}
// Handle type for parent component to call submit
export interface AddGuestsScreenHandle {
submit: () => void;
}
function isValidEmail(email: string): boolean {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email.trim());
}
export const AddGuestsScreen = forwardRef<AddGuestsScreenHandle, AddGuestsScreenProps>(
function AddGuestsScreen(
{ booking, onSuccess, onSavingChange, onGuestCountChange, transparentBackground = false },
ref
) {
const insets = useSafeAreaInsets();
const backgroundStyle = transparentBackground ? "bg-transparent" : "bg-[#F2F2F7]";
const pillStyle = transparentBackground ? "bg-[#E8E8ED]/50" : "bg-[#E8E8ED]";
const [email, setEmail] = useState("");
const [name, setName] = useState("");
const [guests, setGuests] = useState<{ email: string; name?: string }[]>([]);
// Use React Query mutation for automatic cache invalidation
const { mutate: addGuestsMutation, isPending: isSaving } = useAddGuests();
// Notify parent of saving state changes
useEffect(() => {
onSavingChange?.(isSaving);
}, [isSaving, onSavingChange]);
// Notify parent of guest count changes
useEffect(() => {
onGuestCountChange?.(guests.length);
}, [guests.length, onGuestCountChange]);
const handleAddGuest = useCallback(() => {
const trimmedEmail = email.trim();
if (!trimmedEmail) {
Alert.alert("Error", "Please enter an email address");
return;
}
if (!isValidEmail(trimmedEmail)) {
Alert.alert("Error", "Please enter a valid email address");
return;
}
if (guests.some((g) => g.email.toLowerCase() === trimmedEmail.toLowerCase())) {
Alert.alert("Error", "This guest has already been added");
return;
}
setGuests([...guests, { email: trimmedEmail, name: name.trim() || undefined }]);
setEmail("");
setName("");
}, [email, name, guests]);
const handleRemoveGuest = useCallback(
(index: number) => {
setGuests(guests.filter((_, i) => i !== index));
},
[guests]
);
const handleSubmit = useCallback(() => {
if (!booking || isSaving) return;
if (guests.length === 0) {
Alert.alert("Error", "Please add at least one guest");
return;
}
addGuestsMutation(
{
uid: booking.uid,
guests,
},
{
onSuccess: () => {
Alert.alert("Success", "Guests added successfully", [
{ text: "OK", onPress: onSuccess },
]);
},
onError: (error) => {
safeLogError("[AddGuestsScreen] Failed to add guests:", error);
Alert.alert("Error", "Failed to add guests. Please try again.");
},
}
);
}, [booking, guests, onSuccess, isSaving, addGuestsMutation]);
// Expose submit function to parent via ref (same pattern as senior's actionHandlersRef)
useImperativeHandle(
ref,
() => ({
submit: handleSubmit,
}),
[handleSubmit]
);
if (!booking) {
return (
<View className={`flex-1 items-center justify-center ${backgroundStyle}`}>
<Text className="text-gray-500">No booking data</Text>
</View>
);
}
return (
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"}
className={`flex-1 ${backgroundStyle}`}
>
<ScrollView
className="flex-1"
contentContainerStyle={{
padding: 16,
paddingBottom: insets.bottom + 16,
}}
keyboardShouldPersistTaps="handled"
showsVerticalScrollIndicator={!transparentBackground}
>
{/* Email input */}
{transparentBackground && (
<Text className="mb-2 px-1 text-[13px] font-medium text-gray-500">Email *</Text>
)}
<View
className={`mb-3 overflow-hidden rounded-xl px-4 py-3 ${
transparentBackground ? "border border-gray-300/40 bg-white/60" : "bg-white"
}`}
>
{!transparentBackground && (
<Text className="mb-1.5 text-[13px] font-medium text-gray-500">Email *</Text>
)}
<TextInput
className="h-10 text-[17px] text-[#000]"
placeholder="[email protected]"
placeholderTextColor="#9CA3AF"
value={email}
onChangeText={setEmail}
keyboardType="email-address"
autoCapitalize="none"
autoCorrect={false}
editable={!isSaving}
/>
</View>
{/* Name input */}
{transparentBackground && (
<Text className="mb-2 px-1 text-[13px] font-medium text-gray-500">Name (optional)</Text>
)}
<View
className={`mb-4 overflow-hidden rounded-xl px-4 py-3 ${
transparentBackground ? "border border-gray-300/40 bg-white/60" : "bg-white"
}`}
>
{!transparentBackground && (
<Text className="mb-1.5 text-[13px] font-medium text-gray-500">Name (optional)</Text>
)}
<TextInput
className="h-10 text-[17px] text-[#000]"
placeholder="Guest Name"
placeholderTextColor="#9CA3AF"
value={name}
onChangeText={setName}
editable={!isSaving}
/>
</View>
{/* Add button */}
<TouchableOpacity
className={`mb-6 flex-row items-center justify-center rounded-xl py-3 ${
transparentBackground ? "border border-gray-300/40 bg-white/60" : "bg-white"
}`}
onPress={handleAddGuest}
activeOpacity={0.7}
disabled={isSaving}
>
<Ionicons name="add-circle" size={22} color="#007AFF" />
<Text className="ml-2 text-[17px] font-medium text-[#007AFF]">Add</Text>
</TouchableOpacity>
{/* Guest list */}
{guests.length > 0 && (
<View>
<Text className="mb-2 px-1 text-[13px] font-medium uppercase tracking-wide text-gray-500">
Guests to add ({guests.length})
</Text>
<View
className={`overflow-hidden rounded-xl ${
transparentBackground ? "border border-gray-300/40 bg-white/60" : "bg-white"
}`}
>
{guests.map((guest, index) => (
<View
key={guest.email}
className={`flex-row items-center px-4 py-3 ${
index < guests.length - 1 ? "border-b border-gray-100/50" : ""
}`}
>
<View
className={`mr-3 h-10 w-10 items-center justify-center rounded-full ${pillStyle}`}
>
<Ionicons name="person" size={20} color="#6B7280" />
</View>
<View className="flex-1">
<Text className="text-[17px] text-[#000]">{guest.email}</Text>
{guest.name && (
<Text className="mt-0.5 text-[15px] text-gray-500">{guest.name}</Text>
)}
</View>
<TouchableOpacity
onPress={() => handleRemoveGuest(index)}
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
disabled={isSaving}
>
<Ionicons name="close-circle-outline" size={24} color="#800020" />
</TouchableOpacity>
</View>
))}
</View>
</View>
)}
</ScrollView>
</KeyboardAvoidingView>
);
}
);
// Default export for React Native compatibility
export default AddGuestsScreen;