import { Ionicons, MaterialCommunityIcons, MaterialIcons } from '@expo/vector-icons'; import axios from 'axios'; import { addDays, addMonths, endOfMonth, endOfWeek, format, getMonth, getYear, isSameDay, startOfMonth, startOfWeek, subMonths } from 'date-fns'; import { useRouter } from 'expo-router'; import * as SecureStore from 'expo-secure-store'; import React, { useEffect, useState } from "react"; import { ScrollView, StyleSheet, Text, TouchableOpacity, View } from "react-native"; const PRIMARY = '#A24BFA'; const BG = '#0c0a0a'; export default function Schedule() { const [currentMonth, setCurrentMonth] = useState(new Date()); const [workdays, setWorkdays] = useState([]); const [loading, setLoading] = useState(false); const router = useRouter(); useEffect(() => { fetchWorkdays(); }, [currentMonth]); async function fetchWorkdays() { setLoading(true); try { const userCookieRaw = await SecureStore.getItemAsync('cookie'); if (!userCookieRaw) { throw new Error('Nincs elmentett cookie, kérlek jelentkezz be újra!'); } console.log('Lekért cookie:', userCookieRaw); const userCookie = userCookieRaw.split(';')[0]; const year = getYear(currentMonth); const month = getMonth(currentMonth) + 1; console.log('Lekérdezett hónap:', year, month); console.log('Beosztás API hívás:', { year, month }); console.log('Küldött cookie:', userCookie); const response = await axios.post( 'https://mymenu.mcdonalds.hu/api/UserDataApi/GetWorkDayMonthList', { Data: { Year: year, Month: month } }, { headers: { 'Content-Type': 'application/json', 'cookie': userCookie, 'Origin': 'https://mymenu.mcdonalds.hu', 'Referer': 'https://mymenu.mcdonalds.hu/', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36', 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'hu-HU,hu;q=0.9', } } ); const cookie = response.headers['set-cookie']?.join('; '); if (cookie) { await SecureStore.setItemAsync('cookie', cookie); } else { console.warn('Nincs set-cookie fejléc a válaszban!'); } console.log('API teljes válasz:', response.data); if (!response.data || !response.data.data || !response.data.data.Data) { console.log('Nincs beosztás adat a válaszban!'); setWorkdays([]); return; } setWorkdays(response.data.data.Data); } catch (e) { const err = e as any; if (err.response) { console.log('API válasz hiba:', err.response.data); } else { console.log('Beosztás API hiba:', e); } setWorkdays([]); } finally { setLoading(false); } } function renderCalendar() { const monthStart = startOfMonth(currentMonth); const monthEnd = endOfMonth(monthStart); const startDate = startOfWeek(monthStart, { weekStartsOn: 1 }); const endDate = endOfWeek(monthEnd, { weekStartsOn: 1 }); const today = new Date(); const rows = []; let days = []; let day = startDate; let formattedDate = ''; while (day <= endDate) { for (let i = 0; i < 7; i++) { formattedDate = format(day, 'yyyy-MM-dd'); const wd = workdays.find(w => w.WorkDay?.slice(0, 10) === formattedDate); let bg = 'rgba(24,20,28,0.7)'; let color = '#fff'; let borderWidth = 0; if (isSameDay(day, today)) { borderWidth = 2; color = PRIMARY; } if (wd) { bg = wd.color || 'deepskyblue'; color = '#222'; } days.push( {format(day, 'd')} {wd && {wd.text}} ); day = addDays(day, 1); } rows.push({days}); days = []; } return ( setCurrentMonth(subMonths(currentMonth, 1))}> {format(currentMonth, 'yyyy. MMMM')} setCurrentMonth(addMonths(currentMonth, 1))}> {["H", "K", "Sz", "Cs", "P", "Szo", "V"].map(d => ( {d} ))} {loading ? ( Betöltés… ) : ( {rows} )} ); } return ( Beosztás naptár {/* Hibaüzenet, ha nincs bejelentkezve vagy nincs beosztás */} {(!loading && workdays.length === 0) && ( Nincs beosztás vagy nem vagy bejelentkezve! )} {renderCalendar()} ); } function NavBar({ activeTab }: { activeTab: string }) { const router = useRouter(); return ( router.push('/profile')}> Profilom router.push('/schedule')}> Beosztás router.push('/requests')}> Kérelmek ); } const styles = StyleSheet.create({ card: { backgroundColor: 'rgba(24, 20, 28, 0.95)', borderRadius: 24, padding: 32, width: '90%', maxWidth: 400, shadowColor: '#000', shadowOpacity: 0.3, shadowRadius: 24, shadowOffset: { width: 0, height: 8 }, elevation: 8, marginBottom: 32, marginTop: 32, }, label: { color: '#bdbdbd', fontSize: 16, marginBottom: 16, fontWeight: 'bold', textAlign: 'center', }, navBar: { flexDirection: 'row', justifyContent: 'space-around', alignItems: 'center', backgroundColor: 'rgba(24, 20, 28, 0.98)', borderTopWidth: 1, borderTopColor: '#222', position: 'absolute', bottom: 0, left: 0, right: 0, height: 64, paddingHorizontal: 16, }, navItem: { flex: 1, alignItems: 'center', justifyContent: 'center', }, navLabel: { fontSize: 13, marginTop: 2, fontWeight: 'bold', }, });