diff --git a/src/app/test_data.json b/src/app/test_data.json index 4c3f53e..ab82c88 100644 --- a/src/app/test_data.json +++ b/src/app/test_data.json @@ -9,7 +9,7 @@ "description": "This is the first project.", "createdAt": "2023-05-01T10:00:00.000Z", "lastUpdatedAt": "2024-06-30T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "todo", "priority": "high", "tasks": [ @@ -53,7 +53,7 @@ "description": "This is the second project.", "createdAt": "2023-06-01T10:00:00.000Z", "lastUpdatedAt": "2024-06-30T12:00:00.000Z", - "deletedAt": "2024-06-30T12:00:00.000Z", + "archivedAt": "2024-06-30T12:00:00.000Z", "status": "in progress", "priority": "low", "tasks": [ @@ -97,7 +97,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -141,7 +141,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -185,7 +185,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -229,7 +229,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -273,7 +273,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -317,7 +317,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -361,7 +361,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -405,7 +405,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -449,7 +449,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -493,7 +493,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -537,7 +537,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -581,7 +581,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -625,7 +625,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -669,7 +669,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -713,7 +713,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -757,7 +757,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -801,7 +801,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -845,7 +845,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -889,7 +889,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -933,7 +933,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ @@ -977,7 +977,7 @@ "description": "This is the third project.", "createdAt": "2023-07-01T10:00:00.000Z", "lastUpdatedAt": "2024-07-01T12:00:00.000Z", - "deletedAt": null, + "archivedAt": null, "status": "backlog", "priority": "low", "tasks": [ diff --git a/src/components/projects/columns.tsx b/src/components/projects/columns.tsx index dc20770..b897dee 100644 --- a/src/components/projects/columns.tsx +++ b/src/components/projects/columns.tsx @@ -78,10 +78,10 @@ export const columnsXl: ColumnDef[] = [ }, }, { - accessorKey: "deletedAt", - header: ({ column }) => , + accessorKey: "archivedAt", + header: ({ column }) => , cell: ({ row }) => { - const dateValue = row.getValue("deletedAt"); + const dateValue = row.getValue("archivedAt"); const dateString = String(dateValue); const parsedDate = Date.parse(dateString); let formattedDate = ""; diff --git a/src/components/projects/data-table.tsx b/src/components/projects/data-table.tsx index a67ca76..70935b1 100644 --- a/src/components/projects/data-table.tsx +++ b/src/components/projects/data-table.tsx @@ -78,7 +78,7 @@ export function DataTable({ function handleRowClick(id: number): void { if (clickableRows) { - router.push(`/project/${id}`); + router.push(`/projects/${id}`); } } diff --git a/src/models/project.ts b/src/models/project.ts index 5984de8..93d5966 100644 --- a/src/models/project.ts +++ b/src/models/project.ts @@ -20,7 +20,7 @@ export default interface Project { description?: string; createdAt?: Date; lastUpdatedAt?: Date; - deletedAt?: Date | null; + archivedAt?: Date | null; status: Status; priority: Priority; diff --git a/src/pages/projects/[id].tsx b/src/pages/projects/[id].tsx index 6910979..80b2960 100644 --- a/src/pages/projects/[id].tsx +++ b/src/pages/projects/[id].tsx @@ -13,6 +13,7 @@ import { Search, Users, ChevronLeft, + Archive, } from "lucide-react"; // import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; @@ -40,6 +41,8 @@ import { import StatusIconLabel from "@/components/projects/status"; import PriorityIconLabel from "@/components/projects/priority"; import { calcPriorityComparison, calcStatusComparison } from "@/utils/projectUtils"; +import { format } from "date-fns"; +import { saveData } from "@/utils/save"; export default function Project() { const { user, setUser } = useUser(); @@ -48,10 +51,25 @@ export default function Project() { const project = user?.projects.find((project) => project.id === router.query.id); + // unarchive project function + const unarchiveProject = () => { + if (user && project) { + project.archivedAt = null; + const updatedProjects = user.projects.map((proj) => + proj.id === project.id ? project : proj + ); + const updatedUser = { ...user, projects: updatedProjects }; + setUser(updatedUser); + saveData(updatedUser); + } + }; + if (!project) { return
Project not found
; } + const gridColsClass = project.archivedAt ? "xl:grid-cols-5" : "xl:grid-cols-4"; + return (
@@ -71,33 +89,118 @@ export default function Project() { + {project.archivedAt && ( + +
+ + Archived +
+
+ )}
- - - + {!project.archivedAt && ( + + + + )} + {project.archivedAt && ( + + )}
-
+
- Total Revenue + Creation -
$45,231.89
-

+20.1% from last month

+
+ {!isNaN(Date.parse(String(project.createdAt))) + ? format(Date.parse(String(project.createdAt)), "MMMM dd, yyyy") + : "N/A"} +
+

+ {user && + user?.projects.filter( + (proj) => + proj.createdAt && + Date.parse(String(proj.createdAt)) < + Date.parse(String(project.createdAt)) + ).length + + " project" + + (user?.projects.filter( + (proj) => + proj.createdAt && + Date.parse(String(proj.createdAt)) < + Date.parse(String(project.createdAt)) + ).length > 1 + ? "s" + : "") + + " created before this one."} +

- Subscriptions + Last Update -
+2350
-

+180.1% from last month

+
+ {!isNaN(Date.parse(String(project.lastUpdatedAt))) + ? format( + Date.parse(String(project.lastUpdatedAt)), + "MMMM dd, yyyy" + ) + : "N/A"} +
+

+ {( + (new Date(project.lastUpdatedAt).getTime() - + new Date(project.createdAt).getTime()) / + (1000 * 60 * 60 * 24) + ).toFixed(0) + " days after creation"} +

+ {project.archivedAt && ( + + + Deletion + + + +
+ {!isNaN(Date.parse(String(project.archivedAt))) + ? format( + Date.parse(String(project.archivedAt)), + "MMMM dd, yyyy" + ) + : "N/A"} +
+

+ {user && + "One of " + + user?.projects.filter((proj) => proj.archivedAt) + .length + + " archived project" + + (user?.projects.filter((proj) => proj.archivedAt) + .length > 1 + ? "s" + : "") + + "."} +

+
+
+ )} Status @@ -131,13 +234,11 @@ export default function Project() {
- Transactions - - Recent transactions from your store. - + Tasks + Recent tasks for this project.
@@ -205,6 +227,33 @@ export default function EditProduct() {
+ + + Archive Project + + +
+
+

+ The archive is a place where no properties can be + edited any more. You can still view the project and + unarchive it again, but it will be locked. Archived + projects will not be visible in the projects list. +

+ +
+
+
+
diff --git a/src/utils/projectUtils.ts b/src/utils/projectUtils.ts index 01b0fb1..50a167e 100644 --- a/src/utils/projectUtils.ts +++ b/src/utils/projectUtils.ts @@ -6,11 +6,6 @@ export function calcPriorityComparison(user: User | null | undefined, priority: } const projects = user.projects || []; - const currentProject = projects.find((proj) => proj.priority === priority); - - if (!currentProject) { - return ""; - } const higherPriorityCount = projects.filter((proj) => { return proj.priority === "high"; @@ -24,6 +19,8 @@ export function calcPriorityComparison(user: User | null | undefined, priority: return proj.priority === "low"; }).length; + console.log(higherPriorityCount, mediumPriorityCount, lowerPriorityCount); + if (priority === "high") { return `Higher priority than ${lowerPriorityCount + mediumPriorityCount} other projects`; } else if (priority === "medium") { diff --git a/src/utils/taskUtils.ts b/src/utils/taskUtils.ts new file mode 100644 index 0000000..8b5ec82 --- /dev/null +++ b/src/utils/taskUtils.ts @@ -0,0 +1 @@ +import { User } from "@/models";