@@ -65,13 +65,24 @@ const InterviewPopup = ({
65
65
/**
66
66
* Gets the settings from the backend and checks if the calendar is already available
67
67
*/
68
- const getSettings = ( ) => {
68
+ const getSettings = ( options = { preferredStage : POPUP_STAGES . MANAGE_AVAILABILITY } ) => {
69
69
setLoading ( true ) ;
70
70
getUserSettings ( v5UserProfile . id )
71
71
. then ( ( res ) => {
72
72
setUserSettings ( res . data ) ;
73
73
setScheduleDetails ( prepareSlots ( res . data ) ) ;
74
- setStage ( POPUP_STAGES . MANAGE_AVAILABILITY ) ;
74
+
75
+ let nextStage = options . preferredStage ;
76
+ if (
77
+ options . preferredStage === POPUP_STAGES . CONNECT_CALENDAR &&
78
+ _ . findIndex ( res . data . nylasCalendars , ( item ) => item . isPrimary ) !== - 1
79
+ ) {
80
+ // checks if any connected calendars are available by above conditions
81
+ // if available, modify nextStage to POPUP_STAGES.MANAGE_CALENDAR
82
+ nextStage = POPUP_STAGES . MANAGE_CALENDAR ;
83
+ }
84
+
85
+ setStage ( nextStage ) ;
75
86
} )
76
87
. catch ( ( e ) => {
77
88
if ( e . response && e . response . status === 404 ) {
@@ -87,7 +98,7 @@ const InterviewPopup = ({
87
98
} ;
88
99
89
100
/**
90
- * Get the calendar which is not of provider nylas
101
+ * Get the calendar which is not of provider nylas & is a primary calendar
91
102
* @param {* } settings
92
103
* @returns
93
104
*/
@@ -96,10 +107,10 @@ const InterviewPopup = ({
96
107
const calendar =
97
108
( settings . nylasCalendars &&
98
109
settings . nylasCalendars . filter (
99
- ( item ) => item . accountProvider !== "nylas"
110
+ ( item ) => item . accountProvider !== "nylas" && item . isPrimary
100
111
) ) ||
101
112
[ ] ;
102
- // Take the first calendar which are other than nylas calendar
113
+ // Take the first calendar which are other than nylas calendar & which is primary
103
114
return calendar [ 0 ] ;
104
115
} ;
105
116
@@ -146,12 +157,7 @@ const InterviewPopup = ({
146
157
* Removes the calendar from the state once it is removed from the server
147
158
*/
148
159
const onCalendarRemoved = ( ) => {
149
- setUserSettings ( {
150
- ...userSettings ,
151
- nylasCalendars : [ ] ,
152
- } ) ;
153
-
154
- setStage ( POPUP_STAGES . CONNECT_CALENDAR ) ;
160
+ getSettings ( { preferredStage : POPUP_STAGES . CONNECT_CALENDAR } ) ;
155
161
} ;
156
162
157
163
/**
@@ -203,16 +209,15 @@ const InterviewPopup = ({
203
209
return (
204
210
< Confirm
205
211
scheduleDetails = { scheduleDetails }
206
- userProfile = { v5UserProfile }
207
212
onContinue = { onChangeStage }
208
213
onGoBack = { onGoingBack }
209
214
onShowingLoader = { onShowingLoader }
210
- candidateId = { candidate . id }
215
+ candidate = { candidate }
211
216
/>
212
217
) ;
213
218
case POPUP_STAGES . SUCCESS :
214
219
return (
215
- < Success userProfile = { v5UserProfile } onContinue = { onChangeStage } />
220
+ < Success candidate = { candidate } onContinue = { onChangeStage } />
216
221
) ;
217
222
default :
218
223
return null ;
0 commit comments