-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from gloddy-dev/feature/521-set-country
Feature : 국가 설정 구현
- Loading branch information
Showing
42 changed files
with
1,165 additions
and
142 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-12.2 KB
.yarn/cache/react-error-boundary-npm-4.0.10-26f7abd70f-4ad4864d2a.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/app/[lng]/(main)/community/write/components/ImageSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import Image from 'next/image'; | ||
import { memo, useCallback } from 'react'; | ||
import { Control, useController } from 'react-hook-form'; | ||
|
||
import { WriteFormType } from '../type'; | ||
import { Icon } from '@/components/Icon'; | ||
import { Flex } from '@/components/Layout'; | ||
import { Loading } from '@/components/Loading'; | ||
import { useFileUpload } from '@/hooks/useFileUpload'; | ||
|
||
interface ImageSectionProps { | ||
control: Control<WriteFormType>; | ||
} | ||
|
||
export default function ImageSection({ control }: ImageSectionProps) { | ||
const { | ||
field: { value, onChange }, | ||
} = useController({ | ||
name: 'images', | ||
control, | ||
}); | ||
|
||
const { handleFileUploadClick, isLoading } = useFileUpload((files) => { | ||
onChange([...value, ...files]); | ||
}); | ||
|
||
const handleDeleteClick = useCallback( | ||
(imageUrl: string) => onChange(value.filter((v) => v !== imageUrl)), | ||
[onChange, value] | ||
); | ||
|
||
return ( | ||
<section className="px-20 pb-8 pt-16"> | ||
<Flex className="gap-8"> | ||
{value.map((imageUrl, index) => ( | ||
<ImageThumbnail key={imageUrl + index} imageUrl={imageUrl} onClick={handleDeleteClick} /> | ||
))} | ||
{isLoading && ( | ||
<Flex | ||
direction="column" | ||
justify="center" | ||
align="center" | ||
className="h-96 w-96 rounded-8 bg-card-ui" | ||
> | ||
<Loading /> | ||
</Flex> | ||
)} | ||
{value.length < 3 && !(isLoading && value.length === 2) && ( | ||
<AddImageButton imageCount={value.length} onClick={handleFileUploadClick} /> | ||
)} | ||
</Flex> | ||
</section> | ||
); | ||
} | ||
|
||
interface AddImageSectionProps { | ||
imageCount: number; | ||
onClick: () => void; | ||
} | ||
|
||
function AddImageButton({ imageCount, onClick }: AddImageSectionProps) { | ||
return ( | ||
<Flex | ||
direction="column" | ||
justify="center" | ||
align="center" | ||
className="h-96 w-96 cursor-pointer rounded-8 bg-sub" | ||
onClick={onClick} | ||
> | ||
<Icon id="48-add_photo" width={48} height={48} /> | ||
<p className="text-caption text-sign-caption">{imageCount}/3</p> | ||
</Flex> | ||
); | ||
} | ||
|
||
interface ImageThumbnailProps { | ||
imageUrl: string; | ||
onClick: (imageUrl: string) => void; | ||
} | ||
|
||
const ImageThumbnail = memo(({ imageUrl, onClick }: ImageThumbnailProps) => { | ||
return ( | ||
<div className="relative h-96 w-96"> | ||
<Image src={imageUrl} alt="select-img" className="rounded-8 object-cover" fill /> | ||
<Icon | ||
id="32-close" | ||
width={32} | ||
height={32} | ||
className="absolute right-0 top-0 cursor-pointer" | ||
onClick={() => onClick(imageUrl)} | ||
/> | ||
</div> | ||
); | ||
}); |
93 changes: 93 additions & 0 deletions
93
src/app/[lng]/(main)/community/write/components/InputSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use client'; | ||
import { SubmitHandler, useForm } from 'react-hook-form'; | ||
|
||
import WriteModal from '../components/WriteModal'; | ||
import { WriteFormType } from '../type'; | ||
import { useTranslation } from '@/app/i18n/client'; | ||
import { Button, ButtonGroup } from '@/components/Button'; | ||
import MultiImageUploader from '@/components/Image/MultiImageUploader'; | ||
import ListBoxController from '@/components/ListBox/ListBoxController'; | ||
import { Spacing } from '@/components/Spacing'; | ||
import { TextFieldController } from '@/components/TextField'; | ||
import { useModal } from '@/hooks/useModal'; | ||
|
||
export default function InputSection() { | ||
const { open, exit } = useModal(); | ||
const { t } = useTranslation('community'); | ||
const hookForm = useForm<WriteFormType>({ | ||
mode: 'onChange', | ||
defaultValues: { | ||
category: 'NONE', | ||
title: '', | ||
content: '', | ||
images: [], | ||
}, | ||
}); | ||
|
||
const { register, handleSubmit, formState, control } = hookForm; | ||
|
||
const onSubmit: SubmitHandler<WriteFormType> = (formData) => { | ||
console.log(formData); | ||
}; | ||
|
||
const options = [t('create.category.kpop'), t('create.category.qna'), t('create.category.lang')]; | ||
|
||
return ( | ||
<section> | ||
<div className="px-20 pb-8 pt-20"> | ||
<Spacing size={4} /> | ||
<ListBoxController | ||
name={t('create.category.name')} | ||
options={options} | ||
register={register('category', { | ||
required: true, | ||
validate: (value) => value !== 'NONE', | ||
})} | ||
/> | ||
|
||
<Spacing size={4} /> | ||
<TextFieldController | ||
placeholder={t('create.title.placeholder')} | ||
hookForm={hookForm} | ||
register={register('title', { | ||
required: true, | ||
maxLength: 60, | ||
})} | ||
maxCount={60} | ||
/> | ||
</div> | ||
|
||
<div className="px-20 py-8"> | ||
<Spacing size={4} /> | ||
<TextFieldController | ||
placeholder={t('create.content.placeholder')} | ||
register={register('content', { | ||
required: true, | ||
maxLength: 300, | ||
})} | ||
hookForm={hookForm} | ||
as="textarea" | ||
maxCount={300} | ||
className={'h-339'} | ||
/> | ||
</div> | ||
|
||
<MultiImageUploader<WriteFormType> control={control} name={'images'} /> | ||
|
||
<Spacing size={60} /> | ||
<ButtonGroup> | ||
<Button | ||
onClick={() => { | ||
handleSubmit(onSubmit); | ||
open(() => ( | ||
<WriteModal onOkClick={handleSubmit(onSubmit)} onCancelClick={exit} type={'write'} /> | ||
)); | ||
}} | ||
disabled={!formState.isValid} | ||
> | ||
{t('create.submit.label')} | ||
</Button> | ||
</ButtonGroup> | ||
</section> | ||
); | ||
} |
Oops, something went wrong.