Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: APP-508 show book call button on terrasos project bottom banner #2565

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the IS_TERRASOS constant from lib/env in this case?

Copy link
Member Author

@blushi blushi Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no this isn't the same thing
IS_TERRASOS just means it's the terrasos app, which allows us to use their custom theme and features as on https://terrasos.app.regen.network/
(basically it's just VITE_MARKETPLACE_CLIENT env var that we need to set to tell the app to run as regen marketplace or terrasos app)
whereas here, we're checking whether a particular project is a terrasos project or not, and we check the @type value that is stored in the project metadata


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
Loading