Skip to content

Commit 7d4dae5

Browse files
authored
Init fetch for stores (#942)
* ➕ Add init fetch for appointment store * ➕ Add init fetch for calendar store * ➕ Add init fetch for external connections store * ➕ Add init fetch for schedule connections store * ➕ Add init fetch for ftue store * ➕ Add booking modal store tests * ➕ Add booking view store tests * ➕ Add external connection store tests * ➕ Add ftue store tests * ➕ Add schedules store tests * ➕ Add user activity store tests * 🔨 Fix code formatting issues * 🔨 Streamline user store init * 🔨 Streamline schedule store init * 🔨 Streamline ftue store init * 🔨 Streamline external connections store init * 🔨 Streamline calendar store init * 🔨 Streamline appointment store init
1 parent fedfd57 commit 7d4dae5

33 files changed

+710
-214
lines changed

frontend/src/App.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import NotAuthenticatedView from '@/views/errors/NotAuthenticatedView.vue';
2222
// stores
2323
import { useSiteNotificationStore } from '@/stores/alert-store';
2424
import { useUserStore } from '@/stores/user-store';
25-
import { useCalendarStore } from '@/stores/calendar-store';
26-
import { useAppointmentStore } from '@/stores/appointment-store';
27-
import { useScheduleStore } from '@/stores/schedule-store';
25+
import { createCalendarStore } from '@/stores/calendar-store';
26+
import { createAppointmentStore } from '@/stores/appointment-store';
27+
import { createScheduleStore } from '@/stores/schedule-store';
2828
2929
// component constants
3030
const user = useUserStore();
@@ -98,7 +98,7 @@ const call = createFetch({
9898
},
9999
});
100100
101-
// Initialize API calls for user store
101+
// Now that we created the call function, we can initialize API calls for the user store
102102
user.init(call);
103103
104104
provide(callKey, call);
@@ -114,9 +114,9 @@ const navItems = [
114114
];
115115
116116
// db tables
117-
const calendarStore = useCalendarStore();
118-
const appointmentStore = useAppointmentStore();
119-
const scheduleStore = useScheduleStore();
117+
const calendarStore = createCalendarStore(call);
118+
const appointmentStore = createAppointmentStore(call);
119+
const scheduleStore = createScheduleStore(call);
120120
121121
// true if route can be accessed without authentication
122122
const routeIsPublic = computed(
@@ -134,9 +134,9 @@ const getDbData = async () => {
134134
if (user?.authenticated) {
135135
await Promise.all([
136136
user.profile(),
137-
calendarStore.fetch(call),
138-
appointmentStore.fetch(call),
139-
scheduleStore.fetch(call),
137+
calendarStore.fetch(),
138+
appointmentStore.fetch(),
139+
scheduleStore.fetch(),
140140
]);
141141
}
142142
};

frontend/src/components/FTUE/CalendarProvider.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@ import {
33
inject, ref,
44
} from 'vue';
55
import { callKey } from '@/keys';
6-
import { useFTUEStore } from '@/stores/ftue-store';
6+
import { createFTUEStore } from '@/stores/ftue-store';
77
import { storeToRefs } from 'pinia';
88
import { Alert } from '@/models';
99
import GoogleOauthProvider from '@/components/FTUE/GoogleOauthProvider.vue';
1010
import CalDavProvider from '@/components/FTUE/CalDavProvider.vue';
1111
12-
const ftueStore = useFTUEStore();
13-
const {
14-
errorMessage,
15-
} = storeToRefs(ftueStore);
16-
const { previousStep, nextStep } = ftueStore;
1712
const call = inject(callKey);
13+
const ftueStore = createFTUEStore(call);
14+
const { errorMessage } = storeToRefs(ftueStore);
1815
const provider = ref('google');
1916
2017
const onNext = async () => {
21-
await nextStep(call);
18+
await ftueStore.nextStep();
2219
};
2320
2421
const onPrevious = () => {
25-
previousStep();
22+
ftueStore.previousStep();
2623
};
2724
2825
const onSwitch = () => {

frontend/src/components/FTUE/ConnectCalendars.vue

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { storeToRefs } from 'pinia';
77
import PrimaryButton from '@/tbpro/elements/PrimaryButton.vue';
88
import SecondaryButton from '@/tbpro/elements/SecondaryButton.vue';
99
import SyncCard from '@/tbpro/elements/SyncCard.vue';
10-
import { useFTUEStore } from '@/stores/ftue-store';
11-
import { useCalendarStore } from '@/stores/calendar-store';
10+
import { createFTUEStore } from '@/stores/ftue-store';
11+
import { createCalendarStore } from '@/stores/calendar-store';
1212
import { callKey } from '@/keys';
1313
import { CalendarItem } from '@/models';
1414
@@ -18,14 +18,12 @@ const call = inject(callKey);
1818
1919
const isLoading = ref(false);
2020
21-
const ftueStore = useFTUEStore();
21+
const ftueStore = createFTUEStore(call);
2222
const {
2323
hasNextStep, hasPreviousStep, infoMessage, warningMessage,
2424
} = storeToRefs(ftueStore);
2525
26-
const { previousStep, nextStep } = ftueStore;
27-
28-
const calendarStore = useCalendarStore();
26+
const calendarStore = createCalendarStore(call);
2927
const calendars = ref<CalendarItem[]>([]);
3028
const selectedCount = computed(() => calendars.value.filter((item) => item.checked).length);
3129
const continueTitle = computed(() => (selectedCount.value ? t('label.continue') : t('ftue.oneCalendarRequired')));
@@ -49,7 +47,7 @@ onMounted(async () => {
4947
details: null,
5048
};
5149
52-
await calendarStore.fetch(call, true);
50+
await calendarStore.fetch(true);
5351
calendars.value = calendarStore.calendars.map((calendar) => ({
5452
key: calendar.id,
5553
label: calendar.title,
@@ -64,10 +62,10 @@ const onSubmit = async () => {
6462
// FIXME: This is just lazy, we should be checking for checkbox dirty state but no one really should have a calendar connected here!
6563
const calendarKeysConnect = calendars.value.filter((calendar) => calendar.checked).map((calendar) => calendar.key);
6664
const calendarKeysDisconnect = calendars.value.filter((calendar) => !calendar.checked).map((calendar) => calendar.key);
67-
await Promise.all(calendarKeysDisconnect.map((id) => calendarStore.disconnectCalendar(call, id)));
68-
await Promise.all(calendarKeysConnect.map((id) => calendarStore.connectCalendar(call, id)));
65+
await Promise.all(calendarKeysDisconnect.map((id) => calendarStore.disconnectCalendar(id)));
66+
await Promise.all(calendarKeysConnect.map((id) => calendarStore.connectCalendar(id)));
6967
70-
await nextStep(call);
68+
await ftueStore.nextStep();
7169
};
7270
7371
</script>
@@ -90,7 +88,7 @@ const onSubmit = async () => {
9088
:title="t('label.back')"
9189
v-if="hasPreviousStep"
9290
:disabled="isLoading"
93-
@click="previousStep()"
91+
@click="ftueStore.previousStep()"
9492
>
9593
{{ t('label.back') }}
9694
</secondary-button>

frontend/src/components/FTUE/ConnectVideo.vue

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,36 @@ import { storeToRefs } from 'pinia';
55
import SecondaryButton from '@/tbpro/elements/SecondaryButton.vue';
66
import PrimaryButton from '@/tbpro/elements/PrimaryButton.vue';
77
import TextInput from '@/tbpro/elements/TextInput.vue';
8-
import { useFTUEStore } from '@/stores/ftue-store';
9-
import { useExternalConnectionsStore } from '@/stores/external-connections-store';
8+
import { createFTUEStore } from '@/stores/ftue-store';
9+
import { createExternalConnectionsStore } from '@/stores/external-connections-store';
1010
import { callKey } from '@/keys';
1111
import {
1212
AuthUrl, AuthUrlResponse, BooleanResponse, Error, Exception, ExceptionDetail,
1313
} from '@/models';
14-
import { useScheduleStore } from '@/stores/schedule-store';
14+
import { createScheduleStore } from '@/stores/schedule-store';
1515
1616
const { t } = useI18n();
1717
1818
const call = inject(callKey);
1919
const isLoading = ref(false);
2020
21-
const ftueStore = useFTUEStore();
22-
const scheduleStore = useScheduleStore();
21+
const ftueStore = createFTUEStore(call);
22+
const scheduleStore = createScheduleStore(call);
23+
const externalConnectionStore = createExternalConnectionsStore(call);
2324
2425
const {
2526
hasNextStep, hasPreviousStep, errorMessage,
2627
} = storeToRefs(ftueStore);
27-
const { previousStep, nextStep } = ftueStore;
2828
const { schedules } = storeToRefs(scheduleStore);
2929
30-
const externalConnectionStore = useExternalConnectionsStore();
3130
const customMeetingLink = ref('');
3231
const customMeetingLinkRef = ref<typeof TextInput>();
3332
3433
const initFlowKey = 'tba/startedMeetingConnect';
3534
3635
onMounted(async () => {
3736
isLoading.value = true;
38-
await externalConnectionStore.fetch(call);
37+
await externalConnectionStore.fetch();
3938
isLoading.value = false;
4039
4140
const isBackFromConnectFlow = localStorage?.getItem(initFlowKey);
@@ -52,14 +51,14 @@ onMounted(async () => {
5251
return;
5352
}
5453
55-
await nextStep(call);
54+
await ftueStore.nextStep();
5655
}
5756
});
5857
5958
const onSubmit = async () => {
6059
isLoading.value = true;
6160
62-
const data = await scheduleStore.updateSchedule(call, schedules.value[0].id, {
61+
const data = await scheduleStore.updateSchedule(schedules.value[0].id, {
6362
...schedules.value[0],
6463
location_url: customMeetingLink.value,
6564
});
@@ -70,18 +69,18 @@ const onSubmit = async () => {
7069
return;
7170
}
7271
73-
await nextStep(call);
72+
await ftueStore.nextStep();
7473
};
7574
7675
const onSkip = async () => {
7776
isLoading.value = true;
78-
await nextStep(call);
77+
await ftueStore.nextStep();
7978
};
8079
8180
const connectZoom = async () => {
8281
// If they have zoom attached, just skip for now.
8382
if (externalConnectionStore.zoom.length > 0) {
84-
await nextStep(call);
83+
await ftueStore.nextStep();
8584
return;
8685
}
8786
@@ -129,7 +128,7 @@ const connectZoom = async () => {
129128
:title="t('label.back')"
130129
v-if="hasPreviousStep"
131130
:disabled="isLoading"
132-
@click="previousStep()"
131+
@click="ftueStore.previousStep()"
133132
>{{ t('label.back') }}
134133
</secondary-button>
135134
<primary-button

frontend/src/components/FTUE/GoogleOauthProvider.vue

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { storeToRefs } from 'pinia';
55
import { useRoute, useRouter } from 'vue-router';
66
import SecondaryButton from '@/tbpro/elements/SecondaryButton.vue';
77
import { useFTUEStore } from '@/stores/ftue-store';
8-
import { useCalendarStore } from '@/stores/calendar-store';
8+
import { createCalendarStore } from '@/stores/calendar-store';
99
import { useUserStore } from '@/stores/user-store';
10-
import { useExternalConnectionsStore } from '@/stores/external-connections-store';
10+
import { createExternalConnectionsStore } from '@/stores/external-connections-store';
1111
import { callKey } from '@/keys';
1212
import { ExternalConnectionProviders } from '@/definitions';
1313
import {
@@ -32,17 +32,15 @@ const emits = defineEmits(['next', 'previous', 'switch']);
3232
const isLoading = ref(false);
3333
3434
const ftueStore = useFTUEStore();
35-
const {
36-
hasNextStep, errorMessage,
37-
} = storeToRefs(ftueStore);
35+
const { hasNextStep, errorMessage } = storeToRefs(ftueStore);
3836
39-
const calendarStore = useCalendarStore();
40-
const externalConnectionStore = useExternalConnectionsStore();
37+
const calendarStore = createCalendarStore(call);
38+
const externalConnectionStore = createExternalConnectionsStore(call);
4139
const { calendars } = storeToRefs(calendarStore);
4240
const initFlowKey = 'tba/startedCalConnect';
4341
4442
onMounted(async () => {
45-
await calendarStore.fetch(call, true);
43+
await calendarStore.fetch(true);
4644
const hasFlowKey = localStorage?.getItem(initFlowKey);
4745
const noCalendarsError = hasFlowKey && calendars.value.length === 0;
4846
@@ -57,7 +55,7 @@ onMounted(async () => {
5755
5856
// Also remove the google calendar
5957
if (externalConnectionStore.google.length > 0) {
60-
await externalConnectionStore.disconnect(call, ExternalConnectionProviders.Google);
58+
await externalConnectionStore.disconnect(ExternalConnectionProviders.Google);
6159
}
6260
} else {
6361
errorMessage.value = {
@@ -92,7 +90,7 @@ const onSubmit = async () => {
9290
9391
// Create key so we can move to the next page after we come back
9492
localStorage?.setItem(initFlowKey, 'true');
95-
await calendarStore.connectGoogleCalendar(call, user.data.email);
93+
await calendarStore.connectGoogleCalendar(user.data.email);
9694
};
9795
9896
</script>

frontend/src/components/FTUE/SetupProfile.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
22
import { inject, ref } from 'vue';
33
import { storeToRefs } from 'pinia';
4-
import { useFTUEStore } from '@/stores/ftue-store';
5-
import { useUserStore } from '@/stores/user-store';
4+
import { createFTUEStore } from '@/stores/ftue-store';
5+
import { createUserStore } from '@/stores/user-store';
66
import { useI18n } from 'vue-i18n';
77
import { dayjsKey, callKey } from '@/keys';
88
import TextInput from '@/tbpro/elements/TextInput.vue';
@@ -13,11 +13,9 @@ const { t } = useI18n();
1313
const dj = inject(dayjsKey);
1414
const call = inject(callKey);
1515
16-
const ftueStore = useFTUEStore();
16+
const ftueStore = createFTUEStore(call);
1717
const { hasNextStep } = storeToRefs(ftueStore);
18-
const { nextStep } = ftueStore;
19-
const user = useUserStore();
20-
user.init(call);
18+
const user = createUserStore(call);
2119
2220
// @ts-expect-error ignore type err
2321
// See https://github.com/microsoft/TypeScript/issues/49231
@@ -62,7 +60,7 @@ const onSubmit = async () => {
6260
return;
6361
}
6462
65-
await nextStep(call);
63+
await ftueStore.nextStep();
6664
};
6765
6866
</script>

frontend/src/components/FTUE/SetupSchedule.vue

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import PrimaryButton from '@/tbpro/elements/PrimaryButton.vue';
1010
import SecondaryButton from '@/tbpro/elements/SecondaryButton.vue';
1111
import BubbleSelect from '@/tbpro/elements/BubbleSelect.vue';
1212
import { DateFormatStrings, DEFAULT_SLOT_DURATION, SLOT_DURATION_OPTIONS } from '@/definitions';
13-
import { useFTUEStore } from '@/stores/ftue-store';
13+
import { createFTUEStore } from '@/stores/ftue-store';
1414
import { useUserStore } from '@/stores/user-store';
15-
import { useCalendarStore } from '@/stores/calendar-store';
16-
import { useScheduleStore } from '@/stores/schedule-store';
15+
import { createCalendarStore } from '@/stores/calendar-store';
16+
import { createScheduleStore } from '@/stores/schedule-store';
1717
import {
1818
dayjsKey, callKey, isoWeekdaysKey,
1919
} from '@/keys';
@@ -24,15 +24,14 @@ const dj = inject(dayjsKey);
2424
const call = inject(callKey);
2525
const isoWeekdays = inject(isoWeekdaysKey);
2626
27-
const ftueStore = useFTUEStore();
27+
const ftueStore = createFTUEStore(call);
2828
const {
2929
hasNextStep, hasPreviousStep,
3030
} = storeToRefs(ftueStore);
31-
const { nextStep, previousStep } = ftueStore;
3231
const { errorMessage, infoMessage } = storeToRefs(ftueStore);
3332
const user = useUserStore();
34-
const calendarStore = useCalendarStore();
35-
const scheduleStore = useScheduleStore();
33+
const calendarStore = createCalendarStore(call);
34+
const scheduleStore = createScheduleStore(call);
3635
const { connectedCalendars } = storeToRefs(calendarStore);
3736
const { schedules } = storeToRefs(scheduleStore);
3837
const { timeToBackendTime, timeToFrontendTime } = scheduleStore;
@@ -95,8 +94,8 @@ const onSubmit = async () => {
9594
};
9695
9796
const data = schedules.value.length > 0
98-
? await scheduleStore.updateSchedule(call, schedules.value[0].id, scheduleData)
99-
: await scheduleStore.createSchedule(call, scheduleData);
97+
? await scheduleStore.updateSchedule(schedules.value[0].id, scheduleData)
98+
: await scheduleStore.createSchedule(scheduleData);
10099
101100
if ((data as Error)?.error) {
102101
errorMessage.value = {
@@ -107,7 +106,7 @@ const onSubmit = async () => {
107106
return;
108107
}
109108
110-
await nextStep(call);
109+
await ftueStore.nextStep();
111110
};
112111
113112
onMounted(async () => {
@@ -118,8 +117,8 @@ onMounted(async () => {
118117
};
119118
120119
await Promise.all([
121-
calendarStore.fetch(call, true),
122-
scheduleStore.fetch(call, true),
120+
calendarStore.fetch(true),
121+
scheduleStore.fetch(true),
123122
]);
124123
125124
schedule.value.calendar = connectedCalendars.value[0].id;
@@ -185,7 +184,7 @@ onMounted(async () => {
185184
:title="t('label.back')"
186185
v-if="hasPreviousStep"
187186
:disabled="isLoading"
188-
@click="previousStep()"
187+
@click="ftueStore.previousStep()"
189188
>
190189
{{ t('label.back') }}
191190
</secondary-button>

0 commit comments

Comments
 (0)