wurde ein datum ausgewähl(unter verfügbakeit anziegen) in… · The Chat Archive
Explore 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]);
Show full message · 1,525 lines Assistant2024-11-14 18:39 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
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 01m7h4294g1543pydj913at905Source & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 71d5500286456266c4c574f415a18df8
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
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}}>
code Copy code
<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',
code Copy code
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,
code Copy code
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 });
code Copy code
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 ;
code Copy code
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);
code Copy code
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);
code Copy code
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;
code Copy code
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);
code Copy code
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;
code Copy code
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>
code Copy code
<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 })
});
code Copy code
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
code Copy code
/>,
<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>
code Copy code
{/* 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 related to how you're handling the initialDate in your openBookingModal function within your StudioScreen component. Specifically, the problem arises from reformatting the selectedDate and then attempting to create a new Date object from a string formatted as 'yyyy-MM-dd'.
In JavaScript, creating a new Date object using a string formatted as 'yyyy-MM-dd' can lead to unexpected results due to timezone issues and inconsistent parsing across different platforms and browsers. This can result in an invalid date or a date that is off by one day.
Here's what you currently have in your openBookingModal function:
javascript Copy code
const openBookingModal = (selectedDate: Date | null) => {
// Convert date to expected format yyyy-MM-dd
if (selectedDate) {
const formattedDate = format(selectedDate, 'yyyy-MM-dd');
setInitialDate(new Date(formattedDate)); // Set new Date object with formatted date
}
setIsBookingVisible(true);
};
Solution:
Instead of reformatting the date and creating a new Date object from the formatted string, you should pass the selectedDate directly to setInitialDate. This ensures that the initialDate remains a valid Date object without any unintended alterations. Here's the corrected openBookingModal function:
javascript Copy code
const openBookingModal = (selectedDate: Date | null) => {
setInitialDate(selectedDate || null); // Directly set the selected date
setIsBookingVisible(true);
};
Explanation:
Avoid Recreating Date from Formatted String: By avoiding the format and new Date operations, you eliminate potential issues with date parsing and timezone offsets.
Passing the Correct Date Object: By directly passing selectedDate to setInitialDate, you ensure that the initialDate in your BookingScreen receives the correct and intended Date object.
Consistency Across Components: Since BookingScreen and DateChooser rely on the selectedDate being in the correct format, this change ensures that the date comparisons and selections work as expected.
Additional Notes:
In your BookingScreen, you're initializing the selectedDate state based on initialDate:
javascript Copy code
const [selectedDate, setSelectedDate] = useState<string | null>(
initialDate ? format(initialDate, 'yyyy-MM-dd') : null
);
This remains correct because initialDate is now a valid Date object, and you can safely format it to 'yyyy-MM-dd' for your state.
In DateChooser, you pass down the selectedDate and use it to determine which date should be marked as selected in your calendar component.
By making this change, selecting a date in the StudioFooter should result in that date being pre-selected when you open the booking process by pressing "Reservieren".
Updated StudioScreen Code:
javascript Copy code
const openBookingModal = (selectedDate: Date | null) => {
setInitialDate(selectedDate); // Use the date directly
setIsBookingVisible(true);
};
Summary:
Issue: Creating a new Date object from a formatted string can cause unexpected behavior.
Fix: Pass the selectedDate directly to setInitialDate without reformatting.
Result: The selected date in the StudioFooter will now be correctly pre-selected in the booking process.
Let me know if you need any further assistance or if you have additional questions!
Copy first response
Not yet included in a published release.