Skip to content

Commit

Permalink
SKY30-495 - Info about terrestrial protected area
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprdhomme committed Oct 18, 2024
1 parent 3ebbc80 commit e193300
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
13 changes: 10 additions & 3 deletions frontend/src/components/terrestrial-data-disclaimer-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ import {
import Icon from '@/components/ui/icon';
import { terrestrialDataDisclaimerDialogAtom } from '@/containers/map/store';
import Notification from '@/styles/icons/notification.svg';
import { FCWithMessages } from '@/types';

interface TerrestrialDataDisclaimerDialogProps {}
interface TerrestrialDataDisclaimerDialogProps {
onClose?: () => void;
}

const TerrestrialDataDisclaimerDialog = ({}: TerrestrialDataDisclaimerDialogProps) => {
const TerrestrialDataDisclaimerDialog: FCWithMessages<TerrestrialDataDisclaimerDialogProps> = ({
onClose,
}) => {
const t = useTranslations('pages.progress-tracker');
const [, setOpen] = useAtom(terrestrialDataDisclaimerDialogAtom);

Expand All @@ -39,7 +44,7 @@ const TerrestrialDataDisclaimerDialog = ({}: TerrestrialDataDisclaimerDialogProp
<Button
type="button"
className="font-mono text-xs font-normal normal-case"
onClick={() => setOpen(false)}
onClick={() => (onClose ? onClose() : setOpen(false))}
>
{t('i-understand')}
</Button>
Expand All @@ -49,4 +54,6 @@ const TerrestrialDataDisclaimerDialog = ({}: TerrestrialDataDisclaimerDialogProp
);
};

TerrestrialDataDisclaimerDialog.messages = ['pages.progress-tracker'];

export default TerrestrialDataDisclaimerDialog;
15 changes: 14 additions & 1 deletion frontend/src/containers/homepage/intro/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useState } from 'react';

import Image from 'next/image';

import { useLocale, useTranslations } from 'next-intl';

import TerrestrialDataDisclaimerDialog from '@/components/terrestrial-data-disclaimer-dialog';
import Icon from '@/components/ui/icon';
import SidebarItem from '@/containers/homepage/intro/sidebar-item';
import { formatPercentage } from '@/lib/utils/formats';
Expand All @@ -17,6 +20,8 @@ const Intro: FCWithMessages<IntroProps> = ({ onScrollClick }) => {
const t = useTranslations('containers.homepage-intro');
const locale = useLocale();

const [openDisclaimer, setOpenDisclaimer] = useState(false);

const { data: protectionStatsData } = useGetProtectionCoverageStats<{
marine?: string;
terrestrial?: string;
Expand Down Expand Up @@ -117,7 +122,11 @@ const Intro: FCWithMessages<IntroProps> = ({ onScrollClick }) => {
percentage={protectionStatsData.terrestrial}
text={t('current-total-protected-area')}
icon="icon2"
onClickInfoButton={() => setOpenDisclaimer(true)}
/>
{openDisclaimer && (
<TerrestrialDataDisclaimerDialog onClose={() => setOpenDisclaimer(false)} />
)}
<div className="flex h-full w-full justify-center">
<button
type="button"
Expand All @@ -134,6 +143,10 @@ const Intro: FCWithMessages<IntroProps> = ({ onScrollClick }) => {
);
};

Intro.messages = ['containers.homepage-intro', ...SidebarItem.messages];
Intro.messages = [
'containers.homepage-intro',
...SidebarItem.messages,
...TerrestrialDataDisclaimerDialog.messages,
];

export default Intro;
27 changes: 24 additions & 3 deletions frontend/src/containers/homepage/intro/sidebar-item/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Image from 'next/image';

import { Info } from 'lucide-react';
import { useTranslations } from 'next-intl';

import { Button } from '@/components/ui/button';
import { FCWithMessages } from '@/types';

const ICONS = {
Expand All @@ -13,16 +15,35 @@ type SidebarItemProps = {
text: string;
percentage: number | string;
icon?: keyof typeof ICONS;
onClickInfoButton?: () => void;
};

const SidebarItem: FCWithMessages<SidebarItemProps> = ({ text, percentage, icon = 'icon1' }) => {
const SidebarItem: FCWithMessages<SidebarItemProps> = ({
text,
percentage,
icon = 'icon1',
onClickInfoButton,
}) => {
const t = useTranslations('containers.homepage-intro');

return (
<div className="flex flex-row gap-6 border-b border-white px-10 py-6">
<div className="flex flex-1 flex-col gap-2 font-mono">
<span className="text-6xl font-light">{percentage}%</span>
<span className="text-xs">{text}</span>
<div className="text-6xl font-light">{percentage}%</div>
<div className="text-xs">
{text}
{!!onClickInfoButton && (
<Button
className="ml-1.5 h-auto w-auto align-middle hover:bg-transparent hover:text-white"
size="icon"
variant="ghost"
onClick={onClickInfoButton}
>
<span className="sr-only">{t('info')}</span>
<Info className="h-4 w-4" aria-hidden="true" />
</Button>
)}
</div>
</div>
<div className="items-en flex w-[64px] items-end">
<Image
Expand Down
3 changes: 2 additions & 1 deletion frontend/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
"product-powered-by": "Product powered by",
"current-ocean-protected-area": "Current global ocean protected area",
"current-total-protected-area": "Current global land and inland waters protected area",
"statistics-icon": "Statistics icon"
"statistics-icon": "Statistics icon",
"info": "Info"
},
"homepage-link-cards": {
"card-1-title": "Progress Tracker",
Expand Down

0 comments on commit e193300

Please sign in to comment.