Commit 104666e87bfacfb1a69f655fd33b6f9665e0b26a

Authored by Vu Bui
1 parent 68e1c69327
Exists in master

update

Showing 3 changed files with 101 additions and 21 deletions Side-by-side Diff

... ... @@ -0,0 +1,62 @@
  1 +
  2 +
  3 +import axios from 'axios'
  4 +const baseAPIUrl = process.env.REACT_APP_API_URL;
  5 +
  6 +const parseErrorMessage = ( error ) => {
  7 + let message = ''
  8 + try {
  9 + if ( typeof error.response != 'undefined'
  10 + && typeof error.response.data != 'undefined'
  11 + && typeof error.response.data.message != 'undefined' )
  12 + {
  13 + message = error.response.data.message
  14 + }
  15 + else {
  16 + message = error.message
  17 + }
  18 + }
  19 + catch(e) {
  20 + message = 'Something wrong. Please try again!'
  21 + }
  22 + return message
  23 +}
  24 +/**
  25 + *
  26 + * Get profile [getUserProfile]
  27 + *
  28 + */
  29 +export const getUserProfile = async ( token ) => {
  30 +
  31 + const header2 = {
  32 + headers: {
  33 + "Content-Type": "application/json",
  34 + "Content-Type": "application/json",
  35 + 'Access-Control-Allow-Origin': "*",
  36 + 'Access-Control-Allow-Headers': "*",
  37 + 'x-app-name': 'dashboard',
  38 + 'Authorization':`Bearer ${token}`,
  39 + 'x-api-key': window?.GDClinic?.api_key || ''
  40 + }
  41 + }
  42 +
  43 + let result = { success: false }
  44 + try {
  45 + let { data } = await axios.get(`${baseAPIUrl}/ehealth/patients/profile/`, header2)
  46 + if ( data.status === true && typeof data.data.result !== 'undefined' ) {
  47 + result = {
  48 + success: true,
  49 + data: data.data.result,
  50 + message: data.message
  51 + }
  52 + }else {
  53 + result.message = data.message
  54 + }
  55 +
  56 + }
  57 + catch(error) {
  58 + console.error( 'Login error: ', error.message )
  59 + result.message = parseErrorMessage( error )
  60 + }
  61 + return result
  62 +}
0 63 \ No newline at end of file
... ... @@ -9,39 +9,42 @@ import PickTime from '../../components/Steps/PickTime'
9 9 import PickDoctor from '../../components/Steps/PickDoctor';
10 10 import Profile from '../../components/Steps/Profile';
11 11 import Payment from '../../components/Steps/Payment';
  12 +import {getUserProfile} from './apis'
