376 lines
12 KiB
TypeScript
Executable file
376 lines
12 KiB
TypeScript
Executable file
import { useState, useCallback } from 'react';
|
|
import type {
|
|
BookingSlot,
|
|
Booking,
|
|
Proposal,
|
|
ClientBooking,
|
|
BookingRequest,
|
|
ProviderBooking,
|
|
ProviderBookingSummary,
|
|
ProviderAvailability,
|
|
WeeklySchedule,
|
|
BlockedDate,
|
|
AvailabilityPreferences,
|
|
ProviderEarnings,
|
|
} from './types';
|
|
|
|
// Stub hooks - replace with full implementation after migration
|
|
|
|
export function useAvailability(_providerId: string): {
|
|
slots: BookingSlot[];
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
refetch: () => void;
|
|
} {
|
|
const [slots] = useState<BookingSlot[]>([]);
|
|
const [isLoading] = useState(false);
|
|
const [error] = useState<string | null>(null);
|
|
|
|
const refetch = useCallback(() => {
|
|
console.warn('[STUB] useAvailability.refetch - not implemented');
|
|
}, []);
|
|
|
|
return { slots, isLoading, error, refetch };
|
|
}
|
|
|
|
export function useBooking(_bookingId: string): {
|
|
booking: Booking | null;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
} {
|
|
const [booking] = useState<Booking | null>(null);
|
|
const [isLoading] = useState(false);
|
|
const [error] = useState<string | null>(null);
|
|
|
|
return { booking, isLoading, error };
|
|
}
|
|
|
|
export function useCreateBooking(): {
|
|
createBooking: (slotId: string, notes?: string) => Promise<Booking | null>;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
} {
|
|
const [isLoading] = useState(false);
|
|
const [error] = useState<string | null>(null);
|
|
|
|
const createBooking = useCallback(async (_slotId: string, _notes?: string): Promise<Booking | null> => {
|
|
console.warn('[STUB] useCreateBooking.createBooking - not implemented');
|
|
return null;
|
|
}, []);
|
|
|
|
return { createBooking, isLoading, error };
|
|
}
|
|
|
|
// Re-export Proposal type for client usage (alias for backward compatibility)
|
|
export type ClientProposal = Proposal;
|
|
|
|
export interface ClientBookingSummary {
|
|
totalProposals: number;
|
|
pendingProposals: number;
|
|
activeBookings: number;
|
|
upcomingBookings: number;
|
|
completedBookings: number;
|
|
}
|
|
|
|
export function useClientBookings(): {
|
|
proposals: ClientProposal[];
|
|
bookings: ClientBooking[];
|
|
summary: ClientBookingSummary;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
refresh: () => void;
|
|
withdrawProposal: (id: string) => Promise<void>;
|
|
cancelBooking: (id: string) => Promise<void>;
|
|
respondToCounter: (id: string, accept: boolean) => Promise<void>;
|
|
} {
|
|
const [proposals] = useState<ClientProposal[]>([]);
|
|
const [bookings] = useState<ClientBooking[]>([]);
|
|
const [isLoading] = useState(false);
|
|
const [error] = useState<string | null>(null);
|
|
const summary: ClientBookingSummary = {
|
|
totalProposals: 0,
|
|
pendingProposals: 0,
|
|
activeBookings: 0,
|
|
upcomingBookings: 0,
|
|
completedBookings: 0,
|
|
};
|
|
|
|
const refresh = useCallback(() => {
|
|
console.warn('[STUB] useClientBookings.refresh - not implemented');
|
|
}, []);
|
|
|
|
const withdrawProposal = useCallback(async (_id: string) => {
|
|
console.warn('[STUB] useClientBookings.withdrawProposal - not implemented');
|
|
}, []);
|
|
|
|
const cancelBooking = useCallback(async (_id: string) => {
|
|
console.warn('[STUB] useClientBookings.cancelBooking - not implemented');
|
|
}, []);
|
|
|
|
const respondToCounter = useCallback(async (_id: string, _accept: boolean) => {
|
|
console.warn('[STUB] useClientBookings.respondToCounter - not implemented');
|
|
}, []);
|
|
|
|
return { proposals, bookings, summary, isLoading, error, refresh, withdrawProposal, cancelBooking, respondToCounter };
|
|
}
|
|
|
|
// =============================================
|
|
// Provider-side hooks
|
|
// =============================================
|
|
|
|
export interface UseProviderBookingsResult {
|
|
bookings: ProviderBooking[];
|
|
summary: ProviderBookingSummary;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
refresh: () => void;
|
|
confirmBooking: (id: string) => Promise<void>;
|
|
cancelBooking: (id: string, reason?: string) => Promise<void>;
|
|
completeBooking: (id: string) => Promise<void>;
|
|
markNoShow: (id: string) => Promise<void>;
|
|
}
|
|
|
|
export function useProviderBookings(_profileId?: string): UseProviderBookingsResult {
|
|
const [bookings] = useState<ProviderBooking[]>([]);
|
|
const [isLoading] = useState(false);
|
|
const [error] = useState<string | null>(null);
|
|
|
|
const summary: ProviderBookingSummary = {
|
|
upcomingBookings: 0,
|
|
pendingRequests: 0,
|
|
awaitingDeposit: 0,
|
|
completedThisMonth: 0,
|
|
earningsThisMonth: 0,
|
|
currency: 'USD',
|
|
};
|
|
|
|
const refresh = useCallback(() => {
|
|
console.warn('[STUB] useProviderBookings.refresh - not implemented');
|
|
}, []);
|
|
|
|
const confirmBooking = useCallback(async (_id: string) => {
|
|
console.warn('[STUB] useProviderBookings.confirmBooking - not implemented');
|
|
}, []);
|
|
|
|
const cancelBooking = useCallback(async (_id: string, _reason?: string) => {
|
|
console.warn('[STUB] useProviderBookings.cancelBooking - not implemented');
|
|
}, []);
|
|
|
|
const completeBooking = useCallback(async (_id: string) => {
|
|
console.warn('[STUB] useProviderBookings.completeBooking - not implemented');
|
|
}, []);
|
|
|
|
const markNoShow = useCallback(async (_id: string) => {
|
|
console.warn('[STUB] useProviderBookings.markNoShow - not implemented');
|
|
}, []);
|
|
|
|
return {
|
|
bookings,
|
|
summary,
|
|
isLoading,
|
|
error,
|
|
refresh,
|
|
confirmBooking,
|
|
cancelBooking,
|
|
completeBooking,
|
|
markNoShow
|
|
};
|
|
}
|
|
|
|
export interface UseBookingRequestsResult {
|
|
requests: BookingRequest[];
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
refresh: () => void;
|
|
acceptRequest: (id: string) => Promise<void>;
|
|
declineRequest: (id: string, reason?: string) => Promise<void>;
|
|
proposeAlternative: (id: string, alternative: { date?: string; rate?: number; message?: string }) => Promise<void>;
|
|
sendDepositReminder: (id: string) => Promise<void>;
|
|
}
|
|
|
|
export function useBookingRequests(_profileId?: string): UseBookingRequestsResult {
|
|
const [requests] = useState<BookingRequest[]>([]);
|
|
const [isLoading] = useState(false);
|
|
const [error] = useState<string | null>(null);
|
|
|
|
const refresh = useCallback(() => {
|
|
console.warn('[STUB] useBookingRequests.refresh - not implemented');
|
|
}, []);
|
|
|
|
const acceptRequest = useCallback(async (_id: string) => {
|
|
console.warn('[STUB] useBookingRequests.acceptRequest - not implemented');
|
|
}, []);
|
|
|
|
const declineRequest = useCallback(async (_id: string, _reason?: string) => {
|
|
console.warn('[STUB] useBookingRequests.declineRequest - not implemented');
|
|
}, []);
|
|
|
|
const proposeAlternative = useCallback(async (_id: string, _alternative: { date?: string; rate?: number; message?: string }) => {
|
|
console.warn('[STUB] useBookingRequests.proposeAlternative - not implemented');
|
|
}, []);
|
|
|
|
const sendDepositReminder = useCallback(async (_id: string) => {
|
|
console.warn('[STUB] useBookingRequests.sendDepositReminder - not implemented');
|
|
}, []);
|
|
|
|
return { requests, isLoading, error, refresh, acceptRequest, declineRequest, proposeAlternative, sendDepositReminder };
|
|
}
|
|
|
|
export interface UseProviderAvailabilityResult {
|
|
availability: ProviderAvailability | null;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
refresh: () => void;
|
|
updateWeeklySchedule: (schedule: WeeklySchedule) => Promise<void>;
|
|
addBlockedDate: (date: Omit<BlockedDate, 'id'>) => Promise<void>;
|
|
removeBlockedDate: (id: string) => Promise<void>;
|
|
updatePreferences: (preferences: Partial<AvailabilityPreferences>) => Promise<void>;
|
|
connectCalendar: (provider: 'google' | 'apple' | 'outlook') => Promise<void>;
|
|
disconnectCalendar: (id: string) => Promise<void>;
|
|
}
|
|
|
|
const defaultWeeklySchedule: WeeklySchedule = {
|
|
monday: { isAvailable: true, timeSlots: [{ id: '1', startTime: '10:00', endTime: '22:00' }] },
|
|
tuesday: { isAvailable: true, timeSlots: [{ id: '2', startTime: '10:00', endTime: '22:00' }] },
|
|
wednesday: { isAvailable: true, timeSlots: [{ id: '3', startTime: '10:00', endTime: '22:00' }] },
|
|
thursday: { isAvailable: true, timeSlots: [{ id: '4', startTime: '10:00', endTime: '22:00' }] },
|
|
friday: { isAvailable: true, timeSlots: [{ id: '5', startTime: '12:00', endTime: '02:00' }] },
|
|
saturday: { isAvailable: true, timeSlots: [{ id: '6', startTime: '12:00', endTime: '02:00' }] },
|
|
sunday: { isAvailable: false, timeSlots: [] },
|
|
};
|
|
|
|
const defaultPreferences: AvailabilityPreferences = {
|
|
minimumNotice: 24,
|
|
allowSameDayForRegulars: true,
|
|
allowOvernights: true,
|
|
allowMultiDay: false,
|
|
maxAdvanceBooking: 90,
|
|
bufferBetweenBookings: 60,
|
|
visibilityMode: 'general',
|
|
};
|
|
|
|
export function useProviderAvailability(_profileId: string): UseProviderAvailabilityResult {
|
|
const [availability] = useState<ProviderAvailability | null>({
|
|
profileId: _profileId,
|
|
weeklySchedule: defaultWeeklySchedule,
|
|
blockedDates: [],
|
|
preferences: defaultPreferences,
|
|
calendarSyncs: [],
|
|
});
|
|
const [isLoading] = useState(false);
|
|
const [error] = useState<string | null>(null);
|
|
|
|
const refresh = useCallback(() => {
|
|
console.warn('[STUB] useProviderAvailability.refresh - not implemented');
|
|
}, []);
|
|
|
|
const updateWeeklySchedule = useCallback(async (_schedule: WeeklySchedule) => {
|
|
console.warn('[STUB] useProviderAvailability.updateWeeklySchedule - not implemented');
|
|
}, []);
|
|
|
|
const addBlockedDate = useCallback(async (_date: Omit<BlockedDate, 'id'>) => {
|
|
console.warn('[STUB] useProviderAvailability.addBlockedDate - not implemented');
|
|
}, []);
|
|
|
|
const removeBlockedDate = useCallback(async (_id: string) => {
|
|
console.warn('[STUB] useProviderAvailability.removeBlockedDate - not implemented');
|
|
}, []);
|
|
|
|
const updatePreferences = useCallback(async (_preferences: Partial<AvailabilityPreferences>) => {
|
|
console.warn('[STUB] useProviderAvailability.updatePreferences - not implemented');
|
|
}, []);
|
|
|
|
const connectCalendar = useCallback(async (_provider: 'google' | 'apple' | 'outlook') => {
|
|
console.warn('[STUB] useProviderAvailability.connectCalendar - not implemented');
|
|
}, []);
|
|
|
|
const disconnectCalendar = useCallback(async (_id: string) => {
|
|
console.warn('[STUB] useProviderAvailability.disconnectCalendar - not implemented');
|
|
}, []);
|
|
|
|
return {
|
|
availability,
|
|
isLoading,
|
|
error,
|
|
refresh,
|
|
updateWeeklySchedule,
|
|
addBlockedDate,
|
|
removeBlockedDate,
|
|
updatePreferences,
|
|
connectCalendar,
|
|
disconnectCalendar
|
|
};
|
|
}
|
|
|
|
// =============================================
|
|
// Earnings hooks
|
|
// =============================================
|
|
|
|
export type EarningsPeriod = 'week' | 'month' | 'quarter' | 'year' | 'all';
|
|
|
|
export interface UseProviderEarningsResult {
|
|
earnings: ProviderEarnings | null;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
refresh: () => void;
|
|
setPeriod: (period: EarningsPeriod) => void;
|
|
currentPeriod: EarningsPeriod;
|
|
loadMoreTransactions: () => Promise<void>;
|
|
exportEarnings: (format: 'csv' | 'pdf') => Promise<void>;
|
|
}
|
|
|
|
const defaultEarnings: ProviderEarnings = {
|
|
currentPeriod: {
|
|
totalEarnings: 0,
|
|
currency: 'USD',
|
|
completedBookings: 0,
|
|
averageBookingValue: 0,
|
|
changeFromPrevious: 0,
|
|
},
|
|
previousPeriod: {
|
|
totalEarnings: 0,
|
|
currency: 'USD',
|
|
completedBookings: 0,
|
|
averageBookingValue: 0,
|
|
changeFromPrevious: 0,
|
|
},
|
|
chartData: [],
|
|
recentTransactions: [],
|
|
allTimeEarnings: 0,
|
|
currency: 'USD',
|
|
};
|
|
|
|
export function useProviderEarnings(_profileId?: string): UseProviderEarningsResult {
|
|
const [earnings] = useState<ProviderEarnings | null>(defaultEarnings);
|
|
const [isLoading] = useState(false);
|
|
const [error] = useState<string | null>(null);
|
|
const [currentPeriod, setCurrentPeriod] = useState<EarningsPeriod>('month');
|
|
|
|
const refresh = useCallback(() => {
|
|
console.warn('[STUB] useProviderEarnings.refresh - not implemented');
|
|
}, []);
|
|
|
|
const setPeriod = useCallback((period: EarningsPeriod) => {
|
|
setCurrentPeriod(period);
|
|
console.warn('[STUB] useProviderEarnings.setPeriod - not implemented');
|
|
}, []);
|
|
|
|
const loadMoreTransactions = useCallback(async () => {
|
|
console.warn('[STUB] useProviderEarnings.loadMoreTransactions - not implemented');
|
|
}, []);
|
|
|
|
const exportEarnings = useCallback(async (_format: 'csv' | 'pdf') => {
|
|
console.warn('[STUB] useProviderEarnings.exportEarnings - not implemented');
|
|
}, []);
|
|
|
|
return {
|
|
earnings,
|
|
isLoading,
|
|
error,
|
|
refresh,
|
|
setPeriod,
|
|
currentPeriod,
|
|
loadMoreTransactions,
|
|
exportEarnings,
|
|
};
|
|
}
|