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

Form/#16 #39

Merged
merged 28 commits into from
Mar 8, 2024
Merged

Form/#16 #39

merged 28 commits into from
Mar 8, 2024

Conversation

seonghunYang
Copy link
Collaborator

@seonghunYang seonghunYang commented Mar 1, 2024

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

๊ตฌํ˜„ ๋‚ด์šฉ ๋ฐ ์ž‘์—… ํ–ˆ๋˜ ๋‚ด์—ญ

  • form view ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐœ๋ฐœํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • form์— ์‚ฌ์šฉ๋˜๋Š” input, select, button ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฆฌํŒฉํ† ๋งํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • zod ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•˜๊ณ , ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋กœ์ง์„ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • form ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ stories๋ฅผ ๋งŒ๋“ค๊ณ  interaction์„ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๐Ÿค” ๊ณ ๋ฏผ ํ–ˆ๋˜ ๋ถ€๋ถ„

  • form ์ปดํฌ๋„ŒํŠธ์— ์ปดํŒŒ์šด๋“œ ํŒจํ„ด์„ ์ ์šฉํ•˜์—ฌ form์˜ ํ•˜์œ„ ์š”์†Œ์— ๋Œ€ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋ถ„๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๊ฐ ํ•˜์œ„ ์š”์†Œ์— ์ ์ ˆํ•œ ์ฑ…์ž„์„ ๋ถ„๋ฆฌํ•˜๊ณ ์ž ๋…ธ๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค.
  • interaction์ด ํ•„์š”ํ•œ form ๊ฐ™์€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์œ„ํ•ด storybook์˜ play ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋„ˆ๋ฌด๋„ˆ๋ฌด๋„ˆ๋ฌด ์‹ ๊ธฐํ•˜๋„ค์š”. ๊ผญ ํ™•์ธํ•ด์ฃผ์„ธ์š”(interactions tab์— ์žˆ์–ด์š”)
  • ๋ฒ„ํŠผ ์ปดํฌ๋„ŒํŠธ๊ฐ€ label์„ props๋กœ ๋ฐ›๊ณ  ์žˆ์–ด, form ๊ตฌํ˜„ ์‹œ ํ•„์š”ํ•œ spinner icon์„ ์–ด๋–ป๊ฒŒ ํ™•์žฅํ• ์ง€ ๊ณ ๋ฏผํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด์— ์„ค๊ณ„์ƒ props๋กœ ๋ฐ›๋Š” ๊ฒƒ์ด ์ ์ ˆํ•˜๋‹ค๊ณ  ํŒ๋‹จํ•˜๊ณ , loading props๋ฅผ ์ „๋‹ฌํ•˜์—ฌ ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, disabled ์ƒํƒœ์˜ ๋ฒ„ํŠผ์— ๋Œ€ํ•œ ์Šคํƒ€์ผ๋ง์ด ์—†์–ด ์ถ”๊ฐ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๐Ÿ”Š ๋„์›€์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„

  • form-root ์ปดํฌ๋„ŒํŠธ ํŒŒ์ผ์— filterChildrenByType๋ผ๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ํ•จ์ˆ˜๋ฅผ utils ํด๋”์— ๋นผ๋†“๊ณ  ์‹ถ์€๋ฐ, ์–ด๋–ค ํŒŒ์ผ๋กœ ๋นผ๋†“์„์ง€ ๊ณ ๋ฏผ์ด ๋์Šต๋‹ˆ๋‹ค. ์ข‹์€ ์˜๊ฒฌ ์žˆ์œผ์‹ ๊ฐ€์š”?

Copy link

github-actions bot commented Mar 1, 2024

@Myongji-Graduate Myongji-Graduate deleted a comment from github-actions bot Mar 1, 2024
import { createContext } from 'react';
import type { FormState } from './form-root';

type FormContext = FormState & { formId: string };
Copy link
Member

Choose a reason for hiding this comment

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

์ €๋Š” ํ™•์žฅ์ด ์‰ฝ๋‹ค๋Š” ์ด์œ ๋กœ ๊ฐ์ฒด์˜ ํƒ€์ž…์„ ์„ ์–ธํ•˜๋Š” ๊ฒฝ์šฐ์— interface๋กœ ํƒ€์ž…์„ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์„ ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค. ์ธ๋ฑ์Šค ์‹œ๊ทธ๋‹ˆ์ฒ˜์˜ ์‚ฌ์šฉ๊ณผ ๊ฐ™์ด type์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋Š” ์„ž์–ด์„œ ์‚ฌ์šฉ์„ ํ•ด์™”์—ˆ๋Š”๋ฐ์š”.

