Skip to content

Commit

Permalink
changed the superUser data, make the task-request/script.js type module
Browse files Browse the repository at this point in the history
  • Loading branch information
AnujChhikara committed Oct 24, 2024
1 parent ed7a260 commit f8046db
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 41 deletions.
42 changes: 27 additions & 15 deletions mock-data/taskRequests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,27 +338,39 @@ const userInformation = {
},
};
const superUserData = {
id: 'V4rqL1aDecNGoa1IxiCu',
incompleteUserDetails: false,
discordId: '12345',
id: 'XAF7rSUvk4p0d098qWYS',
profileURL: 'https://my.realdevsquad.com/identity',
discordJoinedAt: '2020-02-01T08:33:38.278000+00:00',
roles: {
archived: false,
in_discord: true,
member: true,
super_user: true,
admin: true,
},
linkedin_id: 'kotesh',
last_name: 'Mudila',
yoe: '5',
github_display_name: 'kotesh Mudila',
company_name: 'Juniper networks ',
github_id: 'kotesh-arya',
designation: 'Front end engineer',
twitter_id: 'Codesh_',
first_name: 'Kotesh',
username: 'kotesh',
created_at: 1693166951852,
yoe: '8',
github_created_at: 1341655281000,
updated_at: 1693224375990,
company: 'Amazon',
twitter_id: 'ankushdharkar',
first_name: 'Ankush',
' instagram_id': 'ankushdharkar',
website: 'NA',
incompleteUserDetails: false,
discordId: '154585730465660929',
linkedin_id: 'ankushdharkar',
last_name: 'Dharkar',
picture: {
publicId: 'profile/w2XR9Gkid6Kg5xCJ5Elm/rzh3cwff7hh7srvg63mb',
url: 'https://res.cloudinary.com/realdevsquad/image/upload/v1692990078/profile/w2XR9Gkid6Kg5xCJ5Elm/rzh3cwff7hh7srvg63mb.png',
publicId: 'profile/XAF7rSUvk4p0d098qWYS/me40uk7taytbjaa67mhe',
url: 'https://res.cloudinary.com/realdevsquad/image/upload/v1692058952/profile/XAF7rSUvk4p0d098qWYS/me40uk7taytbjaa67mhe.jpg',
},
github_display_name: 'Ankush Dharkar',
company_name: 'Amazon',
github_id: 'ankushdharkar',
designation: 'SDE',
status: 'idle',
username: 'ankush',
};
const defaultMockResponseHeaders = {
status: 200,
Expand Down
2 changes: 1 addition & 1 deletion task-requests/details/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script src="/task-requests/details/script.js" defer></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"
integrity="sha512-LhccdVNGe2QMEfI3x4DVV3ckMRe36TfydKss6mJpdHjNFiV07dFpS2xzeZedptKZrwxfICJpez09iNioiSZ3hA=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script type="module" src="/task-requests/details/script.js" defer></script>
</head>
<body>
<div class="header">
Expand Down
31 changes: 6 additions & 25 deletions task-requests/details/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const API_BASE_URL =
window.location.hostname === 'localhost'
? 'https://staging-api.realdevsquad.com'
: window.API_BASE_URL;

import { getIsSuperUser } from '../../applications/utils.js';
let taskRequest;
let isSuperUser;

Expand All @@ -18,31 +18,12 @@ const requestDetailContainer =
document.getElementsByClassName('request-details');
const taskContainer = document.getElementById('task-details');
const toast = document.getElementById('toast_task_details');
// const rejectButton = document.getElementById('reject-button');
const requestorsContainer = document.getElementById('requestors-details');
const taskRequestId = new URLSearchParams(window.location.search).get('id');
history.pushState({}, '', window.location.href);
const errorMessage =
'The requested operation could not be completed. Please try again later.';

async function getSelfUser() {
const res = await fetch(`${API_BASE_URL}/users/self`, {
method: 'GET',
credentials: 'include',
headers: {
'Content-type': 'application/json',
},
});

const self_user = await res.json();
return self_user;
}

async function checkUserIsSuperUser() {
const self_user = await getSelfUser();
return self_user?.roles['super_user'];
}

function renderTaskRequestDetails(taskRequest) {
taskRequestContainer.append(
createCustomElement({
Expand Down Expand Up @@ -335,7 +316,7 @@ async function fetchTaskRequest() {
}

const renderGithubIssue = async () => {
converter = new showdown.Converter({
const converter = new showdown.Converter({
tables: true,
simplifiedAutoLink: true,
tasklists: true,
Expand Down Expand Up @@ -374,7 +355,7 @@ const renderGithubIssue = async () => {
}),
);
const body = DOMPurify.sanitize(res?.body ?? '');
html = converter.makeHtml(body);
const html = converter.makeHtml(body);
taskContainer.appendChild(
createCustomElement({
tagName: 'div',
Expand Down Expand Up @@ -472,7 +453,7 @@ const renderTaskRequest = async () => {
taskContainer.classList.remove('hidden');
try {
taskRequest = await fetchTaskRequest();
isSuperUser = await checkUserIsSuperUser();
isSuperUser = await getIsSuperUser();
taskRequestSkeleton.classList.add('hidden');
renderRejectButton(taskRequest);
renderTaskRequestDetails(taskRequest);
Expand Down Expand Up @@ -615,7 +596,7 @@ function populateModalContent(index) {
);

if (userData?.markdownEnabled ?? false) {
converter = new showdown.Converter({
const converter = new showdown.Converter({
tables: true,
simplifiedAutoLink: true,
tasklists: true,
Expand All @@ -624,7 +605,7 @@ function populateModalContent(index) {
openLinksInNewWindow: true,
});
const sanitizedDescription = DOMPurify.sanitize(userData.description ?? '');
html = converter.makeHtml(sanitizedDescription);
const html = converter.makeHtml(sanitizedDescription);
descriptionValue.innerHTML = html;
descriptionValue.className = 'requestor_description_details';
} else {
Expand Down

0 comments on commit f8046db

Please sign in to comment.