-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from STAPLE-verse/small-refactors
Small refactors
- Loading branch information
Showing
161 changed files
with
2,503 additions
and
2,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Routes } from "@blitzjs/next" | ||
import Link from "next/link" | ||
import { getPrivilegeText } from "src/core/utils/getPrivilegeText" | ||
import { MemberPrivileges, User } from "db" | ||
import Card from "src/core/components/Card" | ||
import DeleteContributor from "./DeleteContributor" | ||
|
||
interface ContributorInformationProps { | ||
contributorId: number | ||
projectId: number | ||
privilege: MemberPrivileges | ||
teamNames: (string | null)[] | ||
contributorPrivilege: MemberPrivileges | ||
contributorUser: User | ||
} | ||
|
||
const ContributorInformation = ({ | ||
contributorId, | ||
projectId, | ||
privilege, | ||
teamNames, | ||
contributorPrivilege, | ||
contributorUser, | ||
}: ContributorInformationProps) => { | ||
const contributorName = | ||
contributorUser.firstName && contributorUser.lastName | ||
? `${contributorUser.firstName} ${contributorUser.lastName}` | ||
: contributorUser.username | ||
|
||
return ( | ||
<Card | ||
title={contributorName} | ||
className="w-full" | ||
actions={ | ||
privilege === MemberPrivileges.PROJECT_MANAGER ? ( | ||
<div className="flex flex-row gap-2"> | ||
<Link | ||
href={Routes.EditContributorPage({ | ||
projectId: projectId, | ||
contributorId: contributorId, | ||
})} | ||
className="btn btn-primary" | ||
> | ||
Edit Contributor | ||
</Link> | ||
<DeleteContributor | ||
projectId={projectId} | ||
contributorUser={contributorUser} | ||
contributorId={0} | ||
/> | ||
</div> | ||
) : null | ||
} | ||
> | ||
{contributorUser.firstName && contributorUser.lastName && ( | ||
<p> | ||
<span className="font-semibold">Username:</span> {contributorUser.username} | ||
</p> | ||
)} | ||
<p> | ||
<span className="font-semibold">Email:</span> {contributorUser.email} | ||
</p> | ||
<p> | ||
<span className="font-semibold">Privilege:</span> {getPrivilegeText(contributorPrivilege)} | ||
</p> | ||
<p> | ||
<span className="font-semibold">Team Membership:</span>{" "} | ||
{teamNames.length > 0 ? teamNames.join(", ") : "No team memberships"} | ||
</p> | ||
</Card> | ||
) | ||
} | ||
|
||
export default ContributorInformation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { MemberPrivileges } from "db" | ||
import Link from "next/link" | ||
import { Routes } from "@blitzjs/next" | ||
import Card from "src/core/components/Card" | ||
import ProjectMemberRolesList from "src/projectmembers/components/ProjectMemberRolesList" | ||
import { ContributorRolesListColumns } from "../tables/columns/ContributorRolesListColumns" | ||
import { processContributorRolesList } from "../tables/processing/processContributorRolesList" | ||
|
||
interface ContributorRolesListProps { | ||
usersId: number[] | ||
projectId: number | ||
privilege: MemberPrivileges | ||
} | ||
|
||
export const ContributorRolesList = ({ | ||
usersId, | ||
projectId, | ||
privilege, | ||
}: ContributorRolesListProps) => ( | ||
<Card | ||
title={"Contributor Roles"} | ||
className="w-full" | ||
actions={ | ||
privilege === MemberPrivileges.PROJECT_MANAGER && ( | ||
<Link className="btn btn-primary" href={Routes.RolesPage({ projectId: projectId! })}> | ||
Edit Roles | ||
</Link> | ||
) | ||
} | ||
> | ||
<ProjectMemberRolesList | ||
usersId={usersId} | ||
projectId={projectId} | ||
tableColumns={ContributorRolesListColumns} | ||
dataProcessor={processContributorRolesList} | ||
/> | ||
</Card> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,38 @@ | ||
import { useQuery } from "@blitzjs/rpc" | ||
import Table from "src/core/components/Table" | ||
import getTasks from "src/tasks/queries/getTasks" | ||
import { ProjectMember, Task, TaskLog } from "db" | ||
import { FinishedTasksColumns } from "src/tasks/tables/columns/FinishedTasksColumns" | ||
import { processFinishedTasks } from "src/tasks/tables/processing/processFinishedTasks" | ||
import { MemberPrivileges } from "db" | ||
import ProjectMemberTaskListDone from "src/projectmembers/components/ProjectMemberTaskListDone" | ||
import Card from "src/core/components/Card" | ||
import Link from "next/link" | ||
import { Routes } from "@blitzjs/next" | ||
import { ContributorTaskListDoneColumns } from "../tables/columns/ContributorTaskListDoneColumns" | ||
import { processContributorTaskListDone } from "../tables/processing/processContributorTaskListDone" | ||
|
||
type TaskWithLogs = Task & { | ||
taskLogs: TaskLog[] | ||
assignedMembers: ProjectMember[] | ||
interface ContributorTaskListDoneProps { | ||
contributorId: number | ||
projectId: number | ||
privilege: MemberPrivileges | ||
} | ||
|
||
export const ContributorTaskListDone = ({ contributor }) => { | ||
const [{ tasks }] = useQuery(getTasks, { | ||
where: { | ||
assignedMembers: { | ||
some: { | ||
id: contributor.id, // Filter tasks assigned to this specific project member | ||
}, | ||
}, | ||
}, | ||
include: { | ||
taskLogs: { | ||
where: { | ||
assignedToId: contributor.id, // Ensure task logs are only for this project member | ||
}, | ||
orderBy: { createdAt: "desc" }, // Order by createdAt, descending | ||
}, | ||
assignedMembers: { | ||
include: { | ||
users: true, // Include user details for each assigned project member | ||
}, | ||
}, | ||
project: true, // Include project details if needed | ||
roles: true, // Include roles details if needed | ||
}, | ||
orderBy: { id: "asc" }, // Order tasks by ID | ||
}) as unknown as [{ tasks: TaskWithLogs[] }] | ||
|
||
const completedTasks = tasks.filter((task) => { | ||
const latestLog = task.taskLogs[0] // Since logs are ordered by createdAt desc, the first one is the latest | ||
return latestLog && latestLog.status === "COMPLETED" | ||
}) | ||
|
||
const processedTasks = processFinishedTasks(completedTasks) | ||
|
||
return ( | ||
<div> | ||
<Table columns={FinishedTasksColumns} data={processedTasks} addPagination={true} /> | ||
</div> | ||
) | ||
} | ||
export const ContributorTaskListDone = ({ | ||
contributorId, | ||
projectId, | ||
privilege, | ||
}: ContributorTaskListDoneProps) => ( | ||
<Card | ||
title="Contributor Tasks" | ||
className="w-full" | ||
tooltipContent="Only completed tasks are included" | ||
actions={ | ||
privilege === MemberPrivileges.PROJECT_MANAGER && ( | ||
<Link className="btn btn-primary" href={Routes.RolesPage({ projectId })}> | ||
Edit Roles | ||
</Link> | ||
) | ||
} | ||
> | ||
<ProjectMemberTaskListDone | ||
projectMemberId={contributorId} | ||
tableColumns={ContributorTaskListDoneColumns} | ||
dataProcessor={processContributorTaskListDone} | ||
/> | ||
</Card> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useRouter } from "next/router" | ||
import { useMutation } from "@blitzjs/rpc" | ||
import { Routes } from "@blitzjs/next" | ||
import toast from "react-hot-toast" | ||
import { useCurrentUser } from "src/users/hooks/useCurrentUser" | ||
import deleteContributor from "../mutations/deleteContributor" | ||
import { User } from "db" | ||
|
||
interface DeleteContributorProps { | ||
projectId: number | ||
contributorUser: User | ||
contributorId: number | ||
} | ||
|
||
const DeleteContributor = ({ | ||
projectId, | ||
contributorUser, | ||
contributorId, | ||
}: DeleteContributorProps) => { | ||
const [deleteContributorMutation] = useMutation(deleteContributor) | ||
const router = useRouter() | ||
|
||
const currentUser = useCurrentUser() | ||
|
||
const handleDelete = async () => { | ||
if ( | ||
window.confirm("This Contributor will be removed from the project. Are you sure to continue?") | ||
) { | ||
try { | ||
await deleteContributorMutation({ id: contributorId }) | ||
|
||
// Navigate based on whether the current user was deleted | ||
if (contributorUser.id === currentUser?.id) { | ||
await router.push(Routes.ProjectsPage()) | ||
} else { | ||
await router.push(Routes.ContributorsPage({ projectId })) | ||
} | ||
|
||
toast.success("Contributor successfully removed") | ||
} catch (error) { | ||
toast.error("Failed to delete contributor: " + error.message) | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<button className="btn btn-secondary" onClick={handleDelete}> | ||
Delete Contributor | ||
</button> | ||
) | ||
} | ||
|
||
export default DeleteContributor |
Oops, something went wrong.