Skip to content

Commit

Permalink
Updating the loadSession function to redirect user to the default acc…
Browse files Browse the repository at this point in the history
…ountList Id if they have an underscore as their accountList ID
  • Loading branch information
dr-bizz committed Dec 13, 2024
1 parent 8cd426f commit 18afe4d
Show file tree
Hide file tree
Showing 43 changed files with 149 additions and 88 deletions.
4 changes: 2 additions & 2 deletions pages/acceptInvite.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
import { SetupPage } from 'src/components/Setup/SetupPage';
import useGetAppSettings from 'src/hooks/useGetAppSettings';
import { useRequiredSession } from 'src/hooks/useRequiredSession';
import { loadSession } from './api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from './api/utils/pagePropsHelpers';

interface FetchAcceptInviteProps {
apiToken: string;
Expand Down Expand Up @@ -149,6 +149,6 @@ const AcceptInvitePage = (): ReactElement => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default AcceptInvitePage;
13 changes: 12 additions & 1 deletion pages/accountLists/[accountListId].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
GetDefaultAccountDocument,
GetDefaultAccountQuery,
} from 'pages/api/getDefaultAccount.generated';
import { makeGetServerSideProps } from 'pages/api/utils/pagePropsHelpers';
import {
handleUnderscoreAccountListRedirect,
makeGetServerSideProps,
} from 'pages/api/utils/pagePropsHelpers';
import { logErrorOnRollbar } from 'pages/api/utils/rollBar';
import Dashboard from 'src/components/Dashboard';
import {
Expand Down Expand Up @@ -81,6 +84,14 @@ const AccountListIdPage = ({

export const getServerSideProps = makeGetServerSideProps(
async (session, { query, req }) => {
const underscoreRedirect = await handleUnderscoreAccountListRedirect(
session,
req.url,
);
if (underscoreRedirect) {
return underscoreRedirect;
}

const ssrClient = makeSsrClient(session.user.apiToken);

try {
Expand Down
4 changes: 2 additions & 2 deletions pages/accountLists/[accountListId]/coaching.page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from 'next/head';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { CoachingList } from 'src/components/Coaching/CoachingList';
import Loading from 'src/components/Loading';
import { useAccountListId } from 'src/hooks/useAccountListId';
Expand All @@ -26,6 +26,6 @@ const CoachingPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default CoachingPage;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Head from 'next/head';
import { useRouter } from 'next/router';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import {
AccountListTypeEnum,
CoachingDetail,
Expand Down Expand Up @@ -35,6 +35,6 @@ const CoachingPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default CoachingPage;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from 'next/head';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import {
ContactsContext,
ContactsType,
Expand Down Expand Up @@ -72,4 +72,4 @@ const ContactsPage: React.FC = () => (

export default ContactsPage;

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { useTranslation } from 'react-i18next';
import { v4 as uuidv4 } from 'uuid';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { colorMap } from 'src/components/Contacts/ContactFlow/ContactFlow';
import { ContactFlowSetupColumn } from 'src/components/Contacts/ContactFlow/ContactFlowSetup/Column/ContactFlowSetupColumn';
import { UnusedStatusesColumn } from 'src/components/Contacts/ContactFlow/ContactFlowSetup/Column/UnusedStatusesColumn';
Expand Down Expand Up @@ -228,6 +228,6 @@ const ContactFlowSetupPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default ContactFlowSetupPage;
4 changes: 2 additions & 2 deletions pages/accountLists/[accountListId]/reports/coaching.page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from 'next/head';
import React, { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import {
AccountListTypeEnum,
CoachingDetail,
Expand Down Expand Up @@ -32,6 +32,6 @@ const CoachingReportPage = (): ReactElement => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default CoachingReportPage;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useState } from 'react';
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
import Loading from 'src/components/Loading';
import { DesignationAccountsReport } from 'src/components/Reports/DesignationAccountsReport/DesignationAccountsReport';
Expand Down Expand Up @@ -67,6 +67,6 @@ const DesignationAccountsReportPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default DesignationAccountsReportPage;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useState } from 'react';
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { DynamicContactsRightPanel } from 'src/components/Contacts/ContactsRightPanel/DynamicContactsRightPanel';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
import Loading from 'src/components/Loading';
Expand Down Expand Up @@ -89,6 +89,6 @@ const DonationsReportPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default DonationsReportPage;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { ReactElement, useState } from 'react';
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { DynamicContactsRightPanel } from 'src/components/Contacts/ContactsRightPanel/DynamicContactsRightPanel';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
import Loading from 'src/components/Loading';
Expand Down Expand Up @@ -101,6 +101,6 @@ const ExpectedMonthlyTotalReportPage = (): ReactElement => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default ExpectedMonthlyTotalReportPage;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Head from 'next/head';
import React, { useState } from 'react';
import { Box } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
import Loading from 'src/components/Loading';
import { AccountSummary } from 'src/components/Reports/FinancialAccountsReport/AccountSummary/AccountSummary';
Expand Down Expand Up @@ -61,6 +61,6 @@ const FinancialAccountSummaryPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default FinancialAccountSummaryPage;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Head from 'next/head';
import React, { ReactElement, useContext, useMemo } from 'react';
import { Box } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
import Loading from 'src/components/Loading';
import { AccountTransactions } from 'src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions';
Expand Down Expand Up @@ -168,6 +168,6 @@ const FinancialAccountsPage: React.FC = () => (
</FinancialAccountsWrapper>
);

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default FinancialAccountsPage;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Head from 'next/head';
import React, { useState } from 'react';
import { Box } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
import Loading from 'src/components/Loading';
import { FinancialAccounts } from 'src/components/Reports/FinancialAccountsReport/FinancialAccounts/FinancialAccounts';
Expand Down Expand Up @@ -64,6 +64,6 @@ const FinancialAccountsPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default FinancialAccountsPage;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useState } from 'react';
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { DynamicContactsRightPanel } from 'src/components/Contacts/ContactsRightPanel/DynamicContactsRightPanel';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
import Loading from 'src/components/Loading';
Expand Down Expand Up @@ -90,6 +90,6 @@ const PartnerCurrencyReportPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default PartnerCurrencyReportPage;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useMemo, useRef, useState } from 'react';
import { sortBy } from 'lodash';
import { useTranslation } from 'react-i18next';
import { ReportContactFilterSetInput } from 'pages/api/graphql-rest.page.generated';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { ContactsProvider } from 'src/components/Contacts/ContactsContext/ContactsContext';
import { DynamicContactsRightPanel } from 'src/components/Contacts/ContactsRightPanel/DynamicContactsRightPanel';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
Expand Down Expand Up @@ -174,6 +174,6 @@ const PartnerGivingAnalysisReportPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default PartnerGivingAnalysisReportPage;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useState } from 'react';
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { DynamicContactsRightPanel } from 'src/components/Contacts/ContactsRightPanel/DynamicContactsRightPanel';
import { SidePanelsLayout } from 'src/components/Layouts/SidePanelsLayout';
import Loading from 'src/components/Loading';
Expand Down Expand Up @@ -90,6 +90,6 @@ const SalaryCurrencyReportPage: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default SalaryCurrencyReportPage;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useRouter } from 'next/router';
import React, { useEffect, useState } from 'react';
import { Button } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { ChalklineAccordion } from 'src/components/Settings/integrations/Chalkline/ChalklineAccordion';
import { GoogleAccordion } from 'src/components/Settings/integrations/Google/GoogleAccordion';
import { TheKeyAccordion } from 'src/components/Settings/integrations/Key/TheKeyAccordion';
Expand Down Expand Up @@ -120,6 +120,6 @@ const Integrations: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default Integrations;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRouter } from 'next/router';
import React, { ReactElement, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { ManageAccountAccessAccordion } from 'src/components/Settings/Accounts/ManageAccountAccess/ManageAccountAccessAccordion';
import { MergeAccountsAccordion } from 'src/components/Settings/Accounts/MergeAccounts/MergeAccountsAccordion';
import { MergeSpouseAccountsAccordion } from 'src/components/Settings/Accounts/MergeSpouseAccounts/MergeSpouseAccountsAccordion';
Expand Down Expand Up @@ -50,6 +50,6 @@ const ManageAccounts = (): ReactElement => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default ManageAccounts;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRouter } from 'next/router';
import React, { ReactElement, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { ManageCoachesAccessAccordion } from 'src/components/Settings/Coaches/ManageCoachesAccess/ManageCoachesAccessAccordion';
import { AccordionGroup } from 'src/components/Shared/Forms/Accordions/AccordionGroup';
import { SettingsWrapper } from './Wrapper';
Expand Down Expand Up @@ -36,6 +36,6 @@ const ManageCoaching = (): ReactElement => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default ManageCoaching;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useRouter } from 'next/router';
import React from 'react';
import { Box, Button } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { NotificationsTable } from 'src/components/Settings/notifications/NotificationsTable';
import { SetupBanner } from 'src/components/Settings/preferences/SetupBanner';
import { useSetupContext } from 'src/components/Setup/SetupProvider';
Expand Down Expand Up @@ -78,6 +78,6 @@ const Notifications: React.FC = () => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default Notifications;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { ReactElement, useEffect, useState } from 'react';
import { Autocomplete, Box, Skeleton, TextField } from '@mui/material';
import { styled } from '@mui/material/styles';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { ImpersonateUserAccordion } from 'src/components/Settings/Organization/ImpersonateUser/ImpersonateUserAccordion';
import { ManageOrganizationAccessAccordion } from 'src/components/Settings/Organization/ManageOrganizationAccess/ManageOrganizationAccessAccordion';
import { AccordionGroup } from 'src/components/Shared/Forms/Accordions/AccordionGroup';
Expand Down Expand Up @@ -139,6 +139,6 @@ const Organizations = (): ReactElement => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default Organizations;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { styled } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { AccountLists } from 'src/components/Settings/Organization/AccountLists/AccountLists';
import { useDebouncedValue } from 'src/hooks/useDebounce';
import { SettingsWrapper } from '../Wrapper';
Expand Down Expand Up @@ -143,6 +143,6 @@ const AccountListsOrganizations = (): ReactElement => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default AccountListsOrganizations;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { styled } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { ensureSessionAndAccountList } from 'pages/api/utils/pagePropsHelpers';
import { Contacts } from 'src/components/Settings/Organization/Contacts/Contacts';
import { useDebouncedValue } from 'src/hooks/useDebounce';
import { SettingsWrapper } from '../Wrapper';
Expand Down Expand Up @@ -130,6 +130,6 @@ const OrganizationsContacts = (): ReactElement => {
);
};

export const getServerSideProps = loadSession;
export const getServerSideProps = ensureSessionAndAccountList;

export default OrganizationsContacts;
Loading

0 comments on commit 18afe4d

Please sign in to comment.