Skip to content

Commit

Permalink
feat(web/activity): Basic page
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Nov 5, 2023
1 parent f0236f6 commit 22efb9c
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 1 deletion.
65 changes: 65 additions & 0 deletions frontend/web/app/dashboard/activity/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"use client";

import { useTranslation } from "react-i18next";

import { useEffect, useState } from "react";
import DashboardPageWrapper from "@/layouts/dashboard/DashboardPageWrapper";
import { Activity } from "@/types/activity";
import services from "@/services";

const ActivityPage = () => {
const { t } = useTranslation();
const [page, setPage] = useState(0);
const [activities, setActivities] = useState<Activity[]>([]);

useEffect(() => {
(async () => {
const fetchedActivities = await services.workflows.getActivities(page);
setActivities(fetchedActivities.data ?? []);
})();
}, [page]);

return (
<DashboardPageWrapper title={t("activity.title")}>
<table className="table">
<thead className="text-neutral-content">
<tr>
<th>Time</th>
<th>Workflow</th>
<th>Activity</th>
</tr>
</thead>
<tbody>
{activities.map((activity) => (
<tr key={activity.id}>
<td>{activity.createdAt}</td>
<td>{activity.workflow.name}</td>
<td>{activity.type}</td>
</tr>
))}
</tbody>
</table>
<div className="flex justify-around items-center mt-10">
<button
className="btn btn-accent"
onClick={() => {
if (page > 0) setPage((prev) => prev - 1);
}}
>
{t("editor.back")}
</button>
<span>Page {page + 1}</span>
<button
className="btn btn-accent"
onClick={() => {
if (activities.length >= 20) setPage((prev) => prev + 1);
}}
>
{t("editor.next")}
</button>
</div>
</DashboardPageWrapper>
);
};

export default ActivityPage;
2 changes: 1 addition & 1 deletion frontend/web/layouts/library/LibraryWorkflowTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const LibraryWorkflowTable = () => {
<table className="table">
<thead className="text-neutral-content">
<tr>
<th className="table-cell " colSpan={2}>
<th className="table-cell" colSpan={2}>
<div className="flex">
<label className="custom-checkbox">
<input
Expand Down
3 changes: 3 additions & 0 deletions frontend/web/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const translations = {
reactions: "Reactions",
noArea: "This service doesn't have any action or reaction",
},
activity: {
title: "Activity",
},
landing: {
actions: {
downloadApk: " Download APK",
Expand Down
3 changes: 3 additions & 0 deletions frontend/web/locales/fr-FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ const translations = {
reactions: "Réactions",
noArea: "Ce service n'a pas d'action ou de réaction",
},
activity: {
title: "Activité",
},
landing: {
actions: {
downloadApk: " Télécharger l'APK",
Expand Down
3 changes: 3 additions & 0 deletions frontend/web/locales/is-IS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const translations = {
reactions: "Viðbrögð",
noArea: "Þessi þjónusta hefur engar aðgerðir eða viðbrögð",
},
activity: {
title: "Virkni",
},
landing: {
actions: {
downloadApk: " Sækja APK",
Expand Down
15 changes: 15 additions & 0 deletions frontend/web/services/workflows/activity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ServiceReturn } from "@/types/api";
import { axiosInstance } from "@/services";
import { SERVICE_ERROR_UNKNOWN } from "@/config/services";
import { Activity } from "@/types/activity";

const getActivities = async (page: number): Promise<ServiceReturn<Activity[]>> => {
try {
const response = await axiosInstance.get<Activity[]>(`/activity?page=${page}&itemsPerPage=20`);
return { data: response.data, error: undefined };
} catch (error) {
return { data: null, error: SERVICE_ERROR_UNKNOWN };
}
};

export default getActivities;
2 changes: 2 additions & 0 deletions frontend/web/services/workflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { deleteBulk, deleteOne } from "@/services/workflows/delete";
import { toggleBulk, toggleOne } from "@/services/workflows/update";
import { create, rename, update } from "@/services/workflows/editor";
import { getAll, getOne } from "@/services/workflows/get";
import getActivities from "@/services/workflows/activity";

const workflowsService = {
toggleOne,
Expand All @@ -13,6 +14,7 @@ const workflowsService = {
rename,
getOne,
getAll,
getActivities,
};

export default workflowsService;
16 changes: 16 additions & 0 deletions frontend/web/types/activity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type Activity = {
id: string;
type: string;
createdAt: string;
workflowArea: {
id: string;
area: {
id: string;
serviceId: string;
};
};
workflow: {
id: string;
name: string;
};
};

0 comments on commit 22efb9c

Please sign in to comment.