Skip to content

Commit

Permalink
Merge pull request #2327 from Plant-for-the-Planet-org/feature/consis…
Browse files Browse the repository at this point in the history
…tent-type-import-webapp

refactor: apply 'import type' for type-only imports via ESLint
  • Loading branch information
mohitb35 authored Jan 3, 2025
2 parents 29a966d + 34a281a commit e639c93
Show file tree
Hide file tree
Showing 418 changed files with 1,965 additions and 1,391 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ module.exports = {
'import/extensions': 'off',
'import/no-unresolved': 'off',
'react/jsx-no-literals': 'off',
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/consistent-type-imports': [
'warn',
{
prefer: 'type-imports',
},
],
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-empty-function': 'off',
Expand Down
4 changes: 3 additions & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';

import { NextResponse } from 'next/server';
import { getTenantConciseInfo } from './src/utils/multiTenancy/helpers';
import { match as matchLocale } from '@formatjs/intl-localematcher';
import Negotiator from 'negotiator';
Expand Down
11 changes: 6 additions & 5 deletions pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Custom404Image from '../public/assets/images/Custom404Image';
import { useRouter } from 'next/router';
import Footer from '../src/features/common/Layout/Footer';
import {
import type {
GetStaticProps,
GetStaticPropsContext,
GetStaticPropsResult,
} from 'next';
import { AbstractIntlMessages } from 'next-intl';
import type { AbstractIntlMessages } from 'next-intl';

import Custom404Image from '../public/assets/images/Custom404Image';
import { useRouter } from 'next/router';
import Footer from '../src/features/common/Layout/Footer';
import getMessagesForPage from '../src/utils/language/getMessagesForPage';

interface Props {
Expand Down
19 changes: 12 additions & 7 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import type { EmotionCache } from '@emotion/react';
import type { ReactElement, ReactNode } from 'react';
import type { AppContext, AppInitialProps, AppProps } from 'next/app';
import type { Tenant } from '@planet-sdk/common/build/types/tenant';
import type { AbstractIntlMessages } from 'next-intl';
import type { NextPage } from 'next';
import type { SetState } from '../src/features/common/types/common';

import CssBaseline from '@mui/material/CssBaseline';
import { CacheProvider, EmotionCache } from '@emotion/react';
import { CacheProvider } from '@emotion/react';
import createEmotionCache from '../src/createEmotionCache';
import 'mapbox-gl/dist/mapbox-gl.css';
import 'mapbox-gl-compare/dist/mapbox-gl-compare.css';
import React, { ReactElement, ReactNode, useMemo } from 'react';
import React, { useMemo } from 'react';
import TagManager from 'react-gtm-module';
import Router from 'next/router';
import App, { AppContext, AppInitialProps, AppProps } from 'next/app';
import App from 'next/app';
import { Auth0Provider } from '@auth0/auth0-react';
// NOTE - needs to be removed when old projects code is removed
import '../src/features/projects/styles/MapPopup.scss';
Expand Down Expand Up @@ -43,10 +51,7 @@ import {
getTenantConfig,
getTenantSlug,
} from '../src/utils/multiTenancy/helpers';
import { Tenant } from '@planet-sdk/common/build/types/tenant';
import { AbstractIntlMessages, NextIntlClientProvider } from 'next-intl';
import { NextPage } from 'next';
import { SetState } from '../src/features/common/types/common';
import { NextIntlClientProvider } from 'next-intl';

const VideoContainer = dynamic(
() => import('../src/features/common/LandingVideo'),
Expand Down
16 changes: 5 additions & 11 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import Document, {
DocumentContext,
DocumentInitialProps,
Head,
Html,
Main,
NextScript,
} from 'next/document';
import type { EmotionCache } from '@emotion/react';
import type { AppType } from 'next/app';
import type { DocumentContext, DocumentInitialProps } from 'next/document';

import Document, { Head, Html, Main, NextScript } from 'next/document';
import createEmotionServer from '@emotion/server/create-instance';
import createEmotionCache from '../src/createEmotionCache';
import { EmotionCache } from '@emotion/react';

import React from 'react';
import { AppType } from 'next/app';

class MyDocument extends Document {
static async getInitialProps(
Expand Down
5 changes: 3 additions & 2 deletions pages/api/data-explorer/export.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { NextApiRequest, NextApiResponse } from 'next';
import type { NextApiRequest, NextApiResponse } from 'next';
import type { IExportData } from '../../../src/features/common/types/dataExplorer';

import db from '../../../src/utils/connectDB';
import nc from 'next-connect';
import {
rateLimiter,
speedLimiter,
} from '../../../src/middlewares/rate-limiter';
import { IExportData } from '../../../src/features/common/types/dataExplorer';

const handler = nc<NextApiRequest, NextApiResponse>();

Expand Down
11 changes: 6 additions & 5 deletions pages/api/data-explorer/map/distinct-species/[projectId].ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { NextApiRequest, NextApiResponse } from 'next';
import type { NextApiRequest, NextApiResponse } from 'next';
import type {
DistinctSpecies,
UncleanDistinctSpecies,
} from '../../../../../src/features/common/types/dataExplorer';

import db from '../../../../../src/utils/connectDB';
import nc from 'next-connect';
import {
rateLimiter,
speedLimiter,
} from '../../../../../src/middlewares/rate-limiter';
import {
DistinctSpecies,
UncleanDistinctSpecies,
} from '../../../../../src/features/common/types/dataExplorer';
import redisClient from '../../../../../src/redis-client';
import { cacheKeyPrefix } from '../../../../../src/utils/constants/cacheKeyPrefix';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { NextApiRequest, NextApiResponse } from 'next';
import nc from 'next-connect';
import db from '../../../../../src/utils/connectDB';
import {
import type { NextApiRequest, NextApiResponse } from 'next';
import type {
PlantLocationDetails,
PlantLocationDetailsQueryRes,
} from '../../../../../src/features/common/types/dataExplorer';

import nc from 'next-connect';
import db from '../../../../../src/utils/connectDB';

const handler = nc<NextApiRequest, NextApiResponse>();

handler.get(async (req, response) => {
Expand Down
7 changes: 4 additions & 3 deletions pages/api/data-explorer/map/plant-location/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { NextApiRequest, NextApiResponse } from 'next';
import type { NextApiRequest, NextApiResponse } from 'next';
import type { Geometry } from '@turf/turf';
import type { SinglePlantLocationApiResponse } from '../../../../../src/features/common/types/dataExplorer';

import nc from 'next-connect';
import db from '../../../../../src/utils/connectDB';
import { Geometry } from '@turf/turf';
import { SinglePlantLocationApiResponse } from '../../../../../src/features/common/types/dataExplorer';
import { QueryType } from '../../../../../src/features/user/TreeMapper/Analytics/constants';

const handler = nc<NextApiRequest, NextApiResponse>();
Expand Down
11 changes: 6 additions & 5 deletions pages/api/data-explorer/map/sites/[projectId].ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { NextApiRequest, NextApiResponse } from 'next';
import type { NextApiRequest, NextApiResponse } from 'next';
import type {
FeatureCollection,
UncleanSite,
} from '../../../../../src/features/common/types/dataExplorer';

import db from '../../../../../src/utils/connectDB';
import nc from 'next-connect';
import {
rateLimiter,
speedLimiter,
} from '../../../../../src/middlewares/rate-limiter';
import {
FeatureCollection,
UncleanSite,
} from '../../../../../src/features/common/types/dataExplorer';
import redisClient from '../../../../../src/redis-client';
import { cacheKeyPrefix } from '../../../../../src/utils/constants/cacheKeyPrefix';

Expand Down
5 changes: 3 additions & 2 deletions pages/api/data-explorer/species-planted.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { NextApiRequest, NextApiResponse } from 'next';
import type { NextApiRequest, NextApiResponse } from 'next';
import type { ISpeciesPlanted } from '../../../src/features/common/types/dataExplorer';

import db from '../../../src/utils/connectDB';
import nc from 'next-connect';
import {
rateLimiter,
speedLimiter,
} from '../../../src/middlewares/rate-limiter';
import { getCachedKey } from '../../../src/utils/getCachedKey';
import { ISpeciesPlanted } from '../../../src/features/common/types/dataExplorer';
import redisClient from '../../../src/redis-client';
import { cacheKeyPrefix } from '../../../src/utils/constants/cacheKeyPrefix';

Expand Down
5 changes: 3 additions & 2 deletions pages/api/data-explorer/total-species-planted.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { NextApiRequest, NextApiResponse } from 'next';
import type { NextApiRequest, NextApiResponse } from 'next';
import type { TotalSpeciesPlanted } from '../../../src/features/common/types/dataExplorer';

import db from '../../../src/utils/connectDB';
import nc from 'next-connect';
import {
rateLimiter,
speedLimiter,
} from '../../../src/middlewares/rate-limiter';
import { getCachedKey } from '../../../src/utils/getCachedKey';
import { TotalSpeciesPlanted } from '../../../src/features/common/types/dataExplorer';
import redisClient from '../../../src/redis-client';
import { cacheKeyPrefix } from '../../../src/utils/constants/cacheKeyPrefix';

Expand Down
5 changes: 3 additions & 2 deletions pages/api/data-explorer/total-trees-planted.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { NextApiRequest, NextApiResponse } from 'next';
import type { NextApiRequest, NextApiResponse } from 'next';
import type { TotalTreesPlanted } from '../../../src/features/common/types/dataExplorer';

import db from '../../../src/utils/connectDB';
import nc from 'next-connect';
import {
rateLimiter,
speedLimiter,
} from '../../../src/middlewares/rate-limiter';
import { getCachedKey } from '../../../src/utils/getCachedKey';
import { TotalTreesPlanted } from '../../../src/features/common/types/dataExplorer';
import redisClient from '../../../src/redis-client';
import { cacheKeyPrefix } from '../../../src/utils/constants/cacheKeyPrefix';

Expand Down
15 changes: 8 additions & 7 deletions pages/api/data-explorer/trees-planted.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { NextApiRequest, NextApiResponse } from 'next';
import type { NextApiRequest, NextApiResponse } from 'next';
import type {
IDailyFrame,
IMonthlyFrame,
IWeeklyFrame,
IYearlyFrame,
} from '../../../src/features/common/types/dataExplorer';

import db from '../../../src/utils/connectDB';
import { TIME_FRAME } from '../../../src/features/user/TreeMapper/Analytics/components/TreePlanted/TimeFrameSelector';
import nc from 'next-connect';
Expand All @@ -7,12 +14,6 @@ import {
speedLimiter,
} from '../../../src/middlewares/rate-limiter';
import { getCachedKey } from '../../../src/utils/getCachedKey';
import {
IDailyFrame,
IMonthlyFrame,
IWeeklyFrame,
IYearlyFrame,
} from '../../../src/features/common/types/dataExplorer';
import redisClient from '../../../src/redis-client';
import { cacheKeyPrefix } from '../../../src/utils/constants/cacheKeyPrefix';

Expand Down
41 changes: 25 additions & 16 deletions pages/sites/[slug]/[locale]/all.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import type { APIError } from '@planet-sdk/common';
import type {
LeaderBoardList,
TenantScore,
TreesDonated,
} from '../../../../src/features/common/types/leaderboard';
import type { Tenant } from '@planet-sdk/common/build/types/tenant';
import type {
GetStaticProps,
GetStaticPropsContext,
GetStaticPropsResult,
} from 'next';
import type { AbstractIntlMessages } from 'next-intl';

import React from 'react';
import LeaderBoard from '../../../../src/tenants/planet/LeaderBoard';
import { getRequest } from '../../../../src/utils/apiRequests/api';
import GetLeaderboardMeta from '../../../../src/utils/getMetaTags/GetLeaderboardMeta';
import { ErrorHandlingContext } from '../../../../src/features/common/Layout/ErrorHandlingContext';
import { handleError, APIError } from '@planet-sdk/common';
import {
LeaderBoardList,
TenantScore,
TreesDonated,
} from '../../../../src/features/common/types/leaderboard';
import { handleError } from '@planet-sdk/common';
import { useTenant } from '../../../../src/features/common/Layout/TenantContext';
import { Tenant } from '@planet-sdk/common/build/types/tenant';
import { useRouter } from 'next/router';
import {
constructPathsForTenantSlug,
getTenantConfig,
} from '../../../../src/utils/multiTenancy/helpers';
import {
GetStaticProps,
GetStaticPropsContext,
GetStaticPropsResult,
} from 'next';
import { defaultTenant } from '../../../../tenant.config';
import { AbstractIntlMessages } from 'next-intl';
import getMessagesForPage from '../../../../src/utils/language/getMessagesForPage';

interface Props {
Expand Down Expand Up @@ -78,7 +80,6 @@ export default function Home({ pageProps }: Props) {
loadTenantScore();
}, []);


const [treesDonated, setTreesDonated] = React.useState<TreesDonated | null>(
null
);
Expand All @@ -103,12 +104,20 @@ export default function Home({ pageProps }: Props) {
switch (pageProps.tenantConfig.config.slug) {
case 'planet':
AllPage = (
<LeaderBoard leaderboard={leaderboard} tenantScore={tenantScore} treesDonated={treesDonated} />
<LeaderBoard
leaderboard={leaderboard}
tenantScore={tenantScore}
treesDonated={treesDonated}
/>
);
return AllPage;
case 'ttc':
AllPage = (
<LeaderBoard leaderboard={leaderboard} tenantScore={tenantScore} treesDonated={treesDonated}/>
<LeaderBoard
leaderboard={leaderboard}
tenantScore={tenantScore}
treesDonated={treesDonated}
/>
);
return AllPage;
default:
Expand Down
15 changes: 8 additions & 7 deletions pages/sites/[slug]/[locale]/complete-signup.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import type { Tenant } from '@planet-sdk/common/build/types/tenant';
import type {
GetStaticProps,
GetStaticPropsContext,
GetStaticPropsResult,
} from 'next';
import type { AbstractIntlMessages } from 'next-intl';

import React from 'react';
import CompleteSignup from '../../../../src/features/user/CompleteSignup';
import Head from 'next/head';
import {
constructPathsForTenantSlug,
getTenantConfig,
} from '../../../../src/utils/multiTenancy/helpers';
import { Tenant } from '@planet-sdk/common/build/types/tenant';
import { useRouter } from 'next/router';
import { useTenant } from '../../../../src/features/common/Layout/TenantContext';
import {
GetStaticProps,
GetStaticPropsContext,
GetStaticPropsResult,
} from 'next';
import { defaultTenant } from '../../../../tenant.config';
import { AbstractIntlMessages } from 'next-intl';
import getMessagesForPage from '../../../../src/utils/language/getMessagesForPage';

interface Props {
Expand Down
Loading

0 comments on commit e639c93

Please sign in to comment.