Skip to content

Commit

Permalink
feat: APP-508 show book call button on terrasos project bottom banner (
Browse files Browse the repository at this point in the history
  • Loading branch information
blushi authored Dec 3, 2024
1 parent f97c1c7 commit 7c5dc18
Show file tree
Hide file tree
Showing 12 changed files with 3,625 additions and 568 deletions.
3,690 changes: 3,145 additions & 545 deletions web-marketplace/sanity-graphql.schema.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function ProjectTopSection({
projectPrefinancing,
isSoldOut,
normalizedProject,
terrasosBookCall,
}: ProjectTopSectionProps): JSX.Element {
const { _ } = useLingui();
const { classes } = useProjectTopSectionStyles();
Expand Down Expand Up @@ -316,6 +317,7 @@ function ProjectTopSection({
projectPageMetadata={projectPageMetadata}
projectMetadata={projectMetadata}
complianceInfo={allComplianceInfo}
bookCall={terrasosBookCall}
isComplianceProject={isComplianceProject}
projectBatchTotals={
onChainProjectId && batchData?.totals ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AllCreditClassQuery,
ProjectPrefinancing,
SdgByIriQuery,
TerrasosBookCall,
} from 'generated/sanity-graphql';
import {
BatchInfoWithSupply,
Expand Down Expand Up @@ -47,6 +48,7 @@ export type ProjectTopSectionProps = {
projectPrefinancing?: ProjectPrefinancing | null;
isSoldOut: boolean;
normalizedProject?: NormalizeProject;
terrasosBookCall?: TerrasosBookCall;
};

export type SdgType = SdgByIriQuery['allSdg'][0];
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Params = {
onClickCreatePost?: () => void;
isCreatePostButtonDisabled?: boolean;
tooltipText?: string;
isTerrasos?: boolean;
};

export const SellOrdersActionsBar = ({
Expand All @@ -73,6 +74,7 @@ export const SellOrdersActionsBar = ({
onClickCreatePost,
isCreatePostButtonDisabled,
tooltipText,
isTerrasos,
}: Params): JSX.Element => {
const { _ } = useLingui();
const location = useLocation();
Expand Down Expand Up @@ -156,6 +158,7 @@ export const SellOrdersActionsBar = ({
</Box>
)}
{(!isCommunityCredit ||
isTerrasos ||
(!onChainProjectId && isPrefinanceProject)) && (
<OutlinedButton
onClick={onBookCallButtonClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import {
} from 'lib/constants/shared.constants';
import { CreditClassMetadataLD, ProjectMetadataLD } from 'lib/db/types/json-ld';
import { getBatchesTotal } from 'lib/ecocredit/api';
import { IS_REGEN } from 'lib/env';
import { IS_REGEN, IS_TERRASOS } from 'lib/env';
import { normalizeProjectWithMetadata } from 'lib/normalizers/projects/normalizeProjectsWithMetadata';
import { getGeocodingQuery } from 'lib/queries/react-query/mapbox/getGeocodingQuery/getGeocodingQuery';
import { getMetadataQuery } from 'lib/queries/react-query/registry-server/getMetadataQuery/getMetadataQuery';
import { getAllSanityCreditClassesQuery } from 'lib/queries/react-query/sanity/getAllCreditClassesQuery/getAllCreditClassesQuery';
import { getAllProjectPageQuery } from 'lib/queries/react-query/sanity/getAllProjectPageQuery/getAllProjectPageQuery';
import { getSoldOutProjectsQuery } from 'lib/queries/react-query/sanity/getSoldOutProjectsQuery/getSoldOutProjectsQuery';
import { getTerrasosBookCallQuery } from 'lib/queries/react-query/sanity/getTerrasosBookCallQuery/getTerrasosBookCallQuery';
import { useWallet } from 'lib/wallet/wallet';

import { CreateSellOrderFlow } from 'features/marketplace/CreateSellOrderFlow/CreateSellOrderFlow';
Expand Down Expand Up @@ -309,10 +310,22 @@ function ProjectDetails(): JSX.Element {
],
);

const { data: terrasosBookCallData } = useQuery(
getTerrasosBookCallQuery({
sanityClient,
languageCode: selectedLanguage,
enabled: !!sanityClient && IS_TERRASOS,
}),
);
const terrasosBookCall = terrasosBookCallData?.allTerrasosBookCall?.[0];

const projectPhotos = getProjectGalleryPhotos({ offChainProjectMetadata });
const hasProjectPhotos = projectPhotos.length > 0;
const onBookCallButtonClick = () =>
onBtnClick(() => void 0, sanityProjectPage?.otcCard?.button);
onBtnClick(
() => void 0,
IS_REGEN ? sanityProjectPage?.otcCard?.button : terrasosBookCall?.button,
);
const otcCard = formatOtcCardData({
data: sanityProjectPage?.otcCard,
isConnected,
Expand All @@ -338,6 +351,8 @@ function ProjectDetails(): JSX.Element {
projectBySlug?.data.projectBySlug?.published;
const projectLocation = projectMetadata?.['schema:location'];

const isTerrasos = normalizedProject.type === 'TerrasosProjectInfo';

if (noProjectFound) return <NotFoundPage />;

return (
Expand Down Expand Up @@ -377,6 +392,7 @@ function ProjectDetails(): JSX.Element {

{(onChainProjectId ||
isPrefinanceProject ||
isTerrasos ||
(isAdmin && !loginDisabled)) && (
<SellOrdersActionsBar
isBuyButtonDisabled={isBuyFlowDisabled || loadingSanityProject}
Expand Down Expand Up @@ -411,6 +427,7 @@ function ProjectDetails(): JSX.Element {
onClickCreatePost={openCreatePostModal}
isCreatePostButtonDisabled={!projectLocation || !isProjectPublished}
tooltipText={_(CREATE_POST_DISABLED_TOOLTIP_TEXT)}
isTerrasos={isTerrasos}
>
{!isAdmin &&
isPrefinanceProject &&
Expand Down Expand Up @@ -468,6 +485,7 @@ function ProjectDetails(): JSX.Element {
projectPrefinancing={projectPrefinancing}
isSoldOut={isSoldOut}
normalizedProject={normalizedProject}
terrasosBookCall={terrasosBookCall}
/>

{hasProjectPhotos && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { msg } from '@lingui/macro';
import { IconTabProps } from 'web-components/src/components/tabs/IconTab';
import { LinkType } from 'web-components/src/types/shared/linkType';

import { ComplianceInfoQuery } from 'generated/sanity-graphql';
import {
ComplianceInfoQuery,
TerrasosBookCall,
} from 'generated/sanity-graphql';
import { getLinkHref } from 'lib/button';
import { ProjectMetadataLD, ProjectPageMetadataLD } from 'lib/db/types/json-ld';
import { TranslatorType } from 'lib/i18n/i18n.types';

Expand All @@ -21,6 +25,7 @@ type GetTerrasosCreditsTabsProps = {
complianceInfo?: ComplianceInfoQuery;
complianceCredits?: JSX.Element;
isComplianceProject: boolean;
bookCall?: TerrasosBookCall;
};

export function getTerrasosCreditsTabs({
Expand All @@ -31,11 +36,12 @@ export function getTerrasosCreditsTabs({
complianceInfo,
complianceCredits,
isComplianceProject,
bookCall,
}: GetTerrasosCreditsTabsProps): IconTabProps[] {
const complianceInfoItem = complianceInfo?.allComplianceInfo[0];
const learnMoreLink: LinkType = {
href: complianceInfoItem?.bookCallLink?.href ?? '',
text: complianceInfoItem?.bookCallLink?.text ?? '',
href: getLinkHref(bookCall?.button?.buttonLink),
text: bookCall?.button?.buttonText ?? '',
};
const description = complianceInfoItem?.descriptionRaw;
const metadata = projectPageMetadata || projectMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Box } from '@mui/material';

import { pxToRem } from 'web-components/src/theme/muiTheme';

import { ComplianceInfoQuery } from 'generated/sanity-graphql';
import {
ComplianceInfoQuery,
TerrasosBookCall,
} from 'generated/sanity-graphql';
import { ProjectMetadataLD, ProjectPageMetadataLD } from 'lib/db/types/json-ld';
import { TranslatorType } from 'lib/i18n/i18n.types';

Expand All @@ -20,6 +23,7 @@ type Props = {
complianceCredits?: JSX.Element;
isComplianceProject: boolean;
className?: string;
bookCall?: TerrasosBookCall;
};

export default function TerrasosCreditsInfo({
Expand All @@ -32,6 +36,7 @@ export default function TerrasosCreditsInfo({
complianceCredits,
isComplianceProject,
className,
bookCall,
}: Props) {
const tabs = getTerrasosCreditsTabs({
_,
Expand All @@ -42,6 +47,7 @@ export default function TerrasosCreditsInfo({
complianceInfo,
complianceCredits,
isComplianceProject,
bookCall,
});
return tabs.length > 0 ? (
<Box sx={{ mt: 0 }} className={className}>
Expand Down
Loading

0 comments on commit 7c5dc18

Please sign in to comment.