Skip to content

Commit

Permalink
feat(web): Dashboard (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola authored Nov 5, 2023
1 parent 65f8f3d commit e4fec1e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
39 changes: 38 additions & 1 deletion frontend/web/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,49 @@

import { useTranslation } from "react-i18next";

import { useEffect, useState } from "react";
import DashboardPageWrapper from "@/layouts/dashboard/DashboardPageWrapper";
import { UserStats } from "@/services/user/me";
import services from "@/services";

const DashboardPage = () => {
const [stats, setStats] = useState<UserStats | null>(null);
const { t } = useTranslation();

return <DashboardPageWrapper title={t("dashboard.title")} />;
useEffect(() => {
(async () => {
const response = await services.user.getStats();
setStats(response.data ?? null);
})();
}, []);

return (
<DashboardPageWrapper title={t("dashboard.title")}>
{stats && (
<div className="stats shadow bg-primary w-full">
<div className="stat place-items-center">
<div className="stat-title">{t("landing.workflows")}</div>
<div className="stat-value text-secondary">{stats.workflows}</div>
</div>

<div className="stat place-items-center bg-primary">
<div className="stat-title">{t("landing.active")}</div>
<div className="stat-value text-secondary">{stats.activeWorkflows}</div>
</div>

<div className="stat place-items-center bg-primary">
<div className="stat-title">{t("landing.errors")}</div>
<div className="stat-value text-secondary">{stats.workflowErrors}</div>
</div>

<div className="stat place-items-center bg-primary">
<div className="stat-title">{t("landing.runs")}</div>
<div className="stat-value text-secondary">{stats.workflowRuns}</div>
</div>
</div>
)}
</DashboardPageWrapper>
);
};

export default DashboardPage;
4 changes: 4 additions & 0 deletions frontend/web/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const translations = {
actions: {
downloadApk: " Download APK",
},
workflows: "Workflows",
active: "Active workflows",
errors: "Workflow errors",
runs: "Workflow runs",
},
actions: {
rename: "Rename",
Expand Down
4 changes: 4 additions & 0 deletions frontend/web/locales/fr-FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ const translations = {
actions: {
downloadApk: " Télécharger l'APK",
},
workflows: "Workflows",
active: "Workflows actifs",
errors: "Erreurs des workflows",
runs: "Workflow lancés",
},
actions: {
rename: "Renommer",
Expand Down
4 changes: 4 additions & 0 deletions frontend/web/locales/is-IS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const translations = {
actions: {
downloadApk: " Sækja APK",
},
workflows: "Verkflæði",
active: "Virk vinnuflæði",
errors: "Verkflæðisvillur",
runs: "Verkflæði sett af stað",
},
actions: {
rename: "Endurnefna",
Expand Down
3 changes: 2 additions & 1 deletion frontend/web/services/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getProfile, updateProfile } from "@/services/user/me";
import { getProfile, getStats, updateProfile } from "@/services/user/me";

const userService = {
getProfile,
updateProfile,
getStats,
};

export default userService;
17 changes: 16 additions & 1 deletion frontend/web/services/user/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ const updateProfile = async (data: UserProfileUpdate): Promise<ServiceReturn<voi
}
};

export { getProfile, updateProfile };
export type UserStats = {
workflowRuns: number;
workflowErrors: number;
workflows: number;
activeWorkflows: number;
};
const getStats = async (): Promise<ServiceReturn<UserStats>> => {
try {
const response = await axiosInstance.get<UserStats>(`/workflows/summary`);
return { data: response.data, error: undefined };
} catch (error) {
return { data: null, error: SERVICE_ERROR_UNKNOWN };
}
};

export { getProfile, updateProfile, getStats };

0 comments on commit e4fec1e

Please sign in to comment.