Skip to content

Commit

Permalink
3989 - Topic/Footer: useShowActions hook
Browse files Browse the repository at this point in the history
  • Loading branch information
sorja committed Oct 4, 2024
1 parent 62e56c9 commit e6013ee
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Areas, AssessmentStatus } from 'meta/area'
import { MessageTopic, MessageTopicStatus, MessageTopicType } from 'meta/messageCenter'
import { Users } from 'meta/user'

import { useCountry } from 'client/store/area'
import { useCycle } from 'client/store/assessment'
import { useUser } from 'client/store/user'
import { useCountryIso } from 'client/hooks'

export const useShowActions = (topic: MessageTopic) => {
const cycle = useCycle()
const user = useUser()
const countryIso = useCountryIso()
const country = useCountry(countryIso)
const status = Areas.getStatus(country)

const isAdmin = Users.isAdministrator(user)
const isReviewer = Users.isReviewer(user, countryIso, cycle)

const isEditing = status === AssessmentStatus.editing
const isReview = topic.type === MessageTopicType.review
const isOpened = topic.status === MessageTopicStatus.opened
const isResolved = topic.status === MessageTopicStatus.resolved
const hasMessages = topic.messages?.length > 0

const showResolve = isEditing && isReview && isOpened && hasMessages && (isAdmin || isReviewer)

const showMessageInput = isEditing && (isOpened || (isResolved && (isAdmin || isReviewer)))

return { showResolve, showMessageInput }
}

0 comments on commit e6013ee

Please sign in to comment.