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 2 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
98 changes: 98 additions & 0 deletions css/main.css
sahsisunny marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,100 @@ footer {
}
}

.roles-container {
display: none;
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: #fff;
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;
/* background-color: #f0f2f5; */
}

.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: 10px;
}

.role-button {
position: relative;
}

.role-button button {
padding: 0.75rem 2rem;
border-radius: 10px;
outline: none;
background-color: #008000;
color: #ffffff;
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 #f3f3f3;
border-top: 3px solid #1d1283;
border-radius: 50%;
animation: spin 1s linear infinite;
}

.role-button button:disabled {
background-color: #ccc;
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 +679,10 @@ footer {
.card {
padding: 20px 10px;
}
.role-details {
max-width: 100%;
border-radius: 0;
}
}

@media screen and (max-width: 800px) {
Expand Down
33 changes: 33 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,39 @@
</nav>

<main>
<div class="roles-container">
<div class="role-details">
<h2 class="role-heading">Select your role</h2>
<div class="role-details-field">
<label class="checkbox-label">
<input type="checkbox" name="developer" class="checkbox-input" />
Developer
sahsisunny marked this conversation as resolved.
Show resolved Hide resolved
</label>
<label class="checkbox-label">
<input type="checkbox" name="designer" class="checkbox-input" />
Designer
</label>
<label class="checkbox-label">
<input type="checkbox" name="maven" class="checkbox-input" />
Maven
</label>
<label class="checkbox-label">
<input
type="checkbox"
name="productmanager"
class="checkbox-input"
/>
Product Manager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with changes. can you please check latest commit message

</label>
</div>
<div class="role-button">
<button>
<span class="spinner"></span>
Submit
</button>
</div>
</div>
</div>
<h1 class="welcome-title">Welcome to Real Dev Squad</h1>
<img
class="hero-img"
Expand Down
8 changes: 8 additions & 0 deletions js/goto.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ function redirectUserToPage(page) {
function redirectionHandler(data) {
if (data.incompleteUserDetails) {
redirectUserToPage(SIGNUP_URL);
} else if (
data.incompleteUserDetails === false &&
sahsisunny marked this conversation as resolved.
Show resolved Hide resolved
data.roles.developer === undefined &&
data.roles.designer === undefined &&
data.roles.maven === undefined &&
data.roles.productmanager === undefined
) {
redirectUserToPage(HOME_URL);
} else if (hasVisitedJoin == 'true' || hasVisitedJoin == null) {
redirectUserToPage(`${HOME_URL}/join`);
} else {
Expand Down
93 changes: 93 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,96 @@ modalTriggers.forEach((trigger) => {
});
});
});

function popup(data) {
if (
sahsisunny marked this conversation as resolved.
Show resolved Hide resolved
data.incompleteUserDetails === false &&
data.roles.developer === undefined &&
data.roles.designer === undefined &&
data.roles.maven === undefined &&
data.roles.productmanager === undefined
) {
const popupContainer = document.querySelector('.roles-container');
const submitButton = document.querySelector('.role-button button');
const checkboxes = document.querySelectorAll('.checkbox-input');
const spinner = submitButton.querySelector('.spinner');
const roles = {};

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

function showPopup() {
popupContainer.style.display = 'flex';
}

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 {
//have to add toast here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

till then you can show some alert or something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with changes. can you please check latest commit message

//will work on next pr
sahsisunny 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 () {
showPopup();
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('https://api.realdevsquad.com/users/self', {
sahsisunny marked this conversation as resolved.
Show resolved Hide resolved
headers: { 'content-type': 'application/json' },
credentials: 'include',
})
.then((res) => res.json())
.then((data) => {
popup(data);
})
.catch((err) => {
console.error(err);
});
}
userData();