feat: complete dashboard mvp
This commit is contained in:
@@ -6,3 +6,9 @@ dayjs.extend(relativeTime);
|
||||
export const calDateDiff = (date: string | number | Date): string => {
|
||||
return dayjs(date).fromNow(true) + ` ago`;
|
||||
};
|
||||
|
||||
export const getGreeting = () => {
|
||||
const date = new Date();
|
||||
const hours = date.getHours();
|
||||
return hours < 12 ? 'Good Morning' : hours < 18 ? 'Good Afternoon' : 'Good Evening';
|
||||
};
|
||||
|
||||
@@ -1,19 +1,41 @@
|
||||
import type { UserLessonDataType } from '$lib/utils/types';
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
|
||||
function getFirstAndLastDayOfMonth(): { firstDay: string; lastDay: string } {
|
||||
const date = new Date();
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth();
|
||||
|
||||
// Create a date object for the first day of the month
|
||||
const firstDay = new Date(year, month, 1).toISOString();
|
||||
|
||||
// Find the last day of the next month and subtract one day to get the last day of the current month
|
||||
const nextMonth: any = new Date(year, month + 1, 1);
|
||||
const lastDay = new Date(nextMonth - 1).toISOString();
|
||||
|
||||
return {
|
||||
firstDay,
|
||||
lastDay
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchUserUpcomingData(
|
||||
profileId: string | null
|
||||
profileId: string | null,
|
||||
orgId: string
|
||||
): Promise<UserLessonDataType[] | []> {
|
||||
if (!profileId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const { data: userUpcomingData } = await supabase.rpc(
|
||||
'get_user_upcoming_lessons',
|
||||
{
|
||||
const { lastDay, firstDay } = getFirstAndLastDayOfMonth();
|
||||
|
||||
const { data: userUpcomingData } = await supabase
|
||||
.rpc('get_user_upcoming_lessons', {
|
||||
profile_id_arg: profileId,
|
||||
}
|
||||
);
|
||||
org_id_arg: orgId
|
||||
})
|
||||
.filter('lesson_at', 'gte', firstDay)
|
||||
.filter('lesson_at', 'lte', lastDay);
|
||||
|
||||
console.log(`userUpcomingData`, userUpcomingData);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { STEPS } from '../constants/quiz';
|
||||
import type { Writable } from 'svelte/store';
|
||||
import type { CurrentOrg, OrgTeamMember } from '../types/org';
|
||||
import { ROLE } from '$lib/utils/constants/roles';
|
||||
import type { UserLessonDataType } from '$lib/utils/types';
|
||||
|
||||
export const orgs = writable<CurrentOrg[]>([]);
|
||||
export const currentOrg: Writable<CurrentOrg> = writable({
|
||||
@@ -54,3 +55,5 @@ export const quizStore = writable({
|
||||
export const playQuizStore = writable({
|
||||
step: STEPS.CONNECT_TO_PLAY
|
||||
});
|
||||
|
||||
export const userUpcomingData = writable<UserLessonDataType[]>([]);
|
||||
|
||||
Reference in New Issue
Block a user