Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Mark button with on Lesson details page #3198

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

Mav-Ivan
Copy link
Contributor

@Mav-Ivan Mav-Ivan commented Feb 13, 2025

2025-02-14.20-12-20.mp4

@Mav-Ivan Mav-Ivan self-assigned this Feb 13, 2025
@Mav-Ivan Mav-Ivan changed the title Implemented button with logic and added tests Implemented Mark button with on Lesson details page Feb 13, 2025
@Mav-Ivan Mav-Ivan marked this pull request as ready for review February 14, 2025 18:17
@Mav-Ivan Mav-Ivan linked an issue Feb 14, 2025 that may be closed by this pull request
Comment on lines +102 to +113
if (!cooperation?.sections) return

cooperation?.sections?.some((section) => {
const resource = section.resources?.find(
(resource) => resource.resource._id === lessonId
)

if (resource) {
setCompletionStatus(resource.completionStatus)
return true
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should refactor this.

Why did you use some if you don't use return value of that function?

return true in if statement is a very bad practice

Also, you could have an array of resourceId values, with flatMap usage and use that to check if there is id that you need

Comment on lines +96 to +99
const { data: cooperation } = useQuery({
queryFn: getCooperation,
queryKey: ['cooperation', id]
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add staleTime: Infinity to this useQuery. So you can use the cached value of cooperation since you can go to the Lesson page from the Cooperation page.
And also add caching to useQuery inside this component

Comment on lines +127 to +129
const handleResponse = () => {
setCompletionStatus(CompletionStatusEnum.Completed)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should mutate some keys to invalidate this lesson and trigger auto-refetch instead of setting local state

})

useEffect(() => {
if (!cooperation?.sections) return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add braces here, please

useEffect(() => {
if (!cooperation?.sections) return

cooperation?.sections?.some((section) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already checked that in 102 line

Suggested change
cooperation?.sections?.some((section) => {
cooperation.sections?.some((section) => {


const noteData = {
isPrivate: false,
text: 'This is Note'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
text: 'This is Note'
text: 'This is Note'

})

it('should create new cooperation', async () => {
mockAxiosClient.onPost(new RegExp(URLs.cooperations.create)).reply(200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, check if it works without RegExp

Suggested change
mockAxiosClient.onPost(new RegExp(URLs.cooperations.create)).reply(200)
mockAxiosClient.onPost(URLs.cooperations.create).reply(200)

Comment on lines +49 to +53
new RegExp(
URLs.cooperations.updateStatusById
.replace(':id', id)
.replace(':resourceId', lessonId)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new RegExp(
URLs.cooperations.updateStatusById
.replace(':id', id)
.replace(':resourceId', lessonId)
)
URLs.cooperations.updateStatusById
.replace(':id', id)
.replace(':resourceId', lessonId)

import { createUrlPath } from '~/utils/helper-functions'
import { useAppSelector } from '~/hooks/use-redux'
import { useModalContext } from '~/context/modal-context'
import ChangeResourceConfirmModal from '~/containers/change-resource-confirm-modal/ChangeResourceConfirmModal'

const LessonDetails = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add React.FC please

CompletionStatusEnum,
TypographyVariantEnum,
UserRoleEnum
} from '~/types'
import { createUrlPath } from '~/utils/helper-functions'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, try to replace createUrlPath with getFullUrl function. We are trying to get rid of old one, so since you are working in this component, try to replace that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(SP: 2) Add complete lesson button
2 participants