import { useSchedule } from '@novu/react-native';
import { View, Text, TouchableOpacity, StyleSheet, ActivityIndicator } from 'react-native';
function ScheduleManager() {
const { schedule, isLoading, error, refetch } = useSchedule();
if (isLoading) {
return <ActivityIndicator size="large" style={styles.loader} />;
}
if (error) {
return <Text style={styles.errorText}>Error: {error.message}</Text>;
}
const handleUpdateSchedule = async () => {
await schedule?.update({
isEnabled: true,
weeklySchedule: {
monday: {
isEnabled: true,
hours: [{ start: '09:00 AM', end: '05:00 PM' }],
},
// Disable Wednesday
wednesday: {
isEnabled: false,
hours: [],
},
},
});
};
return (
<View style={styles.container}>
<Text style={styles.heading}>My Notification Schedule</Text>
<Text style={styles.text}>
Schedule Enabled:
<Text style={styles.boldText}> {schedule?.isEnabled ? 'Yes' : 'No'}</Text>
</Text>
<View style={styles.dayContainer}>
<Text style={styles.subHeading}>Monday Hours:</Text>
{schedule?.weeklySchedule?.monday?.isEnabled ? (
schedule.weeklySchedule.monday.hours.map((range, index) => (
<Text key={index} style={styles.text}>{`• ${range.start} - ${range.end}`}</Text>
))
) : (
<Text style={styles.text}>Not scheduled</Text>
)}
</View>
<TouchableOpacity
onPress={handleUpdateSchedule}
style={styles.button}
>
<Text style={styles.buttonText}>Set Work Hours</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
container: {
padding: 16,
backgroundColor: '#FFFFFF',
},
loader: {
marginTop: 20,
},
errorText: {
color: 'red',
textAlign: 'center',
},
heading: {
fontSize: 18,
fontWeight: 'bold',
marginBottom: 12,
},
subHeading: {
fontSize: 16,
fontWeight: 'bold',
marginBottom: 4,
},
text: {
fontSize: 16,
marginBottom: 4,
},
boldText: {
fontWeight: 'bold',
},
dayContainer: {
marginTop: 12,
},
button: {
marginTop: 16,
backgroundColor: '#007BFF',
padding: 12,
borderRadius: 8,
alignItems: 'center',
},
buttonText: {
color: '#FFFFFF',
fontSize: 16,
fontWeight: 'bold',
},
});
export default ScheduleManager;