This commit is contained in:
Harini312821
2024-08-02 08:32:30 +08:00

View File

@@ -123,10 +123,19 @@ export default function CommunityPostManagement() {
} }
}; };
// Function to safely render item values
const renderCellValue = (item: any, columnKey: any) => {
const value = getKeyValue(item, columnKey);
if (typeof value === "object" && value !== null) {
return JSON.stringify(value); // Convert object to string
}
return value;
};
return ( return (
<div> <div>
{mergedList.length > 0 && ( {mergedList.length > 0 && (
<div className="flex flex-col gap-8 p-8"> <div className="flex flex-col p-8">
<p className="text-4xl font-bold">Community Post</p> <p className="text-4xl font-bold">Community Post</p>
<Table aria-label="User Information Table"> <Table aria-label="User Information Table">
<TableHeader columns={columns}> <TableHeader columns={columns}>
@@ -137,51 +146,63 @@ export default function CommunityPostManagement() {
<TableBody items={mergedList}> <TableBody items={mergedList}>
{(item) => ( {(item) => (
<TableRow key={item.postId}> <TableRow key={item.postId}>
{(columnKey) => ( {(columnKey) => {
<TableCell> const value = renderCellValue(item, columnKey);
{columnKey === "profilePicture" ? (
item.profilePicture ? ( return (
<Avatar <TableCell>
src={item.profilePicture} {columnKey === "profilePicture" ? (
alt="Profile" item.profilePicture ? (
size="lg" <Avatar
/> src={item.profilePicture}
alt="Profile"
size="lg"
/>
) : (
"No Image"
)
) : columnKey === "postImage" ? (
value ? (
<img src={`${config.serverAddress}/post/post-image/${item.postId}`}
className="w-[150px] h-auto rounded-lg object-cover"/>
) : (
"No Image"
)
) : columnKey === "actions" ? (
<div className="flex gap-2">
<Tooltip content="Copy ID">
<Button
variant="light"
isIconOnly
onClick={() =>
handleCopyID(item.postId, item.title)
}
aria-label="Copy postId, title"
>
<ClipboardDocumentIcon />
</Button>
</Tooltip>
<Tooltip content="Delete">
<Button
variant="light"
isIconOnly
aria-label="Delete-Post"
className="text-red-500"
onClick={() => handleDeleteClick(item)}
>
<TrashDeleteIcon />
</Button>
</Tooltip>
</div>
) : ( ) : (
"No Image" <p>
) {value}
) : columnKey === "actions" ? ( </p>
<div className="flex gap-2"> )}
<Tooltip content="Copy ID">
<Button </TableCell>
variant="light" );
isIconOnly }}
onClick={() =>
handleCopyID(item.postId, item.title)
}
aria-label="Copy postId, title"
>
<ClipboardDocumentIcon />
</Button>
</Tooltip>
<Tooltip content="Delete">
<Button
variant="light"
isIconOnly
aria-label="Delete-Post"
className="text-red-500"
onClick={() => handleDeleteClick(item)}
>
<TrashDeleteIcon />
</Button>
</Tooltip>
</div>
) : (
<p className={item.isArchived ? "opacity-50" : ""}>
{getKeyValue(item, columnKey)}
</p>
)}
</TableCell>
)}
</TableRow> </TableRow>
)} )}
</TableBody> </TableBody>