Merge pull request 'vaibhav_dashboard_feature' (#7) from vaibhav_dashboard_feature into Feature_Task_Management
Reviewed-on: #7
This commit is contained in:
commit
2b24351316
@ -6,19 +6,9 @@ const HorizontalBarChart = ({
|
||||
seriesData = [],
|
||||
categories = [],
|
||||
colors = [
|
||||
"#1E90FF", // Dodger Blue - Primary
|
||||
"#00BFFF", // Deep Sky Blue - Info
|
||||
"#9370DB", // Medium Purple - Success (replacing Lime Green)
|
||||
"#6A0DAD", // Amethyst Purple - On Route (replacing Forest Green)
|
||||
"#A9A9A9", // Dark Gray - Neutral
|
||||
"#6A5ACD", // Slate Blue - Secondary
|
||||
"#FFA500", // Orange - Warning
|
||||
"#FF4500", // Orange Red - Danger
|
||||
"#20B2AA", // Light Sea Green - Late
|
||||
"#708090", // Slate Gray - Muted
|
||||
"#1E90FF", "#00BFFF", "#9370DB", "#6A0DAD", "#A9A9A9",
|
||||
"#6A5ACD", "#FFA500", "#FF4500", "#20B2AA", "#708090",
|
||||
],
|
||||
|
||||
|
||||
}) => {
|
||||
// Guard clause for invalid or incomplete data
|
||||
const hasValidData =
|
||||
@ -31,25 +21,34 @@ const HorizontalBarChart = ({
|
||||
return <div className="text-center text-gray-500">No data to display</div>;
|
||||
}
|
||||
|
||||
const chartOptions = {
|
||||
// Combine seriesData and categories, then sort in descending order
|
||||
const combined = seriesData.map((value, index) => ({
|
||||
value,
|
||||
label: categories[index],
|
||||
}));
|
||||
const sorted = combined.sort((a, b) => b.value - a.value);
|
||||
|
||||
// Extract sorted values
|
||||
const sortedSeriesData = sorted.map(item => item.value);
|
||||
const sortedCategories = sorted.map(item => item.label);
|
||||
|
||||
// Replace 0 with 1 for visual purposes, but display "0%" in labels
|
||||
const adjustedSeriesData = sortedSeriesData.map(val => (val === 0 ? 1 : val));
|
||||
|
||||
const chartOptions = {
|
||||
chart: {
|
||||
type: "bar",
|
||||
height: 380,
|
||||
toolbar: {
|
||||
show: false, // This removes the menu
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
show: false
|
||||
toolbar: { show: false },
|
||||
},
|
||||
grid: { show: false },
|
||||
plotOptions: {
|
||||
bar: {
|
||||
barHeight: "60%",
|
||||
distributed: true,
|
||||
horizontal: true,
|
||||
dataLabels: {
|
||||
position: "center",
|
||||
position: "start",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -58,49 +57,33 @@ const HorizontalBarChart = ({
|
||||
enabled: true,
|
||||
textAnchor: "start",
|
||||
style: {
|
||||
colors: ["#000"], // Switch to black for better visibility
|
||||
colors: ["#000"], // Black labels
|
||||
},
|
||||
formatter: function (val, opt) {
|
||||
return `${opt.w.globals.labels[opt.dataPointIndex]}: ${val}`;
|
||||
},
|
||||
offsetX: 10, // Push label slightly to the right
|
||||
dropShadow: {
|
||||
enabled: false,
|
||||
formatter: function (_, opt) {
|
||||
const originalVal = sortedSeriesData[opt.dataPointIndex]; // Show real value
|
||||
return `${originalVal}%`;
|
||||
},
|
||||
offsetX: 10,
|
||||
dropShadow: { enabled: false },
|
||||
},
|
||||
|
||||
stroke: {
|
||||
width: 1,
|
||||
colors: ["#fff"],
|
||||
},
|
||||
xaxis: {
|
||||
categories,
|
||||
axisBorder: {
|
||||
show: false,
|
||||
},
|
||||
axisTicks: {
|
||||
show: false,
|
||||
},
|
||||
labels: {
|
||||
show: false,
|
||||
},
|
||||
categories: sortedCategories,
|
||||
axisBorder: { show: false },
|
||||
axisTicks: { show: false },
|
||||
labels: { show: false },
|
||||
},
|
||||
yaxis: {
|
||||
labels: {
|
||||
show: false,
|
||||
},
|
||||
axisBorder: {
|
||||
show: false,
|
||||
},
|
||||
axisTicks: {
|
||||
show: false,
|
||||
},
|
||||
labels: { show: false },
|
||||
axisBorder: { show: false },
|
||||
axisTicks: { show: false },
|
||||
},
|
||||
tooltip: {
|
||||
theme: "dark",
|
||||
x: {
|
||||
show: false,
|
||||
},
|
||||
x: { show: true },
|
||||
y: {
|
||||
title: {
|
||||
formatter: () => "",
|
||||
@ -113,7 +96,7 @@ const HorizontalBarChart = ({
|
||||
<div className="w-full">
|
||||
<ReactApexChart
|
||||
options={chartOptions}
|
||||
series={[{ data: seriesData }]}
|
||||
series={[{ data: adjustedSeriesData }]}
|
||||
type="bar"
|
||||
height={380}
|
||||
/>
|
||||
|
@ -31,7 +31,7 @@ const LineChart = ({
|
||||
},
|
||||
stroke: {
|
||||
curve: 'straight',
|
||||
width: 2
|
||||
width: 2
|
||||
},
|
||||
grid: {
|
||||
show: false,
|
||||
@ -55,11 +55,18 @@ const LineChart = ({
|
||||
},
|
||||
xaxis: {
|
||||
categories,
|
||||
labels: { show: false },
|
||||
labels: {
|
||||
show: true,
|
||||
rotate: -45,
|
||||
style: {
|
||||
fontSize: '12px'
|
||||
}
|
||||
},
|
||||
axisBorder: { show: false },
|
||||
axisTicks: { show: false },
|
||||
tooltip: { enabled: false }
|
||||
},
|
||||
|
||||
yaxis: {
|
||||
labels: { show: false },
|
||||
axisBorder: { show: false },
|
||||
|
@ -1,25 +1,57 @@
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import HorizontalBarChart from '../Charts/HorizontalBarChart';
|
||||
import LineChart from '../Charts/LineChart';
|
||||
const dummyCategories = ['Project 1', 'Project 2', 'Project 3', 'Project 4', 'Project 5'];
|
||||
const dummyData = [45, 38, 30, 25, 20];
|
||||
|
||||
const lineChartseries = [
|
||||
{
|
||||
name: "Planned Projects",
|
||||
data: [20, 25, 30, 35, 40, 45, 50]
|
||||
},
|
||||
{
|
||||
name: "Completed Projects",
|
||||
data: [5, 15, 28, 36, 42, 46, 48]
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
const lineChartCategories = ["January", "February", "March", "April", "May", "June", "July"];
|
||||
|
||||
import { useProjects } from '../../hooks/useProjects';
|
||||
import {
|
||||
useDashboard_Data,
|
||||
useDashboardProjectsCardData,
|
||||
useDashboardTeamsCardData,
|
||||
useDashboardTasksCardData,
|
||||
} from "../../hooks/useDashboard_Data";
|
||||
|
||||
const Dashboard = () => {
|
||||
const { projects } = useProjects();
|
||||
const [selectedProjectId, setSelectedProjectId] = useState('all');
|
||||
const [FromDate, setFromDate] = useState(() => {
|
||||
const today = new Date();
|
||||
return today.toISOString().split('T')[0]; // YYYY-MM-DD
|
||||
});
|
||||
const [days, setDays] = useState(10);
|
||||
const { projectsCardData, } = useDashboardProjectsCardData();
|
||||
const { teamsCardData,} = useDashboardTeamsCardData();
|
||||
const { tasksCardData, } = useDashboardTasksCardData();
|
||||
|
||||
const { dashboard_data, loading: lineLoading } = useDashboard_Data({
|
||||
days,
|
||||
FromDate,
|
||||
projectId: selectedProjectId === 'all' ? 0 : selectedProjectId,
|
||||
});
|
||||
|
||||
// Bar chart logic
|
||||
const projectNames = projects?.map(p => p.name) || [];
|
||||
const projectProgress = projects?.map(p => {
|
||||
const completed = p.completedWork || 0;
|
||||
const planned = p.plannedWork || 1;
|
||||
const percent = (completed / planned) * 100;
|
||||
return Math.min(Math.round(percent), 100);
|
||||
}) || [];
|
||||
|
||||
// Line chart data
|
||||
const lineChartSeries = [
|
||||
{
|
||||
name: 'Planned Work',
|
||||
data: dashboard_data.map(d => d.plannedWork || 0),
|
||||
},
|
||||
{
|
||||
name: 'Completed Work',
|
||||
data: dashboard_data.map(d => d.completedWork || 0),
|
||||
},
|
||||
];
|
||||
|
||||
const lineChartCategories = dashboard_data.map(d =>
|
||||
new Date(d.date).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="container-xxl flex-grow-1 container-p-y">
|
||||
<div className="row gy-4">
|
||||
@ -28,15 +60,15 @@ const Dashboard = () => {
|
||||
<div className="col-sm-6 col-lg-4">
|
||||
<div className="card p-3 h-100 text-center d-flex justify-content-between">
|
||||
<div className="d-flex justify-content-start align-items-center mb-3">
|
||||
<h5 class="fw-bold mb-0 ms-2"><i class="rounded-circle bx bx-building-house" ></i> Projects</h5>
|
||||
<h5 className="fw-bold mb-0 ms-2"><i className="rounded-circle bx bx-building-house"></i> Projects</h5>
|
||||
</div>
|
||||
<div className="d-flex justify-content-around align-items-start mt-n2">
|
||||
<div>
|
||||
<h4 className="mb-0 fw-bold">25</h4>
|
||||
<h4 className="mb-0 fw-bold">{projectsCardData.totalProjects?.toLocaleString()}</h4>
|
||||
<small className="text-muted">Total</small>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="mb-0 fw-bold">30</h4>
|
||||
<h4 className="mb-0 fw-bold">{projectsCardData.ongoingProjects?.toLocaleString()}</h4>
|
||||
<small className="text-muted">Ongoing</small>
|
||||
</div>
|
||||
</div>
|
||||
@ -47,15 +79,15 @@ const Dashboard = () => {
|
||||
<div className="col-sm-6 col-lg-4">
|
||||
<div className="card p-3 h-100 text-center d-flex justify-content-between">
|
||||
<div className="d-flex justify-content-start align-items-center mb-3">
|
||||
<h5 class="fw-bold mb-0 ms-2"><i className="bx bx-group text-warning" ></i> Teams</h5>
|
||||
<h5 className="fw-bold mb-0 ms-2"><i className="bx bx-group text-warning"></i> Teams</h5>
|
||||
</div>
|
||||
<div className="d-flex justify-content-around align-items-start mt-n2">
|
||||
<div>
|
||||
<h4 className="mb-0 fw-bold">500</h4>
|
||||
<h4 className="mb-0 fw-bold">{teamsCardData.totalEmployees?.toLocaleString()}</h4>
|
||||
<small className="text-muted">Total Employees</small>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="mb-0 fw-bold">360</h4>
|
||||
<h4 className="mb-0 fw-bold">{teamsCardData.inToday?.toLocaleString()}</h4>
|
||||
<small className="text-muted">In Today</small>
|
||||
</div>
|
||||
</div>
|
||||
@ -66,66 +98,106 @@ const Dashboard = () => {
|
||||
<div className="col-sm-6 col-lg-4">
|
||||
<div className="card p-3 h-100 text-center d-flex justify-content-between">
|
||||
<div className="d-flex justify-content-start align-items-center mb-3">
|
||||
<h5 class="fw-bold mb-0 ms-2"><i className="bx bx-task text-success" ></i> Tasks</h5>
|
||||
<h5 className="fw-bold mb-0 ms-2"><i className="bx bx-task text-success"></i> Tasks</h5>
|
||||
</div>
|
||||
<div className="d-flex justify-content-around align-items-start mt-n2">
|
||||
<div>
|
||||
<h4 className="mb-0 fw-bold">10,000</h4>
|
||||
<h4 className="mb-0 fw-bold">{tasksCardData.totalTasks?.toLocaleString()}</h4>
|
||||
<small className="text-muted">Total</small>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="mb-0 fw-bold">4,000</h4>
|
||||
<h4 className="mb-0 fw-bold">{tasksCardData.completedTasks?.toLocaleString()}</h4>
|
||||
<small className="text-muted">Completed</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* Chart Section */}
|
||||
<div class="col-xxl-6 col-lg-7">
|
||||
<div class="card h-100">
|
||||
<div class="card-header d-flex align-items-start justify-content-between">
|
||||
<div class="card-title mb-0">
|
||||
<h5 class="mb-1">Projects </h5>
|
||||
<p class="card-subtitle">Total Projects Overview</p>
|
||||
|
||||
{/* Bar Chart */}
|
||||
<div className="col-xxl-6 col-lg-6">
|
||||
<div className="card h-100">
|
||||
<div className="card-header d-flex align-items-start justify-content-between">
|
||||
<div className="card-title mb-0 text-start">
|
||||
<h5 className="mb-1">Projects</h5>
|
||||
<p className="card-subtitle">Total Projects Overview</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div className="card-body">
|
||||
<HorizontalBarChart
|
||||
categories={dummyCategories}
|
||||
seriesData={dummyData}
|
||||
categories={projectNames}
|
||||
seriesData={projectProgress}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xxl-6 col-lg-7">
|
||||
<div class="card h-100">
|
||||
<div class="card-header d-flex align-items-center justify-content-between">
|
||||
<div class="card-title mb-0">
|
||||
<h5 class="mb-1">Project Progress</h5>
|
||||
<p class="card-subtitle">Progress Overview by Project</p>
|
||||
|
||||
{/* Line Chart */}
|
||||
<div className="col-xxl-6 col-lg-6">
|
||||
<div className="card h-100">
|
||||
<div className="card-header d-flex flex-wrap align-items-center justify-content-between">
|
||||
<div className="card-title mb-0 text-start">
|
||||
<h5 className="mb-1">Project Progress</h5>
|
||||
<p className="card-subtitle">Progress Overview by Project</p>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-label-primary">Project A</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-label-primary dropdown-toggle dropdown-toggle-split"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-expanded="false">
|
||||
<span class="visually-hidden">Toggle Dropdown</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="javascript:void(0);">Project A</a></li>
|
||||
<li><a class="dropdown-item" href="javascript:void(0);">Project B</a></li>
|
||||
<li><a class="dropdown-item" href="javascript:void(0);">Project C</a></li>
|
||||
<li><a class="dropdown-item" href="javascript:void(0);">Project D</a></li>
|
||||
</ul>
|
||||
<div className="d-flex flex-wrap gap-2 align-items-center">
|
||||
{/* Project Dropdown */}
|
||||
<div className="btn-group">
|
||||
<button type="button" className="btn btn-label-primary">
|
||||
{selectedProjectId === 'all'
|
||||
? 'All Projects'
|
||||
: projects?.find(p => p.id === selectedProjectId)?.name || 'Select Project'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-label-primary dropdown-toggle dropdown-toggle-split"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-expanded="false"
|
||||
>
|
||||
<span className="visually-hidden">Toggle Dropdown</span>
|
||||
</button>
|
||||
<ul className="dropdown-menu">
|
||||
<li>
|
||||
<button className="dropdown-item" onClick={() => setSelectedProjectId('all')}>
|
||||
All Projects
|
||||
</button>
|
||||
</li>
|
||||
{projects?.map((project) => (
|
||||
<li key={project.id}>
|
||||
<button className="dropdown-item" onClick={() => setSelectedProjectId(project.id)}>
|
||||
{project.name}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* From Date */}
|
||||
<input
|
||||
type="date"
|
||||
className="form-control"
|
||||
value={FromDate}
|
||||
onChange={(e) => setFromDate(e.target.value)}
|
||||
style={{ maxWidth: '150px' }}
|
||||
/>
|
||||
|
||||
{/* Days */}
|
||||
<input
|
||||
type="number"
|
||||
className="form-control"
|
||||
value={days}
|
||||
min={1}
|
||||
onChange={(e) => setDays(Number(e.target.value))}
|
||||
style={{ maxWidth: '100px' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<LineChart seriesData={lineChartseries} categories={lineChartCategories} />
|
||||
<div className="card-body ">
|
||||
<LineChart seriesData={lineChartSeries} categories={lineChartCategories} />
|
||||
{lineLoading && <p className="text-center mt-3">Loading...</p>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
122
src/hooks/useDashboard_Data.jsx
Normal file
122
src/hooks/useDashboard_Data.jsx
Normal file
@ -0,0 +1,122 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import GlobalRepository from "../repositories/GlobalRepository";
|
||||
|
||||
// 🔹 Dashboard Progression Data Hook
|
||||
export const useDashboard_Data = ({ days, FromDate, projectId }) => {
|
||||
const [dashboard_data, setDashboard_Data] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
if (!days) return;
|
||||
|
||||
const fetchData = async () => {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
|
||||
try {
|
||||
const payload = {
|
||||
days,
|
||||
FromDate: FromDate || '',
|
||||
projectId: projectId || 0,
|
||||
};
|
||||
|
||||
const response = await GlobalRepository.getDashboardProgressionData(payload);
|
||||
setDashboard_Data(response.data);
|
||||
} catch (err) {
|
||||
setError("Failed to fetch dashboard data.");
|
||||
console.error(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchData();
|
||||
}, [days, FromDate, projectId]);
|
||||
|
||||
return { dashboard_data, loading, error };
|
||||
};
|
||||
|
||||
// 🔹 Dashboard Projects Card Data Hook
|
||||
export const useDashboardProjectsCardData = () => {
|
||||
const [projectsCardData, setProjectsData] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
const fetchProjectsData = async () => {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
|
||||
try {
|
||||
const response = await GlobalRepository.getDashboardProjectsCardData();
|
||||
setProjectsData(response.data);
|
||||
} catch (err) {
|
||||
setError("Failed to fetch projects card data.");
|
||||
console.error(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchProjectsData();
|
||||
}, []);
|
||||
|
||||
return { projectsCardData, loading, error };
|
||||
};
|
||||
|
||||
// 🔹 Dashboard Teams Card Data Hook
|
||||
export const useDashboardTeamsCardData = () => {
|
||||
const [teamsCardData, setTeamsData] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
const fetchTeamsData = async () => {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
|
||||
try {
|
||||
const response = await GlobalRepository.getDashboardTeamsCardData();
|
||||
setTeamsData(response.data);
|
||||
} catch (err) {
|
||||
setError("Failed to fetch teams card data.");
|
||||
console.error(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchTeamsData();
|
||||
}, []);
|
||||
|
||||
return { teamsCardData, loading, error };
|
||||
};
|
||||
|
||||
// 🔹 Dashboard Tasks Card Data Hook
|
||||
export const useDashboardTasksCardData = () => {
|
||||
const [tasksCardData, setTasksData] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
const fetchTasksData = async () => {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
|
||||
try {
|
||||
const response = await GlobalRepository.getDashboardTasksCardData();
|
||||
setTasksData(response.data);
|
||||
} catch (err) {
|
||||
setError("Failed to fetch tasks card data.");
|
||||
console.error(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchTasksData();
|
||||
}, []);
|
||||
|
||||
return { tasksCardData, loading, error };
|
||||
};
|
25
src/repositories/GlobalRepository.jsx
Normal file
25
src/repositories/GlobalRepository.jsx
Normal file
@ -0,0 +1,25 @@
|
||||
import { api } from "../utils/axiosClient";
|
||||
|
||||
const GlobalRepository = {
|
||||
getDashboardProgressionData: ({ days = '', FromDate = '', projectId = '' }) => {
|
||||
const params = new URLSearchParams({
|
||||
days: days.toString(),
|
||||
FromDate,
|
||||
projectId,
|
||||
});
|
||||
|
||||
return api.get(`/api/Dashboard/Progression?${params.toString()}`);
|
||||
},
|
||||
getDashboardProjectsCardData: () => {
|
||||
return api.get(`/api/Dashboard/projects`);
|
||||
},
|
||||
getDashboardTeamsCardData: () => {
|
||||
return api.get(`/api/Dashboard/teams`);
|
||||
},
|
||||
getDashboardTasksCardData: () => {
|
||||
return api.get(`/api/Dashboard/tasks`);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
export default GlobalRepository;
|
Loading…
x
Reference in New Issue
Block a user