wurde ein datum ausgewähl(unter verfügbakeit anziegen) in… · The Chat Archive
Explore o1-preview-2024-09-12 · OpenAI WildChat-4.8M (AI2)wurde ein datum ausgewähl(unter verfügbakeit anziegen) in studiofooter, dann soll WENN… Save Share Download ▾ Reportwurde ein datum ausgewähl(unter verfügbakeit anziegen) in studiofooter, dann soll WENN auf reservieren gedrückt wird(also zum booking prozess geht) das es dort dieser datum in datechooser schon ausgewählt ist.
reservieren ist auch klickbar, auch wenn kein datum in studiofooter-> customcalender ausgewählt wurd.
konkrekt : wird ein datum in customcalender gewählt, und wenn auf reservieren gedrückt wird, dann soll dieser ausgwählte datum in datechooser schon ausgewählt sein
ich habs versucht zu implementieren aber das hat nicht geklappt, warum auch immer ...
Studioscreen code :
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { View, Text, ActivityIndicator, Pressable, Animated, StyleSheet } from 'react-native';
import DetailsStudioItem from '../../components/DetailsStudioItem';
import defaultStyles from '../../theme/Styles';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import LogoHeader from '../../components/LogoHeader';
import { useNavigation, useRoute } from '@react-navigation/native';
import { RouteProp } from '@react-navigation/native';
import { RootStackParamList } from '../../components/StudioFeedItem/StudioFeedItem';
import { useQuery } from '@apollo/client';
import { GET_STUDIO } from './queries';
import { GetStudioQuery, GetStudioQueryVariables, Studio } from '../../API';
import CloseStudioIconOnStudioPage from '../../assets/icons/StudioIcons/CloseStudioIconOnStudioPage';
import { useAuthContext } from '../../contexts/AuthContext';
import { TouchableOpacity } from 'react-native-gesture-handler';
import PfeilLinksGross from '../../assets/icons/PfeilLinksGross';
import Button from '../../components/Button';
import colors from '../../theme/colors';
import BookingScreen from '../Booking/BookingScreen';
import StudioFooter from './StudioFooter';
import { format } from 'date-fns/format';
type StudioScreenRouteProp = RouteProp<RootStackParamList, 'StudioDetails'>;
const StudioScreen = () => {
const route = useRoute();
const insets = useSafeAreaInsets();
const navigation = useNavigation();
const { userId: currentUserId } = useAuthContext();
const [isBookingVisible, setIsBookingVisible] = useState(false);
const [initialDate, setInitialDate] = useState<Date | null>(null);
const openBookingModal = (selectedDate: Date | null) => {
// Konvertiere das Date-Objekt in das erwartete Format yyyy-MM-dd
if (selectedDate) {
const formattedDate = format(selectedDate, 'yyyy-MM-dd');
setInitialDate(new Date(formattedDate)); // Setze ein neues Date-Objekt mit dem formatierten Datum
}
setIsBookingVisible(true);
};
const closeBookingModal = () => {
setIsBookingVisible(false);
};
const { loading, error, data } = useQuery<GetStudioQuery, GetStudioQueryVariables>(GET_STUDIO, {
variables: { id: route.params.studioID },
});
const navigateToUpdateStudio = useCallback(() => {
if (data?.getStudio) {
navigation.navigate('EditStudioScreen', { studioId: data.getStudio.id });
}
}, [navigation, data]);
Assistant2024-11-14 18:40 UTC Copy response
Copy first prompt
Other models, same or similar prompt Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Details
Model o1-preview-2024-09-12
Provider OpenAI
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language de
Conversation date Nov 14, 2024
Added to archive Nov 16, 2026
ID 01m7h4294g3ebr74smyaccwrk7Source & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: a5f271ccc94497a1d741485d66f0d070
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
Dataset releases Not yet included in a published release.
if (loading) {
return ;
}
if (error) {
return {error.message};
}
const studio = data?.getStudio;
if (!studio) {
return No studio data available;
}
const slideAnimation = new Animated.Value(200); // Startposition für das Modal
// Das Modal wird direkt sichtbar, daher starten wir die Animation sofort
Animated.timing(slideAnimation, {
toValue: 0, // Modal fährt nach oben
duration: 300,
useNativeDriver: true,
}).start();
const navigationToBookingScreen = () => {
navigation.navigate('Booking');
};
return (
<View style={[defaultStyles.container, { paddingTop: insets.top }]}>
<View style={{ marginBottom: 10}}>
<View style={{
flexDirection: 'row',
justifyContent: 'space-between',
alignSelf: 'center',
alignItems: 'center',
marginTop: 0,
width: '95%',
marginBottom: 0,
top: -10,
}}>
<TouchableOpacity
style={{
width: 50, height: 30,
alignSelf: 'center',
alignItems: 'center',
justifyContent: 'center',
}}
hitSlop={{ top: 20, bottom: 20, left: 30, right: 20 }}
onPress={() => navigation.goBack()}>
<CloseStudioIconOnStudioPage/>
</TouchableOpacity>
{studio.User?.id === currentUserId && (
<View style={{ alignItems: 'center' }}>
<TouchableOpacity onPress={navigateToUpdateStudio}>
<Text style={defaultStyles.regularMiddle}>
{'Bearbeiten'}
</Text>
<View style={{
width: '100%',
borderWidth: 1,
}} />
</TouchableOpacity>
</View>
)}
</View>
{/*Studio */}
<View style={{ paddingBottom: 0 }}>
<DetailsStudioItem studioItem={studio} />
</View>
<Animated.View
style={[
styles.modalContent,
{ transform: [{ translateY: slideAnimation }] },
]}
>
<StudioFooter
price={studio.pricePerHour}
onBookingPress={openBookingModal}
studioId={studio.id}
/>
</Animated.View>
{/* Modal, das direkt unten angezeigt wird */}
{/* <Animated.View
style={[
styles.modalContent,
{ transform: [{ translateY: slideAnimation }] },
]}
>
<View style={styles.textContainer}>
<View style={styles.priceContainer}>
<Text style={[defaultStyles.semiboldMiddle , {color:colors.DarkGrey}]}>{studio.pricePerHour} €</Text>
<Text style={[defaultStyles.regularMiddle, {color:colors.DarkGrey}]}> pro Stunde</Text>
</View>
<View style={styles.availabilityContainer}>
<TouchableOpacity >
<Text style={[defaultStyles.semiboldMiddle , {color:colors.DarkGrey3, textDecorationLine: 'underline'}]}>Verfügbarkeit zeigen</Text>
</TouchableOpacity>
</View>
</View>
<TouchableOpacity onPress={openBookingModal}>
<View style={styles.rectangleView}>
<Text style={[defaultStyles.regularLarge, {color: colors.white}]}>
Reservieren
</Text>
</View>
</TouchableOpacity>
{/* BookingScreen Modal
<BookingScreen
isVisible={isBookingVisible}
onClose={closeBookingModal}
studioId={studio.id} // Übergebe die Studio-ID
/>
</Animated.View> */}
<BookingScreen
isVisible={isBookingVisible}
onClose={closeBookingModal}
studioId={studio.id}
initialDate={initialDate}
/>
</View>
const styles = StyleSheet.create({
modalContent: {
flex: 1,
position: 'absolute',
bottom: 0,
width: '100%',
backgroundColor: '#ffffff',
marginTop: 100,
paddingBottom: 40,
flexDirection: 'row',
justifyContent: 'space-between',
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 5, // Schatten für Android
},
priceContainer: {
flexDirection:'row',
paddingBottom: 14,
},
availabilityContainer: {
flexDirection:'row',
},
price: {
},
textContainer: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'flex-start',
alignContent : 'center',
alignSelf: 'center',
},
rectangleView: {
borderRadius: 13,
backgroundColor: colors.LightBlack,
flex: 1,
//width: "100%",
width: 164,
height: 54,
marginTop: 0,
marginRight: 'auto',
marginBottom: 0,
marginLeft: 'auto',
justifyContent: 'center',
alignItems: 'center',
alignContent : 'center',
alignSelf: 'center',
export default StudioScreen;
import React, { useState, useCallback, useEffect } from 'react';
import {
View,
Text,
TouchableOpacity,
StyleSheet,
ScrollView,
Platform,
ActivityIndicator,
Dimensions
} from 'react-native';
import {
format,
addMonths,
startOfMonth,
eachDayOfInterval,
endOfMonth,
isSameDay,
getDay
} from 'date-fns';
import { de } from 'date-fns/locale';
import { useQuery } from '@apollo/client';
import { getStudio } from '../queries';
import ApiErrorMessage from '../../../ApiErrorMessage';
import colors from '../../../theme/colors';
const WEEKDAYS = ['Mo.', 'Di.', 'Mi.', 'Do.', 'Fr.', 'Sa.', 'So.'];
interface DateChooserProps {
nextSlide: () => void;
studioId: string;
selectedDate: string | null;
onDateSelect: (date: string) => void;
initialDate: Date | null;
}
interface CalendarProps {
onDateSelect: (date: string) => void;
minDate: Date;
availableDates: Record<string, any>;
selectedDate: string | null;
}
const Calendar: React.FC = ({
onDateSelect,
minDate = new Date(),
availableDates,
selectedDate,
}) => {
const renderMonthGrid = useCallback((monthDate) => {
const start = startOfMonth(monthDate);
const end = endOfMonth(monthDate);
const days = eachDayOfInterval({ start, end });
const firstDayOfMonth = getDay(start);
const emptyDays = firstDayOfMonth === 0 ? 6 : firstDayOfMonth - 1;
const emptySlots = Array(emptyDays).fill(null);
const weeks = [];
let currentWeek = [...emptySlots];
days.forEach((day) => {
currentWeek.push(day);
if (currentWeek.length === 7) {
weeks.push(currentWeek);
currentWeek = [];
}
});
if (currentWeek.length > 0) {
weeks.push([...currentWeek, ...Array(7 - currentWeek.length).fill(null)]);
}
return weeks;
const renderDay = useCallback((date) => {
if (!date) return ;
const dateString = format(date, 'yyyy-MM-dd');
const dateInfo = availableDates[dateString];
const isUnavailable = dateInfo?.disabled;
const isSelected = selectedDate === dateString;
const dayNumber = format(date, 'd');
// Wenn das Datum vor heute liegt, ist es auch nicht verfügbar
const isPastDate = date < new Date().setHours(0, 0, 0, 0);
const isDisabled = isUnavailable || isPastDate;
return (
<TouchableOpacity
style={[
styles.dayContainer,
isSelected && styles.selectedDay,
isDisabled && styles.disabledDay,
]}
onPress={() => {
if (!isDisabled) {
onDateSelect(dateString);
}
}}
disabled={isDisabled}
activeOpacity={isDisabled ? 1 : 0.2} // Verhindert den Opacity-Effekt bei deaktivierten Tagen
>
<Text style={[
styles.dayText,
isSelected && styles.selectedDayText,
isDisabled && styles.disabledDayText,
]}>
{dayNumber}
</Text>
{dateInfo?.marked && !isSelected && !isDisabled && (
<View style={styles.dotMarker} />
)}
</TouchableOpacity>
);
}, [availableDates, selectedDate, onDateSelect]);
const renderMonth = useCallback((monthIndex) => {
const monthDate = addMonths(new Date(), monthIndex);
const monthGrid = renderMonthGrid(monthDate);
return (
<View style={styles.monthContainer} key={monthIndex}>
<Text style={styles.monthTitle}>
{format(monthDate, 'MMMM yyyy', { locale: de })}
</Text>
{monthGrid.map((week, weekIndex) => (
<View style={styles.weekRow} key={weekIndex}>
{week.map((day, dayIndex) => (
<View key={dayIndex} style={styles.dayWrapper}>
{renderDay(day)}
</View>
))}
</View>
))}
</View>
);
}, [renderDay, renderMonthGrid]);
return (
{[0, 1, 2, 3].map((monthIndex) => renderMonth(monthIndex))}
);
};
export const DateChooser: React.FC = ({
nextSlide,
studioId,
selectedDate,
onDateSelect,
initialDate
}) => {
const [availableDates, setAvailableDates] = useState({});
const [isLoading, setIsLoading] = useState(true);
// Use initialDate if provided
useEffect(() => {
if (initialDate && !selectedDate) {
onDateSelect(format(initialDate, 'yyyy-MM-dd'));
}
}, [initialDate, selectedDate]);
const { data, loading, error } = useQuery(getStudio, {
variables: { id: studioId },
});
const processAvailability = (availabilities, bookings, minBookingDuration) => {
const markedDates = {};
const today = new Date();
const nextYear = new Date();
nextYear.setFullYear(today.getFullYear() + 1);
for (let d = new Date(today); d <= nextYear; d.setDate(d.getDate() + 1)) {
const dayOfWeek = d.getDay();
const dateString = format(d, 'yyyy-MM-dd');
const dayAvailability = availabilities.find(a => a.dayOfWeek === (dayOfWeek === 0 ? 7 : dayOfWeek));
if (dayAvailability && dayAvailability.startTime && dayAvailability.endTime) {
const [availStartHour, availStartMin] = dayAvailability.startTime.split(':').map(Number);
const [availEndHour, availEndMin] = dayAvailability.endTime.split(':').map(Number);
const availStartMins = availStartHour * 60 + availStartMin;
const availEndMins = availEndHour * 60 + availEndMin;
const dayBookings = bookings.filter(
booking => booking.date === dateString && booking.status !== 'CANCELLED'
).sort((a, b) => {
const [aHour, aMin] = a.startTime.split(':').map(Number);
const [bHour, bMin] = b.startTime.split(':').map(Number);
return (aHour * 60 + aMin) - (bHour * 60 + bMin);
});
let hasValidTimeSlot = false;
let currentTime = availStartMins;
for (const booking of dayBookings) {
const [bookStartHour, bookStartMin] = booking.startTime.split(':').map(Number);
const bookingStartMins = bookStartHour * 60 + bookStartMin;
if (bookingStartMins - currentTime > minBookingDuration * 60) {
hasValidTimeSlot = true;
break;
}
const [bookEndHour, bookEndMin] = booking.endTime.split(':').map(Number);
currentTime = bookEndHour * 60 + bookEndMin;
}
if (!hasValidTimeSlot && availEndMins - currentTime > minBookingDuration * 60) {
hasValidTimeSlot = true;
}
markedDates[dateString] = hasValidTimeSlot ? {
marked: true,
dotColor: '#000',
} : {
disabled: true,
disableTouchEvent: true
};
} else {
markedDates[dateString] = {
disabled: true,
disableTouchEvent: true
};
}
}
return markedDates;
useEffect(() => {
if (data?.getStudio) {
const studio = data.getStudio;
const availabilities = studio.availabilities.items;
const bookings = studio.bookings.items;
const minBookingDuration = studio.minNumberOfHours || 2;
const markedDates = processAvailability(availabilities, bookings, minBookingDuration);
setAvailableDates(markedDates);
setIsLoading(false);
}
}, [data, selectedDate]);
if (loading) {
return ;
}
if (error || !data || !data.getStudio) {
return (
<ApiErrorMessage
title='Error fetching the studio'
message={error?.message || "Studio not found"}
/>
);
}
return (
{WEEKDAYS.map((day, index) => (
{day}
))}
<Calendar
onDateSelect={onDateSelect}
minDate={new Date()}
availableDates={availableDates}
selectedDate={selectedDate}
/>
<TouchableOpacity
style={[styles.weiterButton, !selectedDate && styles.weiterButtonDisabled]}
disabled={!selectedDate}
onPress={nextSlide}
>
Weiter
);
};
const styles = StyleSheet.create({
outsideContainer: {
flex: 1,
backgroundColor: 'white',
},
container: {
flex: 1,
},
datePickerWrapper: {
padding: 15,
},
calendarContainer: {
width: '100%',
},
weekContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
paddingHorizontal: 15,
paddingVertical: 10,
borderBottomWidth: 1,
borderBottomColor: '#E5E5E5',
},
weekDay: {
flex: 1,
alignItems: 'center',
},
weekDayText: {
fontSize: 14,
color: '#666',
},
monthContainer: {
marginBottom: 20,
},
monthTitle: {
fontSize: 20,
fontWeight: '600',
marginBottom: 10,
marginLeft: 10,
color: '#212121',
},
weekRow: {
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: 5,
},
dayWrapper: {
flex: 1,
aspectRatio: 1,
padding: 2,
},
dayContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
borderRadius: 25,
minHeight: 40, // Fügt eine Mindesthöhe hinzu
minWidth: 40,
},
dayText: {
fontSize: 14,
color: '#212121',
},
emptyDay: {
flex: 1,
},
selectedDay: {
backgroundColor: '#212121',
},
selectedDayText: {
color: 'white',
},
unavailableDay: {
opacity: 0.3,
},
unavailableDayText: {
color: '#999',
},
dotMarker: {
width: 4,
height: 4,
borderRadius: 2,
backgroundColor: '#000',
marginTop: 2,
},
weiterButtonContainer: {
padding: 20,
borderTopWidth: 1,
borderTopColor: '#E5E5E5',
backgroundColor: 'white',
},
weiterButton: {
backgroundColor: colors.LightBlack,
borderRadius: 12,
padding: 17,
alignItems: 'center',
},
weiterButtonDisabled: {
opacity: 0.5,
},
weiterButtonText: {
color: '#FAFAFA',
fontSize: 16,
fontWeight: '500',
},
disabledDay: {
//backgroundColor: '#F5F5F5',
opacity: 1,
},
disabledDayText: {
color: '#CCCCCC',
},
export default DateChooser;
import React, { useState, useRef, useEffect } from 'react';
import { View, Text, TouchableOpacity, Animated, StyleSheet } from 'react-native';
import Svg, { Path } from 'react-native-svg';
import CustomCalendar from '../../components/CustomCalendar';
import { useQuery } from '@apollo/client';
import { getStudio } from '../../screens/Booking/queries';
import defaultStyles from '../../theme/Styles';
import colors from '../../theme/colors';
import { format } from 'date-fns';
import { de } from 'date-fns/locale';
interface StudioFooterProps {
price: number;
onBookingPress: (selectedDate: Date | null) => void;
studioId: string;
}
const StudioFooter: React.FC = ({
price,
onBookingPress,
studioId
}) => {
const [selectedDate, setSelectedDate] = useState<Date | null>(null);
const [showDatePicker, setShowDatePicker] = useState(false);
const dateContainerHeight = useRef(new Animated.Value(0)).current;
const [availableDates, setAvailableDates] = useState({});
const [isLoading, setIsLoading] = useState(true);
const { data, loading, error } = useQuery(getStudio, {
variables: { id: studioId },
});
const formatSelectedDate = (date: Date | null) => {
if (!date) return null;
return format(date, 'dd. MMMM yyyy', { locale: de });
};
const processAvailability = (availabilities: any[], bookings: any[], minBookingDuration: number) => {
const markedDates: Record<string, any> = {};
const today = new Date();
const nextYear = new Date();
nextYear.setFullYear(today.getFullYear() + 1);
for (let d = new Date(today); d <= nextYear; d.setDate(d.getDate() + 1)) {
const dayOfWeek = d.getDay();
const dateString = format(d, 'yyyy-MM-dd');
const dayAvailability = availabilities.find(a => a.dayOfWeek === (dayOfWeek === 0 ? 7 : dayOfWeek));
if (dayAvailability && dayAvailability.startTime && dayAvailability.endTime) {
const [availStartHour, availStartMin] = dayAvailability.startTime.split(':').map(Number);
const [availEndHour, availEndMin] = dayAvailability.endTime.split(':').map(Number);
const availStartMins = availStartHour * 60 + availStartMin;
const availEndMins = availEndHour * 60 + availEndMin;
const dayBookings = bookings.filter(
booking => booking.date === dateString && booking.status !== 'CANCELLED'
).sort((a, b) => {
const [aHour, aMin] = a.startTime.split(':').map(Number);
const [bHour, bMin] = b.startTime.split(':').map(Number);
return (aHour * 60 + aMin) - (bHour * 60 + bMin);
});
let hasValidTimeSlot = false;
let currentTime = availStartMins;
for (const booking of dayBookings) {
const [bookStartHour, bookStartMin] = booking.startTime.split(':').map(Number);
const bookingStartMins = bookStartHour * 60 + bookStartMin;
if (bookingStartMins - currentTime > minBookingDuration * 60) {
hasValidTimeSlot = true;
break;
}
const [bookEndHour, bookEndMin] = booking.endTime.split(':').map(Number);
currentTime = bookEndHour * 60 + bookEndMin;
}
if (!hasValidTimeSlot && availEndMins - currentTime > minBookingDuration * 60) {
hasValidTimeSlot = true;
}
markedDates[dateString] = hasValidTimeSlot ? {
marked: true,
dotColor: '#000',
} : {
disabled: true,
disableTouchEvent: true
};
} else {
markedDates[dateString] = {
disabled: true,
disableTouchEvent: true
};
}
}
return markedDates;
useEffect(() => {
if (data?.getStudio) {
const studio = data.getStudio;
const availabilities = studio.availabilities.items;
const bookings = studio.bookings.items;
const minBookingDuration = studio.minNumberOfHours || 2;
const markedDates = processAvailability(availabilities, bookings, minBookingDuration);
setAvailableDates(markedDates);
setIsLoading(false);
}
const showDateContainer = () => {
setShowDatePicker(true);
Animated.timing(dateContainerHeight, {
toValue: 1,
duration: 300,
useNativeDriver: false,
}).start();
};
const hideDateContainer = () => {
Animated.timing(dateContainerHeight, {
toValue: 0,
duration: 300,
useNativeDriver: false,
}).start(() => {
setShowDatePicker(false);
});
};
const handleDateChange = (date: Date) => {
setSelectedDate(date);
hideDateContainer();
};
return (
<>
<Animated.View
style={[
styles.dateContainer,
{
height: dateContainerHeight.interpolate({
inputRange: [0, 1],
outputRange: [0, 600]
}),
opacity: dateContainerHeight,
transform: [{
translateY: dateContainerHeight.interpolate({
inputRange: [0, 1],
outputRange: [50, 0]
})
}]
}
]}
>
Verfügbarkeit zeigen
{showDatePicker && (
)}
</Animated.View>
<View style={styles.footerContainer}>
<View style={styles.phoneFooterContainer}>
<View style={styles.footerTextContainer}>
<View style={styles.footerTextContainer2}>
<Text style={styles.priceText}>{price}€</Text>
<Text style={styles.perHourText}>pro Stunde</Text>
</View>
<TouchableOpacity onPress={showDateContainer}>
<Text style={styles.availability}>
{selectedDate
? formatSelectedDate(selectedDate)
: "Verfügbarkeit zeigen"}
</Text>
</TouchableOpacity>
</View>
<TouchableOpacity
style={[
styles.footerButton
]}
onPress={() => onBookingPress(selectedDate)}
>
<Text style={styles.buttonText}>Reservieren</Text>
</TouchableOpacity>
</View>
</View>
</>
const styles = StyleSheet.create({
footerContainer: {
borderTopWidth: 1,
borderTopColor: 'rgba(217, 217, 217, 0.50)',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
position: 'absolute',
zIndex: 1,
bottom: 0,
left: 0,
backgroundColor: '#FFFFFF',
},
dateContainer: {
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
backgroundColor: '#FFFFFF',
borderTopWidth: 1,
borderTopColor: 'rgba(217, 217, 217, 0.50)',
overflow: 'hidden',
},
dateHeaderContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center', // Geändert zu center
width: '100%',
padding: 19,
borderBottomWidth: 1,
borderBottomColor: 'rgba(217, 217, 217, 0.50)',
marginBottom: 23,
position: 'relative', // Hinzugefügt
},
headerText: {
fontSize: 16,
fontWeight: '500',
textAlign: 'center',
flex: 1, // Hinzugefügt
},
container: {
width: '100%',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
},
phoneFooterContainer: {
flexDirection: 'row',
width: '100%',
padding: 21,
alignItems: 'center',
justifyContent: 'space-between',
gap: 57,
},
footerTextContainer: {
flexDirection: 'column',
alignItems: 'flex-start',
justifyContent: 'flex-start',
gap: 14,
},
footerTextContainer2: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
gap: 5,
},
priceText: {
fontSize: 16,
fontWeight: '600',
},
perHourText: {
fontSize: 16,
fontWeight: '400',
},
availability: {
color: '#4A4A4A',
fontSize: 13,
fontWeight: '400',
textDecorationLine: 'underline',
textDecorationStyle: 'solid',
textDecorationColor: '#4A4A4A',
},
footerButton: {
padding: 17,
flex: 1,
backgroundColor: '#1F1F1F',
borderRadius: 13,
alignItems: 'center',
justifyContent: 'center',
},
footerButtonDisabled: {
backgroundColor: '#CCCCCC',
},
buttonText: {
color: '#FFFFFF',
fontSize: 16,
fontWeight: '400',
},
});
export default StudioFooter;
import React, { useState } from 'react';
import { View, Text, TouchableOpacity, StyleSheet, ActivityIndicator } from 'react-native';
import { de } from 'date-fns/locale';
import Svg, { Path } from 'react-native-svg';
import {
format,
addMonths,
subMonths,
startOfMonth,
endOfMonth,
eachDayOfInterval,
isSameDay,
isBefore,
startOfWeek,
endOfWeek,
eachWeekOfInterval,
isSameMonth
} from 'date-fns';
interface CustomCalendarProps {
selectedDate: Date | null;
onDateChange: (date: Date) => void;
availableDates: Record<string, any>;
isLoading?: boolean;
}
const CustomCalendar: React.FC = ({
selectedDate,
onDateChange,
availableDates,
isLoading = false
}) => {
const [currentMonth, setCurrentMonth] = useState(new Date());
const today = new Date();
const renderNavigationButton = (direction: 'next' | 'prev') => (
<TouchableOpacity
style={styles.navigationButton}
onPress={() => {
setCurrentMonth(direction === 'next'
? addMonths(currentMonth, 1)
: subMonths(currentMonth, 1)
);
}}
>
<Svg width={8} height={12} viewBox="0 0 8 12" fill="none" style={direction === 'prev' ? { transform: [{ rotate: '180deg' }] } : {}}>
);
const weeks = eachWeekOfInterval(
{
start: startOfMonth(currentMonth),
end: endOfMonth(currentMonth)
},
{ weekStartsOn: 1 }
);
const renderWeeks = () => {
return weeks.map((week) => {
const days = eachDayOfInterval({
start: startOfWeek(week, { weekStartsOn: 1 }),
end: endOfWeek(week, { weekStartsOn: 1 })
});
return (
<View key={week.toString()} style={styles.week}>
{days.map((day) => {
const dateString = format(day, 'yyyy-MM-dd');
const dateInfo = availableDates[dateString];
const isSelected = selectedDate && isSameDay(day, selectedDate);
const isDisabled = isBefore(day, today) ||
!isSameMonth(day, currentMonth) ||
dateInfo?.disabled;
const isAvailable = !isDisabled && dateInfo?.marked;
return (
<TouchableOpacity
key={day.toString()}
style={[
styles.day,
isSelected && styles.selectedDay,
isAvailable && styles.availableDay,
!isSameMonth(day, currentMonth) && styles.outsideMonthDay,
]}
onPress={() => !isDisabled && onDateChange(day)}
disabled={isDisabled}
>
<Text style={[
styles.dayText,
isSelected && styles.selectedDayText,
isDisabled && styles.disabledDayText,
!isSameMonth(day, currentMonth) && styles.outsideMonthDayText,
]}>
{format(day, 'd')}
</Text>
{isAvailable && !isSelected && (
<View style={styles.dotMarker} />
)}
</TouchableOpacity>
);
})}
</View>
);
});
if (isLoading) {
return ;
}
return (
{renderNavigationButton('prev')}
{format(currentMonth, 'MMMM yyyy', { locale: de })}
{renderNavigationButton('next')}
{['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'].map((day) => (
{day}
))}
{renderWeeks()}
);
};
const styles = StyleSheet.create({
calendar: {
width: '100%',
padding: 20,
backgroundColor: 'white',
},
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 20,
paddingHorizontal: 10,
},
navigationButton: {
padding: 10,
},
monthText: {
color: '#1F1F1F',
fontSize: 19.2,
fontWeight: '600',
letterSpacing: -0.5,
textAlign: 'center',
},
weekdayHeader: {
flexDirection: 'row',
justifyContent: 'space-around',
marginBottom: 10,
},
weekdayText: {
color: '#666',
fontSize: 12,
},
daysContainer: {
width: '100%',
},
week: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
width: '100%',
},
day: {
width: 30,
height: 30,
justifyContent: 'center',
alignItems: 'center',
margin: 7,
},
dayText: {
fontSize: 12.7,
color: '#1F1F1F',
fontWeight: '400',
letterSpacing: -0.272,
},
selectedDay: {
backgroundColor: '#1F1F1F',
borderRadius: 15,
},
selectedDayText: {
color: '#FFFFFF',
},
disabledDayText: {
opacity: 0.3,
},
availableDay: {
// Optional: Spezielle Styling für verfügbare Tage
},
outsideMonthDay: {
opacity: 0.3,
},
outsideMonthDayText: {
color: '#666',
},
dotMarker: {
width: 4,
height: 4,
borderRadius: 2,
backgroundColor: '#000',
marginTop: 2,
},
});
export default CustomCalendar;
import React, { useState, useEffect, useRef } from 'react';
import { View, Text, StyleSheet, Modal, Animated, TouchableOpacity, Dimensions } from 'react-native';
import DateChooser from './BookingSteps/DateChooser';
import TimePicker from './BookingSteps/TimePicker';
import BookingOverview from './BookingSteps/BookingOverview';
import BookingConfirmation from './BookingSteps/BookingConfirmation';
import PfeilLinks from '../../assets/icons/PfeilLinks';
import colors from '../../theme/colors';
import { format } from 'date-fns/format';
interface BookingScreenProps {
isVisible: boolean;
onClose: () => void;
studioId: string;
initialDate: Date | null;
}
const { height: screenHeight } = Dimensions.get('window');
const BookingScreen: React.FC = ({ isVisible, onClose, studioId, initialDate }) => {
const slideAnim = useRef(new Animated.Value(screenHeight * 0.65)).current;
const [currentSlide, setCurrentSlide] = useState(0);
const [isTransitioning, setIsTransitioning] = useState(false);
const [showTimePicker, setShowTimePicker] = useState(false);
//const [selectedDate, setSelectedDate] = useState<string | null>(null);
const [selectedDate, setSelectedDate] = useState<string | null>(
initialDate ? format(initialDate, 'yyyy-MM-dd') : null
);
const [selectedTime, setSelectedTime] = useState<string | null>(null);
const [selectedEndTime, setSelectedEndTime] = useState<string | null>(null);
const titles = [
"Datum auswählen",
"Buchungsdetails",
"Checkout"
];
const slideHeights: { [key: number]: number } = {
0: 0.90,
1: 0.90,
};
useEffect(() => {
if (isVisible) {
const targetHeight = slideHeights[currentSlide] ?? 0.92;
Animated.timing(slideAnim, {
toValue: screenHeight * targetHeight,
duration: 300,
useNativeDriver: false,
}).start();
} else {
Animated.timing(slideAnim, {
toValue: 0,
duration: 300,
useNativeDriver: false,
}).start();
}
}, [isVisible, currentSlide]);
const nextSlide = () => {
if (currentSlide < titles.length - 1) {
setIsTransitioning(true);
setTimeout(() => {
setCurrentSlide(currentSlide + 1);
setIsTransitioning(false);
}, 300);
}
};
const prevSlide = () => {
if (currentSlide > 0) {
setIsTransitioning(true);
setTimeout(() => {
setCurrentSlide(currentSlide - 1);
setIsTransitioning(false);
}, 300);
}
};
const handleClose = () => {
Animated.timing(slideAnim, {
toValue: 0,
duration: 300,
useNativeDriver: false,
}).start(() => {
onClose();
setCurrentSlide(0);
setSelectedDate(null);
setSelectedTime(null);
setSelectedEndTime(null);
setShowTimePicker(false);
});
};
const handleDateSelect = (date: string) => {
setSelectedDate(date);
setShowTimePicker(true);
};
const handleTimeSelect = (startTime: string, endTime: string) => {
setSelectedTime(startTime);
setSelectedEndTime(endTime);
};
const handleTimePickerComplete = () => {
setShowTimePicker(false);
nextSlide();
};
const handleEditDateTime = () => {
setCurrentSlide(0); // Zurück zum DateChooser
};
const renderTimePickerModal = () => {
return (
<Modal
transparent={true}
visible={showTimePicker}
animationType="slide"
onRequestClose={() => setShowTimePicker(false)}
>
<TouchableOpacity
style={styles.timePickerBackground}
activeOpacity={1}
onPress={() => setShowTimePicker(false)}
/>
<TimePicker
nextSlide={handleTimePickerComplete} // Verwende den neuen Handler
studioId={studioId}
selectedDate={selectedDate}
selectedTime={selectedTime}
selectedEndTime={selectedEndTime}
onTimeSelect={handleTimeSelect}
/>
);
};
const slides = [
,
<BookingOverview
nextSlide={nextSlide}
studioId={studioId}
selectedDate={selectedDate}
selectedTime={selectedTime}
selectedEndTime={selectedEndTime}
onEditDateTime={handleEditDateTime} // Neue Prop
/>,
<BookingConfirmation
onClose={handleClose}
studioId={studioId}
selectedDate={selectedDate || ''}
selectedTime={selectedTime || ''}
selectedEndTime={selectedEndTime || ''}
/>
const progressPercentage = ((currentSlide + 1) / slides.length) * 100;
return (
<Animated.View
style={[
styles.container,
{ height: slideAnim }
]}
>
<TouchableOpacity
style={styles.closeButton}
onPress={currentSlide === 0 ? handleClose : prevSlide}
>
<View style={{left: -5}}>
{titles[currentSlide]}
<View style={[styles.progressBarInner, { width: ${progressPercentage}% }]} />
<View style={[styles.slide, isTransitioning && styles.transitioning]}>
{slides[currentSlide]}
</Animated.View>
{/* TimePicker Modal */}
{renderTimePickerModal()}
</View>
</Modal>
const styles = StyleSheet.create({
overlay: {
flex: 1,
justifyContent: 'flex-end',
},
background: {
...StyleSheet.absoluteFillObject,
backgroundColor: 'rgba(0, 0, 0, 0.9)',
},
container: {
backgroundColor: '#fff',
borderTopLeftRadius: 20,
borderTopRightRadius: 20,
overflow: 'hidden',
},
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingHorizontal: 20,
paddingVertical: 16,
borderBottomColor: '#F5F5F5',
borderBottomWidth: 1,
},
closeButton: {
padding: 8,
},
headerTitle: {
fontSize: 18,
fontWeight: '600',
color: '#000',
textAlign: 'center',
flex: 1,
},
progressBarTop: {
width: '100%',
height: 3,
backgroundColor: 'rgba(217, 217, 217, 0.50)',
overflow: 'hidden',
position: 'relative',
},
progressBarInner: {
height: '100%',
backgroundColor: colors.StuRed,
transition: 'width 0.3s ease',
},
content: {
flex: 1,
width: '100%',
},
slide: {
flex: 1,
opacity: 1,
transition: 'opacity 0.3s ease-in-out',
},
transitioning: {
opacity: 0,
},
timePickerOverlay: {
flex: 1,
justifyContent: 'flex-end',
},
timePickerBackground: {
...StyleSheet.absoluteFillObject,
backgroundColor: 'rgba(0, 0, 0, 0.9)', // Dunklerer Hintergrund
},
timePickerContainer: {
backgroundColor: 'white',
borderTopLeftRadius: 20,
borderTopRightRadius: 20,
height: '68%',
width: '100%',
// Optional: Schatten hinzufügen
shadowColor: '#000',
shadowOffset: {
width: 0,
height: -2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
});
export default BookingScreen;
The issue you're experiencing is due to inconsistencies in how dates are handled and passed between components in your code. You're switching between Date objects and formatted date strings, which can lead to unexpected behavior, especially with time zones and date comparisons.
Here's a step-by-step solution to fix the problem:
Use Consistent Date Formats:
Handle dates as strings in the yyyy-MM-dd format throughout your components. This ensures consistency and avoids issues with Date object parsing, especially when creating new Date objects from formatted strings (which can introduce unexpected time zone offsets).
Modify StudioFooter:
Change the selectedDate state to be of type string | null instead of Date | null.
When a date is selected in the CustomCalendar, store it as a string in the yyyy-MM-dd format.
Update the handleDateChange function to accept a date string.
Pass the selectedDate string to onBookingPress.
// In StudioFooter.tsx
const [selectedDate, setSelectedDate] = useState<string | null>(null);
const handleDateChange = (dateString: string) => {
setSelectedDate(dateString);
hideDateContainer();
};
// Format date for display
const formatSelectedDate = (dateString: string | null) => {
if (!dateString) return null;
const date = new Date(dateString);
return format(date, 'dd. MMMM yyyy', { locale: de });
};
// Disable 'Reservieren' button if no date is selected
<TouchableOpacity
style={[
styles.footerButton,
!selectedDate && styles.footerButtonDisabled,
]}
onPress={() => onBookingPress(selectedDate)}
disabled={!selectedDate}
>
<Text style={styles.buttonText}>Reservieren</Text>
</TouchableOpacity>
Update StudioScreen:
Modify the openBookingModal function to accept a date string.
Set initialDate as a string | null.
Pass initialDate to BookingScreen.
// In StudioScreen.tsx
const [initialDate, setInitialDate] = useState<string | null>(null);
const openBookingModal = (selectedDate: string | null) => {
if (selectedDate) {
setInitialDate(selectedDate);
}
setIsBookingVisible(true);
};
// Pass initialDate to BookingScreen
<BookingScreen
isVisible={isBookingVisible}
onClose={closeBookingModal}
studioId={studio.id}
initialDate={initialDate}
/>
Modify BookingScreen:
Update initialDate prop type to string | null.
Initialize selectedDate state with initialDate.
Remove unnecessary date formatting.
// In BookingScreen.tsx
interface BookingScreenProps {
isVisible: boolean;
onClose: () => void;
studioId: string;
initialDate: string | null; // Changed to string | null
}
const [selectedDate, setSelectedDate] = useState<string | null>(initialDate);
// Pass selectedDate to DateChooser
const slides = [
<DateChooser
nextSlide={nextSlide}
studioId={studioId}
selectedDate={selectedDate}
onDateSelect={handleDateSelect}
key="date-chooser"
/>,
...
];
Update DateChooser:
Remove the initialDate prop (since we're using selectedDate).
Ensure selectedDate is passed down and used consistently.
Remove the useEffect that was previously used to handle initialDate.
// In DateChooser.tsx
interface DateChooserProps {
nextSlide: () => void;
studioId: string;
selectedDate: string | null;
onDateSelect: (date: string) => void;
}
// Use selectedDate directly, no need for initialDate or extra effects.
Ensure Calendar Component Uses selectedDate:
Calendar should accept selectedDate of type string | null.
In the renderDay function, compare dates as strings.
// In CustomCalendar.tsx or Calendar component within DateChooser
const isSelected = selectedDate === dateString;
Update CustomCalendar:
When a date is selected, return the date string in yyyy-MM-dd format.
Ensure all date comparisons are done using date strings.
// In CustomCalendar.tsx
const renderDay = useCallback((date) => {
...
return (
<TouchableOpacity
...
onPress={() => {
if (!isDisabled) {
onDateSelect(dateString); // Pass dateString
}
}}
...
>
...
</TouchableOpacity>
);
});
Disable 'Reservieren' Button When No Date Is Selected:
In StudioFooter, disable the 'Reservieren' button when selectedDate is null.
// In StudioFooter.tsx
<TouchableOpacity
style={[
styles.footerButton,
!selectedDate && styles.footerButtonDisabled,
]}
onPress={() => onBookingPress(selectedDate)}
disabled={!selectedDate}
>
<Text style={styles.buttonText}>Reservieren</Text>
</TouchableOpacity>
const styles = StyleSheet.create({
footerButtonDisabled: {
backgroundColor: '#CCCCCC',
},
});
By ensuring that dates are consistently handled as strings in the yyyy-MM-dd format and removing unnecessary conversions between Date objects and strings, you eliminate potential errors due to time zones and formatting mismatches. This approach also simplifies the logic in your components and makes it easier to manage state and props.
Summary:
Handle dates as strings ('yyyy-MM-dd') throughout all components.
Remove unnecessary date parsing and formatting to avoid time zone issues.
Ensure selectedDate is consistently passed and compared as a string.
Disable the 'Reservieren' button when no date is selected in StudioFooter.
After implementing these changes, when a user selects a date in StudioFooter and presses 'Reservieren', the BookingScreen's DateChooser will have that date pre-selected, providing the desired functionality.
Copy first response