Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions screens/generate-code-field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ export const generateCodeSnippet = (field: FormFieldType) => {
<FormLabel>${field.label}</FormLabel>
<FormControl>
<FileUploader
value={files}
onValueChange={setFiles}
value={field.value}
onValueChange={field.onChange}
dropzoneOptions={dropZoneConfig}
className="relative bg-background rounded-lg p-2"
>
Expand All @@ -479,9 +479,9 @@ export const generateCodeSnippet = (field: FormFieldType) => {
</div>
</FileInput>
<FileUploaderContent>
{files &&
files.length > 0 &&
files.map((file, i) => (
{field.value &&
field.value.length > 0 &&
field.value.map((file, i) => (
<FileUploaderItem key={i} index={i}>
<Paperclip className="h-4 w-4 stroke-current" />
<span>{file.name}</span>
Expand Down
11 changes: 9 additions & 2 deletions screens/generate-code-parts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export const generateZodSchema = (
fieldSchema = z.string().min(1, { message: 'Required' })
break
}
case 'File Input':
fieldSchema = z.array(z.instanceof(File))
break
case 'Location Input':
fieldSchema = z.tuple([
z.string().min(1, { message: 'Country is required' }),
Expand Down Expand Up @@ -73,7 +76,7 @@ export const generateZodSchema = (
fieldSchema = z
.array(z.string())
.min(1, { message: 'Please select at least one item' })
break
break
case 'Rating':
fieldSchema = z.coerce.number().min(1, { message: 'Rating is required' })
break
Expand Down Expand Up @@ -193,6 +196,11 @@ export const zodSchemaToString = (schema: z.ZodTypeAny): string => {
return `${zodSchemaToString(schema.unwrap() as z.ZodTypeAny)}.optional()`
}

// @ts-ignore
if (schema instanceof z.ZodType<InstanceType<File>>) {
return `z.instanceof(File)`
}

return 'z.unknown()'
}

Expand Down Expand Up @@ -336,7 +344,6 @@ export const generateConstants = (
] as const;`)
} else if (field.variant === 'File Input') {
constantSet.add(`
const [files, setFiles] = useState<File[] | null>(null);

const dropZoneConfig = {
maxFiles: 5,
Expand Down