Skip to content

Commit 4b62a55

Browse files
authored
Fix applications route to render application by id (#782)
1 parent b7d2aed commit 4b62a55

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

applications/script.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getIsSuperUser,
55
showToast,
66
updateApplication,
7+
getApplicationById,
78
} from './utils.js';
89
let nextLink;
910
let isDataLoading = false;
@@ -271,8 +272,33 @@ async function renderApplicationCards(next, status, isInitialRender) {
271272
});
272273
}
273274

275+
async function renderApplicationById(id) {
276+
noApplicationFoundText.classList.add('hidden');
277+
changeLoaderVisibility({ hide: false });
278+
isDataLoading = true;
279+
280+
try {
281+
const application = await getApplicationById(id);
282+
283+
if (!application) {
284+
return noApplicationFoundText.classList.remove('hidden');
285+
}
286+
287+
const applicationCard = createApplicationCard({ application });
288+
applicationContainer.appendChild(applicationCard);
289+
applicationContainer.classList.add('center');
290+
} catch (error) {
291+
console.error('Error fetching application by user ID:', error);
292+
noApplicationFoundText.classList.remove('hidden');
293+
} finally {
294+
isDataLoading = false;
295+
changeLoaderVisibility({ hide: true });
296+
}
297+
}
298+
274299
(async function renderCardsInitial() {
275300
changeLoaderVisibility({ hide: false });
301+
276302
const isSuperUser = await getIsSuperUser();
277303
if (!isSuperUser) {
278304
const unAuthorizedText = createElement({
@@ -284,8 +310,19 @@ async function renderApplicationCards(next, status, isInitialRender) {
284310
changeLoaderVisibility({ hide: true });
285311
return;
286312
}
287-
await renderApplicationCards('', status, true);
288-
addIntersectionObserver();
313+
314+
const queryString = window.location.search;
315+
const urlParams = new URLSearchParams(queryString);
316+
const applicationId = urlParams.get('id');
317+
318+
if (applicationId) {
319+
await renderApplicationById(applicationId);
320+
} else {
321+
await renderApplicationCards('', status, true);
322+
addIntersectionObserver();
323+
}
324+
325+
changeLoaderVisibility({ hide: true });
289326
})();
290327

291328
const intersectionObserver = new IntersectionObserver(async (entries) => {

applications/style.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ body {
4848
.container {
4949
max-width: 1100px;
5050
margin: 0 auto;
51-
padding: 2.5rem;
51+
padding: 2rem;
5252
overflow-y: auto;
5353
}
5454

@@ -144,13 +144,16 @@ body {
144144

145145
.application-container {
146146
display: flex;
147-
margin-top: 30px;
148147
flex-wrap: wrap;
149148
justify-content: space-between;
150149
padding-bottom: 10px;
151150
gap: 25px;
152151
}
153152

153+
.application-container.center {
154+
justify-content: center;
155+
}
156+
154157
.application-card {
155158
border-radius: 15px;
156159
box-shadow: var(--elevation-1);

applications/utils.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ async function getApplications({ applicationStatus, size = 5, next = '' }) {
4040
}
4141
}
4242

43+
async function getApplicationById(applicationId) {
44+
try {
45+
const res = await fetch(`${BASE_URL}/applications/${applicationId}`, {
46+
method: 'GET',
47+
credentials: 'include',
48+
headers: {
49+
'Content-type': 'application/json',
50+
},
51+
});
52+
53+
if (!res.ok) {
54+
const error = await res.json();
55+
throw error;
56+
}
57+
58+
const data = await res.json();
59+
return data.application;
60+
} catch (error) {
61+
throw error;
62+
}
63+
}
64+
4365
async function getIsSuperUser() {
4466
try {
4567
const res = await fetch(`${BASE_URL}/users/self`, {
@@ -104,6 +126,7 @@ function showToast({ message, type }) {
104126
export {
105127
createElement,
106128
getApplications,
129+
getApplicationById,
107130
updateApplication,
108131
getIsSuperUser,
109132
showToast,

0 commit comments

Comments
 (0)