-
Notifications
You must be signed in to change notification settings - Fork 3
Fix/youl bug fix #150
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
Fix/youl bug fix #150
Changes from all commits
6b7ea7c
3257b25
536f3b2
17d4514
59ac630
e0e83ee
0878802
ff82386
f8f4f95
52eb474
013fde3
8ecaabf
fef8165
fea5c28
de86036
4dc9e50
3ce5331
cbb4d4e
2656c9c
43a4179
43fd284
9260be9
96f1e22
0a5ab41
5e014cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect, useState } from 'react'; | ||
| import { FormEvent, useEffect, useState } from 'react'; | ||
| import { Controller, useForm, useWatch } from 'react-hook-form'; | ||
| import useFormPersist from 'react-hook-form-persist'; | ||
| import { toast } from 'react-toastify'; | ||
| import { useRouter } from 'next/navigation'; | ||
| import { NumberInput } from '@mantine/core'; | ||
| import { getImageUrl } from '@/src/_apis/image/get-image-url'; | ||
|
|
@@ -39,13 +40,14 @@ export default function CreateCrewForm({ | |
| trigger, | ||
| clearErrors, | ||
| watch, | ||
| setError, | ||
| formState: { errors, isValid, isSubmitting, isSubmitSuccessful }, | ||
| } = useForm<CreateCrewFormTypes>({ | ||
| defaultValues: data, | ||
| mode: 'onBlur', | ||
| }); | ||
|
|
||
| useFormPersist(type === 'create' ? 'createCrew' : 'editCrew', { | ||
| useFormPersist(type === 'create' ? 'createCrew' : '', { | ||
| watch, | ||
| setValue, | ||
| storage: typeof window !== 'undefined' ? window.localStorage : undefined, | ||
|
|
@@ -88,9 +90,30 @@ export default function CreateCrewForm({ | |
| file: File | string | null, | ||
| onChange: (value: string | File) => void, | ||
| ) => { | ||
| if (file instanceof File) { | ||
| const imgResponse = await getImageUrl(file, 'CREW'); | ||
| onChange(imgResponse?.imageUrl || ''); | ||
| try { | ||
| // νμΌ λ±λ‘ μ²λ¦¬ | ||
| if (file instanceof File) { | ||
| const imgResponse = await getImageUrl(file, 'CREW'); | ||
| if (imgResponse?.imageUrl) { | ||
| clearErrors('imageUrl'); // μλ¬ μ΄κΈ°ν | ||
| onChange(imgResponse.imageUrl); // μ΄λ―Έμ§ URL μ€μ | ||
| } else { | ||
| throw new Error('μ΄λ―Έμ§ μ λ‘λ μ€ λ¬Έμ κ° λ°μνμ΅λλ€.'); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| // API μλ¬ μ²λ¦¬ | ||
| setError('imageUrl', { type: 'server', message: errors.imageUrl?.message }); | ||
| setValue('imageUrl', ''); | ||
| } | ||
| }; | ||
|
|
||
| const handleSendForm = (e: FormEvent<HTMLFormElement>) => { | ||
| e.preventDefault(); | ||
| if (type === 'create') { | ||
| handleSubmit(onSubmit)(); | ||
| } else { | ||
| handleSubmit(onEdit)(); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -112,7 +135,7 @@ export default function CreateCrewForm({ | |
| }, [mainCategory, mainLocation, isSubmitSuccessful]); | ||
|
|
||
| return ( | ||
| <form onSubmit={type === 'edit' ? handleSubmit(onEdit) : handleSubmit(onSubmit)}> | ||
| <form onSubmit={handleSendForm}> | ||
| <div className="flex flex-col gap-6"> | ||
| <div className="flex flex-col gap-3"> | ||
| <div className="flex justify-between"> | ||
|
|
@@ -154,7 +177,7 @@ export default function CreateCrewForm({ | |
| </div> | ||
| <div className="flex flex-col gap-3"> | ||
| <label | ||
| htmlFor="crew-category" | ||
| htmlFor="crew-mainCategory" | ||
| className="text-base font-semibold text-gray-800 md:text-xl" | ||
| > | ||
| μΉ΄ν κ³ λ¦¬λ₯Ό μ νν΄μ£ΌμΈμ. | ||
|
|
@@ -167,6 +190,7 @@ export default function CreateCrewForm({ | |
| render={({ field }) => ( | ||
| <DropDown | ||
| {...field} | ||
| id="crew-mainCategory" | ||
| variant="default" | ||
| inWhere="form" | ||
| placeholder={isEdit && field.value ? field.value : 'λ©μΈ μΉ΄ν κ³ λ¦¬'} | ||
|
|
@@ -180,12 +204,16 @@ export default function CreateCrewForm({ | |
| /> | ||
| )} | ||
| /> | ||
| <label htmlFor="crew-subCategory" className="sr-only"> | ||
| μΈλΆ μΉ΄ν κ³ λ¦¬λ₯Ό μ νν΄μ£ΌμΈμ. | ||
| </label> | ||
| <Controller | ||
| name="subCategory" | ||
| control={control} | ||
| render={({ field }) => ( | ||
| <DropDown | ||
| {...field} | ||
| id="crew-subCategory" | ||
| variant="default" | ||
| inWhere="form" | ||
| placeholder={isEdit && field.value ? field.value : 'μΈλΆ μΉ΄ν κ³ λ¦¬'} | ||
|
|
@@ -199,31 +227,21 @@ export default function CreateCrewForm({ | |
| </div> | ||
|
|
||
| <div className="flex flex-col gap-3"> | ||
| <label htmlFor="crew-image" className="text-base font-semibold text-gray-800 md:text-xl"> | ||
| <span className="text-base font-semibold text-gray-800 md:text-xl"> | ||
| λνμ΄λ―Έμ§λ₯Ό μ ννκ±°λ 첨λΆν΄μ£ΌμΈμ. | ||
| </label> | ||
| </span> | ||
|
Comment on lines
+230
to
+232
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion μ΄λ―Έμ§ μ ν UIμ μλ§¨ν± λ§ν¬μ κ°μ μ΄ νμν©λλ€.
λ€μκ³Ό κ°μ΄ μμ νλ κ²μ μ μλ립λλ€: - <span className="text-base font-semibold text-gray-800 md:text-xl">
+ <label htmlFor="crew-image" className="text-base font-semibold text-gray-800 md:text-xl">
λνμ΄λ―Έμ§λ₯Ό μ ννκ±°λ 첨λΆν΄μ£ΌμΈμ.
- </span>
+ </label>
|
||
| <Controller | ||
| name="imageUrl" | ||
| control={control} | ||
| rules={{ | ||
| required: 'μ΄λ―Έμ§λ₯Ό μ νν΄μ£ΌμΈμ.', | ||
| validate: { | ||
| fileSize: (file) => | ||
| file && file instanceof File | ||
| ? file.size <= 5242880 || 'νμΌ ν¬κΈ°λ 5MB μ΄νμ¬μΌ ν©λλ€.' | ||
| : true, // λ¬Έμμ΄μΈ κ²½μ° ν¬κΈ° κ²μ¬λ₯Ό 건λλλλ€. | ||
| fileType: (file) => | ||
| file && file instanceof File | ||
| ? ['image/jpeg', 'image/jpg', 'image/png'].includes(file.type) || | ||
| 'JPG, PNG νμΌλ§ μ λ‘λ κ°λ₯ν©λλ€.' | ||
| : true, // λ¬Έμμ΄μΈ κ²½μ° νμΌ νμ κ²μ¬λ₯Ό 건λλλλ€. | ||
| }, | ||
| }} | ||
| render={({ field }) => ( | ||
| <FileInputWrap | ||
| {...field} | ||
| isEdit={isEdit} | ||
| sample={ImgCrewSampleUrls} | ||
| error={errors.imageUrl} | ||
| onChange={(newValue) => { | ||
| handleFileChange(newValue, field.onChange); | ||
| field.onChange(newValue); | ||
|
|
@@ -232,12 +250,12 @@ export default function CreateCrewForm({ | |
| /> | ||
| )} | ||
| /> | ||
| {errors.imageUrl && <p className="text-red-500">{errors.imageUrl.message}</p>} | ||
| {errors.imageUrl && <p className="text-xs text-red-500">{errors.imageUrl.message}</p>} | ||
| </div> | ||
|
|
||
| <div className="flex flex-col gap-3"> | ||
| <label | ||
| htmlFor="crew-category" | ||
| htmlFor="crew-mainLocation" | ||
| className="text-base font-semibold text-gray-800 md:text-xl" | ||
| > | ||
| μ§μμ μ νν΄μ£ΌμΈμ. | ||
|
|
@@ -250,6 +268,7 @@ export default function CreateCrewForm({ | |
| render={({ field }) => ( | ||
| <DropDown | ||
| {...field} | ||
| id="crew-mainLocation" | ||
| variant="default" | ||
| inWhere="form" | ||
| placeholder={isEdit && field.value ? field.value : 'νΉλ³μ/λ'} | ||
|
|
@@ -263,13 +282,17 @@ export default function CreateCrewForm({ | |
| /> | ||
| )} | ||
| /> | ||
| <label htmlFor="crew-subLocation" className="sr-only"> | ||
| μΈλΆ μ§μμ μ νν΄μ£ΌμΈμ. | ||
| </label> | ||
| <Controller | ||
| name="subLocation" | ||
| control={control} | ||
| rules={{ required: 'μ/κ΅°/ꡬλ₯Ό μ νν΄μ£ΌμΈμ.' }} | ||
| render={({ field }) => ( | ||
| <DropDown | ||
| {...field} | ||
| id="crew-subLocation" | ||
| variant="default" | ||
| inWhere="form" | ||
| placeholder={isEdit && field.value ? field.value : 'μ/κ΅°/ꡬ'} | ||
|
|
@@ -314,11 +337,14 @@ export default function CreateCrewForm({ | |
| </div> | ||
| <div className="flex flex-col gap-3"> | ||
| <div className="flex justify-between"> | ||
| <label htmlFor="gathering-introduce" className="text-base font-semibold text-gray-800"> | ||
| <label | ||
| htmlFor="crew-introduce" | ||
| className="text-base font-semibold text-gray-800 md:text-xl" | ||
| > | ||
| ν¬λ£¨ μκ° | ||
| </label> | ||
| <span> | ||
| <span className="text-blue-500">{introduce?.length}</span>/100 | ||
| <span className="text-blue-500">{introduce.length}</span>/100 | ||
| </span> | ||
| </div> | ||
| <Controller | ||
|
|
@@ -327,6 +353,7 @@ export default function CreateCrewForm({ | |
| render={({ field }) => ( | ||
| <Textarea | ||
| {...field} | ||
| id="crew-introduce" | ||
| placeholder="ν¬λ£¨ μκ°κΈμ 100μ μ΄λ΄λ‘ μ λ ₯ν΄μ£ΌμΈμ." | ||
| maxLength={100} | ||
| inputClassNames="h-40 py-2.5 px-4 bg-gray-100 placeholder:text-gray-400 font-pretendard text-base font-medium rounded-xl" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π‘ Codebase verification
createCrewlocalStorage μ 리 μ½λκ° λ κ³³μμ λ°κ²¬λμμ΅λλ€localStorage.removeItem('createCrew')κ° λ€μ λ μμΉμμ λ°κ²¬λμμ΅λλ€:src/app/(crew)/crew/create/_components/create-crew-form/index.tsxsrc/_queries/crew/crew-detail-queries.tsλμΌν cleanup μμ μ΄ λ κ³³μμ μνλκ³ μμ΄ μ€λ³΅ μ½λκ° μ‘΄μ¬ν©λλ€. ν κ³³μΌλ‘ ν΅ν©νλ κ²μ΄ μ’κ² μ΅λλ€.
π Analysis chain
CreateCrewPageμμ μ€λ³΅ cleanup μ½λ νμΈμ΄ νμν©λλ€.
μ΄μ μμΉμΈ CreateCrewPage μ»΄ν¬λνΈμμ λμΌν cleanup μ½λκ° μμ ν μ κ±°λμλμ§ νμΈμ΄ νμν©λλ€.
λ€μ μ€ν¬λ¦½νΈλ‘ νμΈν΄λ³΄μΈμ:
π Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 91
Script:
Length of output: 543