Skip to content

Commit

Permalink
refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mav-Ivan committed Oct 10, 2024
1 parent 8e1921e commit be7e7b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
15 changes: 11 additions & 4 deletions src/containers/course-section/CourseSectionContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const CourseSectionContainer: FC<SectionProps> = ({
sectionId: sectionData.id
})
}

const handleAddResources = async <T extends CourseResource>(
resources: T[],
isDuplicate: boolean
Expand Down Expand Up @@ -273,7 +274,6 @@ const CourseSectionContainer: FC<SectionProps> = ({
}
}
}
//

resourceEventHandler?.({
type: CourseResourceEventType.AddSectionResources,
Expand All @@ -283,12 +283,19 @@ const CourseSectionContainer: FC<SectionProps> = ({
})
}

const onAddResourcesWrapper = (
resources: (Lesson | Quiz | Attachment)[],
isDuplicate: boolean
) => {
void handleAddResources(resources, isDuplicate)
}

const handleOpenAddLessonsModal = () => {
openModal({
component: (
<AddResources<Lesson>
columns={lessonColumns}
onAddResources={() => handleAddResources}
onAddResources={onAddResourcesWrapper}
removeColumnRules={removeLessonColumnRules}
requestService={ResourceService.getUsersLessons}
resourceTab={resourcesData.lessons.resourceTab}
Expand All @@ -304,7 +311,7 @@ const CourseSectionContainer: FC<SectionProps> = ({
component: (
<AddResources<Quiz>
columns={quizColumns}
onAddResources={() => handleAddResources}
onAddResources={onAddResourcesWrapper}
removeColumnRules={removeQuizColumnRules}
requestService={ResourceService.getQuizzes}
resourceTab={resourcesData.quizzes.resourceTab}
Expand All @@ -320,7 +327,7 @@ const CourseSectionContainer: FC<SectionProps> = ({
component: (
<AddResources<Attachment>
columns={attachmentColumns}
onAddResources={() => handleAddResources}
onAddResources={onAddResourcesWrapper}
removeColumnRules={removeAttachmentColumnRules}
requestService={ResourceService.getAttachments}
resourceTab={resourcesData.attachments.resourceTab}
Expand Down
11 changes: 3 additions & 8 deletions tests/unit/redux/cooperationsSlice.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('Test cooperationsSlice', () => {

const addedResource = state.sections[0].resources[0].resource

expect(isValidUUID(addedResource.id)).toBe(true)
expect(addedResource.id).toBe(resources[0]._id)
expect(addedResource).toMatchObject({
_id: 'some id',
title: 'Resource 1',
Expand Down Expand Up @@ -214,13 +214,8 @@ describe('Test cooperationsSlice', () => {

const addedResource = state.sections[0].resources[0].resource

expect(isValidUUID(addedResource.id)).toBe(true)
expect(addedResource).toMatchObject({
_id: '',
title: 'Resource 1',
resourceType: ResourceType.Lesson,
isDuplicate: true
})
expect(addedResource.id).toBe(resources[0]._id)
expect(addedResource).toMatchObject(resources[0])
})

it('should update resources order correctly with updateResourcesOrder', () => {
Expand Down

0 comments on commit be7e7b9

Please sign in to comment.