diff --git a/package.json b/package.json index 4aa61d8c02..231ec8baae 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "dependencies": { "@better-giving/assets": "1.0.18", - "@better-giving/endowment": "1.0.21", + "@better-giving/endowment": "1.0.26", "@better-giving/registration": "1.0.24", "@better-giving/schemas": "1.0.1", "@better-giving/types": "1.0.1", @@ -43,7 +43,7 @@ "@paypal/react-paypal-js": "8.3.0", "@radix-ui/react-slider": "1.1.2", "@radix-ui/react-tooltip": "1.1.2", - "@reduxjs/toolkit": "2.2.3", + "@reduxjs/toolkit": "2.3.0", "@sentry/react": "8.22.0", "@stripe/react-stripe-js": "2.7.1", "@stripe/stripe-js": "3.5.0", diff --git a/src/App/Header/SearchDropdown/SearchDropdown.tsx b/src/App/Header/SearchDropdown/SearchDropdown.tsx index 01886cdb4f..6980722a2c 100644 --- a/src/App/Header/SearchDropdown/SearchDropdown.tsx +++ b/src/App/Header/SearchDropdown/SearchDropdown.tsx @@ -18,7 +18,6 @@ interface Props { export default function SearchDropdown({ classes = "", query }: Props) { const [debouncedQuery, isDebouncing] = useDebouncer(query, 500); const { currentData, isLoading, isFetching, isError, isUninitialized } = - /** @ts-ignore: temp */ useEndowmentCardsQuery( { query: debouncedQuery, diff --git a/src/App/Header/UserMenu/EndowmentLink.tsx b/src/App/Header/UserMenu/EndowmentLink.tsx index b9fd53662e..b913c0dbda 100644 --- a/src/App/Header/UserMenu/EndowmentLink.tsx +++ b/src/App/Header/UserMenu/EndowmentLink.tsx @@ -11,7 +11,7 @@ interface IBookmarkLink { endowId: number; } export function BookmarkLink({ endowId }: IBookmarkLink) { - const query = useEndowment({ id: endowId }, ["logo", "name"]); + const query = useEndowment(endowId, ["logo", "name"]); return ( { - /** @ts-ignore: temp */ const { data } = useEndowmentCardsQuery({ claimed: "true", page: "1", diff --git a/src/pages/Admin/Charity/EditProfile/index.tsx b/src/pages/Admin/Charity/EditProfile/index.tsx index 67677fa97e..dcf6d20ac0 100644 --- a/src/pages/Admin/Charity/EditProfile/index.tsx +++ b/src/pages/Admin/Charity/EditProfile/index.tsx @@ -13,12 +13,7 @@ import type { FV } from "./schema"; export function Component() { const { id } = useAdminContext(); - const { - data: profile, - isLoading, - isError, - isFetching, - } = useEndowment({ id }); + const { data: profile, isLoading, isError, isFetching } = useEndowment(id); const content = isLoading || isFetching ? ( diff --git a/src/pages/Admin/Charity/EditProfile/useEditProfile.ts b/src/pages/Admin/Charity/EditProfile/useEditProfile.ts index af3afa1b8c..df349cded1 100644 --- a/src/pages/Admin/Charity/EditProfile/useEditProfile.ts +++ b/src/pages/Admin/Charity/EditProfile/useEditProfile.ts @@ -40,7 +40,7 @@ export default function useEditProfile(id: number, df: DirtyFields) { } if (df.slug) { - const result = await endowment({ slug: fv.slug }); + const result = await endowment({ id: fv.slug }); //endow is found with update.slug if (result.isSuccess) { return displayError(`Slug "${fv.slug}" is already taken`); diff --git a/src/pages/Admin/Charity/Media/VideoPreview.tsx b/src/pages/Admin/Charity/Media/VideoPreview.tsx index 640658448d..d13855904f 100644 --- a/src/pages/Admin/Charity/Media/VideoPreview.tsx +++ b/src/pages/Admin/Charity/Media/VideoPreview.tsx @@ -1,4 +1,4 @@ -import type { TMedia } from "@better-giving/endowment"; +import type { IMedia } from "@better-giving/endowment"; import { useErrorContext } from "contexts/ErrorContext"; import { useModalContext } from "contexts/ModalContext"; import { LoaderCircle, Minus, Pencil, Star } from "lucide-react"; @@ -11,7 +11,7 @@ import { } from "services/aws/media"; import VideoEditor from "./VideoEditor"; -export default function VideoPreview(props: TMedia) { +export default function VideoPreview(props: IMedia) { const { id } = useAdminContext(); const { handleError } = useErrorContext(); const { showModal } = useModalContext(); diff --git a/src/pages/Admin/Charity/Seo.tsx b/src/pages/Admin/Charity/Seo.tsx index b2da9903ca..249ae5c706 100644 --- a/src/pages/Admin/Charity/Seo.tsx +++ b/src/pages/Admin/Charity/Seo.tsx @@ -12,7 +12,7 @@ export default function Seo({ url?: string; }) { const { id } = useAdminContext(); - const { data: profile } = useEndowment({ id }, ["logo", "name", "overview"]); + const { data: profile } = useEndowment(id, ["logo", "name", "overview"]); return ( (); const numId = idParamToNum(id); - const queryState = useEndowment({ id: numId }); + const queryState = useEndowment(numId); return ( { diff --git a/src/pages/Marketplace/Cards/index.tsx b/src/pages/Marketplace/Cards/index.tsx index 1b2b7ff2a3..fab5d60beb 100644 --- a/src/pages/Marketplace/Cards/index.tsx +++ b/src/pages/Marketplace/Cards/index.tsx @@ -1,4 +1,5 @@ import QueryLoader from "components/QueryLoader"; +import type { EndowmentCard } from "types/aws"; import Card from "./Card"; import useCards from "./useCards"; @@ -33,7 +34,7 @@ export default function Cards({ classes = "" }: { classes?: string }) {
- {endowments.map((endow) => ( + {endowments.map((endow: EndowmentCard) => ( ))} diff --git a/src/pages/Marketplace/Cards/useCards.ts b/src/pages/Marketplace/Cards/useCards.ts index b556f14628..16d2ac51b8 100644 --- a/src/pages/Marketplace/Cards/useCards.ts +++ b/src/pages/Marketplace/Cards/useCards.ts @@ -24,7 +24,6 @@ export default function useCards() { }), {} ); - const { isLoading, isFetching, @@ -41,7 +40,7 @@ export default function useCards() { /** search for both verified/unverified if user didn't explicitly narrow verified status */ searchText && isEmpty(verified) ? "true,false" : verified.join(","), ..._params, - }, + } as any, { skip: isDebouncing } ); diff --git a/src/pages/Profile/Body/GeneralInfo/Media.tsx b/src/pages/Profile/Body/GeneralInfo/Media.tsx index 4dfc785e5a..852026fdd3 100644 --- a/src/pages/Profile/Body/GeneralInfo/Media.tsx +++ b/src/pages/Profile/Body/GeneralInfo/Media.tsx @@ -1,7 +1,7 @@ -import type { TMedia } from "@better-giving/endowment"; +import type { IMedia } from "@better-giving/endowment"; import ReactPlayer from "react-player"; -export default function Media({ media }: { media: TMedia[] }) { +export default function Media({ media }: { media: IMedia[] }) { return (
{media.map((m) => ( @@ -11,7 +11,7 @@ export default function Media({ media }: { media: TMedia[] }) { ); } -function Medium(props: TMedia) { +function Medium(props: IMedia) { return ( /** @see https://github.com/CookPete/react-player/issues/145 */
diff --git a/src/pages/Profile/index.tsx b/src/pages/Profile/index.tsx index 18ad0b6850..3d79001942 100644 --- a/src/pages/Profile/index.tsx +++ b/src/pages/Profile/index.tsx @@ -1,3 +1,4 @@ +import { endowIdParam, segment } from "@better-giving/endowment/schema"; import fallback_banner from "assets/images/fallback-banner.png"; import flying_character from "assets/images/flying-character.png"; import Image from "components/Image"; @@ -12,8 +13,8 @@ import { useOutletContext, useParams, } from "react-router-dom"; -import { segment } from "schemas/string"; import { useEndowment } from "services/aws/useEndowment"; +import { parse, union } from "valibot"; import { bodyRoute } from "./Body"; import PageError from "./PageError"; import ProfileContext, { useProfileContext } from "./ProfileContext"; @@ -21,11 +22,10 @@ import Skeleton from "./Skeleton"; function Profile() { const legacy = useOutletContext(); - const { id = "" } = useParams<{ id: string }>(); + const params = useParams(); + const id = parse(union([segment, endowIdParam]), params.id); - const { isLoading, isError, data } = useEndowment( - segment.isValidSync(id) ? { slug: id } : { id: Number(id) } - ); + const { isLoading, isError, data } = useEndowment(id); if (isLoading) return ; if (isError || !data) return ; diff --git a/src/pages/Widget/Preview.tsx b/src/pages/Widget/Preview.tsx index b62eec59fa..f710b6551b 100644 --- a/src/pages/Widget/Preview.tsx +++ b/src/pages/Widget/Preview.tsx @@ -13,7 +13,7 @@ export default function Preview({ classes = "", config }: Props) { const { endowment, methods, increments, ...restConfig } = config; const endowName = config.endowment.name; - const { data } = useEndowment({ id: endowment.id }, [ + const { data } = useEndowment(endowment.id, [ "hide_bg_tip", "progDonationsAllowed", ]); diff --git a/src/pages/Widget/Widget.tsx b/src/pages/Widget/Widget.tsx index fca85cde63..b589bdd2d1 100644 --- a/src/pages/Widget/Widget.tsx +++ b/src/pages/Widget/Widget.tsx @@ -14,7 +14,7 @@ import Preview from "./Preview"; import Snippet from "./Snippet"; export function Widget({ endowId = 0 }: { endowId?: number }) { - const queryState = useEndowment({ id: endowId }, undefined, { + const queryState = useEndowment(endowId, undefined, { skip: !endowId, }); diff --git a/src/services/aws/aws.ts b/src/services/aws/aws.ts index cf91971cdb..82806a6a4a 100644 --- a/src/services/aws/aws.ts +++ b/src/services/aws/aws.ts @@ -13,7 +13,6 @@ import { createApi, fetchBaseQuery, retry } from "@reduxjs/toolkit/query/react"; import { fetchAuthSession } from "aws-amplify/auth"; import { TEMP_JWT } from "constants/auth"; import { APIs } from "constants/urls"; -import { apiEnv } from "services/constants"; import type { RootState } from "store/store"; import { userIsSignedIn } from "types/auth"; import type { @@ -24,7 +23,6 @@ import type { EndowmentOption, } from "types/aws"; import { version as v } from "../helpers"; -import type { IdOrSlug } from "../types"; const awsBaseQuery = retry( fetchBaseQuery({ @@ -158,15 +156,14 @@ export const aws = createApi({ }, }), - endowment: builder.query({ + endowment: builder.query< + Endow, + { id: string | number; fields?: (keyof Endow)[] } + >({ providesTags: ["endowment"], - query: ({ fields, ...args }) => ({ - url: "id" in args ? `v10/endowments/${args.id}` : "v10/endowments", - params: { - env: apiEnv, - slug: args.slug, - ...(fields ? { fields: fields.join(",") } : {}), - }, + query: ({ fields, id }) => ({ + url: `${v(1)}/endowments/${id}`, + params: fields ? { fields: fields.join(",") } : {}, }), }), @@ -276,9 +273,7 @@ export const endowByEin = async ( ): Promise< Pick | undefined > => { - const res = await fetch( - `${APIs.aws}/v10/endowments?ein=${ein}&env=${apiEnv}` - ); + const res = await fetch(`${APIs.aws}/${v(1)}/endowments/ein/${ein}`); if (res.status === 404) return undefined; if (!res.ok) throw res; return res.json() as Promise; diff --git a/src/services/aws/media.ts b/src/services/aws/media.ts index f84e61dab1..71f14d803b 100644 --- a/src/services/aws/media.ts +++ b/src/services/aws/media.ts @@ -1,8 +1,8 @@ import type { + IMedia, MediaPage, MediaQueryParamsObj, MediaUpdate, - TMedia, } from "@better-giving/endowment"; import { TEMP_JWT } from "constants/auth"; import { version as v } from "../helpers"; @@ -16,7 +16,7 @@ const media = aws.injectEndpoints({ return { url: `/${v(1)}/endowments/${endowId}/media`, params }; }, }), - medium: builder.query({ + medium: builder.query({ providesTags: ["program"], query: ({ endowId, mediaId }) => `/${v(1)}/endowments/${endowId}/media/${mediaId}`, @@ -36,7 +36,7 @@ const media = aws.injectEndpoints({ }, }), editMedium: builder.mutation< - TMedia, + IMedia, MediaUpdate & { endowId: number; mediaId: string } >({ invalidatesTags: (_, error) => (error ? [] : ["medium", "media"]), diff --git a/src/services/aws/useEndowment.ts b/src/services/aws/useEndowment.ts index 7bab331a43..f915741d91 100644 --- a/src/services/aws/useEndowment.ts +++ b/src/services/aws/useEndowment.ts @@ -1,5 +1,4 @@ import type { Endow } from "@better-giving/endowment"; -import type { IdOrSlug } from "services/types"; import type { QueryState } from "types/third-party/redux"; import { useEndowmentQuery } from "./aws"; @@ -7,17 +6,11 @@ type ArrayValues = T[number]; type K = keyof Endow; export function useEndowment( - idOrSlug: IdOrSlug, + id: string | number, fields?: T, options?: { skip: boolean } ) { - const query = useEndowmentQuery( - { - ...idOrSlug, - fields, - }, - options - ); + const query = useEndowmentQuery({ id, fields }, options); return query as QueryState< T extends K[] ? Pick> : Endow diff --git a/yarn.lock b/yarn.lock index ba251fc6ba..06340d31eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -822,13 +822,14 @@ __metadata: languageName: node linkType: hard -"@better-giving/endowment@npm:1.0.21": - version: 1.0.21 - resolution: "@better-giving/endowment@npm:1.0.21" +"@better-giving/endowment@npm:1.0.26": + version: 1.0.26 + resolution: "@better-giving/endowment@npm:1.0.26" peerDependencies: "@better-giving/schemas": 1.0.1 "@better-giving/types": 1.0.1 - checksum: 10/06bab62039f9cc3b5b9ac5ec5912a5ed2f66fefdc94babe1bfb98c23f3e3aedb1f9780312972cc690b67b08fbecc6ba3cc69691d49f47050671c3f1962586f4b + valibot: 0.42.0 + checksum: 10/c1a0056e764999222b146dc2daaa10ec58f46d0fcc615c6c7948bdd6246855f52342194e8fed5c449500ee457bf0cfedad1f7a2e159ce60edd9e041bf3e1a72e languageName: node linkType: hard @@ -2154,14 +2155,14 @@ __metadata: languageName: node linkType: hard -"@reduxjs/toolkit@npm:2.2.3": - version: 2.2.3 - resolution: "@reduxjs/toolkit@npm:2.2.3" +"@reduxjs/toolkit@npm:2.3.0": + version: 2.3.0 + resolution: "@reduxjs/toolkit@npm:2.3.0" dependencies: immer: "npm:^10.0.3" redux: "npm:^5.0.1" redux-thunk: "npm:^3.1.0" - reselect: "npm:^5.0.1" + reselect: "npm:^5.1.0" peerDependencies: react: ^16.9.0 || ^17.0.0 || ^18 react-redux: ^7.2.1 || ^8.1.3 || ^9.0.0 @@ -2170,7 +2171,7 @@ __metadata: optional: true react-redux: optional: true - checksum: 10/7054747462f8b6a0739b76e227fde8a08143c9deef663f31c2f6f72352e0d1d49a400c8e56c68f320e0e88029412d7f452d88dd2b2a5d6dce7b65c9be646e894 + checksum: 10/3aa0bf29ce4dfe4ae75416cb5338a91ccc89f06c5a2fcdae5dc137dca02b3990c46306062696e158869ac399b50cae6476e5536902df9bd1ad1a998195221af6 languageName: node linkType: hard @@ -3466,7 +3467,7 @@ __metadata: resolution: "angelprotocol-web-app@workspace:." dependencies: "@better-giving/assets": "npm:1.0.18" - "@better-giving/endowment": "npm:1.0.21" + "@better-giving/endowment": "npm:1.0.26" "@better-giving/registration": "npm:1.0.24" "@better-giving/schemas": "npm:1.0.1" "@better-giving/types": "npm:1.0.1" @@ -3478,7 +3479,7 @@ __metadata: "@paypal/react-paypal-js": "npm:8.3.0" "@radix-ui/react-slider": "npm:1.1.2" "@radix-ui/react-tooltip": "npm:1.1.2" - "@reduxjs/toolkit": "npm:2.2.3" + "@reduxjs/toolkit": "npm:2.3.0" "@rsbuild/core": "npm:0.5.9" "@rsbuild/plugin-react": "npm:0.5.9" "@sentry/react": "npm:8.22.0" @@ -6107,7 +6108,7 @@ __metadata: languageName: node linkType: hard -"reselect@npm:^5.0.1": +"reselect@npm:^5.1.0": version: 5.1.1 resolution: "reselect@npm:5.1.1" checksum: 10/1fdae11a39ed9c8d85a24df19517c8372ee24fefea9cce3fae9eaad8e9cefbba5a3d4940c6fe31296b6addf76e035588c55798f7e6e147e1b7c0855f119e7fa5