Created
April 2, 2024 11:32
-
-
Save rotimi-best/78b3d18c41f3b2bb9045acf17cf7b03f to your computer and use it in GitHub Desktop.
Load function for TS file of /setup page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import get from 'lodash/get'; | |
async function getGenericData(orgSlug: string): Promise<{ isCoursePublished: boolean; isCourseCreated: boolean; orgHasAvatarUrl: boolean}> { | |
const { data } = await supabase.from('course').select(` | |
id, | |
is_published, | |
group:group_id!inner( | |
organization!inner ( | |
avatar_url, | |
siteName | |
) | |
) | |
`).eq('group.organization.siteName', orgSlug); | |
const result = data || []; | |
console.log({ result }) | |
return { | |
isCoursePublished: result.find(c => !!c.is_published), | |
isCourseCreated: result.length > 0, | |
orgHasAvatarUrl: !!get(result[0], 'group.organization.avatar_url', '') | |
} | |
} | |
async function getIsLessonCreated(orgSlug: string): Promise<boolean> { | |
const { data } = await supabase.from('lesson').select(` | |
id, | |
course:course_id ( | |
group:group_id( | |
organization ( | |
siteName | |
) | |
) | |
) | |
`).eq('course.group.organization.siteName', orgSlug); | |
return !!data; | |
} | |
async function getIsExerciseCreated(orgSlug: string): Promise<boolean> { | |
const { data } = await supabase.from('exercise').select(` | |
id, | |
lesson:lesson_id ( | |
course:course_id ( | |
group:group_id( | |
organization ( | |
siteName | |
) | |
) | |
) | |
) | |
`).eq('lesson.course.group.organization.siteName', orgSlug); | |
return !!data; | |
} | |
const load = async (params: { slug: string }) => { | |
const { isCourseCreated, isCoursePublished, orgHasAvatarUrl } = await getGenericData(params.slug); | |
const isLessonCreated = await getIsLessonCreated(params.slug); | |
const isExerciseCreated = await getIsExerciseCreated(params.slug); | |
return [ | |
{ | |
id: 'profile', | |
title: 'Upload a profile picture and update username', | |
desc: 'Personalize and a human touch making interactions more personal and memorable', | |
isCompleted: false, | |
buttonLabel: 'Update Profile', | |
}, | |
{ | |
id: 'organization', | |
title: 'Update organisation profile picture', | |
desc: 'Establish a professional and recognizable identity for your organization', | |
isCompleted: orgHasAvatarUrl, | |
buttonLabel: 'Update Org Profile' | |
}, | |
{ | |
id: 'course', | |
title: 'Create Course', | |
desc: 'Create a course that you will share with your students', | |
isCompleted: isCourseCreated, | |
buttonLabel: 'Create Course' | |
}, | |
{ | |
title: 'Create a lesson', | |
desc: 'Break your course into lesson that your students can easily understand', | |
isCompleted: isLessonCreated, | |
buttonLabel: 'Create Lesson' | |
}, | |
{ | |
title: 'Create an exercise', | |
desc: 'Test your students allow them to demonstarte their understanding of the subject matter', | |
isCompleted: isExerciseCreated, | |
buttonLabel: 'Create Assignment' | |
}, | |
{ | |
title: 'Publish a course', | |
desc: 'Make your course public and purchaseable ', | |
isCompleted: isCoursePublished, | |
buttonLabel: 'Publish Course' | |
} | |
]; | |
} | |
/* RUN THIS ON THE CLIENT | |
data = data.map(item => { | |
if (item.id === 'profile') { | |
item.isCompleted = !$profile.avatar_url.includes('avatars/avatar.png') | |
} | |
return item; | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment