Skip to content

Commit

Permalink
Merge branch 'npo-funds' into FB-fundraisers
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-justin committed Sep 4, 2024
2 parents 7292c1f + 6f10633 commit ac0bf52
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const adminRoutes = {
settings: "settings",
members: "members",
media: "media",
funds: "funds",
} as const;

export enum donateWidgetRoutes {
Expand Down
89 changes: 89 additions & 0 deletions src/pages/Admin/Charity/Funds/Funds.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import ContentLoader from "components/ContentLoader";
import Image from "components/Image";
import QueryLoader from "components/QueryLoader";
import { appRoutes } from "constants/routes";
import { useAuthenticatedUser } from "contexts/Auth";
import { Link } from "react-router-dom";
import { useFundsEndowMemberOfQuery } from "services/aws/aws";
import type { Fund } from "types/aws";
import { useAdminContext } from "../../Context";

export function Funds() {
const { id } = useAdminContext();
const query = useFundsEndowMemberOfQuery({ endowId: id });
return (
<div className="grid gap-y-4 grid-cols-[auto_auto_1fr_auto_auto] justify-items-start">
<h3 className="text-3xl mb-2 col-span-full">My Fundraisers</h3>

<QueryLoader
messages={{
loading: (
<>
<Skeleton />
<Skeleton />
<Skeleton />
</>
),
error: "Failed to get fundraisers",
empty: "No fundraisers found.",
}}
queryState={query}
>
{(funds) => (
<>
{funds.map((fund) => (
<FundItem key={fund.id} {...fund} />
))}
</>
)}
</QueryLoader>
</div>
);
}

const FundItem = (props: Fund.Card) => {
const user = useAuthenticatedUser();
const isActive = new Date().toISOString() <= props.expiration && props.active;
const isEditor = user.funds.includes(props.id);

return (
<div className="grid grid-cols-subgrid col-span-5 items-center gap-3 rounded border border-gray-l4">
<Image src={props.logo} className="object-cover h-full w-10" />
<span className="mr-4 p-1.5 font-medium text-navy-l1">{props.name}</span>
<p
className={`uppercase justify-self-start text-2xs rounded-full px-3 py-0.5 ${
isActive ? "text-green bg-green-l4" : "text-red bg-red-l4"
}`}
>
{isActive ? "active" : "closed"}
</p>
<Link
aria-disabled={!isActive || !isEditor}
className={`text-sm hover:text-blue-d1 text-blue uppercase p-3 aria-disabled:pointer-events-none aria-disabled:text-gray ${
isEditor ? "" : "invisible"
}`}
to={`${appRoutes.funds}/${props.id}/edit`}
>
edit
</Link>
<Link
className="text-sm hover:text-blue-d1 text-blue uppercase p-3"
to={`${appRoutes.funds}/${props.id}`}
>
view
</Link>
</div>
);
};

export function Skeleton() {
return (
<div
className="flex items-center gap-x-2 w-full col-span-full"
aria-disabled={true}
>
<ContentLoader className="size-10 rounded-full" />
<ContentLoader className="w-full h-10 rounded" />
</div>
);
}
1 change: 1 addition & 0 deletions src/pages/Admin/Charity/Funds/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Funds as Component } from "./Funds";
1 change: 1 addition & 0 deletions src/pages/Admin/Charity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const charityRoute: RouteObject = {
],
},
{ path: adminRoutes.widget_config, element: <EndowWidget /> },
{ path: adminRoutes.funds, lazy: () => import("./Funds") },
{ index: true, lazy: () => import("./Dashboard") },
...mediaRoutes,
],
Expand Down
8 changes: 8 additions & 0 deletions src/pages/Admin/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ const linkGroup3: LinkGroup = {
size: 25,
},
},
{
title: "Fundraisers",
to: sidebarRoutes.funds,
icon: {
type: "Heart",
size: 20,
},
},
],
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/UserDashboard/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const linkGroups: LinkGroup[] = [
to: routes.donations,
icon: {
type: "DollarCircle",
size: 22,
size: 21,
},
},
{
Expand All @@ -40,7 +40,7 @@ export const linkGroups: LinkGroup[] = [
to: routes.funds,
icon: {
type: "Heart",
size: 21,
size: 19,
},
},
],
Expand Down
11 changes: 10 additions & 1 deletion src/services/aws/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
EndowmentCard,
EndowmentOption,
EndowmentsQueryParams,
Fund,
PaginatedAWSQueryRes,
} from "types/aws";
import { version as v } from "../helpers";
Expand Down Expand Up @@ -156,7 +157,14 @@ export const aws = createApi({
}
},
}),

fundsEndowMemberOf: builder.query<Fund.Card[], { endowId: number }>({
providesTags: ["endowment"],
query: ({ endowId }) => {
return {
url: `${v(8)}/endowments/${endowId}/funds`,
};
},
}),
endowment: builder.query<
Endowment,
IdOrSlug & { fields?: (keyof Endowment)[] }
Expand Down Expand Up @@ -251,6 +259,7 @@ export const {
useDonationsQuery,
useLazyDonationsQuery,
useLazyEndowWithEinQuery,
useFundsEndowMemberOfQuery,
endpoints: {
endowmentCards: { useLazyQuery: useLazyEndowmentCardsQuery },
endowmentOptions: { useLazyQuery: useLazyEndowmentOptionsQuery },
Expand Down
5 changes: 4 additions & 1 deletion src/types/aws/ap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ export namespace Fund {
| "members"
| "target"
| "approvers"
> {}
> {
/** iso | "9999-12-31T23:59:59.000Z" year 9999 */
expiration: string;
}

export interface CardsPage {
items: Card[];
Expand Down

0 comments on commit ac0bf52

Please sign in to comment.