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

Chore: Profile summary, integrate backend API #826

Merged
merged 4 commits into from
Jul 4, 2024
Merged
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
186 changes: 64 additions & 122 deletions src/components/ProfileAnalyticsCard/index.js
Original file line number Diff line number Diff line change
@@ -1,140 +1,82 @@
import React from "react";
import { PieChart, Pie, Cell } from "recharts";
// import moment from "moment";
import styles from "./ProfileAnalyticsCard.module.css";
// import PrimaryButton from "../PrimaryButton";

const COLORS = ["#8884d8", "#82ca9d", "#ffc658"];

const ProfileAnalytics = ({ user }) => {
const data1 = [
{ name: "Apps", value: user.apps },
{ name: "Projects", value: user.projects },
{ name: "Databases", value: user.databases },
const ProfileAnalytics = (UserProfile) => {
const userSummary = UserProfile.user;

const resources = [
{ name: "Apps", value: userSummary?.apps_count },
{ name: "Projects", value: userSummary?.projects_count },
];

const data2 = [
{ name: "Following Projects", value: user.followingProjects },
{ name: "Followers", value: user.followers },
const projects = [
{ name: "Following Projects", value: userSummary?.followed_projects_count },
{ name: "Projects' Followers", value: userSummary?.projects_followers_count },
];

const data3 = [
{ name: "Follows", value: 1 },
{ name: "Followers", value: 7 },
const social = [
{ name: "Follows", value: userSummary?.follower_count },
{ name: "Followers", value: userSummary?.following_count },
];


const renderPieChart = (data, title, label, userCounts) => {
const allZero = data.every(entry => entry.value === 0);

return (
<div className={styles.Chart}>
<div className={styles.SingleChart}>
<h4>{title}</h4>
<PieChart width={200} height={200}>
<Pie
data={allZero ? [{ name: "No Data", value: 1 }] : data}
cx={100}
cy={100}
innerRadius={60}
outerRadius={80}
fill={allZero ? "red" : "#82ca9d"}
paddingAngle={5}
dataKey="value"
>
{data.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={allZero ? "red" : COLORS[index % COLORS.length]}
/>
))}
</Pie>
</PieChart>
<div className={styles.ChartLabel}>{label}</div>
<div className={styles.AdminProfileRowInfo}>
{userCounts.map((count, index) => (
<div className={styles.AdminProfileRowItem} key={index}>
{count.label}: <span>{count.value}</span>
</div>
))}
</div>
</div>
</div>
);
};

return (
<section className="AdminCardArea">
<div className="AdminUserProfileCard">
<div className={styles.ChartsContainer}>
<div className={styles.Chart}>
<div className={styles.SingleChart}>
<h4>Resources</h4>
<PieChart width={200} height={200}>
<Pie
data={data1}
cx={100}
cy={100}
innerRadius={60}
outerRadius={80}
fill="#8884d8"
paddingAngle={5}
dataKey="value"
>
{data1.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={COLORS[index % COLORS.length]}
/>
))}
</Pie>
</PieChart>
<div className={styles.ChartLabel}>Apps/Projects/Databases</div>
<div className={styles.AdminProfileRowInfo}>
<div className={styles.AdminProfileRowItem}>
Apps: <span>{user.apps}</span>
</div>
<div className={styles.AdminProfileRowItem}>
Projects: <span>{user.projects}</span>
</div>
<div className={styles.AdminProfileRowItem}>
Databases: <span>{user.databases}</span>
</div>
</div>
</div>
</div>
<div className={styles.Chart}>
<div className={styles.SingleChart}>
<h4>Projects</h4>
<PieChart width={200} height={200}>
<Pie
data={data2}
cx={100}
cy={100}
innerRadius={60}
outerRadius={80}
fill="#82ca9d"
paddingAngle={5}
dataKey="value"
>
{data2.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={COLORS[index % COLORS.length]}
/>
))}
</Pie>
</PieChart>
<div className={styles.ChartLabel}>
Projects (Following/Followers)
</div>
<div className={styles.AdminProfileRowInfo}>
<div className={styles.AdminProfileRowItem}>
Follows: <span>{user.followingProjects}</span>
</div>
<div className={styles.AdminProfileRowItem}>
Followers: <span>{user.followers}</span>
</div>
</div>
</div>
</div>