์ €ํฌ ํ”„๋กœ์ ํŠธ์•ˆ์—์„œ ์ „๋ฐ˜์ ์œผ๋กœ ์ปจ๋ฒค์…˜ ํ†ต์ผ์ด ํ•„์š”ํ•  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“œ๋„ค์š”. ํ˜น์‹œ type์œผ๋กœ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์„ ์„ ํ˜ธํ•˜์‹œ๋Š” ์ด์œ ๊ฐ€ ์žˆ๋‹ค๋ฉด ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • ์ €๋ฒˆ ํšŒ์˜ ๊ฒฐ๊ณผ๋Œ€๋กœ interface๋กœ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.
    3e5be8c

form={formId}
size={size}
variant={variant}
type="submit"
Copy link
Member

Choose a reason for hiding this comment

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

button์˜ default๊ฐ’์ด submit์ด๋ผ๋Š” ์ด์œ ๋กœ ์ €๋Š” ๋ณ„๋„๋กœ ์ž‘์„ฑ์„ ํ•˜์ง€ ์•Š๋Š” ํŽธ์ธ๋ฐ, ํ˜น์‹œ ์ž‘์„ฑํ•˜์‹œ๋Š” ํŠน๋ณ„ํ•œ ์ด์œ ๊ฐ€ ์žˆ์œผ์‹œ๋‹ค๋ฉด ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • ๊ธฐ๋ณธ๊ฐ’์ด๋ผ๋„ ๋ช…์‹œ์ ์œผ๋กœ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์„ ๋” ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ์ฝ๋Š” ์‚ฌ๋žŒ์ด ๋‚ด๋ถ€ ๊ธฐ๋ณธ๊ฐ’์ด ๋ฌด์—‡์ธ์ง€ ํ™•์ธํ•  ํ•„์š”๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

Copy link
Member

Choose a reason for hiding this comment

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

FormNumberInput, FormPasswordInput, FormTextInput๊ฐ€ type๋งŒ ๋ณ„๋„๋กœ ๊ฐ–๋Š” ๋™์ผํ•œ ์—ญํ• ์„ ํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ์ธ ๊ฒƒ ๊ฐ™์€๋ฐ ๋ณ„๋„๋กœ ๋ถ„๋ฆฌํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด ์ €๋„ ๋งŽ์ด ๊ณ ๋ฏผํ–ˆ์Šต๋‹ˆ๋‹ค. ์„ค๊ณ„ ๋‹น์‹œ์— 3๊ฐ€์ง€ input์ด ๊ฑฐ์˜ ๋™์ผํ•œ ๋กœ์ง์„ ๊ฐ€์งˆ ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜์—ฌ, type์„ ์ด์šฉํ•ด ํ•˜๋‚˜์˜ input์œผ๋กœ ๋ถ„๋ฆฌํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ณ ๋ฏผํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ถ„๋ฆฌํ•œ ์ด์œ ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
  • ํ˜„์žฌ ์ƒํ™ฉ์—์„œ๋Š” 3๊ฐ€์ง€ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ค‘๋ณต๋œ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ผ ์ˆ˜ ์žˆ์œผ๋‚˜, ํ™•์žฅ์ด ์ด๋ฃจ์–ด์งˆ ๊ฒฝ์šฐ์—๋Š” ์ถฉ๋ถ„ํžˆ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๋ด…๋‹ˆ๋‹ค. ์ด๋•Œ type์œผ๋กœ ๋ถ„๋ฆฌํ•ด ๋‘๋ฉด ๋‚˜์ค‘์— ์ˆ˜์ •ํ•˜๊ธฐ๊ฐ€ ๋งค์šฐ ์–ด๋ ค์›Œ์ง‘๋‹ˆ๋‹ค.
  • ์‹ฌ์ง€์–ด ํ™•์žฅ์ด ์ด๋ฃจ์–ด์ง€์ง€ ์•Š๋Š”๋‹ค ํ•ด๋„, type์œผ๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์ปดํฌ๋„ŒํŠธ ์ˆ˜์ค€์œผ๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋” ์„ ์–ธ์ ์ด๊ณ  ๋ช…ํ™•ํ•˜๋ฉฐ, ์ปดํŒŒ์šด๋“œ ํŒจํ„ด์—๋„ ์ ํ•ฉํ•˜๋‹ค๊ณ  ํŒ๋‹จํ•ฉ๋‹ˆ๋‹ค. (์˜ˆ: form ์ปดํฌ๋„ŒํŠธ ๋‚ด์˜ input ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ์—์„œ type์œผ๋กœ ๋ถ„๊ธฐํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค, ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ ์ˆ˜์ค€์—์„œ Number, Password, Text input์ด ์žˆ๋Š” ๊ฒƒ์ด ์ด form์—์„œ ์ง€์›ํ•˜๋Š” ๊ฒƒ์„ ํŒŒ์•…ํ•˜๊ธฐ ๋” ์‰ฝ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.)

