-
Notifications
You must be signed in to change notification settings - Fork 6
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 #242 from Kernel360/feature/my-page-api-edit
페이지 기능: 마이페이지 api 기능
- Loading branch information
Showing
14 changed files
with
350 additions
and
235 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,107 @@ | ||
/* eslint-disable @typescript-eslint/no-misused-promises */ | ||
|
||
'use client'; | ||
|
||
import { useEffect, useMemo } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
import dynamic from 'next/dynamic'; | ||
|
||
import { | ||
CARTYPE_OPTIONS, COLOR_OPTIONS, DRIVING_OPTIONS, PARKING_OPTIONS, SEGMENT_OPTIONS, | ||
} from '@constants/myPage'; | ||
import withRegisterCarDetails from '@hooks/withRegisterCarDetails'; | ||
import { ICarDetails } from '@remote/api/types/additional-info'; | ||
import { CarInfoType } from '@remote/api/types/my-page'; | ||
import useRegisterCarDetails from '@remote/queries/additional-info/car-details/useRegisterCarDetails'; | ||
import DropdownField from '@shared/dropdown-field/DropdownField'; | ||
import Header from '@shared/header/Header'; | ||
import Spacing from '@shared/spacing/Spacing'; | ||
import mappingCarDetails from '@utils/mappingCarDetails'; | ||
|
||
const FixedBottomButton = dynamic(() => { return import('@shared/fixedBottomButton/FixedBottomButton'); }, { | ||
ssr: false, | ||
}); | ||
|
||
function MyCarDetailsPage() { | ||
// TODO: api or store를 통해 defaultValue 설정하기 | ||
function MyCarDetailsPage({ myCarInfo }: { myCarInfo: CarInfoType }) { | ||
const { carOptions, mappingCarOptions } = mappingCarDetails(myCarInfo); | ||
const { mutate } = useRegisterCarDetails(); | ||
const { | ||
register, watch, formState: { | ||
register, watch, reset, formState: { | ||
isDirty, isValid, | ||
}, getValues, | ||
}, handleSubmit, | ||
} = useForm({ | ||
defaultValues: { | ||
segment: '세단', | ||
cartype: '중형', | ||
color: '빨간색', | ||
driving: '복합적', | ||
parking: '노상', | ||
}, | ||
defaultValues: useMemo(() => { | ||
return { | ||
segment: myCarInfo.value.car_info.segment, | ||
cartype: myCarInfo.value.car_info.cartype, | ||
color: myCarInfo.value.car_info.color, | ||
driving: myCarInfo.value.car_info.driving, | ||
parking: myCarInfo.value.car_info.parking, | ||
}; | ||
}, [myCarInfo]), | ||
mode: 'onBlur', | ||
}); | ||
|
||
const onSubmit = () => { | ||
// eslint-disable-next-line no-console | ||
console.log(getValues()); | ||
const onSubmit = (carInfo: ICarDetails) => { | ||
mutate(carInfo); | ||
}; | ||
|
||
useEffect(() => { | ||
reset({ | ||
segment: myCarInfo.value.car_info.segment, | ||
cartype: myCarInfo.value.car_info.cartype, | ||
color: myCarInfo.value.car_info.color, | ||
driving: myCarInfo.value.car_info.driving, | ||
parking: myCarInfo.value.car_info.parking, | ||
}); | ||
}, [myCarInfo, reset]); | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<Spacing size={24} /> | ||
<main className="mainContainer"> | ||
<DropdownField | ||
label="차량 유형" | ||
selectedLabel={watch('segment')} | ||
selectedLabel={mappingCarOptions.segment_options[watch('segment')]} | ||
type="profile" | ||
options={SEGMENT_OPTIONS} | ||
options={carOptions.segment_options} | ||
{...register('segment')} | ||
/> | ||
<Spacing size={12} /> | ||
<DropdownField | ||
label="차량 크기" | ||
selectedLabel={watch('cartype')} | ||
selectedLabel={mappingCarOptions.carType_options[watch('cartype')]} | ||
type="profile" | ||
options={CARTYPE_OPTIONS} | ||
options={carOptions.carType_options} | ||
{...register('cartype')} | ||
/> | ||
<Spacing size={12} /> | ||
<DropdownField | ||
label="차량 색상" | ||
selectedLabel={watch('color')} | ||
selectedLabel={mappingCarOptions.color_options[watch('color')]} | ||
type="profile" | ||
options={COLOR_OPTIONS} | ||
options={carOptions.color_options} | ||
{...register('color')} | ||
/> | ||
<Spacing size={12} /> | ||
<DropdownField | ||
label="주행 환경" | ||
selectedLabel={watch('driving')} | ||
selectedLabel={mappingCarOptions.driving_options[watch('driving')]} | ||
type="profile" | ||
options={DRIVING_OPTIONS} | ||
options={carOptions.driving_options} | ||
{...register('driving')} | ||
/> | ||
<Spacing size={12} /> | ||
<DropdownField | ||
label="주차 환경" | ||
selectedLabel={watch('parking')} | ||
selectedLabel={mappingCarOptions.parking_options[watch('parking')]} | ||
type="profile" | ||
options={PARKING_OPTIONS} | ||
options={carOptions.parking_options} | ||
{...register('parking')} | ||
/> | ||
<FixedBottomButton onClick={onSubmit} type="submit" disabled={!isDirty || !isValid}>변경 사항 저장하기</FixedBottomButton> | ||
<FixedBottomButton onClick={handleSubmit(onSubmit)} type="submit" disabled={!isDirty || !isValid}>변경 사항 저장하기</FixedBottomButton> | ||
</main> | ||
</> | ||
); | ||
} | ||
|
||
export default MyCarDetailsPage; | ||
export default withRegisterCarDetails(MyCarDetailsPage); |
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 |
---|---|---|
@@ -1,72 +1,87 @@ | ||
/* eslint-disable @typescript-eslint/no-misused-promises */ | ||
|
||
'use client'; | ||
|
||
import { useEffect, useMemo } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
import dynamic from 'next/dynamic'; | ||
|
||
import { | ||
COST_OPTIONS, FREQUENCY_OPTIONS, INTEREST_OPTIONS, | ||
} from '@constants/myPage'; | ||
import withRegisterCarWashDetails from '@hooks/withRegisterCarWashDetails'; | ||
import { ICarWashDetails } from '@remote/api/types/additional-info'; | ||
import { CarWashInfoType } from '@remote/api/types/my-page'; | ||
import useRegisterCarWashDetails from '@remote/queries/additional-info/car-wash-details/useRegisterCarWashDetails'; | ||
import DropdownField from '@shared/dropdown-field/DropdownField'; | ||
import Header from '@shared/header/Header'; | ||
import Spacing from '@shared/spacing/Spacing'; | ||
import mappingCarWashDetails from '@utils/mappingCarWashDetails'; | ||
|
||
const FixedBottomButton = dynamic(() => { return import('@shared/fixedBottomButton/FixedBottomButton'); }, { | ||
ssr: false, | ||
}); | ||
|
||
function MyCarWashDetailsPage() { | ||
// TODO: api or store를 통해 defaultValue 설정하기 | ||
function MyCarWashDetailsPage({ myCarWashInfo }: { myCarWashInfo: CarWashInfoType }) { | ||
const { carWashOptions, mappingCarWashOptions } = mappingCarWashDetails(myCarWashInfo); | ||
const { mutate } = useRegisterCarWashDetails(); | ||
const { | ||
register, watch, formState: { | ||
register, watch, reset, formState: { | ||
isDirty, isValid, | ||
}, getValues, | ||
}, handleSubmit, | ||
} = useForm({ | ||
defaultValues: { | ||
frequency: '월 4회 이상', | ||
cost: '월 10만원 이상', | ||
interest: '도장', | ||
}, | ||
defaultValues: useMemo(() => { | ||
return { | ||
frequency: myCarWashInfo.value.wash_info.frequency, | ||
cost: myCarWashInfo.value.wash_info.cost, | ||
interest: myCarWashInfo.value.wash_info.interest, | ||
}; | ||
}, [myCarWashInfo]), | ||
mode: 'onBlur', | ||
}); | ||
|
||
const onSubmit = () => { | ||
// eslint-disable-next-line no-console | ||
console.log(getValues()); | ||
const onSubmit = (carWashInfo: ICarWashDetails) => { | ||
mutate(carWashInfo); | ||
}; | ||
|
||
useEffect(() => { | ||
reset({ | ||
frequency: myCarWashInfo.value.wash_info.frequency, | ||
cost: myCarWashInfo.value.wash_info.cost, | ||
interest: myCarWashInfo.value.wash_info.interest, | ||
}); | ||
}, [myCarWashInfo, reset]); | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<Spacing size={24} /> | ||
<main className="mainContainer"> | ||
<DropdownField | ||
label="세차 횟수" | ||
selectedLabel={watch('frequency')} | ||
selectedLabel={mappingCarWashOptions.frequency_options[watch('frequency')]} | ||
type="profile" | ||
options={FREQUENCY_OPTIONS} | ||
options={carWashOptions.frequency_options} | ||
{...register('frequency')} | ||
/> | ||
<Spacing size={12} /> | ||
<DropdownField | ||
label="지출 비용" | ||
selectedLabel={watch('cost')} | ||
selectedLabel={mappingCarWashOptions.cost_options[watch('cost')]} | ||
type="profile" | ||
options={COST_OPTIONS} | ||
options={carWashOptions.cost_options} | ||
{...register('cost')} | ||
/> | ||
<Spacing size={12} /> | ||
<DropdownField | ||
label="주요 관심사" | ||
selectedLabel={watch('interest')} | ||
selectedLabel={mappingCarWashOptions.interest_options[watch('interest')]} | ||
type="profile" | ||
options={INTEREST_OPTIONS} | ||
options={carWashOptions.interest_options} | ||
{...register('interest')} | ||
/> | ||
<FixedBottomButton onClick={onSubmit} type="submit" disabled={!isDirty || !isValid}>변경 사항 저장하기</FixedBottomButton> | ||
<FixedBottomButton onClick={handleSubmit(onSubmit)} type="submit" disabled={!isDirty || !isValid}>변경 사항 저장하기</FixedBottomButton> | ||
</main> | ||
</> | ||
); | ||
} | ||
|
||
export default MyCarWashDetailsPage; | ||
export default withRegisterCarWashDetails(MyCarWashDetailsPage); |
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
Oops, something went wrong.