Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”€ ํผ ์ƒ์„ฑ api ํ†ต์‹  ์ง„ํ–‰ #85

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

Ethen1264
Copy link
Contributor

@Ethen1264 Ethen1264 commented Jan 27, 2025

๐Ÿ’ก ๋ฐฐ๊ฒฝ ๋ฐ ๊ฐœ์š”

ํผ ์ƒ์„ฑ api ํ†ต์‹  ์ง„ํ–‰

๐Ÿ“ƒ ์ž‘์—…๋‚ด์šฉ

  • route api ์ œ์ž‘
  • tanstack query๋กœ ํ†ต์‹  ์ง„ํ–‰

๐ŸŽธ ๊ธฐํƒ€

  • ์ถ”ํ›„ ํ•„์ˆ˜ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ ์˜ˆ์ •
  • ์ถ”ํ›„ ๊ธฐํƒ€ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ ์˜ˆ์ •
  • ์ถ”ํ›„ ๊ฐœ์ธ์ •๋ณด ๋™์˜ ์ด๋ฏธ์ง€ ์ถ”๊ฐ€ ์˜ˆ์ •
  • ์ถ”ํ›„ ์—๋Ÿฌ ํ•ธ๋“ค๋ง ์ถ”๊ฐ€ ์˜ˆ์ •
  • ์ถ”ํ›„ ํŽ˜์ด์ง€ ์„ฑ๋Šฅ ๊ฐœ์„  ์˜ˆ์ •

์ž‘์„ฑํ•˜์ง€ ์•Š์€ ๋ถ€๋ถ„์€ ์‚ญ์ œํ•˜์—ฌ์ฃผ์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.

Summary by CodeRabbit

  • ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ

    • ์–‘์‹ ์ƒ์„ฑ ํ”„๋กœ์„ธ์Šค์˜ ์ƒˆ๋กœ์šด API ์—”๋“œํฌ์ธํŠธ ์ถ”๊ฐ€
    • ์–‘์‹ ์ƒ์„ฑ์„ ์œ„ํ•œ ์‚ฌ์šฉ์ž ์นœํ™”์ ์ธ ์ œ์ถœ ๋ฉ”์ปค๋‹ˆ์ฆ˜ ๊ตฌํ˜„
    • ์ œ์ถœ ์ƒํƒœ์— ๋Œ€ํ•œ ์‚ฌ์šฉ์ž ํ”ผ๋“œ๋ฐฑ ๊ฐœ์„  (์ œ์ถœ ์ค‘ ์ƒํƒœ, ํ† ์ŠคํŠธ ์•Œ๋ฆผ)
  • ๋ฒ„๊ทธ ์ˆ˜์ •

    • ์–‘์‹ ์ œ์ถœ ์ค‘ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ๋ฉ”์ปค๋‹ˆ์ฆ˜ ๊ฐ•ํ™”
  • ๊ฐœ์„  ์‚ฌํ•ญ

    • ์ œ์ถœ ๋ฒ„ํŠผ์˜ ์ƒํ˜ธ์ž‘์šฉ์„ฑ ๋ฐ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜ ํ–ฅ์ƒ
    • ์–‘์‹ ๋ฐ์ดํ„ฐ ์ œ์ถœ์„ ์œ„ํ•œ ๋” ๊ตฌ์กฐํ™”๋œ ์ ‘๊ทผ ๋ฐฉ์‹ ๋„์ž…

@Ethen1264 Ethen1264 added โœจ Feature ์‹ ๊ทœ ๊ธฐ๋Šฅ ๐Ÿ“ฌ Type: API ์„œ๋ฒ„ API ํ†ต์‹  labels Jan 27, 2025
@Ethen1264 Ethen1264 self-assigned this Jan 27, 2025
Copy link

coderabbitai bot commented Jan 27, 2025

๋ณ€๊ฒฝ ์‚ฌํ•ญ ๋ถ„์„

๊ฐœ์š”

