Skip to content

Commit

Permalink
feat: add ecosystem and eligible activity tags to credit class page (#…
Browse files Browse the repository at this point in the history
…1965)

* feat: add useTags hook

* feat: use ProjectTopCard on class page

* refactor: rename ProjectTopCard to ImpactTags
  • Loading branch information
blushi authored Jul 12, 2023
1 parent 17a6120 commit 2ab0796
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 147 deletions.
61 changes: 0 additions & 61 deletions web-components/src/components/cards/ProjectTopCard.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions web-components/src/components/cards/card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { QuestionItem } from '../faq/Question';
import CurrentCreditsIcon from '../icons/CurrentCreditsIcon';
import FarmerIcon from '../icons/FarmerIcon';
import TrustIcon from '../icons/TrustIcon';
import { User } from '../user/UserInfo';
import Card from './Card';
import GlanceCard from './GlanceCard';
import GreenCard from './GreenCard';
Expand All @@ -19,8 +18,6 @@ import OnBoardingCard from './OnBoardingCard';
import { OverviewCard } from './OverviewCard';
import ProjectCard from './ProjectCard';
import ProjectImpactCard from './ProjectImpactCard/ProjectImpactCard';
import ProjectTopCard from './ProjectTopCard';
// import CreditCard, { CreditInfo } from './CreditCard';
import PurchasedCreditsCard from './PurchasedCreditsCard';
import ResourcesCard from './ResourcesCard';
import { ReviewCard } from './ReviewCard';
Expand All @@ -33,25 +30,6 @@ export default {
component: Card,
};

export const projectTopCard = (): JSX.Element => (
<ProjectTopCard
impact={[
{
name: 'Reforestation',
imgSrc: '/illustrations/reforestation.png',
sdgs: [
{ src: '/sdgs/sdg3.svg', alt: 'sdg3' },
{ src: '/sdgs/sdg4.svg', alt: 'sdg4' },
{ src: '/sdgs/sdg8.svg', alt: 'sdg8' },
],
standard:
'https://regen-registry.s3.amazonaws.com/projects/kasigau/VCS.png',
monitored: true,
},
]}
/>
);

export const impactCard = (): JSX.Element => (
<ImpactCard
name="name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';

import { ImpactTags } from './ImpactTags';

export default {
title: 'organisms/ImpactTags',
component: ImpactTags,
} as ComponentMeta<typeof ImpactTags>;

const Template: ComponentStory<typeof ImpactTags> = args => (
<ImpactTags {...args} />
);

export const Default = Template.bind({});

Default.args = {
impact: [
{
name: 'Reforestation',
imgSrc: '/illustrations/reforestation.png',
sdgs: [
{ src: '/sdgs/sdg3.svg', alt: 'sdg3' },
{ src: '/sdgs/sdg4.svg', alt: 'sdg4' },
{ src: '/sdgs/sdg8.svg', alt: 'sdg8' },
],
standard:
'https://regen-registry.s3.amazonaws.com/projects/kasigau/VCS.png',
monitored: true,
},
],
ecosystems: [
{
name: 'Urban Forest',
icon: { src: '/icons/urban-forest.svg' },
},
],
activities: [
{
name: 'Tree Preservation',
icon: { src: '/icons/tree-preservation.svg' },
},
],
};
61 changes: 61 additions & 0 deletions web-components/src/components/organisms/ImpactTags/ImpactTags.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Box, SxProps } from '@mui/material';

import { Theme } from '../../../theme/muiTheme';
import { sxToArray } from '../../../utils/mui/sxToArray';
import ProjectImpactCard, {
ProjectImpactCardProps,
} from '../../cards/ProjectImpactCard/ProjectImpactCard';
import { ProjectTagType } from '../../molecules/ProjectTag/ProjectTag.types';
import { CollapseList } from '../../organisms/CollapseList/CollapseList';
import { ProjectTags } from '../../organisms/ProjectTags/ProjectTags';

export interface Props {
classes?: {
root?: string;
};
activities?: ProjectTagType[];
ecosystems?: ProjectTagType[];
impact: ProjectImpactCardProps[];
sx?: SxProps<Theme>;
activitiesLabel?: string;
}

