Skip to content

Commit

Permalink
fix: 83 | use projectInputSchema to validate project creation form (#90)
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Madeira <francisco.madeira@diconium.com>
  • Loading branch information
fgmadeira authored Oct 1, 2024
1 parent b6b0876 commit 7807ade
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 72 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-files-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ethereal-nexus/dashboard': patch
---

fix: [83] use projectInputSchema to validate project creation form
120 changes: 62 additions & 58 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"gunzip-maybe": "^1.4.2",
"lucide-react": "^0.274.0",
"newrelic": "^11.10.4",
"next": "14.1.0",
"next": "^14.2.13",
"next-auth": "5.0.0-beta.16",
"next-swagger-doc": "^0.4.0",
"next-themes": "^0.2.1",
Expand Down
11 changes: 2 additions & 9 deletions web/dashboard/src/components/projects/project-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@ import {TextArea} from '@/components/ui/text-area';
import {zodResolver} from "@hookform/resolvers/zod";
import React from "react";
import { useToast } from '@/components/ui/use-toast';
import { ProjectInput } from '@/data/projects/dto';
import { ProjectInput, projectInputSchema } from '@/data/projects/dto';
import { upsertProject } from '@/data/projects/actions';
import { useSession } from 'next-auth/react';

const projectsFormSchema = z.object({
name: z.string().min(3, {
message: "Name must be at least 3 characters.",
}),
description: z.string(),
});

type ProjectsFormProps = {
project?: ProjectInput,
onComplete?: () => void,
Expand All @@ -31,7 +24,7 @@ export default function ProjectsForm({project, onComplete, onCancel}: ProjectsFo
const {data: session} = useSession();
const { toast } = useToast()
const form: any = useForm<ProjectInput>({
resolver: zodResolver(projectsFormSchema),
resolver: zodResolver(projectInputSchema),
defaultValues: project ?? {},
});
const onSubmit = async (data: ProjectInput) => {
Expand Down
8 changes: 4 additions & 4 deletions web/dashboard/src/data/projects/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type ProjectComponentConfig = z.infer<
*/
export const projectWithComponentIdSchema = projectSchema.extend({
components: projectComponentConfigSchema.pick({ component_id: true }).array(),
environments: environmentsSchema.pick({id: true, name: true}).array()
environments: environmentsSchema.pick({ id: true, name: true }).array()
});
export type ProjectWithComponentId = z.infer<
typeof projectWithComponentIdSchema
Expand Down Expand Up @@ -148,7 +148,7 @@ export const projectInputSchema = createInsertSchema(projects, {
name: (schema) =>
schema.name.min(4, 'Name must be longer than 4 characters.')
})
.required({ name: true });
.required({ name: true, description: true });
export type ProjectInput = z.infer<typeof projectInputSchema>;

export const projectComponentConfigInputSchema = createInsertSchema(
Expand All @@ -169,11 +169,11 @@ export const environmentWithComponentsSchema = environmentsSchema.extend({
components: componentsSchema.pick({
id: true,
name: true,
title: true,
title: true
}).extend({
config_id: projectComponentConfigSchema.shape.id,
is_active: projectComponentConfigSchema.shape.is_active,
version: componentVersionsSchema.shape.version.nullable(),
version: componentVersionsSchema.shape.version.nullable()
}).array()
});
export type EnvironmentWithComponents = z.infer<typeof environmentWithComponentsSchema>;

0 comments on commit 7807ade

Please sign in to comment.