Skip to content

Commit

Permalink
Merge branch 'develop' into feature/projects-redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitb35 committed Aug 14, 2024
2 parents eda0610 + ee4f18c commit 1b1c666
Show file tree
Hide file tree
Showing 142 changed files with 7,900 additions and 1,516 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ build-storybook.log
src/stories
.vscode/settings.json
.vscode/launch.json
.env copy.local
2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default async function middleware(req: NextRequest) {
}${cleanPathname}${searchParams}`,
req.url
);
console.log('Populated locale, redirecting to:', newUrl);
console.log('Populated locale, redirecting to:', newUrl.pathname);
return NextResponse.redirect(newUrl);
}

Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const nextConfig = {
SITE_IMAGERY_API_URL: SITE_IMAGERY_API_URL,
WIDGET_URL: process.env.WIDGET_URL,
CONFIG_URL: process.env.CONFIG_URL,
ENABLE_ANALYTICS: DB_CONN_URL ? true : false,
ENABLE_ANALYTICS: DB_CONN_URL ? 'true' : 'false',
REDIS_URL: process.env.REDIS_URL,
REDIS_TOKEN: process.env.REDIS_TOKEN,
WEBHOOK_URL: process.env.WEBHOOK_URL,
Expand Down
1,160 changes: 592 additions & 568 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@mui/x-date-pickers": "^5.0.15",
"@netlify/plugin-nextjs": "^4.33.0",
"@next/bundle-analyzer": "^10.2.3",
"@planet-sdk/common": "^0.1.37",
"@planet-sdk/common": "^0.1.39",
"@prisma/client": "^4.13.0",
"@sentry/browser": "^6.15.0",
"@sentry/integrations": "^6.19.2",
Expand Down Expand Up @@ -101,7 +101,7 @@
"negotiator": "^0.6.3",
"next": "^13.5.6",
"next-connect": "^0.13.0",
"next-intl": "^3.5.3",
"next-intl": "^3.17.2",
"next-useragent": "^2.7.0",
"node-cache": "^5.1.2",
"npm": "^10.2.2",
Expand Down
6 changes: 5 additions & 1 deletion pages/sites/[slug]/[locale]/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ export default function Home({ pageProps }: Props) {
loadLeaderboard();
}, []);

if (!pageProps.tenantConfig.config.header.items['home'].visible) {
if (
!pageProps.tenantConfig.config.header.items.find(
(item) => item.headerKey === 'home' && item.visible
)
) {
if (typeof window !== 'undefined') {
router.push('/');
}
Expand Down
130 changes: 130 additions & 0 deletions pages/sites/[slug]/[locale]/mangrove-challenge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import React, { useEffect, useState } from 'react';
import SalesforceCampaign from '../../../../src/tenants/salesforce/OceanforceCampaign';
import GetHomeMeta from '../../../../src/utils/getMetaTags/GetHomeMeta';
import {
LeaderBoard,
TenantScore,
} from '../../../../src/features/common/types/campaign';
import { AbstractIntlMessages } from 'next-intl';
import { Tenant } from '@planet-sdk/common';
import {
GetStaticProps,
GetStaticPropsContext,
GetStaticPropsResult,
} from 'next';
import { getTenantConfig } from '../../../../src/utils/multiTenancy/helpers';
import { defaultTenant } from '../../../../tenant.config';
import getMessagesForPage from '../../../../src/utils/language/getMessagesForPage';
import { useTenant } from '../../../../src/features/common/Layout/TenantContext';
import router from 'next/router';

interface Props {
pageProps: PageProps;
}

export default function MangroveChallenge({
pageProps: { tenantConfig },
}: Props) {
const [leaderBoard, setLeaderBoard] = useState<LeaderBoard>({
mostDonated: [],
mostRecent: [],
});
const [tenantScore, setTenantScore] = useState<TenantScore>({ total: 0 });
const [isLoaded, setIsLoaded] = useState(false);
const { setTenantConfig } = useTenant();

useEffect(() => {
if (router.isReady) {
setTenantConfig(tenantConfig);
}
}, [router.isReady]);

useEffect(() => {
async function loadData() {
try {
const leaderboardRes = await fetch(
`${process.env.WEBHOOK_URL}/oceanforce-2023-leaderboard`
);
if (leaderboardRes.ok && leaderboardRes.status === 200) {
const leaderBoardArr = await leaderboardRes.json();
setLeaderBoard(leaderBoardArr[0]);
}
} catch (err) {
console.error('Leaderboard could not be loaded:', err);
}

try {
const tenantscoreRes = await fetch(
`${process.env.WEBHOOK_URL}/oceanforce-2023`
);
if (tenantscoreRes.ok && tenantscoreRes.status === 200) {
const tenantScoreArr = await tenantscoreRes.json();
setTenantScore(tenantScoreArr[0]);
setIsLoaded(true);
}
} catch (err) {
console.error('Treecount could not be loaded:', err);
}

setIsLoaded(true);
}

loadData();
}, []);

function getCampaignPage() {
let CampaignPage;
switch (tenantConfig.config.slug) {
case 'salesforce':
CampaignPage = SalesforceCampaign;
return (
<CampaignPage
leaderboard={leaderBoard}
tenantScore={tenantScore}
isLoaded={isLoaded}
/>
);
default:
CampaignPage = null;
return CampaignPage;
}
}

return (
<>
<GetHomeMeta />
{tenantConfig && isLoaded ? getCampaignPage() : <></>}
</>
);
}

export const getStaticPaths = async () => {
return {
paths: [{ params: { slug: 'salesforce', locale: 'en' } }],
fallback: 'blocking',
};
};

interface PageProps {
messages: AbstractIntlMessages;
tenantConfig: Tenant;
}

export const getStaticProps: GetStaticProps<PageProps> = async (
context: GetStaticPropsContext
): Promise<GetStaticPropsResult<PageProps>> => {
const tenantConfig =
(await getTenantConfig(context.params?.slug as string)) ?? defaultTenant;

const messages = await getMessagesForPage({
locale: context.params?.locale as string,
filenames: ['common', 'donate', 'country', 'manageProjects', 'leaderboard'],
});

return {
props: {
messages,
tenantConfig,
},
};
};
82 changes: 82 additions & 0 deletions pages/sites/[slug]/[locale]/mangroves.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { useEffect } from 'react';
import Mangroves from '../../../../src/tenants/salesforce/Mangroves';
import GetHomeMeta from '../../../../src/utils/getMetaTags/GetHomeMeta';
import { AbstractIntlMessages } from 'next-intl';
import { Tenant } from '@planet-sdk/common';
import {
GetStaticProps,
GetStaticPropsContext,
GetStaticPropsResult,
} from 'next';
import { getTenantConfig } from '../../../../src/utils/multiTenancy/helpers';
import { defaultTenant } from '../../../../tenant.config';
import getMessagesForPage from '../../../../src/utils/language/getMessagesForPage';
import { useTenant } from '../../../../src/features/common/Layout/TenantContext';
import router from 'next/router';

interface Props {
pageProps: PageProps;
}

export default function MangrovesLandingPage({
pageProps: { tenantConfig },
}: Props) {
const tenantScore = { total: 16000000 };

const { setTenantConfig } = useTenant();

useEffect(() => {
if (router.isReady) {
setTenantConfig(tenantConfig);
}
}, [router.isReady]);

function getCampaignPage() {
let CampaignPage;
switch (tenantConfig.config.slug) {
case 'salesforce':
return <Mangroves tenantScore={tenantScore} isLoaded={true} />;
default:
CampaignPage = null;
return CampaignPage;
}
}

return (
<>
<GetHomeMeta />
{tenantConfig ? getCampaignPage() : <></>}
</>
);
}

export const getStaticPaths = async () => {
return {
paths: [{ params: { slug: 'salesforce', locale: 'en' } }],
fallback: 'blocking',
};
};

interface PageProps {
messages: AbstractIntlMessages;
tenantConfig: Tenant;
}

export const getStaticProps: GetStaticProps<PageProps> = async (
context: GetStaticPropsContext
): Promise<GetStaticPropsResult<PageProps>> => {
const tenantConfig =
(await getTenantConfig(context.params?.slug as string)) ?? defaultTenant;

const messages = await getMessagesForPage({
locale: context.params?.locale as string,
filenames: ['common', 'donate', 'country', 'manageProjects', 'leaderboard'],
});

return {
props: {
messages,
tenantConfig,
},
};
};
27 changes: 17 additions & 10 deletions pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Head from 'next/head';
import { BulkCodeMethods } from '../../../../../../../src/utils/constants/bulkCodeConstants';
import { useBulkCode } from '../../../../../../../src/features/common/Layout/BulkCodeContext';
import { ErrorHandlingContext } from '../../../../../../../src/features/common/Layout/ErrorHandlingContext';
import { getRequest } from '../../../../../../../src/utils/apiRequests/api';
import { getAuthenticatedRequest } from '../../../../../../../src/utils/apiRequests/api';
import { useRouter } from 'next/router';
import { AbstractIntlMessages, useTranslations } from 'next-intl';
import { handleError, APIError } from '@planet-sdk/common';
Expand All @@ -26,6 +26,7 @@ import {
} from 'next';
import { defaultTenant } from '../../../../../../../tenant.config';
import getMessagesForPage from '../../../../../../../src/utils/language/getMessagesForPage';
import { useUserProps } from '../../../../../../../src/features/common/Layout/UserPropsContext';

interface Props {
pageProps: PageProps;
Expand All @@ -41,20 +42,26 @@ export default function BulkCodeIssueCodesPage({

const { project, setProject, bulkMethod, setBulkMethod, planetCashAccount } =
useBulkCode();
const { token, user, logoutUser, contextLoaded } = useUserProps();

// Checks context and sets project, bulk method if not already set within context
const checkContext = useCallback(async () => {
if (planetCashAccount) {
if (planetCashAccount && token && contextLoaded) {
if (!project) {
if (router.isReady) {
try {
const paymentOptions = await getRequest<PaymentOptions>(
pageProps.tenantConfig.id,
`/app/paymentOptions/${router.query.id}`,
{
currency: planetCashAccount.country,
}
);
const paymentOptions =
await getAuthenticatedRequest<PaymentOptions>(
pageProps.tenantConfig.id,
`/app/paymentOptions/${router.query.id}`,
token,
logoutUser,
undefined,
{
country: planetCashAccount.country,
...(user !== null && { legacyPriceFor: user.id }),
}
);

if (paymentOptions) {
const _project = {
Expand Down Expand Up @@ -92,7 +99,7 @@ export default function BulkCodeIssueCodesPage({
}
}
}
}, [router.isReady, planetCashAccount]);
}, [router.isReady, planetCashAccount, token, contextLoaded]);

React.useEffect(() => {
if (router.isReady) {
Expand Down
Loading

0 comments on commit 1b1c666

Please sign in to comment.