refactor: add logout section with version display to profile and dashboard, and implement conflict check for appointment confirmation
This commit is contained in:
@@ -522,9 +522,30 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
|
||||
const updateAppointmentStatus = async (id: string, status: Appointment['status']) => {
|
||||
const apt = appointments.find((a) => a.id === id);
|
||||
await supabase.from('appointments').update({ status }).eq('id', id);
|
||||
if (!apt) return;
|
||||
|
||||
if (status === 'cancelado' && apt) {
|
||||
if (status === 'confirmado') {
|
||||
// Check if there is already a confirmed appointment for this barber at this time
|
||||
const conflict = appointments.find(a =>
|
||||
a.barberId === apt.barberId &&
|
||||
a.date === apt.date &&
|
||||
a.status === 'confirmado' &&
|
||||
a.id !== id
|
||||
);
|
||||
|
||||
if (conflict) {
|
||||
Alert.alert('Conflito de Horário', 'Já existe uma marcação confirmada para este horário com este profissional.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const { error } = await supabase.from('appointments').update({ status }).eq('id', id);
|
||||
if (error) {
|
||||
Alert.alert('Erro', 'Não foi possível atualizar o estado da marcação.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (status === 'cancelado') {
|
||||
const waitlistDate = apt.date.split(' ')[0]; // Extract YYYY-MM-DD
|
||||
const waitingUsers = waitlists.filter(w => w.barberId === apt.barberId && w.date === waitlistDate && w.status === 'pending');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user