12 13  
13 14 import './styles.scss'
14 15 import { useCommonState, useCommonDispatch } from '../../store/common'
15 16  
16 17 function BookingWizard(props) {
17 18 const [show, setShow] = useState(false)
  19 + const [userProfile, setUserProfile] = useState(null)
18 20 const [step, setStep] = useState('step-login')
19 21 const commonStore = useCommonState()
20 22 const dispatch = useCommonDispatch()
21 23  
22   - const [cookies, setCookie, removeCookie] = useCookies('patient-dashboard')
23   - let { accessToken } = cookies
  24 + const [cookies, setCookie, removeCookie] = useCookies('bw-booking-wizard')
  25 + let { bwaccessToken } = cookies
24 26  
25 27 useEffect(() => {
26   - if (accessToken) {
  28 + if (bwaccessToken) {
27 29 if (!localStorage.getItem('activeStep') || localStorage.getItem('activeStep') === null) {
28 30 dispatch({ type: 'BW_ACTIVE_STEP', payload: 'step-confirm-service' })
29 31 } else {
30 32 dispatch({ type: 'BW_ACTIVE_STEP', payload: localStorage.getItem('activeStep') })
31 33 }
  34 + if (localStorage.getItem('userProfile')) {
  35 + let profile = JSON.parse(localStorage.getItem('userProfile'))
  36 + dispatch({ type: 'USER_PROFILE', payload: profile })
  37 + console.log("check access token", profile)
  38 + }
  39 + // set data Case obj
  40 + if(localStorage.getItem('caseObj')) {
  41 + dispatch({ type: 'BW_CASE', payload: JSON.parse(localStorage.getItem('caseObj')) })
  42 + }
  43 + if(localStorage.getItem('bwHasBooked')) {
  44 + dispatch({type:'BW_HAS_BOOKED', payload: true})
  45 + }
32 46 }
33   - if (localStorage.getItem('userProfile')) {
34   - let profile = JSON.parse(localStorage.getItem('userProfile'))
35   - dispatch({ type: 'USER_PROFILE', payload: profile })
36   - console.log("check access token", profile)
37   - }
38   - // set data Case obj
39   - if(localStorage.getItem('caseObj')) {
40   - dispatch({ type: 'BW_CASE', payload: JSON.parse(localStorage.getItem('caseObj')) })
41   - }
42   - if(localStorage.getItem('bwHasBooked')) {
43   - dispatch({type:'BW_HAS_BOOKED', payload: true})
44   - }
  47 +
45 48  
46 49 }, [])
47 50 useEffect(() => {
... ... @@ -49,13 +52,22 @@ function BookingWizard(props) {
49 52 }, [commonStore.showBookingModal])
50 53  
51 54 useEffect(() => {
52   - if (accessToken === null) {
  55 + if (bwaccessToken === null || !bwaccessToken) {
  56 + console.log("a")
53 57 localStorage.removeItem('bwSteps') // remove steps
54 58 localStorage.removeItem('bwDataBooking') // remove data booking
55 59 localStorage.setItem('activeStep', 'step-login') // remove active step
  60 + localStorage.removeItem('bwHasBooked')
  61 + localStorage.removeItem('marketing_group_id')
  62 + localStorage.removeItem('bwSteps')
  63 + localStorage.removeItem('caseObj')
  64 + localStorage.removeItem('bwDataBooking')
  65 + localStorage.removeItem('userProfile')
56 66 }
57   - }, [accessToken])
  67 + }, [bwaccessToken])
  68 +
58 69  
  70 +
59 71  
60 72  
61 73 useEffect(() => {
... ... @@ -69,9 +81,13 @@ function BookingWizard(props) {
69 81 setShow(commonStore?.showBookingModal)
70 82 }, [commonStore.showBookingModal])
71 83  
  84 +
72 85 const handleCloseModal = () => {
73 86 dispatch({ type: 'BW_SHOW_BOOKING_MODAL', payload: false })
74 87 dispatch({ type: 'BW_CLICK_BOOKING_BTN', payload: false })
  88 + if(!localStorage.getItem('bwHasBooked') && localStorage.getItem('activeStep') !=="step-login" || localStorage.getItem('bwHasBooked') === false && localStorage.getItem('activeStep') !=="step-login") {
  89 + dispatch({ type: 'BW_SHOW_MODAL_IMCOMPLETE', payload: true })
  90 + }
75 91 }
76 92  
77 93  
... ... @@ -90,7 +106,7 @@ function BookingWizard(props) {
90 106 <div className="bw-col-left">
91 107 {process.env.REACT_APP_NAME === 'rce' && <i className="bw-icon-health-care"></i>}
92 108 {process.env.REACT_APP_NAME === 'mm' && <i className="bw-icon-leaf"></i>}
93   - <span>Confirm your services</span>
  109 + <span>Select your services</span>
94 110 </div>
95 111 <div className="bw-col-right">
96 112 <div className="bw-btn bw-btn-primary">
... ... @@ -174,7 +190,9 @@ function BookingWizard(props) {
174 190 </>
175 191 case 'step-profile':
176 192 return <>
177   - <Profile />
  193 + <Profile
  194 + loadprofile={false}
  195 + profile={userProfile} />
178 196 </>
179 197 case 'step-signup-update-profile':
180 198 return <>
... ... @@ -7,7 +7,7 @@
7 7 height: 100vh;
8 8 left: 0;
9 9 top: 0;
10   - z-index: 90;
  10 + z-index: 99999998;
11 11 }
12 12 .bw-booking-popup-wraper {
13 13  
... ... @@ -25,7 +25,7 @@
25 25 bottom: 0;
26 26 display: flex;
27 27 flex-wrap: wrap;
28   - z-index: 100;
  28 + z-index: 99999999;
29 29 .bw-booking-modal {
30 30 flex: 0 0 100%;
31 31 max-width: 100%;