This commit is contained in:
Morten Olsen
2022-05-10 19:04:05 +02:00
parent 0b2f23ecb2
commit 8259232a83
101 changed files with 1752 additions and 1740 deletions

View File

@@ -0,0 +1,45 @@
import { useAsync, useAsyncCallback } from "#/features/async";
import { useContext } from "react"
import { Day, useDate } from "../day";
import { AppointmentsContext, AppointmentsStatus } from "./context"
export const useAppointmentStatus = () => {
const { status } = useContext(AppointmentsContext);
return status;
};
export const useAppointments = () => {
const date = useDate();
const context = useContext(AppointmentsContext);
const result = useAsync(
async () => {
if (context.status !== AppointmentsStatus.approved) {
return [];
}
const appointments = await context.getDay(date);
return appointments;
},
[
context.status === AppointmentsStatus.approved && context.getDay,
date,
],
);
return result;
}
export const useGetAppointments = () => {
const context = useContext(AppointmentsContext);
const result = useAsyncCallback(
async (date: Day) => {
if (context.status !== AppointmentsStatus.approved) {
return [];
}
const appointments = await context.getDay(date);
return appointments;
},
[
context.status === AppointmentsStatus.approved && context.getDay,
],
);
return result;
}