-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
174 additions
and
30 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
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
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,28 @@ | ||
import { screen } from "@testing-library/react"; | ||
import { beforeEach, describe, expect, test } from "vitest"; | ||
|
||
import { UserListRequestHandler } from "@kiesraad/api-mocks"; | ||
import { render, server } from "@kiesraad/test"; | ||
|
||
import { UserListPage } from "./UserListPage"; | ||
|
||
describe("PollingStationListPage", () => { | ||
beforeEach(() => { | ||
server.use(UserListRequestHandler); | ||
}); | ||
|
||
test("Show users", async () => { | ||
render(<UserListPage />); | ||
|
||
const table = await screen.findByRole("table"); | ||
expect(table).toBeVisible(); | ||
expect(table).toHaveTableContent([ | ||
["Gebruikersnaam", "Rol", "Volledige naam", "Laatste activiteit"], | ||
["Sanne", "Beheerder", "Sanne Molenaar", "vandaag 10:20"], | ||
["Jayden", "Coördinator", "Jayden Ahmen", "vandaag 13:37"], | ||
["Gebruiker01", "Invoerder", "Nog niet gebruikt", "–"], | ||
["Gebruiker02", "Invoerder", "Nog niet gebruikt", "–"], | ||
["Gebruiker03", "Invoerder", "Nog niet gebruikt", "–"], | ||
]); | ||
}); | ||
}); |
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,54 @@ | ||
import { useUserListRequest } from "app/module/users/useUserListRequest"; | ||
|
||
import { t } from "@kiesraad/i18n"; | ||
import { Loader, PageTitle, Table } from "@kiesraad/ui"; | ||
import { formatDateTime } from "@kiesraad/util"; | ||
|
||
export function UserListPage() { | ||
const { requestState } = useUserListRequest(); | ||
|
||
if (requestState.status === "loading") { | ||
return <Loader />; | ||
} | ||
|
||
if ("error" in requestState) { | ||
throw requestState.error; | ||
} | ||
|
||
const users = requestState.data.users; | ||
|
||
return ( | ||
<> | ||
<PageTitle title={`${t("user.management")} - Abacus`} /> | ||
<header> | ||
<section> | ||
<h1>{t("user.management")}</h1> | ||
</section> | ||
</header> | ||
<main> | ||
<article> | ||
<Table id="users"> | ||
<Table.Header> | ||
<Table.Column>{t("user.username")}</Table.Column> | ||
<Table.Column>{t("role")}</Table.Column> | ||
<Table.Column>{t("user.fullname")}</Table.Column> | ||
<Table.Column>{t("user.last_activity")}</Table.Column> | ||
</Table.Header> | ||
<Table.Body className="fs-md"> | ||
{users.map((user) => ( | ||
<Table.LinkRow key={user.id} to={`${user.id}/update`}> | ||
<Table.Cell>{user.username}</Table.Cell> | ||
<Table.Cell>{t(user.role)}</Table.Cell> | ||
<Table.Cell>{user.fullname ?? <span className="text-muted">{t("user.not_used")}</span>}</Table.Cell> | ||
<Table.Cell> | ||
{user.last_activity_at ? formatDateTime(new Date(user.last_activity_at)) : "–"} | ||
</Table.Cell> | ||
</Table.LinkRow> | ||
))} | ||
</Table.Body> | ||
</Table> | ||
</article> | ||
</main> | ||
</> | ||
); | ||
} |
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,18 +0,0 @@ | ||
import { t } from "@kiesraad/i18n"; | ||
import { PageTitle } from "@kiesraad/ui"; | ||
|
||
export function UsersHomePage() { | ||
return ( | ||
<> | ||
<PageTitle title={`${t("user.management")} - Abacus`} /> | ||
<header> | ||
<section> | ||
<h1>{t("user.manage")}</h1> | ||
</section> | ||
</header> | ||
<main> | ||
<article>Placeholder</article> | ||
</main> | ||
</> | ||
); | ||
} | ||
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 +1 @@ | ||
export * from "./UsersHomePage"; | ||
export * from "./UserListPage"; |
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,6 @@ | ||
import { useApiRequestWithErrors, USER_LIST_REQUEST_PATH, UserListResponse } from "@kiesraad/api"; | ||
|
||
export function useUserListRequest() { | ||
const path: USER_LIST_REQUEST_PATH = `/api/user`; | ||
return useApiRequestWithErrors<UserListResponse>(path); | ||
} |
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
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,52 @@ | ||
import { ListedUser } from "@kiesraad/api"; | ||
|
||
const today = new Date(); | ||
today.setHours(10, 20); | ||
|
||
const laterToday = new Date(); | ||
laterToday.setHours(13, 37); | ||
|
||
const created_at = new Date().toISOString(); | ||
const updated_at = new Date().toISOString(); | ||
|
||
export const userMockData: ListedUser[] = [ | ||
{ | ||
id: 1, | ||
username: "Sanne", | ||
role: "administrator", | ||
fullname: "Sanne Molenaar", | ||
last_activity_at: today.toISOString(), | ||
created_at, | ||
updated_at, | ||
}, | ||
{ | ||
id: 2, | ||
username: "Jayden", | ||
role: "coordinator", | ||
fullname: "Jayden Ahmen", | ||
last_activity_at: laterToday.toISOString(), | ||
created_at, | ||
updated_at, | ||
}, | ||
{ | ||
id: 3, | ||
username: "Gebruiker01", | ||
role: "typist", | ||
created_at, | ||
updated_at, | ||
}, | ||
{ | ||
id: 4, | ||
username: "Gebruiker02", | ||
role: "typist", | ||
created_at, | ||
updated_at, | ||
}, | ||
{ | ||
id: 5, | ||
username: "Gebruiker03", | ||
role: "typist", | ||
created_at, | ||
updated_at, | ||
}, | ||
]; |
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
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