Skip to content

Commit

Permalink
refactor(ms2/folder-creation): don't parse input twice
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeTrost committed Nov 24, 2024
1 parent 63917c3 commit c216e4f
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/management-system-v2/components/folder-creation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { ComponentProps, FC, useTransition } from 'react';
import { App } from 'antd';
import { useParams, useRouter } from 'next/navigation';
import { useEnvironment } from './auth-can';
import { FolderUserInput, FolderUserInputSchema } from '@/lib/data/folder-schema';
import { FolderUserInput } from '@/lib/data/folder-schema';
import { createFolder as serverCreateFolder } from '@/lib/data/folders';
import FolderModal from './folder-modal';
import useParseZodErrors from '@/lib/useParseZodErrors';
import { wrapServerCall } from '@/lib/wrap-server-call';

export const FolderCreationModal: FC<
Expand All @@ -18,18 +17,12 @@ export const FolderCreationModal: FC<
const spaceId = useEnvironment().spaceId;
const folderId = useParams<{ folderId: string }>().folderId ?? '';
const [isLoading, startTransition] = useTransition();
const [errors, parseInput] = useParseZodErrors(FolderUserInputSchema);

const createFolder = (values: FolderUserInput) => {
startTransition(async () => {
await wrapServerCall({
fn: async () => {
const folderInput = parseInput({ ...values, parentId: folderId, environmentId: spaceId });
if (!folderInput) throw new Error();

return await serverCreateFolder(folderInput);
},
onSuccess: () => {
fn: async () => serverCreateFolder(values),
onSuccess() {
router.refresh();
message.open({ type: 'success', content: 'Folder Created' });
props.close();
Expand Down

0 comments on commit c216e4f

Please sign in to comment.