refactor collections store
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import React, { useState } from "react";
|
||||
import TextInput from "@/components/TextInput";
|
||||
import useCollectionStore from "@/store/collections";
|
||||
import toast from "react-hot-toast";
|
||||
import { HexColorPicker } from "react-colorful";
|
||||
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||
import Modal from "../Modal";
|
||||
import { useTranslation } from "next-i18next";
|
||||
import { useUpdateCollection } from "@/hooks/store/collections";
|
||||
|
||||
type Props = {
|
||||
onClose: Function;
|
||||
@@ -21,7 +20,7 @@ export default function EditCollectionModal({
|
||||
useState<CollectionIncludingMembersAndLinkCount>(activeCollection);
|
||||
|
||||
const [submitLoader, setSubmitLoader] = useState(false);
|
||||
const { updateCollection } = useCollectionStore();
|
||||
const updateCollection = useUpdateCollection();
|
||||
|
||||
const submit = async () => {
|
||||
if (!submitLoader) {
|
||||
@@ -30,16 +29,11 @@ export default function EditCollectionModal({
|
||||
|
||||
setSubmitLoader(true);
|
||||
|
||||
const load = toast.loading(t("updating_collection"));
|
||||
|
||||
let response = await updateCollection(collection as any);
|
||||
|
||||
toast.dismiss(load);
|
||||
|
||||
if (response.ok) {
|
||||
toast.success(t("updated"));
|
||||
onClose();
|
||||
} else toast.error(response.data as string);
|
||||
await updateCollection.mutateAsync(collection, {
|
||||
onSuccess: () => {
|
||||
onClose();
|
||||
},
|
||||
});
|
||||
|
||||
setSubmitLoader(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user