1- import { useEffect , useState } from "react" ;
2- import { fetchRecommendation } from "@/lib/apis/survey" ;
3- import { RecommendationRequest , RecommendationResponse } from "@/lib/type" ;
1+ import { useState } from "react" ;
2+ import { useRouter } from "next/navigation" ;
3+ import { postSurvey } from "@/lib/apis/survey" ;
4+ import { SurveyRequest } from "@/lib/type" ;
45
5- export function useSurveyRecommendation ( ) {
6- const [ spaceData , setSpaceData ] = useState < RecommendationResponse [ ] > ( [ ] ) ;
6+ export function usePostSurvey ( ) {
77 const [ isLoading , setIsLoading ] = useState ( true ) ;
88 const [ isError , setIsError ] = useState ( false ) ;
99
10- const fetchData = async ( ) => {
10+ const router = useRouter ( ) ;
11+
12+ const handleSubmit = async ( ) => {
1113 setIsLoading ( true ) ;
1214 setIsError ( false ) ;
1315
@@ -16,7 +18,7 @@ export function useSurveyRecommendation() {
1618 localStorage . getItem ( "onboardingAnswers" ) ?? "[]"
1719 ) ;
1820
19- const payload : RecommendationRequest = {
21+ const payload : SurveyRequest = {
2022 clientId,
2123 age : Number ( onboarding [ 0 ] ?. substr ( 0 , 2 ) || 0 ) ,
2224 gender : onboarding [ 1 ] ,
@@ -27,8 +29,8 @@ export function useSurveyRecommendation() {
2729 } ;
2830
2931 try {
30- const res = await fetchRecommendation ( payload ) ;
31- setSpaceData ( res ) ;
32+ await postSurvey ( payload ) ;
33+ router . push ( "/recommend" ) ;
3234 } catch ( err ) {
3335 console . error ( err ) ;
3436 setIsError ( true ) ;
@@ -37,9 +39,5 @@ export function useSurveyRecommendation() {
3739 }
3840 } ;
3941
40- useEffect ( ( ) => {
41- fetchData ( ) ;
42- } , [ ] ) ;
43-
44- return { spaceData, isLoading, isError } ;
42+ return { handleSubmit, isLoading, isError } ;
4543}
0 commit comments