Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role option for existing user #541

Open
wants to merge 7 commits into
base: archived-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
--color-events: #e30162;
--color-button: #87d870;
--color-button-hover: #6dc66d;
--role-button-bg: #008000;
--role-button-text: #ffffff;
--loader-gray-color: #f3f3f3;
--loader-blue-color: #1d1283;
--role-button-disabled: #ccc;
}

.dark-theme {
shubhamsinghbundela marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -539,6 +544,98 @@ footer {
}
}

.roles-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
shubhamsinghbundela marked this conversation as resolved.
Show resolved Hide resolved
justify-content: center;
align-items: center;
z-index: 200;
}

.role-details {
background-color: var(--color-bg);
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
shubhamsinghbundela marked this conversation as resolved.
Show resolved Hide resolved
padding: 2rem;
max-width: 50%;
margin: auto;
}

.role-heading {
font-size: 2rem;
margin-bottom: 0;
text-align: center;
}

.role-details-field {
display: flex;
flex-direction: column;
justify-content: center;
padding: 2rem 4rem;
}

.checkbox-label {
display: flex;
width: 12rem;
margin: 0 auto;
font-size: 1.3rem;
}

.checkbox-label .checkbox-input {
shubhamsinghbundela marked this conversation as resolved.
Show resolved Hide resolved
margin-right: 0.4rem;
}

.role-button {
position: relative;
}

.role-button button {
padding: 0.75rem 2rem;
border-radius: 10px;
outline: none;
background-color: var(--role-button-bg);
color: var(--role-button-text);
text-decoration: none;
cursor: pointer;
width: 75%;
display: block;
margin: auto;
font-size: 2rem;
border: none;
}

.spinner {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none;
width: 20px;
height: 20px;
shubhamsinghbundela marked this conversation as resolved.
Show resolved Hide resolved
border: 3px solid var(--loader-gray-color);
border-top: 3px solid var(--loader-blue-color);
border-radius: 50%;
animation: spin 1s linear infinite;
}

.role-button button:disabled {
background-color: var(--role-button-disabled);
cursor: not-allowed;
}

@keyframes spin {
0% {
transform: translate(-50%, -50%) rotate(0deg);
}
100% {
transform: translate(-50%, -50%) rotate(360deg);
}
}

/* Media Queries */

@media (min-width: 420px) {
Expand Down Expand Up @@ -585,6 +682,10 @@ footer {
.card {
padding: 20px 10px;
}
.role-details {
max-width: 100%;
border-radius: 0;
}
}

@media screen and (max-width: 800px) {
Expand Down
12 changes: 12 additions & 0 deletions js/goto.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ function redirectUserToPage(page) {
}

function redirectionHandler(data) {
const isDeveloper = data.roles.developer;
const isDesigner = data.roles.designer;
const isMaven = data.roles.maven;
const isProductManager = data.roles.productmanager;
if (data.incompleteUserDetails) {
redirectUserToPage(SIGNUP_URL);
} else if (
data.incompleteUserDetails === false &&
sahsisunny marked this conversation as resolved.
Show resolved Hide resolved
!isDeveloper &&
!isDesigner &&
!isMaven &&
!isProductManager
) {
redirectUserToPage(HOME_URL);
} else if (hasVisitedJoin == 'true' || hasVisitedJoin == null) {
redirectUserToPage(`${HOME_URL}/join`);
} else {
Expand Down
164 changes: 164 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SELF_URL } from './constants.js';

const selectRandom = (memberImgArr, n) => {
const result = new Set();
const len = memberImgArr.length;
Expand Down Expand Up @@ -101,3 +103,165 @@ modalTriggers.forEach((trigger) => {
});
});
});

