Skip to content

Commit

Permalink
add unarchived
Browse files Browse the repository at this point in the history
  • Loading branch information
xtian7489 committed Oct 24, 2024
1 parent 43f0e31 commit 9582777
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/app/api/_lib/controllers/assetsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ export const archive = async function (req, res) {
try {
const assetId = req.params.assetId;
const now = new Date()
const asset = await Asset.findByIdAndUpdate(assetId, { archivedAt: now })
const asset = await Asset.findById(assetId)
if (asset.archivedAt) {
asset.set({ archivedAt: null })
} else {
asset.set({ archivedAt: now })
}
await asset.save()

return res.status(200).json(asset);
} catch (error) {
console.error(error);
Expand Down
8 changes: 5 additions & 3 deletions src/components/admin/asset/asset-card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@/components/ui/card";
import { fontAwesomeIcons, showCardOptions } from "@/lib/utils/constants";
import { Button, buttonVariants } from "@/components/ui/button";
import { Pencil, Archive } from "lucide-react";
import { Pencil, Archive, ArchiveX } from "lucide-react";
import Link from "next/link";
import { archiveAsset } from "@/lib/actions/admin/asset-actions/asset";
import { useToast } from "@/components/ui/use-toast";
Expand Down Expand Up @@ -135,7 +135,9 @@ const AssetCard = ({ asset }) => {
<Button
onClick={() =>
toast({
description: "Confirmar para archivar el bien",
description: `Confirmar para ${
pathname.includes("archivados") ? "des" : ""
}archivar el bien`,
action: (
<ToastAction
onClick={() => archiveAsset(asset._id)}
Expand All @@ -148,7 +150,7 @@ const AssetCard = ({ asset }) => {
}
variant="ghost"
>
<Archive />
{pathname.includes("archivados") ? <ArchiveX /> : <Archive />}
</Button>
</div>
</CardHeader>
Expand Down

0 comments on commit 9582777

Please sign in to comment.