Skip to content

Commit

Permalink
populate de asset
Browse files Browse the repository at this point in the history
  • Loading branch information
mpvaldez committed Aug 14, 2024
1 parent a1a1b95 commit 443faa8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
35 changes: 22 additions & 13 deletions src/components/admin/asset/asset-card.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
'use client'
import React, { useState } from "react";
import {
Card,
CardContent,
Expand All @@ -11,21 +12,21 @@ import { fontAwesomeIcons, showCardOptions } from "@/lib/utils/constants";
import { Button } from "@/components/ui/button";

const AssetCard = async ({ asset }) => {
const [showMore, setShowMore] = useState(false)
const extraFields = await getExtraFieldsByCategory(asset.category);
const renderFieldShowCard = () => {
return (
<>
<span>
{extraFields.map((field) => {
if (field.showCard === showCardOptions.ALLWAYS.value) {
return (
<span key={field._id}>
<span className="font-bold">{field.name}</span>:
{asset.extras[field.slug]}
<span key={field._id} className="ml-3">
<span className="font-bold">{field.name}</span>: {asset.extras[field.slug]}
</span>
);
}
})}
</>
</span>
);
};
return (
Expand All @@ -44,14 +45,22 @@ const AssetCard = async ({ asset }) => {
</div>
<div>
<CardHeader>
<CardDescription>
#{asset.subCategory?.name},{renderFieldShowCard()}
</CardDescription>
<CardContent>
<div><span className="font-bold">{asset.category.name}:</span> {asset.subCategory?.name} {renderFieldShowCard()}</div>
<div className="mt-2">
{asset.confiscated && <span className="bg-gray-200 rounded-lg p-2 font-sm">Decomisado</span>}
{asset.destination && <span className="bg-red-300 rounded-lg p-2 font-sm ml-2">{asset.destination}</span>}
</div>

<div className={`${!showMore && "hidden" }`}>
<hr />
Hola!
</div>
</CardContent>
</CardHeader>
<CardContent></CardContent>
<CardFooter>
<Button variant="link">Ver menos</Button>
</CardFooter>
{/* <CardFooter>
<Button onClick={() => setShowMore(!showMore)} variant="link">{showMore?"Ver menos":"Ver más"}</Button>
</CardFooter> */}
</div>
</Card>
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/server-actions/admin/asset-actions/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const saveAsset = async (formData) => {

export async function getAssets() {
await isAuthotized()
const assets = await Asset.find({}).populate('subCategory')
const assets = await Asset.find({}).populate('category').populate('subCategory')
return JSON.parse(JSON.stringify(assets))

}

0 comments on commit 443faa8

Please sign in to comment.