const ImpactTags = ({
activities,
ecosystems,
impact,
sx,
activitiesLabel,
}: Props) => (
<Box
sx={[
{
display: 'flex',
flexDirection: 'column',
maxWidth: 367,
},
...sxToArray(sx),
]}
>
<CollapseList
sx={{ pb: [7.5, 10] }}
items={impact.map(imp => (
<Box key={imp.name} sx={{ pb: [2.5, 4.25] }}>
<ProjectImpactCard {...imp} />
</Box>
))}
/>
{(activities || ecosystems) && (
<ProjectTags
activities={activities}
ecosystems={ecosystems}
sx={{
mb: 5,
}}
activitiesLabel={activitiesLabel}
/>
)}
</Box>
);

export { ImpactTags };
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export interface Props {
activities?: ProjectTagType[];
ecosystems?: ProjectTagType[];
sx?: SxProps<Theme>;
activitiesLabel?: string;
}

const ProjectTags = ({
activities = [],
ecosystems = [],
sx = [],
activitiesLabel = PROJECT_ACTIVITY_LABEL,
}: Props): JSX.Element => {
const hasActivities = activities.length > 0;
const hasManyActivities = activities.length > 1;
Expand All @@ -46,9 +48,7 @@ const ProjectTags = ({
mb: { xs: 10, sm: hasManyTags ? 10 : 0 },
}}
>
<Label sx={{ fontSize: { xs: 11 }, mb: 2 }}>
{PROJECT_ACTIVITY_LABEL}
</Label>
<Label sx={{ fontSize: { xs: 11 }, mb: 2 }}>{activitiesLabel}</Label>
<Box
sx={{
display: 'flex',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { useQuery } from '@tanstack/react-query';
import { TRANSPARENT_PIXEL } from 'utils/image/transparentPixel';

import GlanceCard from 'web-components/lib/components/cards/GlanceCard';
import ProjectTopCard from 'web-components/lib/components/cards/ProjectTopCard';
import { ActionCard } from 'web-components/lib/components/molecules/ActionCard/ActionCard';
import { ProjectTagType } from 'web-components/lib/components/molecules/ProjectTag/ProjectTag.types';
import { RoundLogoItemsList } from 'web-components/lib/components/molecules/RoundLogoItemsList/RoundLogoItemsList';
import { ImpactTags } from 'web-components/lib/components/organisms/ImpactTags/ImpactTags';
import ProjectPlaceInfo from 'web-components/lib/components/place/ProjectPlaceInfo';
import Section from 'web-components/lib/components/section';
import { Body, Label, Title } from 'web-components/lib/components/typography';
Expand All @@ -17,10 +16,8 @@ import { client as sanityClient } from 'lib/clients/sanity';
import { CreditClassMetadataLD } from 'lib/db/types/json-ld';
import { getSanityImgSrc } from 'lib/imgSrc';
import { getCreditTypeQuery } from 'lib/queries/react-query/ecocredit/getCreditTypeQuery/getCreditTypeQuery';
import { getAllActivityQuery } from 'lib/queries/react-query/sanity/getAllActivityQuery/getAllActivityQuery';
import { getAllCreditCertificationQuery } from 'lib/queries/react-query/sanity/getAllCreditCertificationQuery/getAllCreditCertificationQuery';
import { getAllCreditTypeQuery } from 'lib/queries/react-query/sanity/getAllCreditTypeQuery/getAllCreditTypeQuery';
import { getAllEcosystemQuery } from 'lib/queries/react-query/sanity/getAllEcosystemQuery/getAllEcosystemQuery';
import { getAllOffsetMethodQuery } from 'lib/queries/react-query/sanity/getAllOffsetMethodQuery/getAllOffsetMethodQuery';
import { getAllProjectRatingQuery } from 'lib/queries/react-query/sanity/getAllProjectRatingQuery/getAllProjectRatingQuery';

Expand All @@ -29,6 +26,7 @@ import {
IMAGE_STORAGE_BASE_URL,
MAPBOX_TOKEN,
} from 'components/templates/ProjectDetails/ProjectDetails.config';
import { useTags } from 'hooks/useTags';

import useImpact from '../../../pages/CreditClassDetails/hooks/useImpact';
import { ProjectBatchTotals } from '../../molecules';
Expand Down Expand Up @@ -102,21 +100,10 @@ function ProjectTopSection({
creditType =>
creditType.name?.toLowerCase() === creditTypeData?.creditType?.name,
);

const { data: sanityOffsetMethodData } = useQuery(
getAllOffsetMethodQuery({ sanityClient, enabled: !!sanityClient }),
);

const { data: allProjectActivityData } = useQuery(
getAllActivityQuery({
sanityClient,
}),
);
const { data: allProjectEcosystemData } = useQuery(
getAllEcosystemQuery({
sanityClient,
}),
);
const { data: allProjectRatingData } = useQuery(
getAllProjectRatingQuery({
sanityClient,
Expand All @@ -128,12 +115,6 @@ function ProjectTopSection({
}),
);

const projectActivityIconsMapping = getIconsMapping({
data: allProjectActivityData?.allProjectActivity,
});
const projectEcosystemIconsMapping = getIconsMapping({
data: allProjectEcosystemData?.allProjectEcosystem,
});
const projectRatingIconsMapping = getIconsMapping({
data: allProjectRatingData?.allProjectRating,
});
Expand Down Expand Up @@ -168,25 +149,11 @@ function ProjectTopSection({

const projectActivity =
projectMetadata?.['regen:projectActivity']?.['schema:name'];
const activityTags: ProjectTagType[] | undefined = projectActivity
? [
{
name: projectActivity,
icon: {
src: projectActivityIconsMapping?.[projectActivity] ?? '',
},
},
]
: undefined;

const ecosystemTags: ProjectTagType[] | undefined = creditClassMetadata?.[
'regen:ecosystemType'
]?.map(ecosystem => ({
name: ecosystem,
icon: {
src: projectEcosystemIconsMapping?.[ecosystem] ?? '',
},
}));
const ecosystemTypes = creditClassMetadata?.['regen:ecosystemType'];
const { activityTags, ecosystemTags } = useTags({
activities: projectActivity ? [projectActivity] : undefined,
ecosystemTypes,
});

const impact = useImpact({ coBenefitsIRIs, primaryImpactIRI });
const hasStandardLogo = impact.some(item => !!item.standard);
Expand Down Expand Up @@ -286,8 +253,8 @@ function ProjectTopSection({
</div>
)}
</Grid>
<Grid item xs={12} md={4} sx={{ pt: { xs: 10, sm: 'inherit' } }}>
<ProjectTopCard
<Grid item xs={12} md={4} sx={{ pt: { xs: 10, sm: 5 } }}>
<ImpactTags
activities={activityTags}
ecosystems={ecosystemTags}
impact={impact.map(
Expand Down
53 changes: 53 additions & 0 deletions web-registry/src/hooks/useTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useQuery } from '@tanstack/react-query';

import { ProjectTagType } from 'web-components/lib/components/molecules/ProjectTag/ProjectTag.types';

import { client as sanityClient } from 'lib/clients/sanity';
import { getAllActivityQuery } from 'lib/queries/react-query/sanity/getAllActivityQuery/getAllActivityQuery';
import { getAllEcosystemQuery } from 'lib/queries/react-query/sanity/getAllEcosystemQuery/getAllEcosystemQuery';

import { getIconsMapping } from 'components/organisms/ProjectTopSection/ProjectTopSection.utils';

type Params = {
activities: string[] | undefined;
ecosystemTypes: string[] | undefined;
};

export const useTags = ({ activities, ecosystemTypes }: Params) => {
const { data: allProjectActivityData } = useQuery(
getAllActivityQuery({
sanityClient,
}),
);
const { data: allProjectEcosystemData } = useQuery(
getAllEcosystemQuery({
sanityClient,
}),
);
const projectActivityIconsMapping = getIconsMapping({
data: allProjectActivityData?.allProjectActivity,
});
const projectEcosystemIconsMapping = getIconsMapping({
data: allProjectEcosystemData?.allProjectEcosystem,
});
const activityTags: ProjectTagType[] | undefined = activities?.map(
activity => ({
name: activity,
icon: { src: projectActivityIconsMapping?.[activity] ?? '' },
}),
);

const ecosystemTags: ProjectTagType[] | undefined = ecosystemTypes?.map(
ecosystem => ({
name: ecosystem,
icon: {
src: projectEcosystemIconsMapping?.[ecosystem] ?? '',
},
}),
);

return {
ecosystemTags,
activityTags,
};
};
Loading

0 comments on commit 2ab0796

Please sign in to comment.