From 2e2f99e0ec3398bfabc8f0a011ea460c6dbb781f Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Wed, 30 Aug 2023 21:48:04 -0500 Subject: [PATCH 01/14] add admin bar with create button --- src/pages/resources/index.tsx | 83 +++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/src/pages/resources/index.tsx b/src/pages/resources/index.tsx index 87a1f4c..6779419 100644 --- a/src/pages/resources/index.tsx +++ b/src/pages/resources/index.tsx @@ -1,5 +1,5 @@ import { LinkIcon } from "@heroicons/react/20/solid"; -import { PrinterIcon } from "@heroicons/react/24/solid"; +import { PrinterIcon, PlusCircleIcon } from "@heroicons/react/24/solid"; import Link from "next/link"; import { useRouter } from "next/router"; import ResourceTable from "~/components/ResourceTable"; @@ -8,6 +8,42 @@ import { parseQueryData } from "~/utils/parseSearchForm"; import { HeaderFooterLayout } from "~/layouts/HeaderFooterLayout"; import { type AuditoryResource } from "@prisma/client"; import { QueryWaitWrapper } from "~/components/LoadingWrapper"; +import { AdminBarLayout } from "~/components/admin/ControlBar"; +import { AdminActionLink } from "~/components/admin/common"; + +const PageHeader = ({ printLink }: { printLink: string }) => { + return ( +
+
+

All Resources

+
+

Fill out the

+ + search form + + +

+ {" "} + for a list of auditory training resource recommendations. +

+
+
+ +
+ + Print Results + + +
+
+ ); +}; const Resources = () => { const router = useRouter(); @@ -49,39 +85,22 @@ const Resources = () => { return ( -
-
-
-

All Resources

-
-

Fill out the

- - search form - - -

- {" "} - for a list of auditory training resource recommendations. -

-
-
+ } + label="Create New" + href={`/resources/create`} + />, + ]} + > +
+ -
- - Print Results - - -
+
- - -
+ ); }; From 6e4efe2842e842518f064bd1846c4b9a9a65f4ae Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Wed, 30 Aug 2023 22:07:56 -0500 Subject: [PATCH 02/14] reuse form to create resource create page --- src/components/admin/resources/form.tsx | 29 +++++++++------ src/pages/resources/create.tsx | 49 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 src/pages/resources/create.tsx diff --git a/src/components/admin/resources/form.tsx b/src/components/admin/resources/form.tsx index 6d6ac69..ceb2fa5 100644 --- a/src/components/admin/resources/form.tsx +++ b/src/components/admin/resources/form.tsx @@ -86,15 +86,22 @@ const SelectImageInput = () => { htmlFor="resource-image-file" className="bg-whit group relative cursor-pointer overflow-hidden rounded-xl border border-neutral-400 drop-shadow-lg" > - - -
- -
+ {photo ? ( + <> + +
+ +
+ + ) : ( +
+ +
+ )} { + const formMethods = useForm(); + + const [serverError, _setServerError] = useState(undefined); + + const onSubmit: SubmitHandler = () => { + // TODO: TRPC request to create resource + }; + + return ( + + } + label="Create" + onClick={() => { + onSubmit(formMethods.getValues()); + }} + />, + } + label="Cancel" + href={`/resources`} + />, + ]} + > +
+ +
+
+
+ ); +}; + +export default EditResourcePage; From 7fc0895177554fd3921d928c85cd580b804e9ecd Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Wed, 30 Aug 2023 22:13:41 -0500 Subject: [PATCH 03/14] fix issue where edit page resource query was refetching causing icon file to be reset --- src/pages/resources/[id]/edit.tsx | 3 +++ src/pages/resources/create.tsx | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/resources/[id]/edit.tsx b/src/pages/resources/[id]/edit.tsx index a5d33c2..471db47 100644 --- a/src/pages/resources/[id]/edit.tsx +++ b/src/pages/resources/[id]/edit.tsx @@ -25,6 +25,9 @@ const EditResourcePage = () => { retry(_failureCount, error) { return error.data?.httpStatus !== 404; }, + refetchOnWindowFocus: false, + refetchOnMount: false, + refetchInterval: false, } ); diff --git a/src/pages/resources/create.tsx b/src/pages/resources/create.tsx index 2a0ced8..9c8dcb9 100644 --- a/src/pages/resources/create.tsx +++ b/src/pages/resources/create.tsx @@ -12,7 +12,9 @@ import { HeaderFooterLayout } from "~/layouts/HeaderFooterLayout"; const EditResourcePage = () => { const formMethods = useForm(); - const [serverError, _setServerError] = useState(undefined); + const [serverError, _setServerError] = useState( + undefined + ); const onSubmit: SubmitHandler = () => { // TODO: TRPC request to create resource From c243fda8e1b878ae085ead600d4e0741bb4728de Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Wed, 30 Aug 2023 22:22:32 -0500 Subject: [PATCH 04/14] fix link add button alignment --- src/components/admin/resources/form.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/admin/resources/form.tsx b/src/components/admin/resources/form.tsx index ceb2fa5..9e2d574 100644 --- a/src/components/admin/resources/form.tsx +++ b/src/components/admin/resources/form.tsx @@ -266,15 +266,15 @@ const ResourceLinkSubForm = () => {

Links

From cd1dc2a555b42c578ca54930f46319720430d4a9 Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Mon, 4 Sep 2023 00:03:42 -0500 Subject: [PATCH 05/14] add create resource trpc function --- src/components/admin/common.tsx | 5 +- src/components/admin/resources/form.tsx | 5 +- src/components/forms/textInput.tsx | 4 +- src/pages/resources/[id]/edit.tsx | 4 +- src/pages/resources/create.tsx | 41 ++++++++--- src/server/api/routers/auditoryResources.ts | 81 +++++++++++---------- 6 files changed, 82 insertions(+), 58 deletions(-) diff --git a/src/components/admin/common.tsx b/src/components/admin/common.tsx index ce1ae95..0f8abd3 100644 --- a/src/components/admin/common.tsx +++ b/src/components/admin/common.tsx @@ -42,13 +42,16 @@ const AdminActionButton = ({ label, onClick, symbol, + type = "button", }: { label: string; - onClick: () => void; + onClick?: () => void; symbol: JSX.Element | undefined; + type?: HTMLButtonElement["type"]; }) => { return (