-
Notifications
You must be signed in to change notification settings - Fork 1
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
스케줄 장소 포함 기능 #299
스케줄 장소 포함 기능 #299
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export {}; | ||
|
||
declare global { | ||
interface Window { | ||
daum: any; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useFieldArray, useFormContext } from 'react-hook-form'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { DatePickerField, InputField, SelectField } from '@/components'; | ||
import { Button, DatePickerField, InputField, RadioButtonField, SelectField } from '@/components'; | ||
import { InputSize } from '@/components/common/Input/Input.component'; | ||
import * as Styled from './ScheduleTemplate.styled'; | ||
import { $generations } from '@/store'; | ||
import { SelectOption } from '@/components/common/Select/Select.component'; | ||
import { SessionTemplate } from '../SessionTemplate'; | ||
import Plus from '@/assets/svg/plus-20.svg'; | ||
import { EventCreateRequest } from '@/types'; | ||
import { ScheduleFormValues } from '@/utils'; | ||
import { LocationType, ScheduleFormValues } from '@/utils'; | ||
|
||
const DEFAULT_SESSION: EventCreateRequest = { | ||
startedAt: '', | ||
|
@@ -19,9 +19,12 @@ const DEFAULT_SESSION: EventCreateRequest = { | |
}; | ||
|
||
const ScheduleTemplate = () => { | ||
const { register, control, formState, getValues } = useFormContext<ScheduleFormValues>(); | ||
const { register, control, formState, getValues, watch, setValue } = | ||
useFormContext<ScheduleFormValues>(); | ||
const generations = useRecoilValue($generations); | ||
|
||
const locationType = watch('locationType'); | ||
|
||
const { fields, append, remove } = useFieldArray({ | ||
name: 'sessions', | ||
control, | ||
|
@@ -37,6 +40,31 @@ const ScheduleTemplate = () => { | |
const defaultOption = generationOptions.find( | ||
(option) => option.value === getValues('generationNumber')?.toString(), | ||
); | ||
const handleClickAddressSearch = () => { | ||
new window.daum.Postcode({ | ||
async oncomplete(data: { address: string }) { | ||
const res = await fetch( | ||
`https://dapi.kakao.com/v2/local/search/address?query=${data.address}`, | ||
{ | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: 'KakaoAK cc4af66dc10aa1a20830f3cc62c40a87', | ||
}, | ||
}, | ||
); | ||
const json = await res.json(); | ||
const roadAddress = json.documents[0].road_address; | ||
setValue('locationInfo', { | ||
address: roadAddress.address_name, | ||
latitude: roadAddress.y, | ||
longitude: roadAddress.x, | ||
placeName: roadAddress.building_name ?? roadAddress.address_name, | ||
}); | ||
setValue('placeName', roadAddress.building_name); | ||
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. 앱에 {
"address_name": "경기 성남시 분당구 서판교로 32",
"building_name": "",
"main_building_no": "32",
"region_1depth_name": "경기",
"region_2depth_name": "성남시 분당구",
"region_3depth_name": "판교동",
"road_name": "서판교로",
"sub_building_no": "",
"underground_yn": "N",
"x": "127.097880906475",
"y": "37.389777093851",
"zone_no": "13479"
} 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. 아 이부분 놓쳤네요! |
||
}, | ||
}).open(); | ||
}; | ||
|
||
return ( | ||
<> | ||
|
@@ -66,6 +94,38 @@ const ScheduleTemplate = () => { | |
defaultDate={getValues('date')} | ||
{...register('date', { required: true })} | ||
/> | ||
<div> | ||
<Styled.InputLabel htmlFor="location"> | ||
<span>장소</span> | ||
<Styled.RequiredDot /> | ||
</Styled.InputLabel> | ||
<Styled.RadioButtonGroup> | ||
<RadioButtonField | ||
label="오프라인" | ||
required | ||
value={LocationType.OFFLINE} | ||
{...register('locationType', { required: true })} | ||
/> | ||
<RadioButtonField | ||
label="온라인" | ||
required | ||
value={LocationType.ONLINE} | ||
{...register('locationType', { required: true })} | ||
/> | ||
</Styled.RadioButtonGroup> | ||
{locationType === LocationType.OFFLINE && ( | ||
<Styled.InputWithButton> | ||
<InputField | ||
$size="md" | ||
placeholder="장소" | ||
{...register('placeName', { required: locationType === LocationType.OFFLINE })} | ||
/> | ||
<Button shape="primaryLine" $size="md" onClick={handleClickAddressSearch}> | ||
주소 검색 | ||
</Button> | ||
</Styled.InputWithButton> | ||
)} | ||
</div> | ||
</Styled.ScheduleContent> | ||
<Styled.SessionContent> | ||
<Styled.Title>세션 정보</Styled.Title> | ||
|
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.
https://stackoverflow.com/a/60964007
해당 페이지에서 useScript와 같은 훅을 통해 동적 스크립트 및 async로 불러오는 게 어떨까요?
스크립트 사이즈가 얼마 안 되긴 하지만 스케줄 생성 페이지에서 한정적으로 사용되는 것으로 보여서요!