Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 Type schedule store
Browse files Browse the repository at this point in the history
devmount committed Jun 21, 2024
1 parent f00cc62 commit 4e87176
Showing 2 changed files with 42 additions and 7 deletions.
32 changes: 31 additions & 1 deletion frontend/src/models.ts
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ export type Appointment = {
};

export type Calendar = {
id: number;
id?: number;
connected: boolean;
title: string;
color: string;
@@ -67,3 +67,33 @@ export type ExternalConnectionCollection = {
google?: ExternalConnection[];
zoom?: ExternalConnection[];
};

// This will be used later if we provide custom availabilities
// in addition to general availability too
export type Availability = {
id?: number;
};

export type Schedule = {
active: boolean;
name: string;
slug: string;
calendar_id: number;
location_type: number;
location_url: string;
details: string;
start_date: string;
end_date: string;
start_time: string;
end_time: string;
earliest_booking: number;
farthest_booking: number;
weekdays: number[];
slot_duration: number;
meeting_link_provider: string;
id: number;
time_created: string;
time_updated: string;
availabilities?: Availability[];
calendar: Calendar;
};
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { defineStore } from 'pinia';
import { ref, computed } from 'vue';
import { useUserStore } from '@/stores/user-store';
import { UseFetchReturn } from '@vueuse/core';
import { Schedule } from '@/models';

// eslint-disable-next-line import/prefer-default-export
export const useScheduleStore = defineStore('schedules', () => {
// State
const isLoaded = ref(false);

// Data
const schedules = ref([]);
const inactiveSchedules = computed(() => schedules.value.filter((schedule) => !schedule.active));
const activeSchedules = computed(() => schedules.value.filter((schedule) => schedule.active));
const schedules = ref<Schedule[]>([]);
const inactiveSchedules = computed((): Schedule[] => schedules.value.filter((schedule) => !schedule.active));
const activeSchedules = computed((): Schedule[] => schedules.value.filter((schedule) => schedule.active));

/**
* Get all calendars for current user
* @param {function} call preconfigured API fetch function
* @param {boolean} force Force a fetch even if we already have data
* @param call preconfigured API fetch function
* @param force Force a fetch even if we already have data
*/
const fetch = async (call, force = false) => {
const fetch = async (
call: (url: string) => UseFetchReturn<Schedule[]> & PromiseLike<UseFetchReturn<Schedule[]>>,
force: boolean = false
) => {
if (isLoaded.value && !force) {
return;
}

0 comments on commit 4e87176

Please sign in to comment.