Skip to content

Commit

Permalink
feat: add StrapiFileInput
Browse files Browse the repository at this point in the history
  • Loading branch information
joschka committed Jan 11, 2024
1 parent f310371 commit c37ce4e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/components/PageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import List from "./List";
import TileGroup from "./inputs/TileGroup";
import { renderCheckboxFromStrapi } from "~/services/cms/models/StrapiCheckbox";
import { renderDateInputFromStrapi } from "~/services/cms/models/StrapiDateInput";
import { renderFileInputFromStrapi } from "~/services/cms/models/StrapiFileInput";
import { renderAlertFromStrapi } from "~/services/cms/models/StrapiAlert";

type PageContentProps = {
Expand Down Expand Up @@ -88,6 +89,8 @@ function cmsToReact(cms: StrapiContent, templateReplacements: Replacements) {
return <Input {...getInputProps(replacedTemplate)} key={key} />;
case "form-elements.date-input":
return renderDateInputFromStrapi(replacedTemplate);
case "form-elements.file-input":
return renderFileInputFromStrapi(replacedTemplate);
case "form-elements.textarea":
return <Textarea {...getTextareaProps(replacedTemplate)} key={key} />;
case "form-elements.select":
Expand Down
2 changes: 2 additions & 0 deletions app/services/cms/models/StrapiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { StrapiListItemSchema } from "./StrapiListItem";
import { StrapiCheckboxSchema } from "./StrapiCheckbox";
import { StrapiTileGroupSchema } from "./StrapiTileGroup";
import { StrapiDateInputSchema } from "~/services/cms/models/StrapiDateInput";
import { StrapiFileInputSchema } from "~/services/cms/models/StrapiFileInput";
import { StrapiAlertSchema } from "./StrapiAlert";

export const StrapiContentSchema = z.discriminatedUnion("__component", [
Expand All @@ -36,6 +37,7 @@ export const StrapiContentSchema = z.discriminatedUnion("__component", [
StrapiListItemSchema.required({ __component: true }),
StrapiTileGroupSchema.required({ __component: true }),
StrapiDateInputSchema.required({ __component: true }),
StrapiFileInputSchema.required({ __component: true }),
StrapiAlertSchema.required({ __component: true }),
]);

Expand Down
17 changes: 17 additions & 0 deletions app/services/cms/models/StrapiFileInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";
import UploadZone from "~/components/inputs/UploadZone";

export const StrapiFileInputSchema = z
.object({
__component: z.literal("form-elements.file-input").optional(),
name: z.string(),
label: z.string().nullable(),
})
.merge(HasOptionalStrapiIdSchema);

type StrapiFileInput = z.infer<typeof StrapiFileInputSchema>;

export const renderFileInputFromStrapi = (strapiFileInput: StrapiFileInput) => {
return <UploadZone />;
};
2 changes: 2 additions & 0 deletions app/services/cms/models/StrapiFormComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { StrapiTextareaSchema } from "./StrapiTextarea";
import { StrapiCheckboxSchema } from "./StrapiCheckbox";
import { StrapiTileGroupSchema } from "./StrapiTileGroup";
import { StrapiDateInputSchema } from "~/services/cms/models/StrapiDateInput";
import { StrapiFileInputSchema } from "~/services/cms/models/StrapiFileInput";

export const StrapiFormComponentSchema = z.discriminatedUnion("__component", [
StrapiInputSchema.required({ __component: true }),
StrapiDateInputSchema.required({ __component: true }),
StrapiFileInputSchema.required({ __component: true }),
StrapiTextareaSchema.required({ __component: true }),
StrapiSelectSchema.required({ __component: true }),
StrapiDropdownSchema.required({ __component: true }),
Expand Down

0 comments on commit c37ce4e

Please sign in to comment.