Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat: allow restarting an activity from a task; scope activity-type link check

Khuram Niaza13d73ec1945
diff --git a/__tests__/TaskForm.spec.tsx b/__tests__/TaskForm.spec.tsx
index b5a0a06..1ea2284 100644
--- a/__tests__/TaskForm.spec.tsx
+++ b/__tests__/TaskForm.spec.tsx
@@ -251,7 +251,7 @@ describe("TaskForm Component", () => {
createdAt: new Date(),
updatedAt: new Date(),
},
- activity: null,
+ activities: [],
createdAt: new Date(),
updatedAt: new Date(),
};
@@ -381,7 +381,7 @@ describe("TaskForm Component", () => {
dueDate: null,
activityTypeId: null,
activityType: null,
- activity: null,
+ activities: [],
createdAt: new Date(),
updatedAt: new Date(),
};
diff --git a/__tests__/TasksContainer.spec.tsx b/__tests__/TasksContainer.spec.tsx
index 1e54a42..137fb27 100644
--- a/__tests__/TasksContainer.spec.tsx
+++ b/__tests__/TasksContainer.spec.tsx
@@ -146,7 +146,7 @@ describe("TasksContainer Component", () => {
createdAt: new Date(),
updatedAt: new Date(),
},
- activity: null,
+ activities: [],
createdAt: new Date(),
updatedAt: new Date(),
},
@@ -167,7 +167,7 @@ describe("TasksContainer Component", () => {
createdAt: new Date(),
updatedAt: new Date(),
},
- activity: null,
+ activities: [],
createdAt: new Date(),
updatedAt: new Date(),
},
diff --git a/__tests__/task.actions.spec.ts b/__tests__/task.actions.spec.ts
index b25ca17..148b4be 100644
--- a/__tests__/task.actions.spec.ts
+++ b/__tests__/task.actions.spec.ts
@@ -58,7 +58,7 @@ describe("taskActions", () => {
label: "Development",
value: "development",
},
- activity: null,
+ activities: [],
};
beforeEach(() => {
@@ -84,7 +84,7 @@ describe("taskActions", () => {
where: { userId: mockUser.id },
include: {
activityType: true,
- activity: {
+ activities: {
select: { id: true },
},
},
@@ -115,7 +115,7 @@ describe("taskActions", () => {
where: { userId: mockUser.id },
include: {
activityType: true,
- activity: {
+ activities: {
select: { id: true },
},
},
@@ -146,7 +146,7 @@ describe("taskActions", () => {
},
include: {
activityType: true,
- activity: {
+ activities: {
select: { id: true },
},
},
@@ -180,7 +180,7 @@ describe("taskActions", () => {
},
include: {
activityType: true,
- activity: {
+ activities: {
select: { id: true },
},
},
@@ -234,7 +234,7 @@ describe("taskActions", () => {
},
include: {
activityType: true,
- activity: {
+ activities: {
select: { id: true },
},
},
@@ -527,7 +527,7 @@ describe("taskActions", () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
const taskWithActivity = {
...mockTask,
- activity: { id: "activity-id" },
+ activities: [{ id: "activity-id" }],
};
(prisma.task.findFirst as any).mockResolvedValue(taskWithActivity);
@@ -622,19 +622,30 @@ describe("taskActions", () => {
});
});
- it("should return error when task already has linked activity", async () => {
+ it("should link a new activity even when the task already has activities", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
- const taskWithActivity = {
- ...mockTask,
- activity: { id: "activity-id" },
- };
- (prisma.task.findFirst as any).mockResolvedValue(taskWithActivity);
+ (prisma.task.findFirst as any).mockResolvedValue(mockTask);
+ (prisma.activity.findFirst as any).mockResolvedValue(null);
+ (prisma.activity.create as any).mockResolvedValue(mockActivity);
const result = await startActivityFromTask("task-id");
expect(result).toEqual({
- success: false,
- message: "Task already has a linked activity.",
+ success: true,
+ data: mockActivity,
+ });
+ expect(prisma.activity.create).toHaveBeenCalledWith({
+ data: {
+ activityName: mockTask.title,
+ activityTypeId: mockTask.activityTypeId,
+ userId: mockUser.id,
+ startTime: expect.any(Date),
+ endTime: null,
+ taskId: mockTask.id,
+ },
+ include: {
+ activityType: true,
+ },
});
});
diff --git a/e2e/tasks.spec.ts b/e2e/tasks.spec.ts
index c101e5d..26cd963 100644
--- a/e2e/tasks.spec.ts
+++ b/e2e/tasks.spec.ts
@@ -270,7 +270,7 @@ test.describe("Tasks Management", () => {
await page.getByRole("button", { name: "Stop" }).click({ force: true });
});
- test("should not allow starting activity when task already has linked activity", async ({
+ test("should restart activity when task already has a linked activity", async ({
page,
cleanup,
}) => {
@@ -295,7 +295,7 @@ test.describe("Tasks Management", () => {
.click({ force: true });
await expect(page).toHaveURL(/\/dashboard\/activities/);
- // Stop the activity so we can test the linked state
+ // Stop the activity so we can test restarting from the task
await page.getByRole("button", { name: "Stop" }).click({ force: true });
// Go back to tasks
@@ -304,21 +304,20 @@ test.describe("Tasks Management", () => {
.getByRole("row", { name: new RegExp(linkedActivityTaskTitle, "i") })
.first();
- // Start activity button should not be visible (task has linked activity)
+ // Start activity button is still available even with a linked activity
await taskRowAfter.hover();
await expect(
taskRowAfter.getByTestId("task-start-activity-btn"),
- ).not.toBeVisible();
+ ).toBeVisible();
- // Menu item should be disabled
+ // Clicking it restarts the activity (redirects to activities page)
await taskRowAfter
- .getByTestId("task-actions-menu-btn")
+ .getByTestId("task-start-activity-btn")
.click({ force: true });
- const startActivityMenuItem = page.getByRole("menuitem", {
- name: "Start Activity",
- });
- await expect(startActivityMenuItem).toBeDisabled();
- await page.keyboard.press("Escape");
+ await expect(page).toHaveURL(/\/dashboard\/activities/);
+
+ // Stop the restarted activity to leave a clean state
+ await page.getByRole("button", { name: "Stop" }).click({ force: true });
});
test("should not allow starting activity on completed task", async ({
diff --git a/prisma/migrations/20260711003153_activity_task_one_to_many/migration.sql b/prisma/migrations/20260711003153_activity_task_one_to_many/migration.sql
new file mode 100644
index 0000000..c41004f
--- /dev/null
+++ b/prisma/migrations/20260711003153_activity_task_one_to_many/migration.sql
@@ -0,0 +1,2 @@
+-- DropIndex
+DROP INDEX "Activity_taskId_key";
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 1744d9f..147ef5a 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -361,7 +361,7 @@ model Activity {
activityType ActivityType @relation(fields: [activityTypeId], references: [id])
activityTypeId String
- taskId String? @unique
+ taskId String?
task Task? @relation(fields: [taskId], references: [id])
}
@@ -380,7 +380,7 @@ model Task {
activityTypeId String?
activityType ActivityType? @relation(fields: [activityTypeId], references: [id])
- activity Activity?
+ activities Activity[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
diff --git a/src/actions/activity.actions.ts b/src/actions/activity.actions.ts
index e026879..0454d0a 100644
--- a/src/actions/activity.actions.ts
+++ b/src/actions/activity.actions.ts
@@ -367,8 +367,8 @@ export const deleteActivityTypeById = async (
}
const [activities, tasks] = await Promise.all([
- prisma.activity.count({ where: { activityTypeId } }),
- prisma.task.count({ where: { activityTypeId } }),
+ prisma.activity.count({ where: { activityTypeId, userId: user.id } }),
+ prisma.task.count({ where: { activityTypeId, userId: user.id } }),
]);
if (activities > 0 || tasks > 0) {
diff --git a/src/actions/task.actions.ts b/src/actions/task.actions.ts
index 66156bb..00aa1a9 100644
--- a/src/actions/task.actions.ts
+++ b/src/actions/task.actions.ts
@@ -48,7 +48,7 @@ export const getTasksList = async (
where: whereClause,
include: {
activityType: true,
- activity: {
+ activities: {
select: { id: true },
},
},
@@ -89,7 +89,7 @@ export const getTaskById = async (
},
include: {
activityType: true,
- activity: {
+ activities: {
select: { id: true },
},
},
@@ -233,7 +233,9 @@ export const deleteTaskById = async (
userId: user.id,
},
include: {
- activity: true,
+ activities: {
+ select: { id: true },
+ },
},
});
@@ -241,7 +243,7 @@ export const deleteTaskById = async (
return { success: false, message: "Task not found" };
}
- if (task.activity) {
+ if (task.activities.length > 0) {
return {
success: false,
message:
@@ -278,19 +280,16 @@ export const startActivityFromTask = async (
id: taskId,
userId: user.id,
},
- include: {
- activity: true,
- },
});
if (!task) {
return { success: false, message: "Task not found" };
}
- if (task.activity) {
+ if (task.status === "complete" || task.status === "cancelled") {
return {
success: false,
- message: "Task already has a linked activity.",
+ message: "Cannot start an activity from a completed or cancelled task.",
};
}
@@ -301,13 +300,6 @@ export const startActivityFromTask = async (
};
}
- if (task.status === "complete" || task.status === "cancelled") {
- return {
- success: false,
- message: "Cannot start an activity from a completed or cancelled task.",
- };
- }
-
const runningActivity = await prisma.activity.findFirst({
where: {
userId: user.id,
@@ -323,6 +315,8 @@ export const startActivityFromTask = async (
};
}
+ // A task can have many activities over time; each start links a new one
+ // to the task so per-task time can be tracked.
const activity = await prisma.activity.create({
data: {
activityName: task.title,
diff --git a/src/components/tasks/TasksTable.tsx b/src/components/tasks/TasksTable.tsx
index 153b7e7..0ffde56 100644
--- a/src/components/tasks/TasksTable.tsx
+++ b/src/components/tasks/TasksTable.tsx
@@ -321,7 +321,6 @@ function TasksTable({
<DropdownMenuItem
className="cursor-pointer text-green-600"
onClick={() => onStartActivity(task.id)}
- disabled={!!task.activity}
>
<CirclePlay className="mr-2 h-4 w-4" />
Start Activity
@@ -339,21 +338,19 @@ function TasksTable({
</DropdownMenu>
</TableCell>
<TableCell className="hidden sm:table-cell py-1 px-1">
- {!task.activity && (
- <Button
- title="Start Activity"
- aria-haspopup="true"
- size="icon"
- variant="ghost"
- onClick={() => onStartActivity(task.id)}
- data-testid="task-start-activity-btn"
- className="opacity-0 group-hover:opacity-100 group-hover:pointer-events-auto transition-opacity duration-300"
- >
- <span>
- <CirclePlay className="text-green-600" />
- </span>
- </Button>
- )}
+ <Button
+ title="Start Activity"
+ aria-haspopup="true"
+ size="icon"
+ variant="ghost"
+ onClick={() => onStartActivity(task.id)}
+ data-testid="task-start-activity-btn"
+ className="opacity-0 group-hover:opacity-100 group-hover:pointer-events-auto transition-opacity duration-300"
+ >
+ <span>
+ <CirclePlay className="text-green-600" />
+ </span>
+ </Button>
</TableCell>
</TableRow>
);
diff --git a/src/models/task.model.ts b/src/models/task.model.ts
index 4908880..f31306f 100644
--- a/src/models/task.model.ts
+++ b/src/models/task.model.ts
@@ -20,7 +20,7 @@ export interface Task {
dueDate?: Date | null;
activityTypeId?: string | null;
activityType?: ActivityType | null;
- activity?: { id: string } | null;
+ activities?: { id: string }[];
createdAt: Date;
updatedAt: Date;
}