์ด ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋Š” ํผ ์ƒ์„ฑ ๋ฐ ์ œ์ถœ ํ”„๋กœ์„ธ์Šค์™€ ๊ด€๋ จ๋œ ์—ฌ๋Ÿฌ ํŒŒ์ผ์— ๋Œ€ํ•œ ์ค‘์š”ํ•œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด API ๋ผ์šฐํŠธ, ํผ ์ƒ์„ฑ API ํ•จ์ˆ˜, ์ปค์Šคํ…€ React ํ›…, ๊ทธ๋ฆฌ๊ณ  ํผ ์ œ์ถœ ์ปดํฌ๋„ŒํŠธ์˜ ๋กœ์ง์ด ์—…๋ฐ์ดํŠธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๋ณ€๊ฒฝ ๋‚ด์šฉ

ํŒŒ์ผ ๋ณ€๊ฒฝ ์š”์•ฝ
src/app/api/form/[expo_id]/route.ts ์ƒˆ๋กœ์šด ๋น„๋™๊ธฐ POST ํ•จ์ˆ˜ ์ถ”๊ฐ€, API ์š”์ฒญ ์ฒ˜๋ฆฌ ๋ฐ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ๋ฉ”์ปค๋‹ˆ์ฆ˜ ๊ตฌํ˜„
src/views/create-form/api/createForm.ts ํผ ์ƒ์„ฑ์„ ์œ„ํ•œ ์ƒˆ๋กœ์šด createForm ๋น„๋™๊ธฐ ํ•จ์ˆ˜ ์ถ”๊ฐ€
src/views/create-form/model/useCreateForm.ts ํผ ์ƒ์„ฑ ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ์ปค์Šคํ…€ React ํ›… ์ถ”๊ฐ€
src/views/create-form/ui/createForm/index.tsx ํผ ์ œ์ถœ ๋กœ์ง ์žฌ๊ตฌ์„ฑ, useCreateForm ํ›… ํ†ตํ•ฉ

๊ด€๋ จ ๊ฐ€๋Šฅ์„ฑ ์žˆ๋Š” PR

์ถ”์ฒœ ๋ฆฌ๋ทฐ์–ด

  • happytaeyoon

์‹œํ€€์Šค ๋‹ค์ด์–ด๊ทธ๋žจ

sequenceDiagram
    participant Client
    participant CreateFormComponent
    participant useCreateForm
    participant CreateFormAPI
    participant BackendServer

    Client->>CreateFormComponent: ํผ ๋ฐ์ดํ„ฐ ์ž…๋ ฅ
    CreateFormComponent->>useCreateForm: createForm ๋ฎคํ…Œ์ด์…˜ ํ˜ธ์ถœ
    useCreateForm->>CreateFormAPI: ํผ ๋ฐ์ดํ„ฐ ์ „์†ก
    CreateFormAPI->>BackendServer: POST ์š”์ฒญ
    BackendServer-->>CreateFormAPI: ์‘๋‹ต
    CreateFormAPI-->>useCreateForm: ์„ฑ๊ณต/์‹คํŒจ ์ฒ˜๋ฆฌ
    useCreateForm-->>CreateFormComponent: ์•Œ๋ฆผ ๋ฐ ๋ผ์šฐํŒ…
Loading

์‹œ (ํ† ๋ผ์˜ ๋…ธ๋ž˜)

๐Ÿฐ ์ฝ”๋“œ์˜ ๋ฌผ๊ฒฐ, ์ƒˆ๋กœ์šด ๊ธธ์„ ์—ด์–ด
ํผ์€ ์ถค์ถ”๊ณ , API๋Š” ๋…ธ๋ž˜ํ•ด
์˜ค๋ฅ˜๋ฅผ ์žก์•„ ๋น›๋‚˜๋Š” ๋กœ์ง
์ œ์ถœ ๋ฒ„ํŠผ์€ ํฌ๋ง์„ ๋…ธ๋ž˜ํ•ด
๊ธฐ์ˆ ์˜ ํ† ๋ผ, ์•ž์œผ๋กœ ๋‹ฌ๋ ค๊ฐ€๋„ค! ๐Ÿš€

โœจ Finishing Touches
  • ๐Ÿ“ Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

โค๏ธ Share
๐Ÿชง Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

๐Ÿงน Nitpick comments (2)
src/views/create-form/model/useCreateForm.ts (1)