<div className={styles.Chart}>
<div className={styles.SingleChart}>
<h4>Users</h4>
<PieChart width={200} height={200}>
<Pie
data={data3}
cx={100}
cy={100}
innerRadius={60}
outerRadius={80}
fill="#82ca9d"
paddingAngle={5}
dataKey="value"
>
{data3.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={COLORS[index % COLORS.length]}
// Tooltip={entry}
/>
))}
</Pie>
</PieChart>
<div className={styles.ChartLabel}>
Users (Followed/Followers)
</div>
<div className={styles.AdminProfileRowInfo}>
<div className={styles.AdminProfileRowItem}>
Follows: <span>1</span>
</div>
<div className={styles.AdminProfileRowItem}>
Followers: <span>7</span>
</div>
</div>
</div>
</div>
{renderPieChart(resources, "Resources", "Apps/Projects", [
{ label: "Apps", value: userSummary?.apps_count },
{ label: "Projects", value: userSummary?.projects_count },
])}
{renderPieChart(projects, "Projects", "Projects (Following/Followers)", [
{ label: "Following Projects", value: userSummary?.followed_projects_count },
{ label: "Projects' Followers", value: userSummary?.projects_followers_count },
])}
{renderPieChart(social, "Users", "Users (Followed/Followers)", [
{ label: "Follows", value: userSummary?.follower_count },
{ label: "Followers", value: userSummary?.following_count },
])}
</div>
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
.noActivityMessage {
font-size: 18px;
color: #555;
}
}
1 change: 0 additions & 1 deletion src/components/RecentActivitySection/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const RecentActivitySection = () => {
userRecentActivities();
};

console.log(recentActivities);

return (
<div className={styles.recentActivity}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
gap: 4em;
padding: 0.3rem 0.3rem 0.4rem 0;
}
.noInformation {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 20rem;
text-align: center;
}

@media only screen and (max-width: 700px) {
.ProfileCard {
Expand Down
4 changes: 2 additions & 2 deletions src/components/SmallerProfileCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const ProfileCardSmall = ({ user, loading, error, onFollowClick, userFollowLoadi
return (
<div className={styles.ProfileCard}>
{loading ? (
<div className="AdminNoResourcesMessage">
<div className={styles.noInformation}>
<Spinner />
</div>
) : null}
{error ? (
<div className="AdminNoResourcesMessage">
<div className={styles.noInformation}>
No user information returned.
</div>
) : null}
Expand Down
29 changes: 18 additions & 11 deletions src/components/UserProfileActivitiesComponent/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// Activities.jsx
import React from 'react';
import Select from '../Select';
import React from "react";
import Select from "../Select";
import { ReactComponent as UpdateIcon } from "../../assets/images/upload-cloud.svg";
import { ReactComponent as CreateIcon } from "../../assets/images/check-circle.svg";
import styles from "../../pages/UsersProfile/UserProfile.module.css";
import PrimaryButton from "../../components/PrimaryButton";

const UserFeedActivities = ({ activities, yearOptions, selectedYear, expanded, toggleExpand }) => {
const UserFeedActivities = ({ activities, yearOptions, selectedYear, expanded, toggleExpand, pagination, fetchMoreActivities }) => {
if (!activities) {
return null;
}

const showMore = pagination.page < pagination.pages;

return (
<section className="">
<div className={styles.ActivitiesHeader}>
Expand All @@ -20,7 +25,7 @@ const UserFeedActivities = ({ activities, yearOptions, selectedYear, expanded, t
</div>
</div>
<div className={styles.ActivitiesContainer}>
{activities.slice(0, 2).map((activity) => (
{activities && activities.slice(0, pagination.per_page).map((activity) => (
<div key={activity.id} className={styles.ActivityMonth}>
<div className={styles.ActivityMonthTitle}>{activity.month}</div>
{activity.activities.map((act, index) => (
Expand All @@ -30,14 +35,14 @@ const UserFeedActivities = ({ activities, yearOptions, selectedYear, expanded, t
onClick={() => toggleExpand(activity.id)}
>
<span className={styles.ActivityType}>
{act.type === `Updated` ? <UpdateIcon /> : <CreateIcon />}
{act.type === "Updated" ? <UpdateIcon /> : <CreateIcon />}
</span>
<span className={styles.ActivityDescription}>
{act.description}
</span>
<span
className={`${styles.ActivityExpandIcon} ${
expanded[activity.id] ? `${styles.expanded}` : ''
expanded[activity.id] ? `${styles.expanded}` : ""
}`}
>
&#9650;
Expand All @@ -52,7 +57,7 @@ const UserFeedActivities = ({ activities, yearOptions, selectedYear, expanded, t
</span>
{project.apps > 0 && (
<span className={styles.ProjectApps}>
{project.apps} {project.apps > 1 ? 'apps' : 'app'}
{project.apps} {project.apps > 1 ? "apps" : "app"}
</span>
)}
</div>
Expand All @@ -63,9 +68,11 @@ const UserFeedActivities = ({ activities, yearOptions, selectedYear, expanded, t
))}
</div>
))}
<PrimaryButton className={styles.ShowMoreButton}>
Show More Activity
</PrimaryButton>
{showMore && (
<PrimaryButton className={styles.ShowMoreButton} onClick={fetchMoreActivities}>
Show More Activity
</PrimaryButton>
)}
</div>
</section>
);
Expand Down
Loading
Loading