1- import { useState , useCallback } from 'react' ;
1+ import { useCallback } from 'react' ;
22
3- import { useToggle } from '@openedx/paragon' ;
43import type { OutlineActionSelection , XBlock } from '@src/data/types' ;
54import {
65 useCourseItemData ,
@@ -11,6 +10,7 @@ import {
1110} from '../data' ;
1211import { useOutlineConfigureAction } from './useOutlineActions' ;
1312import { COURSE_BLOCK_NAMES } from '../constants' ;
13+ import { useModalState } from './useModalState' ;
1414
1515export interface UseConfigureDialogOutput {
1616 isConfigureModalOpen : boolean ;
@@ -27,8 +27,12 @@ export interface UseConfigureDialogOutput {
2727export function useConfigureDialog ( courseId : string ) : UseConfigureDialogOutput {
2828 const { handleConfigureItemSubmit } = useOutlineConfigureAction ( courseId ) ;
2929
30- const [ isConfigureModalOpen , openConfigureModal , closeConfigureModal ] = useToggle ( false ) ;
31- const [ configureModalData , setConfigureModalData ] = useState < OutlineActionSelection | undefined > ( ) ;
30+ const {
31+ isOpen : isConfigureModalOpen ,
32+ open : openConfigureModal ,
33+ close : closeConfigureModal ,
34+ data : configureModalData ,
35+ } = useModalState < OutlineActionSelection > ( ) ;
3236
3337 const { data : configureItemData } = useCourseItemData (
3438 isConfigureModalOpen ? configureModalData ?. currentId : undefined ,
@@ -39,18 +43,26 @@ export function useConfigureDialog(courseId: string): UseConfigureDialogOutput {
3943
4044 const handleConfigureModalClose = useCallback ( ( ) => {
4145 closeConfigureModal ( ) ;
42- setConfigureModalData ( undefined ) ;
4346 } , [ closeConfigureModal ] ) ;
4447
4548 const handleOpenConfigureModal = useCallback ( ( selection : OutlineActionSelection ) => {
46- setConfigureModalData ( selection ) ;
47- openConfigureModal ( ) ;
49+ openConfigureModal ( selection ) ;
4850 } , [ openConfigureModal ] ) ;
4951
50- const payloadBuilders : Record < string , ( data : typeof configureModalData , vars : Record < string , unknown > ) => ConfigureItemPayload > = {
52+ const payloadBuilders : Record <
53+ string ,
54+ ( data : typeof configureModalData , vars : Record < string , unknown > ) => ConfigureItemPayload
55+ > = {
5156 chapter : ( data , vars ) => ( { category : 'chapter' , sectionId : data ! . sectionId , ...vars } ) as ChapterConfigurePayload ,
52- sequential : ( data , vars ) => ( { category : 'sequential' , itemId : data ! . currentId , sectionId : data ! . sectionId , ...vars } ) as SequentialConfigurePayload ,
53- vertical : ( data , vars ) => ( { category : 'vertical' , unitId : data ! . currentId , sectionId : data ! . sectionId , ...vars } ) as UnitConfigurePayload ,
57+ sequential : ( data , vars ) =>
58+ ( {
59+ category : 'sequential' ,
60+ itemId : data ! . currentId ,
61+ sectionId : data ! . sectionId ,
62+ ...vars ,
63+ } ) as SequentialConfigurePayload ,
64+ vertical : ( data , vars ) =>
65+ ( { category : 'vertical' , unitId : data ! . currentId , sectionId : data ! . sectionId , ...vars } ) as UnitConfigurePayload ,
5466 } ;
5567
5668 const handleConfigureItemSubmitWrapper = useCallback ( async ( variables : Record < string , unknown > ) => {
0 commit comments