Copy link
Member

@gahyuun gahyuun left a comment

Choose a reason for hiding this comment

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

๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค

@@ -0,0 +1,67 @@
'use server';

import { State } from '@/app/ui/view/molecule/form/form-root';
Copy link
Member

Choose a reason for hiding this comment

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

form root ํŒŒ์ผ์—์„œ state ๋ฅผ export ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์—๋Ÿฌ๊ฐ€ ๋œจ๋„ค์š” ํ™•์ธ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค!

Copy link
Collaborator Author

@seonghunYang seonghunYang Mar 5, 2024

Choose a reason for hiding this comment

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

  • ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ณ ๋ง™์Šต๋‹ˆ๋‹ค.
    6b0bef3

Comment on lines 37 to 39
type User = z.infer<typeof SignUpFormSchema>;

export async function createUser(prevState: State, formData: FormData): Promise<State> {
Copy link
Member

Choose a reason for hiding this comment

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

User ํƒ€์ž…๊ณผ prevState๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ ๋”ฐ๋กœ ์„ ์–ธํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์šฉ?

Copy link
Collaborator Author

@seonghunYang seonghunYang Mar 2, 2024

Choose a reason for hiding this comment

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

  • User ํƒ€์ž…์€ ํšŒ์›๊ฐ€์ž… ๋กœ์ง์„ ๊ตฌํ˜„ํ•  ๋•Œ ์‚ฌ์šฉํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.
  • react-dom์˜ useFormState๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ปจ๋ฒค์…˜์ž…๋‹ˆ๋‹ค

.max(20, {
message: 'User ID must be at most 20 characters',
}),
password: z.string().regex(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!^%*#?&])[A-Za-z\d@$!^%*#?&]{8,}$/, {
Copy link
Member

Choose a reason for hiding this comment

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

placeholder์—๋Š” ๊ธฐํ˜ธ๋ฅผ ํฌํ•จํ•œ 8์ž ์ด์ƒ 20์ž ์ดํ•˜์ธ๋ฐ ์ •๊ทœ์‹์—๋Š” ์ˆซ์ž๊ฐ€ ๋ฌด์กฐ๊ฑด ํฌํ•จ๋˜๋„๋ก ๋งŒ๋“œ์‹  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ํ™•์ธ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹น

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • ๊ธฐ์กด placeholder๋ฅผ ๊ทธ๋Œ€๋กœ ์˜ฎ๊ฒผ์ง€๋งŒ, ์ด๋ฒˆ์— ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ทœ์น™์„ ์ •๊ทœํ‘œํ˜„์‹์— ๋”ฐ๋ผ ์ˆ˜์ •ํ•  ๊ณ„ํš์ž…๋‹ˆ๋‹ค. ๋กœ์ง์„ ๊ตฌํ˜„ํ•  ๋•Œ placeholder๋„ ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

Copy link
Member

Choose a reason for hiding this comment

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

Required ํ•„๋“œ์—๋Š” ํ•„์ˆ˜ ์ž…๋ ฅ ํ‘œ์‹œ (ex ๋ณ„ํ‘œ)๊ฐ€ ์žˆ์œผ๋ฉด ux์ ์œผ๋กœ ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋•๋ถ„์— ๋” ์ข‹์€ ๊ฒฐ๊ณผ๋ฌผ์ด ๋‚˜์™”๋„ค์š”:)
    a65ada4

Comment on lines 10 to 11
variant?: 'primary' | 'secondary';
size?: 'xs' | 'sm' | 'md' | 'lg' | 'default';
Copy link
Member

Choose a reason for hiding this comment

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

button component props์—์„œ ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉํ•ด๋„ ๋  ๊ฒƒ ๊ฐ™์•„์š”~!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


export const SignUpFormActionWithFailure: Story = {
...SingUpFormTemplate,
play: async ({ canvasElement }) => {
Copy link
Member

Choose a reason for hiding this comment

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

play ๊ธฐ๋Šฅ ์ •๋ง ์‹ ๊ธฐํ•˜๋„ค์š” ๐Ÿ‘๐Ÿป

Comment on lines +1 to +3
import type { Meta, StoryObj } from '@storybook/react';

import Form from '.';
Copy link
Member

Choose a reason for hiding this comment

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

import๋ฌธ ๋„์–ด์“ฐ๊ธฐ๋กœ ๋ถ„๋ฆฌํ•˜์‹  ๊ฒŒ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด์„œ ์˜๋„ํ•˜์‹  ๊ฑฐ ๋งž์„๊นŒ์š”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • ๋„ค, ๋งž์Šต๋‹ˆ๋‹ค. ์‹ค์ œ๋กœ๋„ ๋‹ค๋ฅธ ์„ฑ์งˆ์˜ import๋ฅผ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์„ ์„ ํ˜ธํ•˜๋ฉฐ, storybook docs์˜ ์Šคํƒ€์ผ์„ ๋”ฐ๋ฅธ ๊ฒƒ์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.
    https://storybook.js.org/docs/writing-stories/args#story-args

errors: Record<string, string[] | undefined>;
};

// Refactor: ์• ๋ฅผ ๋”ฐ๋กœ ๋นผ๊ณ ์‹ถ์€๋ฐ utils ํด๋”์— ์–ด๋–ค ํŒŒ์ผ๋ช…์ด ์ข‹์„๊นŒ?
Copy link
Member

Choose a reason for hiding this comment

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

ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ๋‹ค๋ฃจ๋Š” ํ•จ์ˆ˜์ด๊ธฐ์— component.util.ts๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™๋„ค์šฉ

Copy link
Member

Choose a reason for hiding this comment

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

form์—์„œ๋งŒ ์‚ฌ์šฉ๋  ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ๋œ๋‹ค๋ฉด ๊ฐ€ํ˜„์ด๊ฐ€ ์˜๊ฒฌ ๋‚ด์ค€ ๊ฒƒ ์ฒ˜๋Ÿผ form.util.ts๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™๊ณ , ์žฌ์‚ฌ์šฉ์ด ์˜ˆ์ƒ๋œ๋‹ค๋ฉด filter๊ธฐ๋Šฅ์„ ํ•œ๋‹ค๋Š” ์˜๋ฏธ์—์„œ filter.ts๋Š” ์–ด๋–ค๊ฐ€์š”?

Copy link
Member

Choose a reason for hiding this comment

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

์—‡ ์ €๋Š” form.util.ts์ฒ˜๋Ÿผ ์ปดํฌ๋„ŒํŠธ_์ด๋ฆ„.util.ts๊ฐ€ ์•„๋‹Œ component.util.ts ๋„ค์ด๋ฐ์„ ์˜๋ฏธํ–ˆ์Šต๋‹ˆ๋‹ค!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • component.util.ts๋กœ ์ถ”์ถœํ–ˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์‹ค ํ˜ผ๋™์˜ ์—ฌ์ง€๊ฐ€ ์ข€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„์„œ ์•„์ฃผ ๋งˆ์Œ์— ๋“ค์ง„ ์•Š๋Š”๋ฐ, ์ฐจ์„ ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ํ•˜๋‹ค๊ฐ€ ๋” ์ข‹์€ ๋„ค์ด๋ฐ์ด ๋– ์˜ค๋ฅด๋ฉด ๋ณ€๊ฒฝํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค
    71a471c

Copy link
Member

Choose a reason for hiding this comment

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

ํ˜„์žฌ submit button์„ ํด๋ฆญํ–ˆ์„ ๋•Œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ง„ํ–‰ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค!
onChange ๋˜๋Š” ๋‹ค๋ฅธ ํ•„๋“œ๋ฅผ ์„ ํƒํ•œ ๊ฒฝ์šฐ์—๋„ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ์œ„ ๋ฐฉ์‹์„ ์„ ํƒํ•˜์‹  ์ด์œ ๊ฐ€ ๋”ฐ๋กœ ์žˆ๋Š” ์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Next docs์— ๋‚˜์˜ค๋Š” Server Actions๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํผ์„ ๊ตฌํ˜„ํ•˜๋ ค ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ฐฉ๋ฒ•์ด RSC ์‚ฌ์šฉ ๋ชฉ์ ์— ๋” ์ ํ•ฉํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ์†”์งํžˆ, ์‚ฌ์šฉํ•ด๋ณด๋‹ˆ Server Actions์˜ ์žฅ์ ์€ ์•„์ง ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. onChange๋‚˜ ๋‹ค๋ฅธ ํ•„๋“œ ์„ ํƒ ์‹œ ๋ณด์—ฌ์ฃผ๋Š” UX ๊ด€์ ์—์„œ๋Š” ๋” ์ข‹์ง€ ์•Š์„๊นŒ ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค.
  • ์ด์™€ ๊ด€๋ จํ•˜์—ฌ Next์˜ ๋ฌธ์„œ๋ฅผ ์ฝ์–ด๋ดค๋Š”๋ฐ, ์บ์‹ฑ, ๋ณด์•ˆ, ์ ์ง„์  ํ–ฅ์ƒ ์ธก๋ฉด์—์„œ ์žฅ์ ์ด ์žˆ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
  • ๋Œ€๋ถ€๋ถ„์€ ๊ณต๊ฐํ•˜๊ธฐ ์–ด๋ ต์ง€๋งŒ, ๊ธฐ์กด์— ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ง„ํ–‰ํ•˜๋Š” ๊ฒƒ์— ๋ฐ˜ํ•ด ์„œ๋ฒ„ ์•ก์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ์„œ๋ฒ„ ์ธก์—์„œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ง„ํ–‰ํ•˜๋Š” ์•„ํ‚คํ…์ฒ˜๋กœ ๋ณ€๊ฒฝ๋˜๋ฉฐ, ์ด๋Š” ๋ณด์•ˆ ์ธก๋ฉด์—์„œ ํ™•์‹คํžˆ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#server-side-validation-and-error-handling
https://nextjs.org/blog/security-nextjs-server-components-actions
https://nextjs.org/learn/dashboard-app/mutating-data

Copy link
Member

Choose a reason for hiding this comment

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

server action์œผ๋กœ ๊ตฌํ˜„ํ–ˆ์„ ๋•Œ ๋ณด์•ˆ๊ณผ ์„ฑ๋Šฅ์— ์žฅ์ ์ด ์žˆ๋„ค์š”
๊ธฐ์ˆ ์ ์œผ๋กœ server action์„ ์‚ฌ์šฉํ•จ์œผ๋กœ์จ ์ข‹์€ ์‹œ๋„๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค!

ux์ ์œผ๋กœ๋Š” on change๊ฐ€ ๋” ์ข‹์€๊ฒƒ ๊ฐ™์ง€๋งŒ ์ €์˜ ์ฃผ๊ด€์ ์ธ ํŒ๋‹จ์ด ์•„๋‹๊นŒ ์‹ถ๋„ค์š”
์กธ๋ถ€ ํšŒ์›๊ฐ€์ž… form์ด ์‚ฌ์šฉ์ž์—๊ฒŒ ๊ทธ๋ ‡๊ฒŒ ์–ด๋ ต์ง€ ์•Š์€ ์ , placeholder ์ด ์ž‘์„ฑํ•ด์•ผ ํ•˜๋Š” ๋ฐฉํ–ฅ์„ ์•Œ๋ ค์ฃผ๋Š” ์ ์„ ๊ณ ๋ คํ•ด๋ดค์„ ๋•Œ ์ผ๋‹จ์€ onsubmit์œผ๋กœ ์ง„ํ–‰ํ•ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š”!

errors: Record<string, string[] | undefined>;
};

// Refactor: ์• ๋ฅผ ๋”ฐ๋กœ ๋นผ๊ณ ์‹ถ์€๋ฐ utils ํด๋”์— ์–ด๋–ค ํŒŒ์ผ๋ช…์ด ์ข‹์„๊นŒ?
Copy link
Member

Choose a reason for hiding this comment

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

form์—์„œ๋งŒ ์‚ฌ์šฉ๋  ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ๋œ๋‹ค๋ฉด ๊ฐ€ํ˜„์ด๊ฐ€ ์˜๊ฒฌ ๋‚ด์ค€ ๊ฒƒ ์ฒ˜๋Ÿผ form.util.ts๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™๊ณ , ์žฌ์‚ฌ์šฉ์ด ์˜ˆ์ƒ๋œ๋‹ค๋ฉด filter๊ธฐ๋Šฅ์„ ํ•œ๋‹ค๋Š” ์˜๋ฏธ์—์„œ filter.ts๋Š” ์–ด๋–ค๊ฐ€์š”?

@@ -35,10 +47,40 @@ export const SelectRoot = React.forwardRef<HTMLInputElement, SelectProps>(functi

return (
<div className="w-full min-w-[10rem] relative text-base">
<select
title="select-hidden"
Copy link
Member

Choose a reason for hiding this comment

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

ํ•ด๋‹น ์ˆจ๊ฒจ์ง„ select๋Š” ์–ด๋–ป๊ฒŒ ์“ฐ์ด๋‚˜์š”?

Copy link
Collaborator Author

@seonghunYang seonghunYang Mar 2, 2024

Choose a reason for hiding this comment

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

  • Headless UI์˜ listbox๋ฅผ form์—์„œ ์‚ฌ์šฉํ•  ๋•Œ, hidden input์„ ๋งŒ๋“ค์–ด์„œ ๊ฐ’์„ ์ˆจ๊ธฐ๋Š” ๋ฐฉ์‹์ด ๋งˆ์Œ์— ๋“ค์ง€ ์•Š์•„์„œ, ์ง์ ‘ hidden select๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

https://headlessui.com/react/listbox#using-with-html-forms

  • ์ด๋Ÿฐ ๋ฐฉ์‹์ด ๋งˆ์Œ์— ๋“ค์ง€ ์•Š๋Š” ์ด์œ ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์•„์š”.
  • Select์™€ ๊ฐ™์ด ๋™์ž‘ํ•˜์ง€๋งŒ, input์— value๋ฅผ ์ˆจ๊ฒจ๋‘๊ณ  ์žˆ์–ด์„œ ์˜คํ•ด๊ฐ€ ์ƒ๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ด๋ฅผ ์˜ˆ๋กœ ๋“ค๋ฉด, Storybook play๋ฅผ ์ž‘์„ฑํ•  ๋•Œ, select tag๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด selector๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
 await userEvent.selectOptions(canvas.getByLabelText('์˜์–ด', { selector: 'select' }), 'level12', {
      delay: 100,
    });
  • ํ•˜์ง€๋งŒ, ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. select๊ฐ€ ์•„๋‹Œ hidden input์— value๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, selector๋ฅผ input์œผ๋กœ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์ €๋Š” ์ด ์‚ฌํ•ญ์„ ์•Œ๊ณ  ์žˆ์–ด์„œ ๋Œ€์ฒ˜๊ฐ€ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์ด ์‚ฌ์šฉํ•  ๋•Œ๋Š” ์ด ์‚ฌํ•ญ์„ ๋ชจ๋ฅด๊ณ  ๋‚ด๋ถ€ ๊ตฌํ˜„์„ ์ฐพ์•„๋ด์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ์˜คํ•ด๋ฅผ ์—†์• ๊ธฐ ์œ„ํ•ด hidden select๋ฅผ ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

yougyung
yougyung previously approved these changes Mar 2, 2024
@seonghunYang
Copy link
Collaborator Author

  • ๋‚˜๋จธ์ง€ ๋‹ต๋ณ€์€ ์ข€ ๋” ๊ณ ๋ฏผํ•ด๋ณด๊ณ , ์ˆ˜์ •ํ•ด์„œ ๋‚จ๊ธฐ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค

Copy link

github-actions bot commented Mar 5, 2024

@seonghunYang seonghunYang merged commit f8e3283 into main Mar 8, 2024
3 checks passed
@seonghunYang seonghunYang deleted the form/#16 branch March 8, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants