From bedb763fd1d904a4b6e1178fb4f5b940f3fc9eee Mon Sep 17 00:00:00 2001 From: Jade Allen Cook Date: Sat, 25 Nov 2023 23:47:34 -0800 Subject: [PATCH 01/10] feat: added basic components for form toggling --- src/pages/Dashboard/AidRequestsPage.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pages/Dashboard/AidRequestsPage.tsx b/src/pages/Dashboard/AidRequestsPage.tsx index 2212268..8c8377c 100644 --- a/src/pages/Dashboard/AidRequestsPage.tsx +++ b/src/pages/Dashboard/AidRequestsPage.tsx @@ -5,6 +5,7 @@ import { useContext, useState } from 'react'; import DashboardContext from '../../contexts/DashboardContext'; import Loading from '@components/Loading'; import filterRequests from '@utils/filter-requests'; +import { Form, InputGroup } from 'react-bootstrap'; const AidRequestsPage = () => { const { requests, isLoading, requestFilters, setRequestFilters, uid } = @@ -24,6 +25,17 @@ const AidRequestsPage = () => { filters={requestFilters} setFilters={setRequestFilters} /> +
+ + {}} + /> + Request Form Is Live + +
+
{isLoading ? ( ) : ( From eab7e2199421f46d029691d72527fc74e10432e5 Mon Sep 17 00:00:00 2001 From: Jade Allen Cook Date: Sun, 26 Nov 2023 22:52:46 -0800 Subject: [PATCH 02/10] feat: hiding status for to non mods --- src/pages/Dashboard/AidRequestsPage.tsx | 28 +++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/pages/Dashboard/AidRequestsPage.tsx b/src/pages/Dashboard/AidRequestsPage.tsx index 8c8377c..9715cdd 100644 --- a/src/pages/Dashboard/AidRequestsPage.tsx +++ b/src/pages/Dashboard/AidRequestsPage.tsx @@ -5,11 +5,19 @@ import { useContext, useState } from 'react'; import DashboardContext from '../../contexts/DashboardContext'; import Loading from '@components/Loading'; import filterRequests from '@utils/filter-requests'; -import { Form, InputGroup } from 'react-bootstrap'; +import FormStatusForm from '@forms/FormStatusForm'; +import isUserModerator from '@utils/is-user-moderator'; const AidRequestsPage = () => { - const { requests, isLoading, requestFilters, setRequestFilters, uid } = - useContext(DashboardContext); + const { + requests, + isLoading, + requestFilters, + setRequestFilters, + uid, + myOrganizations, + organizations, + } = useContext(DashboardContext); const [show, setShow] = useState(false); const [selected, setSelected] = useState(); const handler = (id?: string): void => { @@ -17,6 +25,9 @@ const AidRequestsPage = () => { setShow((prev) => !prev); }; + const isMod = + !isLoading && isUserModerator(uid, myOrganizations, organizations); + const filteredRequests = filterRequests(requests, requestFilters); return ( @@ -25,16 +36,7 @@ const AidRequestsPage = () => { filters={requestFilters} setFilters={setRequestFilters} /> -
- - {}} - /> - Request Form Is Live - -
+ {isMod && }
{isLoading ? ( From 2420dbd31654c29220cc8f082ffce847d706e3e9 Mon Sep 17 00:00:00 2001 From: Jade Allen Cook Date: Sun, 26 Nov 2023 22:53:34 -0800 Subject: [PATCH 03/10] feat: added reauqest form status context --- src/contexts/RequestFormStatusContext.tsx | 35 ++++++++ src/index.tsx | 101 ++++++++++++---------- 2 files changed, 91 insertions(+), 45 deletions(-) create mode 100644 src/contexts/RequestFormStatusContext.tsx diff --git a/src/contexts/RequestFormStatusContext.tsx b/src/contexts/RequestFormStatusContext.tsx new file mode 100644 index 0000000..9f110c8 --- /dev/null +++ b/src/contexts/RequestFormStatusContext.tsx @@ -0,0 +1,35 @@ +import { createContext, useEffect, useState } from 'react'; +import getFormStatus from '@api/get-form-status'; + +interface RequestFormStatusContext {} + +const RequestFormStatusContext = createContext<{ + requestFormStatus: boolean; + hasFetchedRequestFormStatus: boolean; +}>(null); + +export const RequestFormStatusProvider = ({ children }) => { + const [hasFetchedRequestFormStatus, setHasFetchedRequestFormStatus] = + useState(false); + const [requestFormStatus, setRequestFormStatus] = useState(false); + + useEffect(() => { + getFormStatus().then((response) => { + setRequestFormStatus(response); + setHasFetchedRequestFormStatus(true); + }); + }, []); + + return ( + + {children} + + ); +}; + +export default RequestFormStatusContext; diff --git a/src/index.tsx b/src/index.tsx index dc5b9ac..083a35f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,6 +18,7 @@ import { QueryClientProvider, } from 'react-query'; import { DashboardProvider, log } from './contexts/DashboardContext'; +import { RequestFormStatusProvider } from './contexts/RequestFormStatusContext'; import toast, { ToastBar, Toaster } from 'react-hot-toast'; import { Button } from 'react-bootstrap'; @@ -50,51 +51,61 @@ const queryClient = new QueryClient({ }); root.render( - - - - - - - {routes.map(({ path, element }) => ( - - ))} - -