diff --git a/canopeum_frontend/src/components/inputs/ToggleSwitch.tsx b/canopeum_frontend/src/components/inputs/ToggleSwitch.tsx new file mode 100644 index 000000000..ebdb2836f --- /dev/null +++ b/canopeum_frontend/src/components/inputs/ToggleSwitch.tsx @@ -0,0 +1,26 @@ +type Props = { + readonly text: string, + readonly checked: boolean, + readonly onChange: (checked: boolean) => void, + readonly additionalClassNames?: string, +} + +const ToggleSwitch = ({ text, checked, onChange, additionalClassNames }: Props) => ( +
+ + onChange(event.target.checked)} + role='switch' + type='checkbox' + /> + +
+) + +export default ToggleSwitch diff --git a/canopeum_frontend/src/components/site/SiteSummaryCard.tsx b/canopeum_frontend/src/components/site/SiteSummaryCard.tsx index 87450cc91..592beb4e0 100644 --- a/canopeum_frontend/src/components/site/SiteSummaryCard.tsx +++ b/canopeum_frontend/src/components/site/SiteSummaryCard.tsx @@ -1,40 +1,73 @@ import headerLogo from '@assets/images/map/MARR4059.png' +import ToggleSwitch from '@components/inputs/ToggleSwitch' import PrimaryIconBadge from '@components/PrimaryIconBadge' import type { SiteSocial } from '@services/api' +import { useEffect, useState } from 'react' +import { useTranslation } from 'react-i18next' type Props = { + readonly viewMode: 'admin' | 'user' | 'visitor', readonly site: SiteSocial, } -const SiteSummaryCard = ({ site }: Props) => ( -
-
-
- {/* TODO: replace img source when backend offers an image endpoint */} - header logo -
-
-
-

{site.name}

-
- -

{site.type.en}

-
-

{site.description ?? ''}

-
-
- person - Sponsors: +const onFollowClick = () => { + // TODO implement follow here when backend is available +} + +const updateSiteIsPublic = async (_: boolean) => { + // TODO Implement site update when backend is ready +} +const SiteSummaryCard = ({ site, viewMode }: Props) => { + const { t } = useTranslation() + const [isPublic, setIsPublic] = useState(true) + + useEffect(() => void updateSiteIsPublic(isPublic), [isPublic]) + + return ( +
+
+
+ {/* TODO: replace img source when backend offers an image endpoint */} + header logo +
+
+
+
+

{site.name}

+ {viewMode === 'user' && ( + + )} + {viewMode === 'admin' && ( + + )}
-
- {site.sponsors.map(sponsorName => ( -
{sponsorName}
- ))} +
+ +

{site.type.en}

+
+

{site.description ?? ''}

+
+
+ person + {t('mapSite.siteSummaryCard.sponsors')}: +
+
+ {site.sponsors.map(sponsorName => ( +
{sponsorName}
+ ))} +
-
-) + ) +} export default SiteSummaryCard diff --git a/canopeum_frontend/src/locale/en/index.ts b/canopeum_frontend/src/locale/en/index.ts index 828df9019..f995f17d8 100644 --- a/canopeum_frontend/src/locale/en/index.ts +++ b/canopeum_frontend/src/locale/en/index.ts @@ -1,10 +1,12 @@ import analyticsJSON from './analytics.json' import homeJSON from './home.json' +import mapSiteJSON from './mapSite.json' const enJSON = { translation: { home: { ...homeJSON }, analytics: { ...analyticsJSON }, + mapSite: { ...mapSiteJSON }, }, } diff --git a/canopeum_frontend/src/locale/en/mapSite.json b/canopeum_frontend/src/locale/en/mapSite.json new file mode 100644 index 000000000..1b1061934 --- /dev/null +++ b/canopeum_frontend/src/locale/en/mapSite.json @@ -0,0 +1,7 @@ +{ + "siteSummaryCard": { + "follow": "Follow", + "sponsors": "Sponsors", + "public": "Public" + } +} diff --git a/canopeum_frontend/src/locale/fr/index.ts b/canopeum_frontend/src/locale/fr/index.ts index dea64b48e..3bd6153ed 100644 --- a/canopeum_frontend/src/locale/fr/index.ts +++ b/canopeum_frontend/src/locale/fr/index.ts @@ -1,10 +1,12 @@ import analyticsJSON from './analytics.json' import homeJSON from './home.json' +import mapSiteJSON from './mapSite.json' const frJSON = { translation: { home: { ...homeJSON }, analytics: { ...analyticsJSON }, + mapSite: { ...mapSiteJSON }, }, } diff --git a/canopeum_frontend/src/locale/fr/mapSite.json b/canopeum_frontend/src/locale/fr/mapSite.json new file mode 100644 index 000000000..cf1924891 --- /dev/null +++ b/canopeum_frontend/src/locale/fr/mapSite.json @@ -0,0 +1,7 @@ +{ + "siteSummaryCard": { + "follow": "Suivre", + "sponsors": "Commanditaires", + "public": "Publique" + } +} diff --git a/canopeum_frontend/src/pages/MapSite.tsx b/canopeum_frontend/src/pages/MapSite.tsx index d8681a3e6..a577699be 100644 --- a/canopeum_frontend/src/pages/MapSite.tsx +++ b/canopeum_frontend/src/pages/MapSite.tsx @@ -1,15 +1,22 @@ +import { AuthenticationContext, UserRole } from '@components/context/AuthenticationContext' import SiteSummaryCard from '@components/site/SiteSummaryCard' import type { SiteSocial } from '@services/api' import api from '@services/apiInterface' import { ensureError } from '@services/errors' -import { useEffect, useState } from 'react' +import { useContext, useEffect, useState } from 'react' import { useParams } from 'react-router-dom' const MapSite = () => { const { siteId } = useParams() + const { currentUser } = useContext(AuthenticationContext) const [isLoadingSite, setIsLoadingSite] = useState(true) const [error, setError] = useState(undefined) const [site, setSite] = useState() + const viewMode = currentUser + ? currentUser.role === UserRole.RegularUser + ? 'user' + : 'admin' + : 'visitor' const fetchSiteData = async (parsedSiteId: number) => { setIsLoadingSite(true) @@ -41,7 +48,7 @@ const MapSite = () => {

{error.message}

) - : (site && )} + : (site && )}