@@ -32,6 +32,10 @@ const applyFilterButton = document.getElementById('apply-filter-button');
32
32
const applicationContainer = document . querySelector ( '.application-container' ) ;
33
33
const clearButton = document . getElementById ( 'clear-button' ) ;
34
34
const lastElementContainer = document . getElementById ( 'page_bottom_element' ) ;
35
+
36
+ const urlParams = new URLSearchParams ( window . location . search ) ;
37
+ let applicationId = urlParams . get ( 'id' ) ;
38
+
35
39
let currentApplicationId ;
36
40
37
41
let status = 'all' ;
@@ -46,18 +50,22 @@ function updateUserApplication({ isAccepted }) {
46
50
47
51
payload [ 'status' ] = status ;
48
52
49
- if ( applicationTextarea . value ) payload . feedback = applicationTextarea . value ;
53
+ if ( applicationTextarea . value ) {
54
+ payload . feedback = applicationTextarea . value ;
55
+ }
50
56
51
57
updateApplication ( {
52
58
applicationId : currentApplicationId ,
53
59
applicationPayload : payload ,
54
60
} )
55
61
. then ( ( res ) => {
56
- closeApplicationDetails ( ) ;
62
+ const updatedFeedback = payload . feedback || '' ;
63
+ applicationTextarea . value = updatedFeedback ;
64
+
57
65
showToast ( { type : 'success' , message : res . message } ) ;
66
+ setTimeout ( ( ) => closeApplicationDetails ( ) , 1000 ) ;
58
67
} )
59
68
. catch ( ( error ) => {
60
- closeApplicationDetails ( ) ;
61
69
showToast ( { type : 'error' , message : error . message } ) ;
62
70
} ) ;
63
71
}
@@ -73,6 +81,7 @@ function closeApplicationDetails() {
73
81
applicationDetailsModal . classList . add ( 'hidden' ) ;
74
82
backDropBlur . style . display = 'none' ;
75
83
document . body . style . overflow = 'auto' ;
84
+ removeQueryParamInUrl ( 'id' ) ;
76
85
}
77
86
78
87
function openApplicationDetails ( application ) {
@@ -170,15 +179,35 @@ function openApplicationDetails(application) {
170
179
class : 'application-textarea' ,
171
180
placeHolder : 'Add Feedback here' ,
172
181
} ,
182
+ innerText : application . feedback || '' ,
173
183
} ) ;
174
184
175
185
applicationSection . appendChild ( applicationSectionTitle ) ;
176
186
applicationSection . appendChild ( applicationTextArea ) ;
177
187
applicationDetailsMain . appendChild ( applicationSection ) ;
188
+
189
+ if ( application . status === 'rejected' ) {
190
+ applicationRejectButton . disabled = true ;
191
+ applicationRejectButton . style . cursor = 'not-allowed' ;
192
+ applicationRejectButton . classList . add ( 'disable-button' ) ;
193
+ } else if ( application . status === 'accepted' ) {
194
+ applicationAcceptButton . disabled = true ;
195
+ applicationAcceptButton . style . cursor = 'not-allowed' ;
196
+ applicationAcceptButton . classList . add ( 'disable-button' ) ;
197
+ } else {
198
+ applicationRejectButton . disabled = false ;
199
+ applicationRejectButton . style . cursor = 'pointer' ;
200
+ applicationRejectButton . classList . remove ( 'disable-button' ) ;
201
+
202
+ applicationAcceptButton . disabled = false ;
203
+ applicationAcceptButton . style . cursor = 'pointer' ;
204
+ applicationAcceptButton . classList . remove ( 'disable-button' ) ;
205
+ }
178
206
}
179
207
180
208
function clearFilter ( ) {
181
209
if ( status === 'all' ) return ;
210
+ removeQueryParamInUrl ( 'status' ) ;
182
211
changeFilter ( ) ;
183
212
const selectedFilterOption = document . querySelector (
184
213
'input[name="status"]:checked' ,
@@ -193,6 +222,23 @@ function changeLoaderVisibility({ hide }) {
193
222
else loader . classList . remove ( 'hidden' ) ;
194
223
}
195
224
225
+ function addQueryParamInUrl ( queryParamKey , queryParamVal ) {
226
+ const currentUrlParams = new URLSearchParams ( window . location . search ) ;
227
+ currentUrlParams . append ( queryParamKey , queryParamVal ) ;
228
+ const updatedUrl = '/applications/?' + currentUrlParams . toString ( ) ;
229
+ window . history . replaceState ( window . history . state , '' , updatedUrl ) ;
230
+ }
231
+
232
+ function removeQueryParamInUrl ( queryParamKey ) {
233
+ const currentUrlParams = new URLSearchParams ( window . location . search ) ;
234
+ currentUrlParams . delete ( queryParamKey ) ;
235
+ let updatedUrl = '/applications/' ;
236
+ if ( currentUrlParams . size > 0 ) {
237
+ updatedUrl += '?' + currentUrlParams . toString ( ) ;
238
+ }
239
+ window . history . replaceState ( window . history . state , '' , updatedUrl ) ;
240
+ }
241
+
196
242
function createApplicationCard ( { application } ) {
197
243
const applicationCard = createElement ( {
198
244
type : 'div' ,
@@ -212,13 +258,13 @@ function createApplicationCard({ application }) {
212
258
213
259
const companyNameText = createElement ( {
214
260
type : 'p' ,
215
- attributes : { class : 'company-name' } ,
261
+ attributes : { class : 'company-name hide-overflow ' } ,
216
262
innerText : `Company name: ${ application . professional . institution } ` ,
217
263
} ) ;
218
264
219
265
const skillsText = createElement ( {
220
266
type : 'p' ,
221
- attributes : { class : 'skills' } ,
267
+ attributes : { class : 'skills hide-overflow ' } ,
222
268
innerText : `Skills: ${ application . professional . skills } ` ,
223
269
} ) ;
224
270
@@ -228,7 +274,7 @@ function createApplicationCard({ application }) {
228
274
229
275
const introductionText = createElement ( {
230
276
type : 'p' ,
231
- attributes : { class : 'user-intro' } ,
277
+ attributes : { class : 'user-intro hide-overflow ' } ,
232
278
innerText : application . intro . introduction . slice ( 0 , 200 ) ,
233
279
} ) ;
234
280
@@ -238,9 +284,10 @@ function createApplicationCard({ application }) {
238
284
innerText : 'View Details' ,
239
285
} ) ;
240
286
241
- viewDetailsButton . addEventListener ( 'click' , ( ) =>
242
- openApplicationDetails ( application ) ,
243
- ) ;
287
+ viewDetailsButton . addEventListener ( 'click' , ( ) => {
288
+ addQueryParamInUrl ( 'id' , application . id ) ;
289
+ openApplicationDetails ( application ) ;
290
+ } ) ;
244
291
245
292
applicationCard . appendChild ( userInfoContainer ) ;
246
293
applicationCard . appendChild ( introductionText ) ;
@@ -283,10 +330,7 @@ async function renderApplicationById(id) {
283
330
if ( ! application ) {
284
331
return noApplicationFoundText . classList . remove ( 'hidden' ) ;
285
332
}
286
-
287
- const applicationCard = createApplicationCard ( { application } ) ;
288
- applicationContainer . appendChild ( applicationCard ) ;
289
- applicationContainer . classList . add ( 'center' ) ;
333
+ openApplicationDetails ( application ) ;
290
334
} catch ( error ) {
291
335
console . error ( 'Error fetching application by user ID:' , error ) ;
292
336
noApplicationFoundText . classList . remove ( 'hidden' ) ;
@@ -310,17 +354,18 @@ async function renderApplicationById(id) {
310
354
changeLoaderVisibility ( { hide : true } ) ;
311
355
return ;
312
356
}
357
+ const urlParams = new URLSearchParams ( window . location . search ) ;
358
+ status = urlParams . get ( 'status' ) || 'all' ;
313
359
314
- const queryString = window . location . search ;
315
- const urlParams = new URLSearchParams ( queryString ) ;
316
- const applicationId = urlParams . get ( 'id' ) ;
360
+ if ( status !== 'all' ) {
361
+ document . querySelector ( `input[name="status"]# ${ status } ` ) . checked = true ;
362
+ }
317
363
318
364
if ( applicationId ) {
319
365
await renderApplicationById ( applicationId ) ;
320
- } else {
321
- await renderApplicationCards ( '' , status , true ) ;
322
- addIntersectionObserver ( ) ;
323
366
}
367
+ await renderApplicationCards ( '' , status , true , applicationId ) ;
368
+ addIntersectionObserver ( ) ;
324
369
325
370
changeLoaderVisibility ( { hide : true } ) ;
326
371
} ) ( ) ;
@@ -355,8 +400,11 @@ applyFilterButton.addEventListener('click', () => {
355
400
const selectedFilterOption = document . querySelector (
356
401
'input[name="status"]:checked' ,
357
402
) ;
403
+
404
+ const selectedStatus = selectedFilterOption . value ;
405
+ addQueryParamInUrl ( 'status' , selectedStatus ) ;
358
406
changeFilter ( ) ;
359
- status = selectedFilterOption . value ;
407
+ status = selectedStatus ;
360
408
renderApplicationCards ( nextLink , status ) ;
361
409
} ) ;
362
410
0 commit comments