Finished editing links

This commit is contained in:
Isaac Wise
2024-02-10 16:23:59 -06:00
parent e1ef638f0e
commit 080be856cc
8 changed files with 61 additions and 119 deletions
-22
View File
@@ -1,22 +0,0 @@
import type { NextApiRequest, NextApiResponse } from "next";
import verifyUser from "@/lib/api/verifyUser";
import deleteLinksById from "@/lib/api/controllers/links/bulk/deleteLinksById";
import updateLinksById from "@/lib/api/controllers/links/bulk/updateLinks";
export default async function links(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
if (!user) return;
if (req.method === "PUT") {
const updated = await updateLinksById(user.id, req.body.linkIds, req.body.data);
return res.status(updated.status).json({
response: updated.response,
});
}
else if (req.method === "DELETE") {
const deleted = await deleteLinksById(user.id, req.body.linkIds);
return res.status(deleted.status).json({
response: deleted.response,
});
}
}
+2 -1
View File
@@ -5,6 +5,7 @@ import { LinkRequestQuery } from "@/types/global";
import verifyUser from "@/lib/api/verifyUser";
import deleteLinksById from "@/lib/api/controllers/links/bulk/deleteLinksById";
import updateLinksById from "@/lib/api/controllers/links/bulk/updateLinks";
import updateLinks from "@/lib/api/controllers/links/bulk/updateLinks";
export default async function links(req: NextApiRequest, res: NextApiResponse) {
const user = await verifyUser({ req, res });
@@ -42,7 +43,7 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
response: newlink.response,
});
} else if (req.method === "PUT") {
const updated = await updateLinksById(user.id, req.body.linkIds, req.body.data);
const updated = await updateLinks(user.id, req.body.links, req.body.newData);
return res.status(updated.status).json({
response: updated.response,
});
+7 -1
View File
@@ -27,6 +27,7 @@ import { dropdownTriggerer } from "@/lib/client/utils";
import NewCollectionModal from "@/components/ModalContent/NewCollectionModal";
import BulkDeleteLinksModal from "@/components/ModalContent/BulkDeleteLinksModal";
import toast from "react-hot-toast";
import BulkEditLinksModal from "@/components/ModalContent/BulkEditLinksModal";
export default function Index() {
const { settings } = useLocalSettingsStore();
@@ -94,6 +95,8 @@ export default function Index() {
useState(false);
const [deleteCollectionModal, setDeleteCollectionModal] = useState(false);
const [bulkDeleteLinksModal, setBulkDeleteLinksModal] = useState(false);
const [bulkEditLinksModal, setBulkEditLinksModal] = useState(false);
const [viewMode, setViewMode] = useState<string>(
localStorage.getItem("viewMode") || ViewMode.Card
@@ -319,7 +322,7 @@ export default function Index() {
</div>
<div className="flex gap-3">
{selectedLinks.length > 0 && (permissions === true || permissions?.canUpdate) &&
<button className="btn btn-sm btn-accent dark:border-violet-400 text-white w-fit ml-auto">
<button onClick={() => setBulkEditLinksModal(true)} className="btn btn-sm btn-accent dark:border-violet-400 text-white w-fit ml-auto">
Edit
</button>
}
@@ -373,6 +376,9 @@ export default function Index() {
{bulkDeleteLinksModal && (
<BulkDeleteLinksModal onClose={() => setBulkDeleteLinksModal(false)} />
)}
{bulkEditLinksModal && (
<BulkEditLinksModal onClose={() => setBulkEditLinksModal(false)} />
)}
</>
)}
</MainLayout>