diff --git a/src/components/Dashboard/DashboardData.js b/src/components/Dashboard/DashboardData.js index 0bb86e80..cb98db74 100644 --- a/src/components/Dashboard/DashboardData.js +++ b/src/components/Dashboard/DashboardData.js @@ -3,9 +3,12 @@ import { useParams } from 'react-router-dom' // FPCC import { useUserStore } from 'context/UserContext' import { useSiteStore } from 'context/SiteContext' -import { ASSISTANT, LANGUAGE_ADMIN, MEMBER } from 'common/constants/roles' +import { EDITOR, LANGUAGE_ADMIN, MEMBER } from 'common/constants/roles' import { useMySites } from 'common/dataHooks/useMySites' import useLoginLogout from 'common/hooks/useLoginLogout' +import { TYPES, TYPE_WORD, TYPE_PHRASE } from 'common/constants' +import DashboardEditData from 'components/DashboardEdit/DashboardEditData' +import DashboardCreateData from 'components/DashboardCreate/DashboardCreateData' function DashboardData() { const { user } = useUserStore() @@ -29,47 +32,23 @@ function DashboardData() { sites: userSitesData, } + const { createTiles } = DashboardCreateData({ urlPrefix: 'create' }) + const { editTiles } = DashboardEditData({ urlPrefix: 'edit' }) + const homeTiles = [ - { - icon: 'Widget', - name: 'Create a Widget', - description: "Add a new Widget to your site's collection", - href: 'create/widget', - iconColor: 'wordText', - auth: LANGUAGE_ADMIN, - }, - { - icon: 'WebPages', - name: 'Custom Pages', - description: 'Manage all custom pages on your site', - href: 'edit/pages', - iconColor: 'phraseText', - auth: LANGUAGE_ADMIN, - }, - { - icon: 'Home', - name: 'Edit Your Homepage', - description: 'Edit the main homepage for your site', - href: 'edit/home', - iconColor: 'wordText', - auth: LANGUAGE_ADMIN, - }, - { - icon: 'Word', - name: 'Create a Word', - description: 'Add a new word to your dictionary', - href: 'create/word', - iconColor: 'wordText', - auth: ASSISTANT, - }, + createTiles.WORD, + createTiles.PHRASE, { icon: 'Phrase', - name: 'Create a Phrase', - description: 'Add a new phrase to your dictionary', - href: 'create/phrase', - iconColor: 'phraseText', - auth: ASSISTANT, + name: 'Edit Words and Phrases', + description: 'Edit the words and phrases in your dictionary', + href: `edit/entries?${TYPES}=${TYPE_WORD},${TYPE_PHRASE}`, + iconColor: 'storyText', + auth: EDITOR, }, + createTiles.WIDGET, + editTiles.PAGES, + editTiles.HOMEPAGE, { icon: 'QuestionCircleSolid', name: 'Support', diff --git a/src/components/DashboardCreate/DashboardCreateContainer.js b/src/components/DashboardCreate/DashboardCreateContainer.js index 7d87b848..d0a49732 100644 --- a/src/components/DashboardCreate/DashboardCreateContainer.js +++ b/src/components/DashboardCreate/DashboardCreateContainer.js @@ -17,7 +17,9 @@ import { TYPE_PHRASE, TYPE_WORD } from 'common/constants' import { ASSISTANT, EDITOR, LANGUAGE_ADMIN } from 'common/constants/roles' function DashboardCreateContainer() { - const { tileContent, headerContent, site } = DashboardCreateData() + const { tileContent, headerContent, site } = DashboardCreateData({ + urlPrefix: '', + }) return (
diff --git a/src/components/DashboardCreate/DashboardCreateData.js b/src/components/DashboardCreate/DashboardCreateData.js index bf89ac45..e0f67c18 100644 --- a/src/components/DashboardCreate/DashboardCreateData.js +++ b/src/components/DashboardCreate/DashboardCreateData.js @@ -2,74 +2,93 @@ import { useSiteStore } from 'context/SiteContext' import { ASSISTANT, EDITOR, LANGUAGE_ADMIN } from 'common/constants/roles' -function DashboardCreateData() { +function DashboardCreateData({ urlPrefix = '' }) { const { site } = useSiteStore() - const tileContent = [ - { + function addUrlPrefix(href) { + if (!urlPrefix) { + return href + } + + return [urlPrefix, href].join('/') + } + + const createTiles = { + WORD: { icon: 'Word', name: 'Create a Word', description: 'Add a new word to your dictionary', - href: 'word', + href: addUrlPrefix('word'), iconColor: 'wordText', auth: ASSISTANT, }, - { + PHRASE: { icon: 'Phrase', name: 'Create a Phrase', description: 'Add a new phrase to your dictionary', - href: 'phrase', + href: addUrlPrefix('phrase'), iconColor: 'phraseText', auth: ASSISTANT, }, - { - icon: 'WebPages', - name: 'Create a Custom Page', - description: 'Add a new page to your site', - href: 'page', - iconColor: 'wordText', - auth: LANGUAGE_ADMIN, - }, - { - icon: 'Widget', - name: 'Create a Widget', - description: "Add a new Widget to your site's collection", - href: 'widget', - iconColor: 'wordText', - auth: LANGUAGE_ADMIN, - }, - { + SONG: { icon: 'Song', name: 'Create a Song', description: 'Add a new song to your site', - href: 'song', + href: addUrlPrefix('song'), iconColor: 'songText', auth: ASSISTANT, }, - { + STORY: { icon: 'Story', name: 'Create a Story', description: 'Add a new story to your site', - href: 'story', + href: addUrlPrefix('story'), iconColor: 'storyText', auth: ASSISTANT, }, - { + SPEAKER: { + icon: 'Speak', + name: 'Add a Speaker', + description: 'Add a new speaker to your site', + href: addUrlPrefix('speaker'), + iconColor: 'storyText', + auth: EDITOR, + }, + CATEGORY: { icon: 'Category', name: 'Add a Category', description: 'Add a new category to your dictionary', - href: 'category', - iconColor: 'wordText', + href: addUrlPrefix('category'), + iconColor: 'tertiaryB', auth: LANGUAGE_ADMIN, }, - { - icon: 'Speak', - name: 'Add a Speaker', - description: 'Add a new speaker to your site', - href: 'speaker', - iconColor: 'wordText', - auth: EDITOR, + WIDGET: { + icon: 'Widget', + name: 'Create a Widget', + description: "Add a new Widget to your site's collection", + href: addUrlPrefix('widget'), + iconColor: 'songText', + auth: LANGUAGE_ADMIN, + }, + PAGE: { + icon: 'WebPages', + name: 'Create a Custom Page', + description: 'Add a new page to your site', + href: addUrlPrefix('page'), + iconColor: 'tertiaryA', + auth: LANGUAGE_ADMIN, }, + } + + const tileContent = [ + createTiles.WORD, + createTiles.PHRASE, + createTiles.SONG, + createTiles.STORY, + createTiles.SPEAKER, + createTiles.CATEGORY, + createTiles.WIDGET, + createTiles.PAGE, ] const headerContent = { title: 'Create', @@ -81,6 +100,7 @@ function DashboardCreateData() { headerContent, site, tileContent, + createTiles, } } diff --git a/src/components/DashboardEdit/DashboardEditContainer.js b/src/components/DashboardEdit/DashboardEditContainer.js index 6fc4d0a2..b45faa0a 100644 --- a/src/components/DashboardEdit/DashboardEditContainer.js +++ b/src/components/DashboardEdit/DashboardEditContainer.js @@ -27,7 +27,9 @@ import DashboardWidgets from 'components/DashboardWidgets' import { EDITOR, LANGUAGE_ADMIN } from 'common/constants/roles' function DashboardEditContainer() { - const { tileContent, headerContent, site } = DashboardEditData() + const { tileContent, headerContent, site } = DashboardEditData({ + urlPrefix: '', + }) return (
diff --git a/src/components/DashboardEdit/DashboardEditData.js b/src/components/DashboardEdit/DashboardEditData.js index 938b1dac..7c88ceef 100644 --- a/src/components/DashboardEdit/DashboardEditData.js +++ b/src/components/DashboardEdit/DashboardEditData.js @@ -1,86 +1,121 @@ // FPCC import { useSiteStore } from 'context/SiteContext' -import { TYPES, TYPE_DICTIONARY, TYPE_SONG, TYPE_STORY } from 'common/constants' +import { + TYPES, + TYPE_WORD, + TYPE_PHRASE, + TYPE_SONG, + TYPE_STORY, +} from 'common/constants' import { EDITOR, LANGUAGE_ADMIN } from 'common/constants/roles' -function DashboardEditData() { +function DashboardEditData({ urlPrefix = '' }) { const { site } = useSiteStore() - const tileContent = [ - { + function addUrlPrefix(href) { + if (!urlPrefix) { + return href + } + + return [urlPrefix, href].join('/') + } + + const editTiles = { + WORDS: { + icon: 'Word', + name: 'Edit Words', + description: 'Edit the words in your dictionary', + href: addUrlPrefix(`entries?${TYPES}=${TYPE_WORD}`), + iconColor: 'wordText', + auth: EDITOR, + }, + PHRASES: { icon: 'Phrase', - name: 'Edit Words and Phrases', - description: 'Edit the words and phrases in your dictionary', - href: `entries?${TYPES}=${TYPE_DICTIONARY}`, + name: 'Edit Phrases', + description: 'Edit the phrases in your dictionary', + href: addUrlPrefix(`entries?${TYPES}=${TYPE_PHRASE}`), iconColor: 'phraseText', auth: EDITOR, }, - { + SONGS: { icon: 'Song', name: 'Edit Songs', description: 'Edit the songs on your site', - href: `entries?${TYPES}=${TYPE_SONG}`, + href: addUrlPrefix(`entries?${TYPES}=${TYPE_SONG}`), iconColor: 'songText', auth: EDITOR, }, - { + STORIES: { icon: 'Story', name: 'Edit Stories', description: 'Edit the stories on your site', - href: `entries?${TYPES}=${TYPE_STORY}`, + href: addUrlPrefix(`entries?${TYPES}=${TYPE_STORY}`), iconColor: 'storyText', auth: EDITOR, }, - { - icon: 'Home', - name: 'Edit Homepage', - description: 'Edit the main homepage for your site', - href: 'home', - iconColor: 'wordText', - auth: LANGUAGE_ADMIN, + SPEAKERS: { + icon: 'Speak', + name: 'Edit Speakers', + description: 'Edit the speakers on your site', + href: addUrlPrefix('speakers'), + iconColor: 'storyText', + auth: EDITOR, }, - { - icon: 'WebPages', - name: 'Edit Custom Pages', - description: 'Manage and edit the custom pages on your site', - href: 'pages', - iconColor: 'tertiaryA', + CATEGORIES: { + icon: 'Categories', + name: 'Edit Categories', + description: + 'Edit the categories for words and phrases in your dictionary', + href: addUrlPrefix('categories'), + iconColor: 'tertiaryB', auth: LANGUAGE_ADMIN, }, - { + WIDGETS: { icon: 'Widget', name: 'Edit Widgets', description: 'Manage and edit the Widgets on your site', - href: 'widgets', + href: addUrlPrefix('widgets'), iconColor: 'songText', auth: LANGUAGE_ADMIN, }, - { - icon: 'Categories', - name: 'Edit Categories', - description: - 'Edit the categories for words and phrases in your dictionary', - href: 'categories', - iconColor: 'tertiaryB', + PAGES: { + icon: 'WebPages', + name: 'Edit Custom Pages', + description: 'Manage and edit the custom pages on your site', + href: addUrlPrefix('pages'), + iconColor: 'tertiaryA', auth: LANGUAGE_ADMIN, }, - { - icon: 'Speak', - name: 'Edit Speakers', - description: 'Edit the speakers on your site', - href: 'speakers', - iconColor: 'storyText', - auth: EDITOR, + HOMEPAGE: { + icon: 'Home', + name: 'Edit Homepage', + description: 'Edit the main homepage for your site', + href: addUrlPrefix('home'), + iconColor: 'wordText', + auth: LANGUAGE_ADMIN, }, - { + ALPHABET: { icon: 'Alphabet', name: 'Edit your Alphabet', description: 'Update media and linked content for your alphabet characters', - href: 'alphabet', + href: addUrlPrefix('alphabet'), iconColor: 'primary', auth: LANGUAGE_ADMIN, }, + } + + const tileContent = [ + editTiles.WORDS, + editTiles.PHRASES, + editTiles.SONGS, + editTiles.STORIES, + editTiles.SPEAKERS, + editTiles.CATEGORIES, + editTiles.WIDGETS, + editTiles.PAGES, + editTiles.HOMEPAGE, + editTiles.ALPHABET, // Temp. hiding for FW-4514. // { // icon: 'Translate', @@ -101,6 +136,7 @@ function DashboardEditData() { headerContent, site, tileContent, + editTiles, } } diff --git a/src/components/DashboardTiles/DashboardTilesPresentation.js b/src/components/DashboardTiles/DashboardTilesPresentation.js index 471146d5..f8c1185e 100644 --- a/src/components/DashboardTiles/DashboardTilesPresentation.js +++ b/src/components/DashboardTiles/DashboardTilesPresentation.js @@ -8,46 +8,38 @@ import RequireAuth from 'common/RequireAuth' import { MEMBER } from 'common/constants/roles' function DashboardTilesPresentation({ tileContent }) { + const tileCount = tileContent.length + const rowSize = Math.min(tileCount, 4) + const topLeft = 0 + const topRight = Math.min(rowSize - 1, tileCount - 1) + const bottomLeft = Math.floor(tileCount / rowSize - 1 / rowSize) * rowSize + const bottomRight = tileCount - 1 + const tileClass = (index) => { const baseClass = 'relative group bg-white p-5 focus-within:ring-2 focus-within:ring-inset focus-within:ring-secondary' - if (tileContent?.length === 1) { - return `${baseClass} rounded-lg` - } - if ( - (tileContent.length % 3 === 0 && index === 1) || - (tileContent.length % 3 === 0 && index === tileContent.length - 2) - ) { - return baseClass - } - if (index === tileContent.length - 2) { - return `${baseClass} rounded-bl-lg` + + let tileStyle = baseClass + if (index === topLeft) { + tileStyle += ' rounded-tl-lg' } - if (index === tileContent.length - 1) { - return `${baseClass} rounded-br-lg` + if (index === topRight) { + tileStyle += ' rounded-tr-lg' } - if (index === 0) { - return `${baseClass} rounded-tl-lg` + if (index === bottomLeft) { + tileStyle += ' rounded-bl-lg' } - if (index === 1) { - return `${baseClass} rounded-tr-lg` + if (index === bottomRight) { + tileStyle += ' rounded-br-lg' } - return baseClass - } - const gridClass = () => { - const numberOfTiles = tileContent?.length - switch (numberOfTiles) { - case 1: - return 'max-w-lg rounded-lg bg-gray-200 overflow-hidden shadow' - case 2: - return 'divide-y divide-gray-200 sm:divide-y-0 sm:grid sm:grid-cols-2 sm:gap-px rounded-lg bg-gray-200 overflow-hidden shadow' - case 3: - return 'divide-y divide-gray-200 sm:divide-y-0 sm:grid sm:grid-cols-3 sm:gap-px rounded-lg bg-gray-200 overflow-hidden shadow' - default: - return 'divide-y divide-gray-200 sm:divide-y-0 sm:grid sm:grid-cols-4 sm:gap-px rounded-lg bg-gray-200 overflow-hidden shadow' - } + return tileStyle } + + const gridClass = () => + tileCount === 1 + ? 'max-w-lg rounded-lg bg-gray-200 overflow-hidden shadow' + : `divide-y divide-gray-200 sm:divide-y-0 sm:grid sm:grid-cols-${rowSize} sm:gap-px rounded-lg bg-gray-200 overflow-hidden shadow` return (