function popup(data) {
const isDeveloper = data.roles.developer;
const isDesigner = data.roles.designer;
const isMaven = data.roles.maven;
const isProductManager = data.roles.productmanager;
if (
sahsisunny marked this conversation as resolved.
Show resolved Hide resolved
data.incompleteUserDetails === false &&
!isDeveloper &&
!isDesigner &&
!isMaven &&
!isProductManager
) {
const popupContainer = document.createElement('div');
popupContainer.className = 'roles-container';

const roleDetails = document.createElement('div');
roleDetails.className = 'role-details';

const roleHeading = document.createElement('h2');
roleHeading.className = 'role-heading';
roleHeading.textContent = 'Select your role';

const roleDetailsField = document.createElement('div');
roleDetailsField.className = 'role-details-field';

const roleButton = document.createElement('div');
roleButton.className = 'role-button';

const submitButton = document.createElement('button');
submitButton.textContent = 'Submit';

const spinner = document.createElement('span');
spinner.className = 'spinner';
submitButton.appendChild(spinner);

roleButton.appendChild(submitButton);

roleDetails.appendChild(roleHeading);
roleDetails.appendChild(roleDetailsField);
roleDetails.appendChild(roleButton);

popupContainer.appendChild(roleDetails);
popupContainer.style.display = 'none';
const mainElement = document.querySelector('main');
const firstChild = mainElement.firstChild;
mainElement.insertBefore(popupContainer, firstChild);

const roles = {};

const labels = [
{ name: 'Developer', inputName: 'developer' },
{ name: 'Designer', inputName: 'designer' },
{ name: 'Maven', inputName: 'maven' },
{ name: 'Product Manager', inputName: 'productmanager' },
];

function createCheckbox(labelInfo) {
const label = document.createElement('label');
label.className = 'checkbox-label';

const input = document.createElement('input');
input.type = 'checkbox';
shubhamsinghbundela marked this conversation as resolved.
Show resolved Hide resolved
input.name = labelInfo.inputName;
input.className = 'checkbox-input';

const labelText = document.createTextNode(labelInfo.name);

label.appendChild(input);
label.appendChild(labelText);
return label;
}

labels.forEach((labelInfo) => {
const checkbox = createCheckbox(labelInfo);
roleDetailsField.appendChild(checkbox);
});

const registerUserRoles = async (roles) => {
spinner.style.display = 'inline-block';
submitButton.style.backgroundColor = '#ccc';
const updateRoles = {
roles: {
...data.roles,
...roles,
},
};
const res = await fetch(`${SELF_URL}`, {
method: 'PATCH',
body: JSON.stringify(updateRoles),
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
});
return res;
};

async function hidePopup() {
const response = await registerUserRoles(roles);
if (response.status === 204) {
spinner.style.display = 'none';
submitButton.style.backgroundColor = '#008000';
submitButton.disabled = false;
popupContainer.style.display = 'none';
} else if (response.status === 401) {
alert('You are not logged in! Redirecting you to login.');
location.href = GITHUB_OAUTH;
} else {
alert('Something went wrong please contact admin');
shubhamsinghbundela marked this conversation as resolved.
Show resolved Hide resolved
}
}

function updateRoles(event) {
const checkbox = event.target;
const name = checkbox.name;

if (checkbox.checked) {
roles[name] = true;
} else {
delete roles[name];
}
const anyCheckboxChecked = Object.keys(roles).length > 0;
submitButton.disabled = !anyCheckboxChecked;
}

window.addEventListener('load', function () {
popupContainer.style.display = 'flex';
submitButton.disabled = true;
const checkboxes = document.querySelectorAll('.checkbox-input');
checkboxes.forEach((checkbox) => {
checkbox.addEventListener('change', updateRoles);
});
});

submitButton.addEventListener('click', hidePopup);
} else {
const popupContainer = document.querySelector('.roles-container');
popupContainer.style.display = 'none';
}
}

function userData() {
fetch(`${SELF_URL}`, {
headers: { 'content-type': 'application/json' },
credentials: 'include',
})
.then((res) => res.json())
.then((data) => {
popup(data);
})
.catch((err) => {
console.error(err);
});
shubhamsinghbundela marked this conversation as resolved.
Show resolved Hide resolved
}

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);

if (urlParams.get('dev') === 'true') {
userData();
}