refactor: defer shop validation in Booking pages to allow optional chaining of shop properties

This commit is contained in:
2026-05-04 10:03:56 +01:00
parent 1dc64579bb
commit 05714a8d7b
2 changed files with 40 additions and 40 deletions

View File

@@ -45,17 +45,6 @@ export default function Booking() {
{ label: '24 horas', value: 1440 },
];
if (!shop) {
return (
<SafeAreaView style={styles.container}>
<Text>Barbearia não encontrada</Text>
</SafeAreaView>
);
}
const selectedService = shop.services.find((s) => s.id === serviceId);
const selectedBarber = shop.barbers.find((b) => b.id === barberId);
// Geração de datas (próximos 14 dias)
const availableDates = useMemo(() => {
const dates = [];
@@ -72,6 +61,9 @@ export default function Booking() {
return dates;
}, []);
const selectedService = shop?.services.find((s) => s.id === serviceId);
const selectedBarber = shop?.barbers.find((b) => b.id === barberId);
const generateDefaultSlots = (): string[] => {
const slots: string[] = [];
for (let hour = 9; hour <= 18; hour++) {
@@ -103,6 +95,14 @@ export default function Booking() {
});
}, [selectedBarber, date, barberId, appointments, slot]);
if (!shop) {
return (
<SafeAreaView style={styles.container}>
<Text>Barbearia não encontrada</Text>
</SafeAreaView>
);
}
const canNext = () => {
if (step === 1) return !!serviceId;
if (step === 2) return !!barberId;