From f8f7b7d8d373c6427b34aa07b2098786b5444b97 Mon Sep 17 00:00:00 2001 From: ap-justin <89639563+ap-justin@users.noreply.github.com> Date: Sun, 6 Oct 2024 22:02:15 +0800 Subject: [PATCH] approval prompts --- src/components/Icon/icons.ts | 2 + src/pages/Admin/Charity/Funds/FundItem.tsx | 140 +++++++++++++++------ src/pages/Admin/Charity/Funds/Funds.tsx | 2 +- src/services/aws/endow-funds.ts | 67 +++++----- 4 files changed, 141 insertions(+), 70 deletions(-) diff --git a/src/components/Icon/icons.ts b/src/components/Icon/icons.ts index 223263b370..ece824936d 100644 --- a/src/components/Icon/icons.ts +++ b/src/components/Icon/icons.ts @@ -56,6 +56,7 @@ import { Search, Settings, Shield, + Split, Sprout, SquareArrowOutUpRight, Star, @@ -130,6 +131,7 @@ export const icons = { Save: Save, Search, SecurityScan: Shield, + Split, Sprout, Star, StickyNote, diff --git a/src/pages/Admin/Charity/Funds/FundItem.tsx b/src/pages/Admin/Charity/Funds/FundItem.tsx index d7a60dbb79..b31486709f 100644 --- a/src/pages/Admin/Charity/Funds/FundItem.tsx +++ b/src/pages/Admin/Charity/Funds/FundItem.tsx @@ -1,58 +1,124 @@ import type { FundItem as TFundItem } from "@better-giving/fundraiser"; +import Icon from "components/Icon"; +import Prompt from "components/Prompt"; import { appRoutes } from "constants/routes"; import { useAuthenticatedUser } from "contexts/Auth"; import { useErrorContext } from "contexts/ErrorContext"; +import { useModalContext } from "contexts/ModalContext"; import { Link } from "react-router-dom"; -import { useOptOutMutation } from "services/aws/endow-funds"; +import { + useApproveMutation, + useOptOutMutation, +} from "services/aws/endow-funds"; export const FundItem = (props: TFundItem & { endowId: number }) => { const user = useAuthenticatedUser(); const isActive = new Date().toISOString() <= props.expiration && props.active; const isEditor = user.funds.includes(props.id); const [optOut, { isLoading: isOptingOut }] = useOptOutMutation(); + const [approve, { isLoading: isApproving }] = useApproveMutation(); + const { showModal } = useModalContext(); const { handleError } = useErrorContext(); + const isApproved = props.approvers.includes(props.endowId); + return ( -
- - {props.name} -

- {isActive ? "active" : "closed"} -

- - edit - +
+ - view + {props.name} + + + {isActive ? "active" : "closed"} + - {/** show only when this endow is member of fund */} - + +
+ + + Edit + + {/** fund item won't show once NPO opted out of it: so no need to hide this button */} + + {!isApproved ? ( + + ) : ( +
+ +

Approved

+
+ )} +
); }; diff --git a/src/pages/Admin/Charity/Funds/Funds.tsx b/src/pages/Admin/Charity/Funds/Funds.tsx index 7d8e85fad6..10dc2e1831 100644 --- a/src/pages/Admin/Charity/Funds/Funds.tsx +++ b/src/pages/Admin/Charity/Funds/Funds.tsx @@ -8,7 +8,7 @@ export function Funds() { const { id } = useAdminContext(); const query = useFundsEndowMemberOfQuery({ endowId: id }); return ( -
+

My Fundraisers

({ - fundsEndowMemberOf: builder.query({ - providesTags: ["endow-funds"], - query: ({ endowId }) => { - return { - url: `${v(8)}/endowments/${endowId}/funds`, - }; - }, - }), - optOut: builder.mutation({ - invalidatesTags: ["endow-funds"], - query: ({ fundId, endowId }) => { - return { - url: `${v(8)}/endowments/${endowId}/funds/${fundId}/opt-out`, - method: "POST", - headers: { authorization: TEMP_JWT }, - }; - }, - }), - approve: builder.mutation({ - invalidatesTags: ["endow-funds"], - query: ({ fundId, endowId }) => { - return { - url: `${v(8)}/endowments/${endowId}/funds/${fundId}/approve`, - method: "POST", - headers: { authorization: TEMP_JWT }, - }; - }, - }), +export const { + useFundsEndowMemberOfQuery, + useOptOutMutation, + useApproveMutation, +} = aws.injectEndpoints({ + endpoints: (builder) => ({ + fundsEndowMemberOf: builder.query({ + providesTags: ["endow-funds"], + query: ({ endowId }) => { + return { + url: `${v(8)}/endowments/${endowId}/funds`, + }; + }, }), - }); + optOut: builder.mutation({ + invalidatesTags: ["endow-funds"], + query: ({ fundId, endowId }) => { + return { + url: `${v(8)}/endowments/${endowId}/funds/${fundId}/opt-out`, + method: "POST", + headers: { authorization: TEMP_JWT }, + }; + }, + }), + approve: builder.mutation({ + invalidatesTags: ["endow-funds"], + query: ({ fundId, endowId }) => { + return { + url: `${v(8)}/endowments/${endowId}/funds/${fundId}/approve`, + method: "POST", + headers: { authorization: TEMP_JWT }, + }; + }, + }), + }), +});