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

Remove any from useAsyncLoader #1282

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
80 changes: 0 additions & 80 deletions client/__tests__/loadingComponent.test.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import type { MembersDataApiResponse } from '../../../../shared/productResponse';
import { isProduct } from '../../../../shared/productResponse';
import {
LoadingState,
useAsyncLoader,
} from '../../../utilities/hooks/useAsyncLoader';
import { allRecurringProductsDetailFetcher } from '../../../utilities/productUtils';
import { JsonResponseHandler } from '../../mma/shared/asyncComponents/DefaultApiResponseHandler';

export const SubscriptionInformation = () => {
const {
Expand Down
14 changes: 6 additions & 8 deletions client/components/mma/accountoverview/AccountOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { Stack } from '@guardian/source-react-components';
import { capitalize } from 'lodash';
import { Fragment } from 'react';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import { featureSwitches } from '../../../../shared/featureSwitches';
import type { MPAPIResponse } from '../../../../shared/mpapiResponse';
import { isValidAppSubscription } from '../../../../shared/mpapiResponse';
Expand Down Expand Up @@ -41,7 +42,6 @@ import { NAV_LINKS } from '../../shared/nav/NavConfig';
import { SupportTheGuardianButton } from '../../shared/SupportTheGuardianButton';
import { isCancelled } from '../cancel/CancellationSummary';
import { PageContainer } from '../Page';
import { JsonResponseHandler } from '../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../shared/asyncComponents/DefaultLoadingView';
import type { IsFromAppProps } from '../shared/IsFromAppProps';
import { nonServiceableCountries } from '../shared/NonServiceableCountries';
Expand Down Expand Up @@ -71,13 +71,11 @@ const subHeadingCss = css`
`;

const AccountOverviewPage = ({ isFromApp }: IsFromAppProps) => {
const {
data: accountOverviewResponse,
loadingState,
}: {
data: AccountOverviewResponse | null;
loadingState: LoadingState;
} = useAsyncLoader(accountOverviewFetcher, JsonResponseHandler);
const { data: accountOverviewResponse, loadingState } =
useAsyncLoader<AccountOverviewResponse>(
accountOverviewFetcher,
JsonResponseHandler,
);

if (loadingState == LoadingState.HasError) {
return <GenericErrorScreen />;
Expand Down
2 changes: 1 addition & 1 deletion client/components/mma/accountoverview/ManageProduct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@guardian/source-foundations';
import { useState } from 'react';
import { Link, Navigate, useLocation } from 'react-router-dom';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import { featureSwitches } from '@/shared/featureSwitches';
import { cancellationFormatDate } from '../../../../shared/dates';
import type {
Expand Down Expand Up @@ -43,7 +44,6 @@ import { DeliveryAddressDisplay } from '../delivery/address/DeliveryAddressDispl
import { PageContainer } from '../Page';
import { ErrorIcon } from '../shared/assets/ErrorIcon';
import { GiftIcon } from '../shared/assets/GiftIcon';
import { JsonResponseHandler } from '../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../shared/asyncComponents/DefaultLoadingView';
import { BasicProductInfoTable } from '../shared/BasicProductInfoTable';
import { LinkButton } from '../shared/Buttons';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import { useLocation, useNavigate } from 'react-router-dom';
import { PageContainer } from '@/client/components/mma/Page';
import { ErrorIcon } from '@/client/components/mma/shared/assets/ErrorIcon';
import { JsonResponseHandler } from '@/client/components/mma/shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '@/client/components/mma/shared/asyncComponents/DefaultLoadingView';
import { getNextPaymentDetails } from '@/client/components/mma/shared/NextPaymentDetails';
import { PaymentDetails } from '@/client/components/mma/shared/PaymentDetails';
Expand All @@ -39,6 +38,7 @@ import {
useAsyncLoader,
} from '@/client/utilities/hooks/useAsyncLoader';
import { createProductDetailFetcher } from '@/client/utilities/productUtils';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import { cancellationFormatDate } from '@/shared/dates';
import type {
MembersDataApiResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
} from '@guardian/source-react-components';
import { capitalize } from 'lodash';
import { useEffect, useState } from 'react';
import { TextResponseHandler } from '@/client/utilities/responseHandlers';
import type { PaidSubscriptionPlan } from '../../../../../shared/productResponse';
import { augmentBillingPeriod } from '../../../../../shared/productResponse';
import type { ProductType } from '../../../../../shared/productTypes';
import { trackEvent } from '../../../../utilities/analytics';
import { fetchWithDefaultParameters } from '../../../../utilities/fetch';
import type { ContributionInterval } from '../../../../utilities/pricingConfig/contributionsAmount';
import { contributionAmountsLookup } from '../../../../utilities/pricingConfig/contributionsAmount';
import { TextResponseHandler } from '../../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../../shared/asyncComponents/DefaultLoadingView';

type ContributionUpdateAmountFormMode = 'MANAGE' | 'CANCELLATION_SAVE';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
TextInput,
} from '@guardian/source-react-components';
import { useEffect, useState } from 'react';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import type { PaidSubscriptionPlan } from '../../../../../shared/productResponse';
import { getBillingPeriodAdjective } from '../../../../../shared/productTypes';
import type { CurrencyIso } from '../../../../utilities/currencyIso';
import { fetchWithDefaultParameters } from '../../../../utilities/fetch';
import { getSupporterPlusSuggestedAmountsFromMainPlan } from '../../../../utilities/pricingConfig/suggestedAmounts';
import { supporterPlusPriceConfigByCountryGroup } from '../../../../utilities/pricingConfig/supporterPlusPricing';
import { JsonResponseHandler } from '../../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../../shared/asyncComponents/DefaultLoadingView';

const smallPrintCss = css`
Expand Down
2 changes: 1 addition & 1 deletion client/components/mma/billing/Billing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@guardian/source-foundations';
import { capitalize } from 'lodash';
import { Fragment } from 'react';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import { parseDate } from '../../../../shared/dates';
import { featureSwitches } from '../../../../shared/featureSwitches';
import type {
Expand Down Expand Up @@ -49,7 +50,6 @@ import { SixForSixExplainerIfApplicable } from '../accountoverview/SixForSixExpl
import { PageContainer } from '../Page';
import { ErrorIcon } from '../shared/assets/ErrorIcon';
import { GiftIcon } from '../shared/assets/GiftIcon';
import { JsonResponseHandler } from '../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../shared/asyncComponents/DefaultLoadingView';
import { BasicProductInfoTable } from '../shared/BasicProductInfoTable';
import { LinkButton } from '../shared/Buttons';
Expand Down
2 changes: 1 addition & 1 deletion client/components/mma/cancel/CancellationContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Context, Dispatch, SetStateAction } from 'react';
import { createContext, useState } from 'react';
import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import type {
MembersDataApiResponse,
MembersDataApiUser,
Expand All @@ -23,7 +24,6 @@ import { NAV_LINKS } from '../../shared/nav/NavConfig';
import type { DeliveryRecordDetail } from '../delivery/records/deliveryRecordsApi';
import type { OutstandingHolidayStop } from '../holiday/HolidayStopApi';
import { PageContainer } from '../Page';
import { JsonResponseHandler } from '../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../shared/asyncComponents/DefaultLoadingView';
import type {
CancellationReason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import type { FormEvent } from 'react';
import { useContext, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import {
DATE_FNS_LONG_OUTPUT_FORMAT,
parseDate,
Expand All @@ -30,7 +31,6 @@ import {
import { hasCancellationFlow } from '../../../utilities/productUtils';
import { GenericErrorScreen } from '../../shared/GenericErrorScreen';
import { WithStandardTopMargin } from '../../shared/WithStandardTopMargin';
import { JsonResponseHandler } from '../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../shared/asyncComponents/DefaultLoadingView';
import { ProgressIndicator } from '../shared/ProgressIndicator';
import type { CancellationContextInterface } from './CancellationContainer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button, Stack } from '@guardian/source-react-components';
import { useContext } from 'react';
import { Navigate, useLocation, useNavigate } from 'react-router';
import { CallCentreAccordion } from '@/client/components/shared/CallCentreAccordion';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import type {
MembersDataApiResponse,
ProductDetail,
Expand All @@ -16,7 +17,6 @@ import {
} from '../../../../utilities/hooks/useAsyncLoader';
import { allRecurringProductsDetailFetcher } from '../../../../utilities/productUtils';
import { GenericErrorScreen } from '../../../shared/GenericErrorScreen';
import { JsonResponseHandler } from '../../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../../shared/asyncComponents/DefaultLoadingView';
import { Heading } from '../../shared/Heading';
import type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import type { FormEvent } from 'react';
import { useContext, useState } from 'react';
import { useLocation, useNavigate } from 'react-router';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import {
DATE_FNS_LONG_OUTPUT_FORMAT,
parseDate,
Expand All @@ -33,7 +34,6 @@ import {
} from '../../../../styles/ButtonStyles';
import { headingCss, sectionSpacing } from '../../../../styles/GenericStyles';
import { GenericErrorScreen } from '../../../shared/GenericErrorScreen';
import { JsonResponseHandler } from '../../shared/asyncComponents/DefaultApiResponseHandler';
import type {
CancellationContextInterface,
CancellationRouterState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { useLocation, useNavigate } from 'react-router';
import type { CancellationContextInterface } from '@/client/components/mma/cancel/CancellationContainer';
import { CancellationContext } from '@/client/components/mma/cancel/CancellationContainer';
import type { OptionalCancellationReasonId } from '@/client/components/mma/cancel/cancellationReason';
import { JsonResponseHandler } from '@/client/components/mma/shared/asyncComponents/DefaultApiResponseHandler';
import { benefitsCss } from '@/client/components/mma/shared/benefits/BenefitsStyles';
import { GenericErrorScreen } from '@/client/components/shared/GenericErrorScreen';
import { stackedButtonLayoutCss } from '@/client/styles/ButtonStyles';
import { fetchWithDefaultParameters } from '@/client/utilities/fetch';
import { createProductDetailFetcher } from '@/client/utilities/productUtils';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import type {
MembersDataApiResponse,
ProductDetail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { palette, space, textSans } from '@guardian/source-foundations';
import { Button, Stack } from '@guardian/source-react-components';
import { useContext, useState } from 'react';
import { useLocation, useNavigate } from 'react-router';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import { MDA_TEST_USER_HEADER } from '../../../../../../shared/productResponse';
import type {
MembersDataApiResponse,
Expand All @@ -13,7 +14,6 @@ import { stackedButtonLayoutCss } from '../../../../../styles/ButtonStyles';
import { fetchWithDefaultParameters } from '../../../../../utilities/fetch';
import { createProductDetailFetcher } from '../../../../../utilities/productUtils';
import { GenericErrorScreen } from '../../../../shared/GenericErrorScreen';
import { JsonResponseHandler } from '../../../shared/asyncComponents/DefaultApiResponseHandler';
import { Heading } from '../../../shared/Heading';
import { ProgressStepper } from '../../../shared/ProgressStepper';
import type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { ErrorSummary } from '@guardian/source-react-components-development-kitchen';
import { useContext, useEffect, useState } from 'react';
import { Navigate, useLocation, useNavigate } from 'react-router';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import { dateString, parseDate } from '../../../../../../shared/dates';
import type {
PaidSubscriptionPlan,
Expand All @@ -36,7 +37,6 @@ import {
smallPrintCss,
} from '../../../../../styles/GenericStyles';
import { getOldMembershipPrice } from '../../../../../utilities/pricingConfig/membershipPriceRise';
import { JsonResponseHandler } from '../../../shared/asyncComponents/DefaultApiResponseHandler';
import { Card } from '../../../shared/Card';
import { Heading } from '../../../shared/Heading';
import { PaymentDetails } from '../../../shared/PaymentDetails';
Expand Down
2 changes: 1 addition & 1 deletion client/components/mma/dataPrivacy/DataPrivacyPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { CMP } from '@guardian/consent-management-platform/dist/types';
import { from } from '@guardian/source-foundations';
import { useEffect, useState } from 'react';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import { gridItemPlacement } from '../../../styles/grid';
import { fetchWithDefaultParameters } from '../../../utilities/fetch';
import {
Expand All @@ -14,7 +15,6 @@ import { ConsentOptions, mapSubscriptions } from '../identity/identity';
import { Lines } from '../identity/Lines';
import type { ConsentOption } from '../identity/models';
import { Actions, useConsentOptions } from '../identity/useConsentOptions';
import { JsonResponseHandler } from '../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../shared/asyncComponents/DefaultLoadingView';
import { CookiesOnThisBrowserSection } from './CookiesOnTheBrowserSection';
import { dataPrivacyWrapper } from './DataPrivacy.styles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Button } from '@guardian/source-react-components';
import { useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { JsonResponseHandler } from '@/client/utilities/responseHandlers';
import { DATE_FNS_LONG_OUTPUT_FORMAT } from '../../../../shared/dates';
import { MDA_TEST_USER_HEADER } from '../../../../shared/productResponse';
import {
LoadingState,
useAsyncLoader,
} from '../../../utilities/hooks/useAsyncLoader';
import { JsonResponseHandler } from '../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../shared/asyncComponents/DefaultLoadingView';
import type {
HolidayStopRequest,
Expand Down
7 changes: 2 additions & 5 deletions client/components/mma/holiday/HolidayStopsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Dispatch, SetStateAction } from 'react';
import { Outlet } from 'react-router';
import { handleResponses } from '@/client/utilities/responseHandlers';
import type { DateRange } from '../../../../shared/dates';
import { MDA_TEST_USER_HEADER } from '../../../../shared/productResponse';
import type { ProductDetail } from '../../../../shared/productResponse';
Expand All @@ -9,9 +10,7 @@ import {
useAsyncLoader,
} from '../../../utilities/hooks/useAsyncLoader';
import { GenericErrorScreen } from '../../shared/GenericErrorScreen';
import { handleResponses } from '../shared/asyncComponents/DefaultApiResponseHandler';
import { DefaultLoadingView } from '../shared/asyncComponents/DefaultLoadingView';
import type { ResponseProcessor } from '../shared/asyncComponents/ResponseProcessor';
import { embellishExistingHolidayStops } from './HolidayStopApi';
import type {
GetHolidayStopsResponse,
Expand All @@ -20,9 +19,7 @@ import type {
} from './HolidayStopApi';
import { HolidayStopsContext } from './HolidayStopsContainer';

const HolidayStopsResponseHandler: ResponseProcessor = (
response: Response | Response[],
) => {
const HolidayStopsResponseHandler = (response: Response | Response[]) => {
return handleResponses(response, embellishExistingHolidayStops);
};

Expand Down
Loading
Loading