7-34: Mutation ํ›… ๊ฐœ์„  ํ•„์š”

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฐœ์„ ์‚ฌํ•ญ์„ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค:

 export const useCreateForm = (
   id: string,
   navigation: string | null,
   router: AppRouterInstance,
 ) => {
   const queryClient = useQueryClient();
 
   return useMutation({
     mutationKey: ['createForm', id, navigation],
     mutationFn: (formattedData: {
       informationImage: string;
       participantType: string;
       dynamicForm: {
         title: string;
         formType: string;
         jsonData: Record<string, string>;
       }[];
     }) => createForm({ data: formattedData, id }),
+    retry: 2,
+    retryDelay: 1000,
     onSuccess: () => {
       toast.success('ํผ์ด ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.');
       formCreateRouter({ id, navigation, router });
       queryClient.resetQueries({ queryKey: ['createForm', id, navigation] });
     },
-    onError: () => {
-      toast.error('ํผ ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
+    onError: (error) => {
+      if (axios.isAxiosError(error)) {
+        toast.error(error.response?.data?.message || 'ํผ ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
+      } else {
+        toast.error('๋„คํŠธ์›Œํฌ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.');
+      }
     },
   });
 };
src/views/create-form/ui/createForm/index.tsx (1)

97-101: ๋กœ๋”ฉ ์ƒํƒœ UI ๊ฐœ์„  ํ•„์š”

์ œ์ถœ ๋ฒ„ํŠผ์˜ ๋กœ๋”ฉ ์ƒํƒœ ํ‘œ์‹œ๋ฅผ ๊ฐœ์„ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

 <Button
   type="submit"
   text={isPending ? '์ œ์ถœ ์ค‘...' : '๋‹ค์Œ'}
-  disabled={isPending || isSuccess}
+  disabled={isPending || isSuccess || fields.length === 0}
+  className={isPending ? 'opacity-70 cursor-not-allowed' : ''}
 />
๐Ÿ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between a7c9a53 and d7138fc.

๐Ÿ“’ Files selected for processing (4)
  • src/app/api/form/[expo_id]/route.ts (1 hunks)
  • src/views/create-form/api/createForm.ts (1 hunks)
  • src/views/create-form/model/useCreateForm.ts (1 hunks)
  • src/views/create-form/ui/createForm/index.tsx (3 hunks)

Comment on lines +3 to +20
export const createForm = async ({
data,
id,
}: {
data: {
informationImage: string;
participantType: string;
dynamicForm: {
title: string;
formType: string;
jsonData: Record<string, string>;
}[];
};
id: string;
}) => {
const response = await axios.post(`/api/form/${id}`, data);
return response;
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ› ๏ธ Refactor suggestion

API ๊ตฌํ˜„์— ๋Œ€ํ•œ ๊ฐœ์„  ํ•„์š”

๋‹ค์Œ ์‚ฌํ•ญ๋“ค์„ ๊ฐœ์„ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค:

  1. ์—๋Ÿฌ ์ฒ˜๋ฆฌ ๋กœ์ง ์ถ”๊ฐ€
  2. ์‘๋‹ต ํƒ€์ž… ์ •์˜
  3. ์š”์ฒญ ํƒ€์ž„์•„์›ƒ ์„ค์ •
  4. ์š”์ฒญ ์ทจ์†Œ ์ฒ˜๋ฆฌ
 import axios from 'axios';
+import { AxiosResponse } from 'axios';
+
+interface FormResponse {
+  // TODO: ์‘๋‹ต ํƒ€์ž… ์ •์˜
+}
 
 export const createForm = async ({
   data,
   id,
 }: {
   data: {
     informationImage: string;
     participantType: string;
     dynamicForm: {
       title: string;
       formType: string;
       jsonData: Record<string, string>;
     }[];
   };
   id: string;
-}) => {
-  const response = await axios.post(`/api/form/${id}`, data);
+}): Promise<AxiosResponse<FormResponse>> => {
+  const controller = new AbortController();
+  const timeoutId = setTimeout(() => controller.abort(), 10000);
+
+  try {
+    const response = await axios.post<FormResponse>(`/api/form/${id}`, data, {
+      signal: controller.signal,
+    });
+    return response;
+  } catch (error) {
+    if (axios.isAxiosError(error)) {
+      throw error;
+    }
+    throw new Error('์•Œ ์ˆ˜ ์—†๋Š” ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.');
+  } finally {
+    clearTimeout(timeoutId);
+  }
-  return response;
 };
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const createForm = async ({
data,
id,
}: {
data: {
informationImage: string;
participantType: string;
dynamicForm: {
title: string;
formType: string;
jsonData: Record<string, string>;
}[];
};
id: string;
}) => {
const response = await axios.post(`/api/form/${id}`, data);
return response;
};
import axios from 'axios';
import { AxiosResponse } from 'axios';
interface FormResponse {
// TODO: ์‘๋‹ต ํƒ€์ž… ์ •์˜
}
export const createForm = async ({
data,
id,
}: {
data: {
informationImage: string;
participantType: string;
dynamicForm: {
title: string;
formType: string;
jsonData: Record<string, string>;
}[];
};
id: string;
}): Promise<AxiosResponse<FormResponse>> => {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000);
try {
const response = await axios.post<FormResponse>(`/api/form/${id}`, data, {
signal: controller.signal,
});
return response;
} catch (error) {
if (axios.isAxiosError(error)) {
throw error;
}
throw new Error('์•Œ ์ˆ˜ ์—†๋Š” ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.');
} finally {
clearTimeout(timeoutId);
}
};

Comment on lines +6 to +32
export async function POST(
request: Request,
{ params }: { params: { expo_id: number } },
) {
const body = await request.json();
const { expo_id } = params;
const cookieStore = cookies();
const accessToken = cookieStore.get('accessToken')?.value;
const config = accessToken
? {
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
: {};
try {
const response = await apiClient.post(`/form/${expo_id}`, body, config);
return NextResponse.json(response.data);
} catch (error) {
const axiosError = error as AxiosError<{ message: string }>;

const status = axiosError.response?.status;
const message = axiosError.response?.data?.message;

return NextResponse.json({ error: message }, { status });
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ› ๏ธ Refactor suggestion

API ์—”๋“œํฌ์ธํŠธ ๋ณด์•ˆ ๋ฐ ํƒ€์ž… ์•ˆ์ •์„ฑ ๊ฐœ์„  ํ•„์š”

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฐœ์„ ์‚ฌํ•ญ์„ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค:

+import { z } from 'zod';
+
+const FormDataSchema = z.object({
+  informationImage: z.string(),
+  participantType: z.string(),
+  dynamicForm: z.array(
+    z.object({
+      title: z.string(),
+      formType: z.string(),
+      jsonData: z.record(z.string())
+    })
+  )
+});
+
 export async function POST(
   request: Request,
   { params }: { params: { expo_id: number } },
 ) {
   const body = await request.json();
+  
+  const validationResult = FormDataSchema.safeParse(body);
+  if (!validationResult.success) {
+    return NextResponse.json(
+      { error: '์ž˜๋ชป๋œ ์š”์ฒญ ๋ฐ์ดํ„ฐ์ž…๋‹ˆ๋‹ค.' },
+      { status: 400 }
+    );
+  }
+
   const { expo_id } = params;
   const cookieStore = cookies();
   const accessToken = cookieStore.get('accessToken')?.value;
+  
+  if (!accessToken) {
+    return NextResponse.json(
+      { error: '์ธ์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.' },
+      { status: 401 }
+    );
+  }
+
   const config = accessToken
     ? {
         headers: {
           Authorization: `Bearer ${accessToken}`,
         },
       }
     : {};
   try {
     const response = await apiClient.post(`/form/${expo_id}`, body, config);
     return NextResponse.json(response.data);
   } catch (error) {
     const axiosError = error as AxiosError<{ message: string }>;
 
     const status = axiosError.response?.status;
-    const message = axiosError.response?.data?.message;
+    const message = axiosError.response?.status === 500
+      ? '์„œ๋ฒ„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'
+      : axiosError.response?.data?.message;
 
     return NextResponse.json({ error: message }, { status });
   }
 }
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function POST(
request: Request,
{ params }: { params: { expo_id: number } },
) {
const body = await request.json();
const { expo_id } = params;
const cookieStore = cookies();
const accessToken = cookieStore.get('accessToken')?.value;
const config = accessToken
? {
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
: {};
try {
const response = await apiClient.post(`/form/${expo_id}`, body, config);
return NextResponse.json(response.data);
} catch (error) {
const axiosError = error as AxiosError<{ message: string }>;
const status = axiosError.response?.status;
const message = axiosError.response?.data?.message;
return NextResponse.json({ error: message }, { status });
}
}
import { z } from 'zod';
const FormDataSchema = z.object({
informationImage: z.string(),
participantType: z.string(),
dynamicForm: z.array(
z.object({
title: z.string(),
formType: z.string(),
jsonData: z.record(z.string())
})
)
});
export async function POST(
request: Request,
{ params }: { params: { expo_id: number } },
) {
const body = await request.json();
const validationResult = FormDataSchema.safeParse(body);
if (!validationResult.success) {
return NextResponse.json(
{ error: '์ž˜๋ชป๋œ ์š”์ฒญ ๋ฐ์ดํ„ฐ์ž…๋‹ˆ๋‹ค.' },
{ status: 400 }
);
}
const { expo_id } = params;
const cookieStore = cookies();
const accessToken = cookieStore.get('accessToken')?.value;
if (!accessToken) {
return NextResponse.json(
{ error: '์ธ์ฆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.' },
{ status: 401 }
);
}
const config = accessToken
? {
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
: {};
try {
const response = await apiClient.post(`/form/${expo_id}`, body, config);
return NextResponse.json(response.data);
} catch (error) {
const axiosError = error as AxiosError<{ message: string }>;
const status = axiosError.response?.status;
const message = axiosError.response?.status === 500
? '์„œ๋ฒ„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'
: axiosError.response?.data?.message;
return NextResponse.json({ error: message }, { status });
}
}

Comment on lines +37 to +54
const onSubmit = (data: FormValues) => {
const formattedData = {
informationImage: '',
participantType: navigation?.toUpperCase() || 'STANDARD',
dynamicForm: data.questions.map((question) => ({
title: question.title,
formType: question.formType,
jsonData: question.options.reduce(
(acc, option, index) => {
acc[(index + 1).toString()] = option.value;
return acc;
},
{} as Record<string, string>,
),
})),
};
console.log(formattedData);
formCreateRouter({ id, navigation, router });
createForm(formattedData);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โš ๏ธ Potential issue

ํผ ์ œ์ถœ ๋กœ์ง ๊ฐœ์„  ํ•„์š”

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฌธ์ œ์ ๋“ค์ด ๋ฐœ๊ฒฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค:

  1. ํ”„๋กœ๋•์…˜ ์ฝ”๋“œ์— console.log ์กด์žฌ
  2. ํผ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ถ€์žฌ
  3. informationImage๊ฐ€ ๋นˆ ๋ฌธ์ž์—ด๋กœ ์ „์†ก๋จ
  4. ๋กœ๋”ฉ ์ƒํƒœ์— ๋Œ€ํ•œ UI ํ”ผ๋“œ๋ฐฑ ๋ถ€์กฑ
-  const onSubmit = (data: FormValues) => {
+  const onSubmit = async (data: FormValues) => {
+    if (data.questions.length === 0) {
+      toast.error('์ตœ์†Œ ํ•˜๋‚˜์˜ ์งˆ๋ฌธ์„ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.');
+      return;
+    }
+
     const formattedData = {
-      informationImage: '',
+      informationImage: '๊ธฐ๋ณธ ์ด๋ฏธ์ง€ URL', // TODO: ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ํ•„์š”
       participantType: navigation?.toUpperCase() || 'STANDARD',
       dynamicForm: data.questions.map((question) => ({
         title: question.title,
         formType: question.formType,
         jsonData: question.options.reduce(
           (acc, option, index) => {
             acc[(index + 1).toString()] = option.value;
             return acc;
           },
           {} as Record<string, string>,
         ),
       })),
     };
-    console.log(formattedData);
     createForm(formattedData);
   };

Committable suggestion skipped: line range outside the PR's diff.

@Ethen1264 Ethen1264 merged commit 9a570f5 into develop Jan 27, 2025
2 checks passed
@Ethen1264 Ethen1264 deleted the api/create-form branch February 3, 2025 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
โœจ Feature ์‹ ๊ทœ ๊ธฐ๋Šฅ ๐Ÿ“ฌ Type: API ์„œ๋ฒ„ API ํ†ต์‹ 
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants