Commit 5923d171a712026e8e5ad847359ba6412ee0f801
1 parent
ac34773836
Exists in
master
update
Showing 2 changed files with 223 additions and 10 deletions Side-by-side Diff
apis/index.js
... | ... | @@ -54,6 +54,130 @@ export const getUserProfile = async ( token ) => { |
54 | 54 | result.message = data.message |
55 | 55 | } |
56 | 56 | |
57 | + } | |
58 | + catch(error) { | |
59 | + console.error( 'Login error: ', error.message ) | |
60 | + result.message = parseErrorMessage( error ) | |
61 | + } | |
62 | + return result | |
63 | +} | |
64 | + | |
65 | +/** | |
66 | + * | |
67 | + * Create or update request help | |
68 | + * | |
69 | + */ | |
70 | +export const postRequestHelp = async (dataparam, token ) => { | |
71 | + | |
72 | + const headers = { | |
73 | + headers: { | |
74 | + // "X-CSRFToken": csrfToken, | |
75 | + "Content-Type": "application/json", | |
76 | + "Content-Type": "application/json", | |
77 | + 'Access-Control-Allow-Origin': "*", | |
78 | + 'Access-Control-Allow-Headers': "*", | |
79 | + 'Authorization':`Bearer ${token}`, | |
80 | + 'x-app-name': 'dashboard', | |
81 | + "x-ehealth-role":'PATIENT', | |
82 | + } | |
83 | + } | |
84 | + | |
85 | + let result = { success: false } | |
86 | + try { | |
87 | + let { data } = await axios.post(`${baseAPIUrl}/crm/request-help/`, JSON.stringify(dataparam), headers) | |
88 | + if ( data.status === true && typeof data.data.result !== 'undefined' ) { | |
89 | + result = { | |
90 | + success: true, | |
91 | + data: data.data.result, | |
92 | + message: data.message | |
93 | + } | |
94 | + }else { | |
95 | + result.message = data.message | |
96 | + } | |
97 | + | |
98 | + } | |
99 | + catch(error) { | |
100 | + console.error( 'Login error: ', error.message ) | |
101 | + result.message = parseErrorMessage( error ) | |
102 | + } | |
103 | + return result | |
104 | +} | |
105 | + | |
106 | +/** | |
107 | + * | |
108 | + * Get request help by user | |
109 | + * | |
110 | + */ | |
111 | + | |
112 | +export const getRequestHelp = async ( token ) => { | |
113 | + | |
114 | + const headers = { | |
115 | + headers: { | |
116 | + // "X-CSRFToken": csrfToken, | |
117 | + "Content-Type": "application/json", | |
118 | + "Content-Type": "application/json", | |
119 | + 'Access-Control-Allow-Origin': "*", | |
120 | + 'Access-Control-Allow-Headers': "*", | |
121 | + 'Authorization':`Bearer ${token}`, | |
122 | + 'x-app-name': 'dashboard', | |
123 | + "x-ehealth-role":'PATIENT', | |
124 | + } | |
125 | + } | |
126 | + | |
127 | + let result = { success: false } | |
128 | + try { | |
129 | + let { data } = await axios.get(`${baseAPIUrl}/crm/request-help/user/`, headers) | |
130 | + if ( data.status === true && typeof data.data.result !== 'undefined' ) { | |
131 | + result = { | |
132 | + success: true, | |
133 | + data: data.data.result, | |
134 | + message: data.message | |
135 | + } | |
136 | + }else { | |
137 | + result.message = data.message | |
138 | + } | |
139 | + | |
140 | + } | |
141 | + catch(error) { | |
142 | + console.error( 'Login error: ', error.message ) | |
143 | + result.message = parseErrorMessage( error ) | |
144 | + } | |
145 | + return result | |
146 | +} | |
147 | + | |
148 | +/** | |
149 | + * | |
150 | + * Get Appointent | |
151 | + * | |
152 | + */ | |
153 | +export const getAppointment = async ( patient_id, token ) => { | |
154 | + | |
155 | + const headers = { | |
156 | + headers: { | |
157 | + // "X-CSRFToken": csrfToken, | |
158 | + "Content-Type": "application/json", | |
159 | + "Content-Type": "application/json", | |
160 | + 'Access-Control-Allow-Origin': "*", | |
161 | + 'Access-Control-Allow-Headers': "*", | |
162 | + 'Authorization':`Bearer ${token}`, | |
163 | + 'x-app-name': 'dashboard', | |
164 | + "x-ehealth-role":'PATIENT', | |
165 | + } | |
166 | + } | |
167 | + let result = { success: false } | |
168 | + let params = patient_id!==''?`?patient_id=${patient_id}`:'' | |
169 | + try { | |
170 | + let { data } = await axios.get(`${baseAPIUrl}/ehealth/appointments/patient/${params}`, headers) | |
171 | + if ( data.status === true && typeof data.data.result !== 'undefined' ) { | |
172 | + result = { | |
173 | + success: true, | |
174 | + data: data.data.result, | |
175 | + message: data.message | |
176 | + } | |
177 | + }else { | |
178 | + result.message = data.message | |
179 | + } | |
180 | + | |
57 | 181 | } |
58 | 182 | catch(error) { |
59 | 183 | console.error( 'Login error: ', error.message ) |
index.js
1 | 1 | import React, { useState, useEffect } from 'react' |
2 | 2 | import root from 'react-shadow'; |
3 | -import { useCookies } from 'react-cookie' | |
3 | +import moment from 'moment'; | |
4 | +import _ from 'lodash'; | |
5 | +// import { useCookies } from 'react-cookie' | |
6 | +import { getCookie } from '../../utils/utils'; | |
4 | 7 | import Portal from '../../components/Portal' |
5 | 8 | import BookingWizardStep from '../../components/BookingWizardStep' |
6 | 9 | import LoginStep from '../../components/Steps/Login'; |
... | ... | @@ -13,17 +16,18 @@ import PaymentStep from '../../components/Steps/PaymentStep' |
13 | 16 | |
14 | 17 | import './_styles.scss' |
15 | 18 | import { useCommonState, useCommonDispatch } from '../../store/common' |
16 | - | |
19 | +import {postRequestHelp, getRequestHelp, getAppointment} from './apis' | |
17 | 20 | function BookingWizard(props) { |
18 | 21 | const [show, setShow] = useState(false) |
19 | - | |
20 | 22 | const [userProfile, setUserProfile] = useState(null) |
21 | 23 | const [step, setStep] = useState('step-login') |
24 | + const [requestHelpID, setRequestHelpID] = useState(null) | |
25 | + const [bookingObj, setBookingObj] = useState(null) | |
22 | 26 | const commonStore = useCommonState() |
23 | 27 | const dispatch = useCommonDispatch() |
24 | - | |
25 | - const [cookies, setCookie, removeCookie] = useCookies('bw-booking-wizard') | |
26 | - let { bwaccessToken } = cookies | |
28 | + let bwaccessToken = getCookie( 'bwaccessToken' ) | |
29 | + // const [cookies, setCookie, removeCookie] = useCookies('bw-booking-wizard') | |
30 | + // let { bwaccessToken } = cookies | |
27 | 31 | |
28 | 32 | useEffect(() => { |
29 | 33 | if (bwaccessToken) { |
... | ... | @@ -44,6 +48,8 @@ function BookingWizard(props) { |
44 | 48 | if (localStorage.getItem('bwHasBooked')) { |
45 | 49 | dispatch({ type: 'BW_HAS_BOOKED', payload: true }) |
46 | 50 | } |
51 | + // get request id | |
52 | + GetHelpRequestID(bwaccessToken) | |
47 | 53 | } |
48 | 54 | // First we get the viewport height and we multiple it by 1% to get a value for a vh unit |
49 | 55 | let vh = window.innerHeight * 0.01; |
... | ... | @@ -52,8 +58,11 @@ function BookingWizard(props) { |
52 | 58 | |
53 | 59 | }, []) |
54 | 60 | useEffect(() => { |
55 | - | |
56 | - }, [commonStore.showBookingModal]) | |
61 | + console.log("commonStore.userProfile]",commonStore.userProfile) | |
62 | + if(commonStore.userProfile) { | |
63 | + GetAppoinent(commonStore.userProfile?.patient_id,bwaccessToken ) | |
64 | + } | |
65 | + }, [commonStore.userProfile, bwaccessToken]) | |
57 | 66 | |
58 | 67 | useEffect(() => { |
59 | 68 | if (bwaccessToken === null || !bwaccessToken) { |
... | ... | @@ -95,13 +104,86 @@ function BookingWizard(props) { |
95 | 104 | }, [show]) |
96 | 105 | |
97 | 106 | |
107 | + const GetHelpRequestID = async (token) => { | |
108 | + let res = await getRequestHelp (token) | |
109 | + if(res && res.success) { | |
110 | + if(res?.data?.id) { | |
111 | + localStorage.setItem('request_help_id', res?.data?.id) | |
112 | + setRequestHelpID(res?.data?.id) | |
113 | + } | |
114 | + | |
115 | + } | |
116 | + } | |
117 | + const GetAppoinent = async (patient_id, token) => { | |
118 | + let res = await getAppointment(patient_id,token); | |
119 | + if (res && res.success) { | |
120 | + let today = moment(new Date()).format('YYYY-MM-DD') | |
121 | + let todayHour = moment(new Date()).format('YYYY-MM-DD HH:mm') | |
122 | + let arr2 = [] | |
123 | + let arr3 = [] | |
124 | + if (res.data) { | |
125 | + console.log("data boooking", res.data) | |
126 | + res.data.forEach(el => { | |
127 | + if (el.date_time_start && el.date_time_start!=="") { | |
128 | + let datetime = moment.utc(el.date_time_start).local().format('YYYY-MM-DD HH:mm') | |
129 | + if (moment(el.date).isAfter(today) || moment(el.date).isSame(today, 'day') && datetime && | |
130 | + moment(datetime).isAfter(todayHour, 'minute')) { | |
131 | + el.editable = true | |
132 | + arr2.push(el) | |
133 | + } | |
134 | + | |
135 | + } | |
136 | + }); | |
137 | + } | |
138 | + let fnArr = _.union(arr2, arr3) | |
139 | + console.log("fnArr", fnArr) | |
140 | + if(fnArr.length>0) { | |
141 | + setBookingObj(fnArr[0]) | |
142 | + localStorage.setItem('booking_id',fnArr[0].appointment) | |
143 | + dispatch({ type: 'BOOKING_DATA', payload: JSON.stringify(fnArr[0]) }) | |
144 | + dispatch({ type: 'BW_HAS_BOOKED', payload: true }) | |
145 | + } | |
146 | + } | |
147 | + } | |
148 | + | |
98 | 149 | const handleCloseModal = () => { |
99 | 150 | dispatch({ type: 'BW_SHOW_BOOKING_MODAL', payload: false }) |
100 | 151 | dispatch({ type: 'BW_CLICK_BOOKING_BTN', payload: false }) |
101 | - if (!localStorage.getItem('bwHasBooked') && localStorage.getItem('activeStep') !== "step-login" || localStorage.getItem('bwHasBooked') === false && localStorage.getItem('activeStep') !== "step-login") { | |
152 | + // if (!localStorage.getItem('bwHasBooked') && localStorage.getItem('activeStep') !== "step-login" || | |
153 | + // localStorage.getItem('bwHasBooked') === false && localStorage.getItem('activeStep') !== "step-login") { | |
154 | + // dispatch({ type: 'BW_SHOW_MODAL_IMCOMPLETE', payload: true }) | |
155 | + // } | |
156 | + if (commonStore?.hasBooked === false && localStorage.getItem('activeStep') !== "step-login" ) { | |
102 | 157 | dispatch({ type: 'BW_SHOW_MODAL_IMCOMPLETE', payload: true }) |
103 | 158 | } |
104 | 159 | } |
160 | + | |
161 | + const handleRequestHelp = async(type, step) => { | |
162 | + let dataPram ={ | |
163 | + "metadata" : { | |
164 | + "type": type, | |
165 | + "process_booking": `${step}/4`, | |
166 | + "process_profile": commonStore?.userProfile?.patient_case?.patient?100:0, // has patient profile | |
167 | + "marketing_group_id": localStorage.getItem('marketing_group_id'), | |
168 | + } | |
169 | + } | |
170 | + console.log("userProfile",commonStore?.userProfile) | |
171 | + if(commonStore?.userProfile?.patient_case?.id) { | |
172 | + dataPram.case_id = commonStore?.userProfile?.patient_case?.id | |
173 | + } | |
174 | + if(requestHelpID) { | |
175 | + dataPram.request_id = requestHelpID | |
176 | + } | |
177 | + console.log("bwaccessToken",bwaccessToken) | |
178 | + let res = await postRequestHelp(dataPram, bwaccessToken) | |
179 | + if(res && res.success) { | |
180 | + dispatch({type: 'BW_MODAL_REQUEST_HELP', payload:true}) | |
181 | + setRequestHelpID(res?.data?.id) | |
182 | + localStorage.setItem('request_help_id',res?.data?.id) | |
183 | + dispatch({type:'WB_REQUEST_HELP_ID', payload:res?.data?.id}) | |
184 | + } | |
185 | + | |
186 | + } | |
105 | 187 | |
106 | 188 | |
107 | 189 | const renderStep = (step) => { |
... | ... | @@ -126,12 +208,19 @@ function BookingWizard(props) { |
126 | 208 | <i className="bw-icon-calling"></i> |
127 | 209 | Get Help |
128 | 210 | </div> |
211 | + <div className="bw-btn bw-btn-primary bw-ml-15" onClick={()=> handleRequestHelp('INCOMPLETE_BOOKING', 1)}> | |
212 | + <i className="bw-icon-Call-Center"></i> | |
213 | + Request Help | |
214 | + </div> | |
129 | 215 | </div> |
130 | 216 | </div> |
131 | 217 | </div> |
132 | 218 | <div className="bw-booking-modal-content"> |
133 | 219 | <div className="bw-booking-modal-inner"> |
134 | - <Services /> | |
220 | + <Services | |
221 | + userProfile={commonStore?.userProfile} | |
222 | + hasBooked={commonStore?.hasBooked} | |
223 | + /> | |
135 | 224 | </div> |
136 | 225 | </div> |
137 | 226 | </> |