fix: fix a "Maximum update depth exceeded" error in mods administration page
This commit is contained in:
parent
bd80881e27
commit
614f9a0df1
1 changed files with 11 additions and 9 deletions
|
@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react";
|
||||||
import { useForm, SubmitHandler } from "react-hook-form";
|
import { useForm, SubmitHandler } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button, buttonVariants } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
|
@ -85,9 +85,9 @@ const SvrjsModsAdminPage = () => {
|
||||||
downloadLink: editMod.downloadLink,
|
downloadLink: editMod.downloadLink,
|
||||||
fileSize: editMod.fileSize
|
fileSize: editMod.fileSize
|
||||||
});
|
});
|
||||||
setDialogOpen(true); // Open dialog when a mod is being edited
|
|
||||||
}
|
}
|
||||||
}, [editMod, dialogForm]);
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [editMod, dialogForm.reset]);
|
||||||
|
|
||||||
const fetchMods = async () => {
|
const fetchMods = async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -130,7 +130,6 @@ const SvrjsModsAdminPage = () => {
|
||||||
fetchMods();
|
fetchMods();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setEditMod(null);
|
setEditMod(null);
|
||||||
setDialogOpen(false); // Close dialog on successful submission
|
|
||||||
toast({
|
toast({
|
||||||
description: "Successfully Saved Changes"
|
description: "Successfully Saved Changes"
|
||||||
});
|
});
|
||||||
|
@ -282,11 +281,14 @@ const SvrjsModsAdminPage = () => {
|
||||||
{mod.fileSize}
|
{mod.fileSize}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="border-b px-4 py-2 gap-2 flex-center">
|
<TableCell className="border-b px-4 py-2 gap-2 flex-center">
|
||||||
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
|
<Dialog
|
||||||
<DialogTrigger>
|
open={editMod?._id == mod._id}
|
||||||
<Button variant="outline" onClick={() => setEditMod(mod)}>
|
onOpenChange={(open) => setEditMod(open ? mod : null)}
|
||||||
Edit
|
>
|
||||||
</Button>
|
<DialogTrigger
|
||||||
|
className={`${buttonVariants({ variant: "outline" })}`}
|
||||||
|
>
|
||||||
|
Edit
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogTitle>Edit Content</DialogTitle>
|
<DialogTitle>Edit Content</DialogTitle>
|
||||||
|
|
Loading…
Reference in a new issue