diff --git a/src/components/Header/SearchDropdown/SearchDropdown.tsx b/src/components/Header/SearchDropdown/SearchDropdown.tsx index 730c186879..aaeec094a8 100644 --- a/src/components/Header/SearchDropdown/SearchDropdown.tsx +++ b/src/components/Header/SearchDropdown/SearchDropdown.tsx @@ -16,13 +16,7 @@ interface Props { export default function SearchDropdown({ classes = "", query }: Props) { const [debouncedQuery, isDebouncing] = useDebouncer(query, 500); const { currentData, isLoading, isFetching, isError, isUninitialized } = - useEndowmentCardsQuery( - { - query: debouncedQuery, - page: "1", - }, - { skip: isDebouncing } - ); + useEndowmentCardsQuery({ query: debouncedQuery }, { skip: isDebouncing }); const isCategoriesShown = !debouncedQuery && !isDebouncing && !isLoading && !isFetching; diff --git a/src/pages/Admin/Charity/Dashboard/index.tsx b/src/pages/Admin/Charity/Dashboard/index.tsx index 2629cd6b18..adac0a0189 100644 --- a/src/pages/Admin/Charity/Dashboard/index.tsx +++ b/src/pages/Admin/Charity/Dashboard/index.tsx @@ -25,7 +25,7 @@ export const loader: LoaderFunction = async ({ params }) => { async function getAllocation(id: number) { const url = new URL(APIs.aws); url.searchParams.set("env", apiEnv); - url.searchParams.set("field", "allocation"); + url.searchParams.set("fields", "allocation"); url.pathname = `v9/endowments/${id}`; return cacheGet(url) diff --git a/src/pages/Admin/Charity/Settings/Form.tsx b/src/pages/Admin/Charity/Settings/Form.tsx index 200afe6121..d04fa002fb 100644 --- a/src/pages/Admin/Charity/Settings/Form.tsx +++ b/src/pages/Admin/Charity/Settings/Form.tsx @@ -5,6 +5,7 @@ import { CheckField, RhfForm } from "components/form"; import { BG_ID } from "constants/common"; import { useErrorContext } from "contexts/ErrorContext"; import { useController, useForm } from "react-hook-form"; +import { useLoaderData } from "react-router-dom"; import { schema } from "schemas/shape"; import type { Endowment, EndowmentSettingsAttributes } from "types/aws"; import type { TDonateMethod } from "types/components"; @@ -15,9 +16,12 @@ import ReceiptMsg from "./ReceiptMsg"; import { MAX_RECEIPT_MSG_CHAR } from "./constants"; import type { FV } from "./types"; -type Props = Pick; +export default function Form() { + const endow = useLoaderData() as Pick< + Endowment, + "id" | EndowmentSettingsAttributes + >; -export default function Form(props: Props) { const updateEndow = useUpdateEndowment(); const { displayError } = useErrorContext(); @@ -35,10 +39,10 @@ export default function Form(props: Props) { }) ), values: { - receiptMsg: props.receiptMsg ?? "", - hide_bg_tip: props.hide_bg_tip ?? false, - programDonateDisabled: !(props.progDonationsAllowed ?? true), - donateMethods: fill(props.donateMethods), + receiptMsg: endow.receiptMsg ?? "", + hide_bg_tip: endow.hide_bg_tip ?? false, + programDonateDisabled: !(endow.progDonationsAllowed ?? true), + donateMethods: fill(endow.donateMethods), }, }); @@ -64,7 +68,7 @@ export default function Form(props: Props) { }} onSubmit={handleSubmit( async ({ programDonateDisabled, donateMethods, ...fv }) => { - if (props.id === BG_ID && fv.hide_bg_tip === false) { + if (endow.id === BG_ID && fv.hide_bg_tip === false) { return displayError( "BG donation flow should not show BG tip screen" ); @@ -73,7 +77,7 @@ export default function Form(props: Props) { await updateEndow({ ...fv, progDonationsAllowed: !programDonateDisabled, - id: props.id, + id: endow.id, donateMethods: donateMethods .filter((m) => !m.disabled) .map((m) => m.id), diff --git a/src/pages/Admin/Charity/Settings/Settings.tsx b/src/pages/Admin/Charity/Settings/Settings.tsx deleted file mode 100644 index 0c863e0a8a..0000000000 --- a/src/pages/Admin/Charity/Settings/Settings.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { FormError, FormSkeleton } from "components/admin"; -import { useEndowment } from "services/aws/useEndowment"; -import { useAdminContext } from "../../Context"; -import Form from "./Form"; - -export default function Settings() { - const { id } = useAdminContext(); - const { - data: endow, - isLoading, - isError, - } = useEndowment({ id }, [ - "receiptMsg", - "hide_bg_tip", - "progDonationsAllowed", - "donateMethods", - ]); - - if (isLoading) { - return ; - } - - if (isError || !endow) { - return ; - } - - return
; -} diff --git a/src/pages/Admin/Charity/Settings/index.ts b/src/pages/Admin/Charity/Settings/index.ts index b07ceb7da8..b40b3271a5 100644 --- a/src/pages/Admin/Charity/Settings/index.ts +++ b/src/pages/Admin/Charity/Settings/index.ts @@ -1 +1,23 @@ -export { default as Component } from "./Settings"; +import { APIs } from "constants/urls"; +import { cacheGet } from "helpers/cache-get"; +import type { LoaderFunction } from "react-router-dom"; +import { apiEnv } from "services/constants"; +import type { EndowmentSettingsAttributes } from "types/aws"; + +export { default as Component } from "./Form"; + +const fields: EndowmentSettingsAttributes[] = [ + "receiptMsg", + "hide_bg_tip", + "progDonationsAllowed", + "donateMethods", +]; +export const loader: LoaderFunction = async ({ params }) => { + const url = new URL(APIs.aws); + url.searchParams.set("env", apiEnv); + url.searchParams.set("fields", fields.join(",")); + url.pathname = `v9/endowments/${params.id}`; + + //Pick; + return cacheGet(url); +}; diff --git a/src/pages/Widget/Configurer/EndowmentSelector/Options.tsx b/src/pages/Widget/Configurer/EndowmentSelector/Options.tsx index 2988c7fa1d..1afbbda3f0 100644 --- a/src/pages/Widget/Configurer/EndowmentSelector/Options.tsx +++ b/src/pages/Widget/Configurer/EndowmentSelector/Options.tsx @@ -13,7 +13,6 @@ export default function Options({ searchText, isDebouncing = false }: Props) { query: searchText, sdgs: Object.keys(unsdgs).join(","), kyc_only: "true,false", - page: "1", }); return ( diff --git a/src/services/aws/aws.ts b/src/services/aws/aws.ts index 42c44edf1e..b6af0e7d23 100644 --- a/src/services/aws/aws.ts +++ b/src/services/aws/aws.ts @@ -68,10 +68,10 @@ export const aws = createApi({ }), endowmentOptions: builder.query({ providesTags: ["endowments"], - query: ({ page = "1", ...p }) => { + query: (p) => { return { url: `${v(1)}/cloudsearch-nonprofits`, - params: { ...p, page, fields: endowSelectorOptionFields }, + params: { ...p, page: 1, fields: endowSelectorOptionFields }, }; }, transformResponse(res: EndowListPaginatedAWSQueryRes) {