diff --git a/src/app/(app)/course/[courseId]/setup/(hooks)/useSetupSteps.tsx b/src/app/(app)/course/[courseId]/setup/(hooks)/useSetupSteps.tsx index d930d12..26d5f89 100644 --- a/src/app/(app)/course/[courseId]/setup/(hooks)/useSetupSteps.tsx +++ b/src/app/(app)/course/[courseId]/setup/(hooks)/useSetupSteps.tsx @@ -9,6 +9,7 @@ import { useImportStudentsFromLms } from "@/hooks/use-import-students-from-lms" import { useImportStudentGradebookData } from "@/hooks/use-import-student-gradebook-data" import { GenerateOptInQuiz } from "@/app/(app)/course/[courseId]/setup/(components)/GenerateOptInQuiz" import { useOnboardingProgress } from "@/hooks/use-onboarding-progress" +import { useGenerateTeams } from "@/hooks/use-generate-teams" interface UseSetupStepsReturnType { steps: NonEmptyArray; @@ -21,12 +22,13 @@ export const useSetupSteps = (): UseSetupStepsReturnType => { const { importStudentsFromLmsAsync } = useImportStudentsFromLms() const { importStudentGradebookData } = useImportStudentGradebookData() - - // todo: generate teams mutation + const { generateTeamsAsync } = useGenerateTeams() if (!data || isLoading) { return { - steps: ORDERED_STEPS.map((step) => BASE_STEPS[step]) as NonEmptyArray, + steps: ORDERED_STEPS.map( + (step) => BASE_STEPS[step], + ) as NonEmptyArray, isLoading, onboardingProgress: data, } @@ -41,6 +43,10 @@ export const useSetupSteps = (): UseSetupStepsReturnType => { content: "Import gradebook data", onClick: () => importStudentGradebookData(undefined), }, + GENERATE_TEAMS: { + content: "Generate teams", + onClick: () => generateTeamsAsync(undefined), + }, } const currentStep = getCurrentStep(data) diff --git a/src/hooks/use-generate-teams.ts b/src/hooks/use-generate-teams.ts new file mode 100644 index 0000000..fc433b4 --- /dev/null +++ b/src/hooks/use-generate-teams.ts @@ -0,0 +1,36 @@ +import { useToast } from "@/hooks/use-toast" +import { useCourse } from "@/app/(app)/course/[courseId]/(hooks)/useCourse" +import { useMutation } from "@tanstack/react-query" +import { defaultMutationFn } from "@/app/(providers)/query-client-provider" + +export const useGenerateTeams = () => { + const { toast } = useToast() + const { courseId } = useCourse() + const mutation = useMutation({ + mutationFn: async () => { + return defaultMutationFn( + `courses/${courseId}/generate_teams/`, + undefined, + { allowEmptyResponse: true }, + ) + }, + onSuccess: () => { + toast({ + title: "Teams generated successfully", + }) + }, + onError: () => { + toast({ + variant: "destructive", + title: "Unable to generate teams", + description: + "Something went wrong while generating teams. Please try again later.", + }) + }, + }) + + return { + generateTeamsAsync: mutation.mutateAsync, + ...mutation, + } +} diff --git a/src/hooks/use-import-student-gradebook-data.ts b/src/hooks/use-import-student-gradebook-data.ts index b560678..f247922 100644 --- a/src/hooks/use-import-student-gradebook-data.ts +++ b/src/hooks/use-import-student-gradebook-data.ts @@ -6,7 +6,7 @@ import { defaultMutationFn } from "@/app/(providers)/query-client-provider" export const useImportStudentGradebookData = () => { const { toast } = useToast() const { courseId } = useCourse() - const mutation = useMutation({ + const mutation = useMutation({ mutationFn: async () => { return defaultMutationFn( `courses/${courseId}/import_gradebook_attribute_from_lms/`, diff --git a/src/hooks/use-import-students-from-lms.ts b/src/hooks/use-import-students-from-lms.ts index 2f7c975..5bbe83c 100644 --- a/src/hooks/use-import-students-from-lms.ts +++ b/src/hooks/use-import-students-from-lms.ts @@ -6,7 +6,7 @@ import { defaultMutationFn } from "@/app/(providers)/query-client-provider" export const useImportStudentsFromLms = () => { const { toast } = useToast() const { courseId } = useCourse() - const mutation = useMutation({ + const mutation = useMutation({ mutationFn: async () => { return defaultMutationFn(`courses/${courseId}/import_students_from_lms/`, undefined, {allowEmptyResponse: true}) },