Skip to content

Commit

Permalink
refetch onboarding data after actions (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
Opeyem1a authored Aug 26, 2024
1 parent 3c24caf commit b3da2c5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Button } from "@/components/ui/button"
export interface Action {
onClick: () => void;
content: ReactNode;
loading: boolean;
}

export interface StepDefinition {
Expand Down Expand Up @@ -46,7 +47,7 @@ export const SetupStepDetailCard = ({ steps }: StepDetailCardProps) => {
</div>
<div className="flex gap-2 flex-wrap">
{selectedStep.action && (
<Button onClick={selectedStep.action.onClick}>
<Button onClick={selectedStep.action.onClick} disabled={selectedStep.action.loading}>
{selectedStep.action.content}
</Button>
)}
Expand Down
33 changes: 26 additions & 7 deletions src/app/(app)/course/[courseId]/setup/(hooks)/useSetupSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ interface UseSetupStepsReturnType {
}

export const useSetupSteps = (): UseSetupStepsReturnType => {
const { data, isLoading } = useOnboardingProgress()
const { data, isLoading, refetch } = useOnboardingProgress()

const { importStudentsFromLmsAsync } = useImportStudentsFromLms()
const { importStudentGradebookData } = useImportStudentGradebookData()
const { generateTeamsAsync } = useGenerateTeams()
const {
importStudentsFromLmsAsync,
isPending: importStudentsFromLmsPending,
} = useImportStudentsFromLms()
const {
importStudentGradebookDataAsync,
isPending: importStudentGradebookDataPending,
} = useImportStudentGradebookData()
const { generateTeamsAsync, isPending: generateTeamsPending } =
useGenerateTeams()

if (!data || isLoading) {
return {
Expand All @@ -37,15 +44,27 @@ export const useSetupSteps = (): UseSetupStepsReturnType => {
const actions: Partial<Record<StepKey, Action>> = {
IMPORT_STUDENTS: {
content: "Import students",
onClick: () => importStudentsFromLmsAsync(undefined),
onClick: async () => {
await importStudentsFromLmsAsync(undefined)
await refetch()
},
loading: importStudentsFromLmsPending,
},
STUDENT_DATA: {
content: "Import gradebook data",
onClick: () => importStudentGradebookData(undefined),
onClick: async () => {
await importStudentGradebookDataAsync(undefined)
await refetch()
},
loading: importStudentGradebookDataPending,
},
GENERATE_TEAMS: {
content: "Generate teams",
onClick: () => generateTeamsAsync(undefined),
onClick: async () => {
await generateTeamsAsync(undefined)
await refetch()
},
loading: generateTeamsPending,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const useStudentsProvider = (): StudentsContextType => {
const queryString = createQueryString(queryStringParams)
const fetchStudents = async () => {
try {
const courseMemberResponse = await fetch(`${process.env.BACKEND_BASE_URI}/api/v1/course-members/course/${courseId}/?${queryString}`,)
const courseMemberResponse = await fetch(`${process.env.BACKEND_BASE_URI}/api/v1/course/${courseId}/students?${queryString}`,)
const courseMemberData = await courseMemberResponse.json()
const studentsToDisplay: Student[] = courseMemberData.results.map((member: any) => ({
id: member.user.id,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-import-student-gradebook-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useImportStudentGradebookData = () => {
})

return {
importStudentGradebookData: mutation.mutateAsync,
importStudentGradebookDataAsync: mutation.mutateAsync,
...mutation,
}
}

0 comments on commit b3da2c5

Please sign in to comment.