refactor: defer shop validation in Booking pages to allow optional chaining of shop properties
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user