Skip to content
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
72 changes: 72 additions & 0 deletions src/components/EditSavedDependenciesBanner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';

const EditSavedDependenciesBanner = ({ onClose, id }) => (
<Fragment>
<style jsx>
{`
.bannerWrapper {
display: flex;
color: #fff;
font-size: 14px;
background-color: #5c48e0;
height: 80px;
justify-content: center;
align-items: baseline;
padding: 5px;
margin-bottom: 20px;
border-radius: 15px;
}
.bannerContent {
display: flex;
flex-direction: column;
justify-conent: center;
align-items: center;
}
.viewButton {
padding: 4px 8px;
background: #fff;
color: #5c48e0;
border-radius: 3px;
text-decoration: none;
}
.closeSign {
position: relative;
left: 18%;
}
.closeSign button {
outline: none;
border: none;
background: none;
color: #fff;
font-size: 14px;
cursor: pointer;
}
`}
</style>
<div className="bannerWrapper">
<div className="bannerContent">
<p>
You already have some saved dependencies you want to dipatch to, will
you like to edit them?
</p>
<a
href={`/monthly-plan?id=${id}&type=profile&editSavedDependencies=true`}
className="viewButton"
>
Edit
</a>
</div>
<div className="closeSign">
<button onClick={onClose}>X</button>
</div>
</div>
</Fragment>
);

EditSavedDependenciesBanner.propTypes = {
onClose: PropTypes.func.isRequired,
id: PropTypes.string.isRequired,
};

export default EditSavedDependenciesBanner;
8 changes: 7 additions & 1 deletion src/components/MessageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const MessageBox = ({ type, message, onClose }) => {
.error {
background: red;
}
.success {
background: green;
}
p {
font-size: 16px;
margin: 0;
Expand All @@ -38,7 +41,10 @@ const MessageBox = ({ type, message, onClose }) => {
`}
</style>
<div
className={classnames('messageBoxWrapper', { error: type === 'error' })}
className={classnames('messageBoxWrapper', {
error: type === 'error',
success: type === 'success',
})}
>
<div className="message">
<p>{message}</p>
Expand Down
30 changes: 29 additions & 1 deletion src/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import fetch from 'cross-fetch';

import { getFile, getFiles, getObjectsMetadata } from './s3';

import { fetchWithOctokit, fetchProfile, fetchReposForProfile } from './github';
import {
fetchWithOctokit,
fetchProfile,
fetchReposForProfile,
fetchOrgMembership,
} from './github';

import { fetchAccountWithOrders, fetchOrder } from './opencollective';

Expand Down Expand Up @@ -33,6 +38,29 @@ export function searchUsers(q, accessToken) {
export async function getProfileData(id, accessToken, options = {}) {
const profile = await fetchProfile(id, accessToken);

if (
profile.type === 'Organization' &&
accessToken &&
options.loggedInUsername
) {
const membership = await fetchOrgMembership(
profile.login,
options.loggedInUsername,
accessToken,
);

// Check if the user is an admin of the organization.
profile.isAdmin =
membership.state === 'active' && membership.role === 'admin';
} else if (
accessToken &&
options.loggedInUsername &&
options.loggedInUsername === profile.login
) {
// If the loggedInUser owns the profile
profile.isAdmin = true;
}

const slug = githubToOpenCollectiveMapping[profile.login] || profile.login;
const opencollectiveAccount = await fetchAccountWithOrders(slug);

Expand Down
Loading