1- import { courseOutlineQueryKeys } from '@src/course-outline/data/apiHooks' ;
2- import {
3- fetchCourseSectionVerticalDataSuccess , updateCourseVerticalChildren , updateQueryPendingStatus , updateSavingStatus ,
4- } from '@src/course-unit/data/slice' ;
5- import { RequestStatus } from '@src/data/constants' ;
6- import { hideProcessingNotification , showProcessingNotification } from '@src/generic/processing-notification/data/slice' ;
7- import { useMutation , useQueryClient } from '@tanstack/react-query' ;
8- import { useDispatch } from 'react-redux' ;
1+ import { useMutation } from '@tanstack/react-query' ;
92
10- import { handleResponseErrors } from '@src/generic/saving-error-alert' ;
113import {
124 acceptLibraryBlockChanges ,
13- getCourseContainerChildren ,
14- getVerticalData ,
15- handleCourseUnitVisibilityAndData ,
165 ignoreLibraryBlockChanges ,
176} from './api' ;
18- import { getNotificationMessage } from './utils' ;
197
208/**
219 * Hook that provides a "mutation" that can be used to accept library block changes.
@@ -32,35 +20,3 @@ export const useAcceptLibraryBlockChanges = () => useMutation({
3220export const useIgnoreLibraryBlockChanges = ( ) => useMutation ( {
3321 mutationFn : ignoreLibraryBlockChanges ,
3422} ) ;
35-
36- export const useEditCourseUnitVisibilityAndData = ( ) => {
37- const queryClient = useQueryClient ( ) ;
38- const dispatch = useDispatch ( ) ;
39- return useMutation ( {
40- mutationFn : handleCourseUnitVisibilityAndData ,
41- onMutate : ( variables ) => {
42- dispatch ( updateSavingStatus ( { status : RequestStatus . PENDING } ) ) ;
43- dispatch ( updateQueryPendingStatus ( true ) ) ;
44- dispatch ( showProcessingNotification (
45- getNotificationMessage ( variables . type , variables . isVisible , true ) ,
46- ) ) ;
47- } ,
48- onSuccess : async ( _data , variables ) => {
49- const courseSectionVerticalData = await getVerticalData ( variables . unitId ) ;
50- dispatch ( fetchCourseSectionVerticalDataSuccess ( courseSectionVerticalData ) ) ;
51- const courseVerticalChildrenData = await getCourseContainerChildren ( variables . unitId ) ;
52- dispatch ( updateCourseVerticalChildren ( courseVerticalChildrenData ) ) ;
53- dispatch ( hideProcessingNotification ( ) ) ;
54- dispatch ( updateSavingStatus ( { status : RequestStatus . SUCCESSFUL } ) ) ;
55- } ,
56- onSettled : async ( _data , _err , variables ) => {
57- queryClient . invalidateQueries ( {
58- queryKey : courseOutlineQueryKeys . courseItemId ( variables . unitId ) ,
59- } ) ;
60- } ,
61- onError : ( error ) => {
62- dispatch ( hideProcessingNotification ( ) ) ;
63- handleResponseErrors ( error , dispatch , updateSavingStatus ) ;
64- } ,
65- } ) ;
66- } ;
0 commit comments