@@ -11,16 +11,17 @@ import {
1111 PAYMENT_RESPONSE ,
1212 HANDLE_GOOGLE_AUTH_SIGN_IN ,
1313 HANDLE_GOOGLE_AUTH_SIGN_OUT ,
14- PAYMENT_RESPONSE_ERROR ,
14+ PAYMENT_RESPONSE_ERROR , SEARCH_KEYWORD_ERROR , SEARCH_KEYWORD ,
1515} from './types' ;
1616import { INTERNAL_SERVER_ERROR_CODE , BAD_REQUEST_ERROR_CODE } from '../constants/http_error_codes'
1717import { SHOPPERS_PRODUCT_INFO_COOKIE , CART_TOTAL_COOKIE , AUTH_DETAILS_COOKIE } from '../constants/cookies'
1818import history from "../history" ;
1919import { Base64 } from 'js-base64' ;
2020import Cookies from 'js-cookie' ;
2121import log from "loglevel" ;
22- import { commonServiceAPI , authServiceAPI } from "../api/service_api" ;
22+ import { commonServiceAPI , authServiceAPI , searchSuggestionServiceAPI } from "../api/service_api" ;
2323import axios from 'axios' ;
24+ import { DEFAULT_SEARCH_SUGGESTION_API , SEARCH_SUGGESTION_API } from "../constants/api_routes" ;
2425
2526export const setAuthDetailsFromCookie = savedResponse => {
2627 log . info ( `[ACTION]: setTokenFromCookie savedResponse = ${ savedResponse } ` )
@@ -101,45 +102,45 @@ export const signInUsingOAuth = googleAuth => async dispatch => {
101102 history . push ( "/" ) ;
102103
103104 // try {
104- // let userProfile = googleAuth.currentUser.get().getBasicProfile()
105- // if (userProfile) {
106- // const response = await authServiceAPI.post('/signin-using-google-auth', {
107- // 'id': userProfile.getId(),
108- // 'firstname': userProfile.getGivenName(),
109- // 'lastname': userProfile.getFamilyName(),
110- // 'email': userProfile.getEmail(),
111- // 'username': null,
112- // 'password': null,
113- // }).catch(err => {
114- // log.info(`[ACTION]: signUp dispatch HANDLE_SIGN_UP_ERROR err.message = ${err.message}.`)
115- // });
116- //
117- // if(response.data === "success") {
118- // // here we are sure that we signed in and now dispatch.
119- // dispatch({
120- // type: HANDLE_GOOGLE_AUTH_SIGN_IN,
121- // payload: {
122- // oAuth: googleAuth
123- // }
124- // })
125- // history.push("/");
126- // } else {
127- // dispatch({type: HANDLE_SIGN_IN_ERROR, payload: response.data.error});
128- // }
129-
130- // dispatch({
131- // type: HANDLE_GOOGLE_AUTH_SIGN_IN,
132- // payload: {
133- // oAuth: googleAuth
134- // }
135- // })
136- // history.push("/");
137- // }
138- // } catch
139- // (e) {
140- // log.info(`[signInUsingOAuth] Unable to retrieve user profile.`)
141- // dispatch({type: HANDLE_SIGN_IN_ERROR, payload: "Unable to retrieve user profile."});
142- // }
105+ // let userProfile = googleAuth.currentUser.get().getBasicProfile()
106+ // if (userProfile) {
107+ // const response = await authServiceAPI.post('/signin-using-google-auth', {
108+ // 'id': userProfile.getId(),
109+ // 'firstname': userProfile.getGivenName(),
110+ // 'lastname': userProfile.getFamilyName(),
111+ // 'email': userProfile.getEmail(),
112+ // 'username': null,
113+ // 'password': null,
114+ // }).catch(err => {
115+ // log.info(`[ACTION]: signUp dispatch HANDLE_SIGN_UP_ERROR err.message = ${err.message}.`)
116+ // });
117+ //
118+ // if(response.data === "success") {
119+ // // here we are sure that we signed in and now dispatch.
120+ // dispatch({
121+ // type: HANDLE_GOOGLE_AUTH_SIGN_IN,
122+ // payload: {
123+ // oAuth: googleAuth
124+ // }
125+ // })
126+ // history.push("/");
127+ // } else {
128+ // dispatch({type: HANDLE_SIGN_IN_ERROR, payload: response.data.error});
129+ // }
130+
131+ // dispatch({
132+ // type: HANDLE_GOOGLE_AUTH_SIGN_IN,
133+ // payload: {
134+ // oAuth: googleAuth
135+ // }
136+ // })
137+ // history.push("/");
138+ // }
139+ // } catch
140+ // (e) {
141+ // log.info(`[signInUsingOAuth] Unable to retrieve user profile.`)
142+ // dispatch({type: HANDLE_SIGN_IN_ERROR, payload: "Unable to retrieve user profile."});
143+ // }
143144 }
144145 }
145146 )
@@ -194,15 +195,15 @@ export const signUp = formValues => async dispatch => {
194195
195196export const sendPaymentToken = ( token ) => async dispatch => {
196197 log . info ( `Token = ${ JSON . stringify ( token ) } ` )
197- if ( ! token || ( token && ! token . hasOwnProperty ( "id" ) ) ) {
198+ if ( ! token || ( token && ! token . hasOwnProperty ( "id" ) ) ) {
198199 dispatch ( {
199200 type : PAYMENT_RESPONSE_ERROR ,
200201 payload : { errorMsg : "Unable to fetch token. Try again later" }
201202 } )
202203 }
203204
204205 let url
205- if ( process . env . REACT_APP_PAYMENT_SERVICE_URL ) {
206+ if ( process . env . REACT_APP_PAYMENT_SERVICE_URL ) {
206207 url = `${ process . env . REACT_APP_PAYMENT_SERVICE_URL } /payment`
207208 } else {
208209 url = `http://localhost:${ process . env . REACT_APP_PAYMENT_SERVICE_PORT } /payment`
@@ -318,3 +319,48 @@ export const loadFilterAttributes = filterQuery => async dispatch => {
318319 }
319320 }
320321} ;
322+
323+ export const getSearchSuggestions = ( prefix ) => async dispatch => {
324+ log . info ( `[ACTION]: getSearchSuggestions Calling API.` )
325+
326+ if ( prefix ) {
327+ let responseError = false
328+ const uri = SEARCH_SUGGESTION_API + prefix
329+ const response = await searchSuggestionServiceAPI . get ( uri )
330+ . catch ( err => {
331+ log . info ( `[ACTION]: unable to fetch response for API = ${ uri } ` )
332+ dispatch ( { type : SEARCH_KEYWORD_ERROR } ) ;
333+ responseError = true
334+ } ) ;
335+
336+ if ( responseError ) {
337+ return
338+ }
339+
340+ log . debug ( `[ACTION]: Data = ${ JSON . parse ( JSON . stringify ( response . data ) ) } .` )
341+ dispatch ( {
342+ type : SEARCH_KEYWORD , payload : { data : JSON . parse ( JSON . stringify ( response . data ) ) }
343+ } ) ;
344+ }
345+
346+ }
347+
348+ export const setDefaultSearchSuggestions = ( ) => async dispatch => {
349+ log . info ( `[ACTION]: getSearchSuggestions Calling API.` )
350+ let responseError = false
351+ const response = await searchSuggestionServiceAPI . get ( DEFAULT_SEARCH_SUGGESTION_API )
352+ . catch ( err => {
353+ log . info ( `[ACTION]: unable to fetch response for API = ${ DEFAULT_SEARCH_SUGGESTION_API } ` )
354+ dispatch ( { type : SEARCH_KEYWORD_ERROR } ) ;
355+ responseError = true
356+ } ) ;
357+
358+ if ( responseError ) {
359+ return
360+ }
361+
362+ log . debug ( `[ACTION]: Data = ${ JSON . parse ( JSON . stringify ( response . data ) ) } .` )
363+ dispatch ( {
364+ type : SEARCH_KEYWORD , payload : { data : JSON . parse ( JSON . stringify ( response . data ) ) }
365+ } ) ;
366+ }
0 commit comments