diff --git a/src/helpers/projectHelper.js b/src/helpers/projectHelper.js index 850a59980..cfb84b381 100644 --- a/src/helpers/projectHelper.js +++ b/src/helpers/projectHelper.js @@ -266,7 +266,7 @@ export function getNewProjectLink(orgConfigs) { * @param {Object} project - The project object * @param {string} projectId - The project id */ -export function getProjectNavLinks(project, projectId) { +export function getProjectNavLinks(project, projectId, renderFAQs) { let messagesTab = null // `Discussions` items can be added as soon as project is loaded // if discussions are not hidden for it @@ -283,12 +283,15 @@ export function getProjectNavLinks(project, projectId) { // Commented out till it needs to go live. { label: 'Reports', to: `/projects/${projectId}/reports`, Icon: ReportsIcon, iconClassName: 'stroke' }, { label: 'Assets Library', to: `/projects/${projectId}/assets`, Icon: AssetsLibraryIcon, iconClassName: 'stroke' }, - { label: 'FAQ', to: `/projects/${projectId}/faqs`, Icon: FAQIcon, iconClassName: 'fill' }, ] : [ { label: 'Dashboard', to: `/projects/${projectId}`, Icon: DashboardIcon, iconClassName: 'stroke' }, messagesTab, { label: 'Specification', to: `/projects/${projectId}/specification`, Icon: ScopeIcon, iconClassName: 'fill' }, ] - + + if (renderFAQs) { + const faqTab = { label: 'FAQ', to: `/projects/${projectId}/faqs`, Icon: FAQIcon, iconClassName: 'fill' } + navLinks.push(faqTab) + } return navLinks } diff --git a/src/helpers/templates.js b/src/helpers/templates.js index b2f17a83e..3eb96d6e1 100644 --- a/src/helpers/templates.js +++ b/src/helpers/templates.js @@ -177,3 +177,16 @@ export function getProjectTypeByAlias(projectTypes, alias) { projectType.aliases[0] === alias ) || null } + + + +/** + * Finds whether the template supports FAQ or not + * + * @param {Object} projectTemplate a project template object + * + * @return {Boolean} boolean true/false + */ +export function containsFAQ(projectTemplate) { + return projectTemplate && projectTemplate.metadata && !_.isEmpty(projectTemplate.metadata) && projectTemplate.metadata.contentful && projectTemplate.metadata.contentful.projectFaqId +} \ No newline at end of file diff --git a/src/projects/detail/containers/ProjectInfoContainer.js b/src/projects/detail/containers/ProjectInfoContainer.js index cc86cd0fc..f4d252ecc 100644 --- a/src/projects/detail/containers/ProjectInfoContainer.js +++ b/src/projects/detail/containers/ProjectInfoContainer.js @@ -10,6 +10,7 @@ import { loadDashboardFeeds, loadProjectMessages } from '../../actions/projectTo import { loadTopic } from '../../../actions/topics' import { loadProjectPlan } from '../../actions/projectPlan' import { getProjectNavLinks } from '../../../helpers/projectHelper' +import { getProjectTemplateByKey, containsFAQ } from '../../../helpers/templates' import { PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, @@ -450,7 +451,14 @@ class ProjectInfoContainer extends React.Component { const notReadPhaseNotifications = filterTopicAndPostChangedNotifications(projectNotReadNotifications, /^phase#\d+$/) const notReadAssetsNotifications = filterFileAndLinkChangedNotifications(projectNotReadNotifications) - const navLinks = getProjectNavLinks(project, project.id).map((navLink) => { + const projectTemplateId = project.templateId + const projectTemplateKey = _.get(project, 'details.products[0]') + const projectTemplate = projectTemplateId + ? _.find(projectTemplates, pt => pt.id === projectTemplateId) + : getProjectTemplateByKey(projectTemplates, projectTemplateKey) + + const renderFAQs = containsFAQ(projectTemplate) + const navLinks = getProjectNavLinks(project, project.id, renderFAQs).map((navLink) => { if (navLink.label === 'Messages') { navLink.count = notReadMessageNotifications.length navLink.toolTipText = 'New messages'