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

BG-980: Speed up loading of some profile endpoint #2607

Merged
merged 12 commits into from
Jan 2, 2024
4 changes: 2 additions & 2 deletions src/App/Header/UserMenu/EndowmentLink.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Link } from "react-router-dom";
import { useProfileQuery } from "services/aws/aws";
import { useEndowment } from "services/aws/useEndowment";
import ContentLoader from "components/ContentLoader";
import Image from "components/Image";
import QueryLoader from "components/QueryLoader";
import { appRoutes } from "constants/routes";

type Props = { endowId: number };
export default function EndowmentLink({ endowId }: Props) {
const query = useProfileQuery({ endowId });
const query = useEndowment(endowId, ["logo", "name"]);
return (
<QueryLoader
queryState={query}
Expand Down
9 changes: 1 addition & 8 deletions src/components/QueryLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { BaseQueryFn } from "@reduxjs/toolkit/dist/query";
import { TypedUseQueryHookResult } from "@reduxjs/toolkit/dist/query/react/buildHooks";
import { ReactElement } from "react";
import { QueryState } from "types/third-party/redux";
import Status, { ErrorStatus, LoadingStatus } from "components/Status";
import { isEmpty } from "helpers";

type Base = BaseQueryFn<any, unknown, unknown, {}, {}>;
type QueryState<T> = Pick<
TypedUseQueryHookResult<T, any, Base>,
"isLoading" | "isError" | "data"
>;

type Props<T> = {
queryState: QueryState<T>;
messages: {
Expand Down
60 changes: 0 additions & 60 deletions src/pages/Admin/Charity/Banking/VerificationStatus.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/pages/Admin/Charity/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { PropsWithChildren } from "react";
import { useAdminContext } from "pages/Admin/Context";
import { useProfileQuery } from "services/aws/aws";
import { useEndowBalanceQuery } from "services/apes";
import ContentLoader from "components/ContentLoader";
import QueryLoader from "components/QueryLoader";
import Seo from "../Seo";
import Balance from "./Balance";

export default function Dashboard() {
const { id } = useAdminContext();
const queryState = useProfileQuery({ endowId: id }, { skip: !id });
const queryState = useEndowBalanceQuery(id, { skip: !id });

return (
<div className="@container w-full max-w-4xl grid content-start mt-6">
Expand Down
16 changes: 12 additions & 4 deletions src/pages/Admin/Charity/Donations/DonationsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ import Table from "./Table";
export default function DonationsTable({ classes = "" }) {
const { id: endowmentId } = useAdminContext();

const { data, isLoading, isError, hasMore, loadNextPage, isLoadingNextPage } =
usePaginatedDonationRecords({
endowmentId: endowmentId.toString(),
});
const {
data,
isLoading,
isFetching,
isError,
hasMore,
loadNextPage,
isLoadingNextPage,
} = usePaginatedDonationRecords({
endowmentId: endowmentId.toString(),
});

const isLoadingOrError = isLoading || isLoadingNextPage || isError;
return (
Expand All @@ -21,6 +28,7 @@ export default function DonationsTable({ classes = "" }) {
queryState={{
data: data?.Items,
isLoading,
isFetching,
isError,
}}
messages={{
Expand Down
13 changes: 4 additions & 9 deletions src/pages/Admin/Charity/EditProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
EndowmentProfileUpdate,
EndowmentProfile as TProfile,
} from "types/aws";
import { useProfileQuery } from "services/aws/aws";
import { useEndowment } from "services/aws/useEndowment";
import { country } from "components/CountrySelector";
import { FormError, FormSkeleton } from "components/admin";
import { adminRoutes } from "constants/routes";
Expand All @@ -19,12 +19,7 @@ import { toProfileUpdate } from "./update";

export default function EditProfile() {
const { id } = useAdminContext();
const {
data: profile,
isLoading,
isFetching,
isError,
} = useProfileQuery({ endowId: id });
const { data: profile, isLoading, isError, isFetching } = useEndowment(id);

const content =
isLoading || isFetching ? (
Expand Down Expand Up @@ -57,11 +52,11 @@ function FormWithContext(props: TProfile & { id: number }) {
publicUrl: props.image ?? "",
preview: props.image ?? "",
},
logo: { name: "", publicUrl: props.logo ?? "", preview: props.logo ?? "" },
logo: { name: "", publicUrl: props.logo, preview: props.logo },
SovereignAndrey marked this conversation as resolved.
Show resolved Hide resolved
endow_designation: init.endow_designation
? { label: init.endow_designation, value: init.endow_designation }
: { label: "", value: "" },
hq_country: country(props.hq_country ?? ""),
hq_country: country(props.hq_country),
sdgs: init.sdgs.map((x) => getSDGLabelValuePair(x, unsdgs[x].title)),
active_in_countries: init.active_in_countries.map((x) => ({
label: x,
Expand Down
45 changes: 20 additions & 25 deletions src/pages/Admin/Charity/EditProfile/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,31 @@ export function toProfileUpdate(arg: Arg): EndowmentProfileUpdate {
const { data: d } = arg;
return {
id: d.id,
active_in_countries: d.active_in_countries ?? [],
categories: { sdgs: d.sdgs ?? [], general: [] },
charity_navigator_rating: "",
contact_email: d.contact_email ?? "",
contributor_verification_required:
d.contributor_verification_required ?? false,
endow_designation: d.endow_designation ?? "",
hq_country: d.hq_country ?? "",
image: d.image ?? "",
kyc_donors_only: d.kyc_donors_only ?? false,
logo: d.logo ?? "",
name: d.name ?? "",
overview: d.overview ?? "",
active_in_countries: d.active_in_countries,
contact_email: d.contact_email,
endow_designation: d.endow_designation,
hq_country: d.hq_country,
image: d.image,
kyc_donors_only: d.kyc_donors_only,
logo: d.logo,
name: d.name,
overview: d.overview,
program: [], //program is updated in /create-program
program_id: "",
published: d.published ?? false,
registration_number: d.registration_number ?? "",
sdgs: d.sdgs ?? [],
published: d.published,
registration_number: d.registration_number,
sdgs: d.sdgs,
social_media_urls: {
facebook: d.social_media_urls?.facebook ?? "",
instagram: d.social_media_urls?.instagram ?? "",
linkedin: d.social_media_urls?.linkedin ?? "",
twitter: d.social_media_urls?.twitter ?? "",
discord: d.social_media_urls?.discord ?? "",
youtube: d.social_media_urls?.youtube ?? "",
tiktok: d.social_media_urls?.tiktok ?? "",
facebook: d.social_media_urls.facebook,
instagram: d.social_media_urls.instagram,
linkedin: d.social_media_urls.linkedin,
twitter: d.social_media_urls.twitter,
discord: d.social_media_urls.discord,
youtube: d.social_media_urls.youtube,
tiktok: d.social_media_urls.tiktok,
},
street_address: d.street_address ?? "",
street_address: d.street_address,
tagline: d.tagline ?? "",
tier: 1,
url: d.url ?? "",
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Admin/Charity/Programs/List.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useAdminContext } from "pages/Admin/Context";
import { useProfileQuery } from "services/aws/aws";
import { useEndowment } from "services/aws/useEndowment";
import ContentLoader from "components/ContentLoader";
import QueryLoader from "components/QueryLoader";
import { ErrorStatus, Info } from "components/Status";
import { Program } from "./Program";

export default function List() {
const { id } = useAdminContext();
const queryState = useProfileQuery({ endowId: id });
const queryState = useEndowment(id, ["program"]);

return (
<QueryLoader
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Admin/Charity/Seo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useProfileQuery } from "services/aws/aws";
import { useEndowment } from "services/aws/useEndowment";
import CommonSEO from "components/Seo";
import { APP_NAME, DAPP_URL } from "constants/env";
import { appRoutes } from "constants/routes";
Expand All @@ -12,12 +12,12 @@ export default function Seo({
url?: string;
}) {
const { id } = useAdminContext();
const { data: profile } = useProfileQuery({ endowId: id });
const { data: profile } = useEndowment(id, ["logo", "name", "overview"]);

return (
<CommonSEO
title={`${title} - ${APP_NAME}`}
description={(profile?.overview ?? "").slice(0, 140)}
description={profile?.overview.slice(0, 140)}
name={profile?.name}
image={profile?.logo}
url={`${DAPP_URL}/${appRoutes.admin}/${id}/${url}`}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Admin/Sidebar/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useProfileQuery } from "services/aws/aws";
import { useEndowment } from "services/aws/useEndowment";
import Image from "components/Image";
import { useAdminContext } from "../../Context";

export default function Header() {
const { id } = useAdminContext();
const { data: profile, isLoading } = useProfileQuery({ endowId: id });
const { data: profile, isLoading } = useEndowment(id, ["logo", "name"]);

return (
<div
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Applications/Applications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function Applications() {
<QueryLoader
queryState={{
data: data?.Items,
isLoading: isLoading,
isLoading,
isFetching,
isError: isError,
}}
messages={{
Expand Down
3 changes: 2 additions & 1 deletion src/pages/BankingApplications/BankingApplications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function BankingApplications() {
<QueryLoader
queryState={{
data: data?.items,
isLoading: isLoading,
isLoading,
isFetching,
isError: isError,
}}
messages={{
Expand Down
14 changes: 11 additions & 3 deletions src/pages/Donate/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useParams } from "react-router-dom";
import { useProfileQuery } from "services/aws/aws";
import { useEndowment } from "services/aws/useEndowment";
import QueryLoader from "components/QueryLoader";
import Seo from "components/Seo";
import { idParamToNum } from "helpers";
Expand All @@ -9,7 +9,15 @@ import Content from "./Content";
export default function Donate() {
const { id } = useParams<{ id: string }>();
const numId = idParamToNum(id);
const queryState = useProfileQuery({ endowId: numId }, { skip: numId === 0 });
const queryState = useEndowment(numId, [
"fiscal_sponsored",
"id",
"image",
"kyc_donors_only",
"logo",
"name",
"overview",
]);

return (
<section className="grid content-start w-full font-work min-h-screen sm:min-h-[900px] pb-20">
Expand All @@ -33,7 +41,7 @@ export default function Donate() {
<>
<Seo
title={`Donate to ${profile.name} - ${APP_NAME}`}
description={`${(profile?.overview ?? "").slice(0, 140)}`}
description={profile.overview.slice(0, 140)}
name={`${profile.name}`}
image={`${profile.logo}`}
url={`${DAPP_URL}/donate/${profile.id}`}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/DonateWidget/ApiKeyChecker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export default function ApiKeyChecker(props: PropsWithChildren<{}>) {

return (
<QueryLoader
queryState={{ isError: false, isLoading: false, data: {} }}
queryState={{
isError: false,
isLoading: false,
isFetching: false,
data: {},
}}
messages={{ error: "Invalid API key" }}
classes={{ container: "text-center mt-8" }}
>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/DonateWidget/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function Content({
>
<Seo
title={`Donate to ${profile.name} - ${APP_NAME}`}
description={(profile.overview ?? "").slice(0, 140)}
description={profile.overview.slice(0, 140)}
name={profile.name}
image={`${profile.logo}`}
url={`${DAPP_URL}/donate_widget/${profile.id}`}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/DonateWidget/DonateWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from "react";
import { useParams, useSearchParams } from "react-router-dom";
import { useProfileQuery } from "services/aws/aws";
import { useEndowment } from "services/aws/useEndowment";
import { DappLogo } from "components/Image";
import LoaderRing from "components/LoaderRing";
import QueryLoader from "components/QueryLoader";
Expand All @@ -14,7 +14,7 @@ export default function DonateWidget() {
const routeParams = useParams();
const [searchParams] = useSearchParams();
const endowId = idParamToNum(routeParams.id);
const queryState = useProfileQuery({ endowId }, { skip: endowId === 0 });
const queryState = useEndowment(endowId);

/** Hide the Intercom chatbot */
useEffect(() => {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Donations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default withAuth(function Donations({ user }) {
hasMore,
isError,
isLoading,
isFetching,
isLoadingNextPage,
query,
loadNextPage,
Expand Down Expand Up @@ -62,7 +63,8 @@ export default withAuth(function Donations({ user }) {
<QueryLoader
queryState={{
data: data?.Items,
isLoading: isLoading,
isLoading,
isFetching,
isError: isError,
}}
messages={{
Expand Down
Loading