Skip to content

Commit

Permalink
Merge pull request #42 from maykinmedia/feature/destruction-list-crea…
Browse files Browse the repository at this point in the history
…te-submit

✨ Allow submitting selection to the create destruction list endpoint
  • Loading branch information
svenvandescheur authored May 17, 2024
2 parents 13b7339 + f114921 commit 1840d9b
Show file tree
Hide file tree
Showing 5 changed files with 687 additions and 534 deletions.
2 changes: 2 additions & 0 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "./index.css";
import {
DestructionListCreatePage,
LoginPage,
destructionListCreateAction,
destructionListCreateLoader,
landingLoader,
loginAction,
Expand All @@ -26,6 +27,7 @@ const router = createBrowserRouter([
{
path: "/destruction-lists/create",
element: <DestructionListCreatePage />,
action: destructionListCreateAction,
loader: destructionListCreateLoader,
},
{
Expand Down
48 changes: 47 additions & 1 deletion frontend/src/lib/api/destructionLists.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { isPrimitive } from "@maykin-ui/admin-ui";

import { Zaak } from "../../types";
import { request } from "./request";
import { User } from "./reviewers";

export type DestructionList = {
// TODO
name: string;
assignees: DestructionListAssignee[];
items: DestructionListItem[];
};

export type DestructionListAssignee = {
user: User["pk"];
};

export type DestructionListItem = {
zaak: Zaak["url"];
};

/**
Expand All @@ -12,3 +26,35 @@ export async function listDestructionLists() {
const promise: Promise<DestructionList[]> = response.json();
return promise;
}

/**
* Create a new destruction list.
* @param name
* @param zaken
* @param assignees
*/
export async function createDestructionList(
name: string,
zaken: string[] | Zaak[],
assignees: string[] | number[] | User[],
) {
const urls = zaken.map((zaak) => (isPrimitive(zaak) ? zaak : zaak.url));
const assigneeIds = assignees.map((assignee) =>
isPrimitive(assignee) ? assignee.toString() : assignee.pk.toString(),
);

const destructionList = {
name,
assignees: assigneeIds.map((id) => ({ user: id })),
items: urls.map((url) => ({ zaak: url })),
};

const response = await request(
"POST",
"/destruction-lists/",
{},
destructionList,
);
const promise: Promise<DestructionList> = response.json();
return promise;
}
12 changes: 12 additions & 0 deletions frontend/src/lib/zaakSelection/zaakSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ export async function setZaakSelection(
sessionStorage.setItem(computedKey, json);
}

/**
* Clears zaak selection cache.
* Note: only the `url` of selected `zaken` are stored.
* Note: This function is async to accommodate possible future refactors.
* @param key A key identifying the selection
*/
export async function clearZaakSelection(key: string) {
const computedKey = _getComputedKey(key);
const json = "{}";
sessionStorage.setItem(computedKey, json);
}

/**
* Returns whether zaak is selected.
* @param key A key identifying the selection
Expand Down
Loading

0 comments on commit 1840d9b

Please sign in to comment.