From e7ab8ebfb008f3ac097cdbae0d4f116797aa51f6 Mon Sep 17 00:00:00 2001 From: Diptesh Choudhuri Date: Tue, 22 Oct 2024 05:02:12 +0530 Subject: [PATCH] chore(frontend): prefill type of while creating custom media Fixes #1077. --- .../routes/_dashboard.media.$action.$lot.tsx | 4 ++-- .../app/routes/_dashboard.media.create.tsx | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/frontend/app/routes/_dashboard.media.$action.$lot.tsx b/apps/frontend/app/routes/_dashboard.media.$action.$lot.tsx index 166513c542..7e75023908 100644 --- a/apps/frontend/app/routes/_dashboard.media.$action.$lot.tsx +++ b/apps/frontend/app/routes/_dashboard.media.$action.$lot.tsx @@ -280,9 +280,9 @@ export default function Page() { diff --git a/apps/frontend/app/routes/_dashboard.media.create.tsx b/apps/frontend/app/routes/_dashboard.media.create.tsx index 88c55e75f8..16083cf9d9 100644 --- a/apps/frontend/app/routes/_dashboard.media.create.tsx +++ b/apps/frontend/app/routes/_dashboard.media.create.tsx @@ -21,7 +21,7 @@ import { unstable_parseMultipartFormData, } from "@remix-run/node"; import type { MetaArgs_SingleFetch } from "@remix-run/react"; -import { Form } from "@remix-run/react"; +import { Form, useLoaderData } from "@remix-run/react"; import { CreateCustomMetadataDocument, MediaLot, @@ -30,11 +30,19 @@ import { camelCase, changeCase, processSubmission } from "@ryot/ts-utils"; import { IconCalendar, IconPhoto, IconVideo } from "@tabler/icons-react"; import { $path } from "remix-routes"; import { z } from "zod"; +import { zx } from "zodix"; import { useCoreDetails } from "~/lib/hooks"; import { s3FileUploader, serverGqlService } from "~/lib/utilities.server"; -export const loader = unstable_defineLoader(async (_args) => { - return {}; +const searchParamsSchema = z.object({ + lot: z.nativeEnum(MediaLot).optional(), +}); + +export type SearchParams = z.infer; + +export const loader = unstable_defineLoader(async ({ request }) => { + const query = zx.parseQuery(request, searchParamsSchema); + return { query }; }); export const meta = (_args: MetaArgs_SingleFetch) => { @@ -80,6 +88,7 @@ const schema = z.object({ }); export default function Page() { + const loaderData = useLoaderData(); const coreDetails = useCoreDetails(); const fileUploadNotAllowed = !coreDetails.fileStorageEnabled; @@ -91,13 +100,14 @@ export default function Page() {