Skip to content

Commit

Permalink
FW-4809 Handle visibility select for assistants in Visibility control
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanVH committed Nov 22, 2023
1 parent a2e6c0f commit 148f514
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 52 deletions.
18 changes: 2 additions & 16 deletions src/components/DictionaryCrud/DictionaryCrudPresentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ import {
TYPE_WORD,
TYPE_PHRASE,
PUBLIC,
TEAM,
} from 'common/constants'
import getIcon from 'common/utils/getIcon'
import { definitions } from 'common/utils/validationHelpers'
import useEditForm from 'common/hooks/useEditForm'
import useSearchParamsState from 'common/hooks/useSearchParamsState'
import { useParams } from 'react-router-dom'
import { useUserStore } from 'context/UserContext'
import { ASSISTANT } from '../../common/constants/roles'

function DictionaryCrudPresentation({
backHandler,
Expand Down Expand Up @@ -56,12 +52,6 @@ function DictionaryCrudPresentation({
translations: definitions.textArray(),
})

const { sitename } = useParams()
const { user } = useUserStore()
const userRoles = user?.roles || {}
const userSiteRole = userRoles?.[sitename] || ''
const isAssistant = userSiteRole === ASSISTANT

const defaultValues = {
acknowledgements: [],
alternateSpellings: [],
Expand All @@ -76,7 +66,7 @@ function DictionaryCrudPresentation({
title: '',
type: type || TYPE_WORD,
translations: [],
visibility: isAssistant ? TEAM : PUBLIC,
visibility: PUBLIC,
includeInKids: 'true',
includeInGames: 'true',
}
Expand Down Expand Up @@ -291,11 +281,7 @@ function DictionaryCrudPresentation({
return (
<Fragment key={step}>
<div className="col-span-12">
<Form.Visibility
control={control}
errors={errors}
reduceAssistantOptions={isAssistant}
/>
<Form.Visibility control={control} errors={errors} />
</div>
<div className="col-span-12">
<Form.RadioButtons
Expand Down
12 changes: 8 additions & 4 deletions src/components/Form/Visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import PropTypes from 'prop-types'
// FPCC
import Select from 'components/Form/Select'
import { useSiteStore } from 'context/SiteContext'
import { useUserStore } from 'context/UserContext'
import { ASSISTANT } from '../../common/constants/roles'

function Visibility({
control,
errors,
label = 'Who can see this entry?',
reduceAssistantOptions = false,
} = {}) {
const { site } = useSiteStore()
const { user } = useUserStore()
const userRoles = user?.roles || {}
const userSiteRole = userRoles?.[site?.sitename] || ''
const isAssistant = userSiteRole === ASSISTANT

const options = (function _() {
if (reduceAssistantOptions) {
if (isAssistant) {
const optionsLen = site?.visibilityOptions.length
for (let i = 0; i < optionsLen; i += 1) {
if (site?.visibilityOptions[i]?.value !== 'team') {
Expand Down Expand Up @@ -42,12 +47,11 @@ function Visibility({
)
}
// PROPTYPES
const { object, string, bool } = PropTypes
const { object, string } = PropTypes
Visibility.propTypes = {
label: string,
control: object,
errors: object,
reduceAssistantOptions: bool,
}

export default Visibility
19 changes: 3 additions & 16 deletions src/components/SongCrud/SongCrudPresentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import Form from 'components/Form'
import DeleteButton from 'components/DeleteButton'
import { definitions } from 'common/utils/validationHelpers'
import useEditForm from 'common/hooks/useEditForm'
import { AUDIO, IMAGE, VIDEO, PUBLIC, TEAM } from 'common/constants'
import { useParams } from 'react-router-dom'
import { useUserStore } from 'context/UserContext'
import { ASSISTANT } from '../../common/constants/roles'
import { AUDIO, IMAGE, VIDEO, PUBLIC } from 'common/constants'

function SongCrudPresentation({
backHandler,
Expand All @@ -37,12 +34,6 @@ function SongCrudPresentation({
relatedVideos: definitions.idArray(),
})

const { sitename } = useParams()
const { user } = useUserStore()
const userRoles = user?.roles || {}
const userSiteRole = userRoles?.[sitename] || ''
const isAssistant = userSiteRole === ASSISTANT

const defaultValues = {
title: '',
titleTranslation: '',
Expand All @@ -56,7 +47,7 @@ function SongCrudPresentation({
relatedVideos: [],
includeInKids: 'true',
includeInGames: 'true',
visibility: isAssistant ? TEAM : PUBLIC,
visibility: PUBLIC,
hideOverlay: 'false',
}

Expand Down Expand Up @@ -194,11 +185,7 @@ function SongCrudPresentation({
/>
</div>
<div className="col-span-12">
<Form.Visibility
control={control}
errors={errors}
reduceAssistantOptions={isAssistant}
/>
<Form.Visibility control={control} errors={errors} />
</div>
<div className="col-span-6">
<Form.RadioButtons
Expand Down
19 changes: 3 additions & 16 deletions src/components/StoryAudienceCrud/StoryAudienceCrudPresentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@ import * as yup from 'yup'
import Form from 'components/Form'
// import { definitions } from 'common/utils/validationHelpers'
import useEditForm from 'common/hooks/useEditForm'
import { PUBLIC, TEAM } from 'common/constants'
import { PUBLIC } from 'common/constants'
import StoryCrudStepWrapper from 'components/StoryCrud/StoryCrudStepWrapper'
import { useParams } from 'react-router-dom'
import { useUserStore } from 'context/UserContext'
import { ASSISTANT } from '../../common/constants/roles'

function StoryAudienceCrudPresentation({ dataToEdit, submitHandler }) {
const validator = yup.object().shape({
visibility: yup.string(),
includeInKids: yup.string(),
})

const { sitename } = useParams()
const { user } = useUserStore()
const userRoles = user?.roles || {}
const userSiteRole = userRoles?.[sitename] || ''
const isAssistant = userSiteRole === ASSISTANT

const defaultValues = {
visibility: isAssistant ? TEAM : PUBLIC,
visibility: PUBLIC,
includeInKids: 'true',
}

Expand All @@ -46,11 +37,7 @@ function StoryAudienceCrudPresentation({ dataToEdit, submitHandler }) {
<form onReset={reset}>
<div className="grid grid-cols-12 gap-8 p-8">
<div className="col-span-12">
<Form.Visibility
control={control}
errors={errors}
reduceAssistantOptions={isAssistant}
/>
<Form.Visibility control={control} errors={errors} />
</div>
<div className="col-span-6">
<Form.RadioButtons
Expand Down

0 comments on commit 148f514

Please sign in to comment.