refactor: remove dpracted useStore
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { deleteStorage, updateStorage } from "../utils/api/storages";
|
import { deleteStorage, updateStorage } from "../utils/api/storages";
|
||||||
import { useForm } from "@tanstack/react-form";
|
import { useForm } from "@tanstack/react-form";
|
||||||
import { useStore } from "@tanstack/react-store";
|
|
||||||
import { Button, IconButton, Input } from "@mui/joy";
|
import { Button, IconButton, Input } from "@mui/joy";
|
||||||
import { Trash2 } from "lucide-react";
|
import { Trash2 } from "lucide-react";
|
||||||
import type { Storage } from "../misc/interfaces";
|
import type { Storage } from "../misc/interfaces";
|
||||||
@@ -56,11 +55,6 @@ export const StorageRow = ({ storage, onError }: StorageRowProps) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const values = useStore(form.baseStore, (state) => state.values);
|
|
||||||
const isDirty =
|
|
||||||
values.name !== storage.name ||
|
|
||||||
(values.description ?? "") !== (storage.description ?? "");
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DeleteConfirmation
|
<DeleteConfirmation
|
||||||
@@ -122,17 +116,26 @@ export const StorageRow = ({ storage, onError }: StorageRowProps) => {
|
|||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-5 text-right">
|
<td className="px-6 py-5 text-right">
|
||||||
<div className="flex flex-wrap justify-end gap-2">
|
<div className="flex flex-wrap justify-end gap-2">
|
||||||
{isDirty && (
|
<form.Subscribe
|
||||||
<Button
|
selector={(state) =>
|
||||||
color="primary"
|
state.values.name !== storage.name ||
|
||||||
onClick={form.handleSubmit}
|
(state.values.description ?? "") !== (storage.description ?? "")
|
||||||
disabled={mutation.isPending || deleteMutation.isPending}
|
}
|
||||||
size="sm"
|
>
|
||||||
className="rounded-xl"
|
{(isDirty) =>
|
||||||
>
|
isDirty && (
|
||||||
{mutation.isPending ? "..." : t("save")}
|
<Button
|
||||||
</Button>
|
color="primary"
|
||||||
)}
|
onClick={form.handleSubmit}
|
||||||
|
disabled={mutation.isPending || deleteMutation.isPending}
|
||||||
|
size="sm"
|
||||||
|
className="rounded-xl"
|
||||||
|
>
|
||||||
|
{mutation.isPending ? "..." : t("save")}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</form.Subscribe>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="danger"
|
color="danger"
|
||||||
variant="plain"
|
variant="plain"
|
||||||
|
|||||||
Reference in New Issue
Block a user