fix: restore approveEditorialAction and fix AlbumGrid type signature
This commit is contained in:
1 parent
e555069ee1
commit
6e25739e6e
2 files changed
+97
-15
No files matched your search
@@ -3,6 +3,14 @@
|
||||
import { useState, useTransition } from "react";
|
||||
import Image from "next/image";
|
||||
|
||||
import type { AlbumActionResult } from "./actions";
|
||||
|
||||
type AlbumGridAction = (
|
||||
editorialId: string,
|
||||
_prevState: AlbumActionResult,
|
||||
formData: FormData,
|
||||
) => Promise<AlbumActionResult>;
|
||||
|
||||
type AlbumGridProps = {
|
||||
albums: Array<{
|
||||
id: string;
|
||||
@@ -12,8 +20,8 @@ type AlbumGridProps = {
|
||||
isGranted: boolean;
|
||||
}>;
|
||||
editorialId: string;
|
||||
grantAction: (editorialId: string, formData: FormData) => Promise<void>;
|
||||
revokeAction: (editorialId: string, formData: FormData) => Promise<void>;
|
||||
grantAction: AlbumGridAction;
|
||||
revokeAction: AlbumGridAction;
|
||||
};
|
||||
|
||||
function AlbumCard({
|
||||
@@ -24,17 +32,18 @@ function AlbumCard({
|
||||
}: {
|
||||
album: AlbumGridProps["albums"][0];
|
||||
editorialId: string;
|
||||
grantAction: AlbumGridProps["grantAction"];
|
||||
revokeAction: AlbumGridProps["revokeAction"];
|
||||
grantAction: AlbumGridAction;
|
||||
revokeAction: AlbumGridAction;
|
||||
}) {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const handleAction = (formData: FormData) => {
|
||||
startTransition(async () => {
|
||||
const initial: AlbumActionResult = { ok: true, message: "" };
|
||||
if (album.isGranted) {
|
||||
await revokeAction(editorialId, formData);
|
||||
await revokeAction(editorialId, initial, formData);
|
||||
} else {
|
||||
await grantAction(editorialId, formData);
|
||||
await grantAction(editorialId, initial, formData);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -83,7 +92,7 @@ export function AlbumGrid({ albums, editorialId, grantAction, revokeAction }: Al
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
const filteredAlbums = albums.filter((album) =>
|
||||
album.albumName.toLowerCase().includes(search.toLowerCase())
|
||||
album.albumName.toLowerCase().includes(search.toLowerCase()),
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -96,7 +105,7 @@ export function AlbumGrid({ albums, editorialId, grantAction, revokeAction }: Al
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
aria-label="Alben durchsuchen"
|
||||
/>
|
||||
|
||||
|
||||
{filteredAlbums.length === 0 ? (
|
||||
<p>Keine Alben gefunden.</p>
|
||||
) : (
|
||||
|
||||
Reference in new issue
Block a user