-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ecosystem and eligible activity tags to credit class page (#…
…1965) * feat: add useTags hook * feat: use ProjectTopCard on class page * refactor: rename ProjectTopCard to ImpactTags
- Loading branch information
Showing
13 changed files
with
222 additions
and
147 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
web-components/src/components/organisms/ImpactTags/ImpactTags.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
61
web-components/src/components/organisms/ImpactTags/ImpactTags.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
Oops, something went wrong.