2023-12-17 02:46:21 -06:00
|
|
|
import React, { useState } from "react";
|
2023-12-01 11:01:56 -06:00
|
|
|
import TextInput from "@/components/TextInput";
|
|
|
|
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
2023-12-01 16:42:45 -06:00
|
|
|
import Modal from "../Modal";
|
2024-06-09 08:27:16 -05:00
|
|
|
import { useTranslation } from "next-i18next";
|
2024-07-30 13:57:09 -05:00
|
|
|
import { useUpdateCollection } from "@/hooks/store/collections";
|
2024-08-14 14:22:28 -05:00
|
|
|
import toast from "react-hot-toast";
|
2024-08-19 17:14:09 -05:00
|
|
|
import IconPicker from "../IconPicker";
|
2024-08-20 15:59:01 -05:00
|
|
|
import { IconWeight } from "@phosphor-icons/react";
|
2023-12-01 11:01:56 -06:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onClose: Function;
|
|
|
|
activeCollection: CollectionIncludingMembersAndLinkCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function EditCollectionModal({
|
|
|
|
onClose,
|
|
|
|
activeCollection,
|
|
|
|
}: Props) {
|
2024-06-09 08:27:16 -05:00
|
|
|
const { t } = useTranslation();
|
2023-12-01 11:01:56 -06:00
|
|
|
const [collection, setCollection] =
|
|
|
|
useState<CollectionIncludingMembersAndLinkCount>(activeCollection);
|
|
|
|
|
|
|
|
const [submitLoader, setSubmitLoader] = useState(false);
|
2024-07-30 13:57:09 -05:00
|
|
|
const updateCollection = useUpdateCollection();
|
2023-12-01 11:01:56 -06:00
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
if (!submitLoader) {
|
|
|
|
setSubmitLoader(true);
|
|
|
|
if (!collection) return null;
|
|
|
|
|
|
|
|
setSubmitLoader(true);
|
|
|
|
|
2024-08-14 14:22:28 -05:00
|
|
|
const load = toast.loading(t("updating_collection"));
|
|
|
|
|
2024-07-30 13:57:09 -05:00
|
|
|
await updateCollection.mutateAsync(collection, {
|
2024-08-14 14:22:28 -05:00
|
|
|
onSettled: (data, error) => {
|
|
|
|
toast.dismiss(load);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
toast.error(error.message);
|
|
|
|
} else {
|
|
|
|
onClose();
|
|
|
|
toast.success(t("updated"));
|
|
|
|
}
|
2024-07-30 13:57:09 -05:00
|
|
|
},
|
|
|
|
});
|
2023-12-01 11:01:56 -06:00
|
|
|
|
|
|
|
setSubmitLoader(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-12-01 16:42:45 -06:00
|
|
|
<Modal toggleModal={onClose}>
|
2024-06-09 08:27:16 -05:00
|
|
|
<p className="text-xl font-thin">{t("edit_collection_info")}</p>
|
2023-12-03 22:52:32 -06:00
|
|
|
|
2023-12-05 14:17:36 -06:00
|
|
|
<div className="divider mb-3 mt-1"></div>
|
2023-12-01 16:42:45 -06:00
|
|
|
|
|
|
|
<div className="flex flex-col gap-3">
|
2024-08-20 15:59:01 -05:00
|
|
|
<div className="flex flex-col gap-3">
|
|
|
|
<div className="flex gap-3 items-end">
|
|
|
|
<IconPicker
|
|
|
|
color={collection.color || "#0ea5e9"}
|
|
|
|
setColor={(color: string) =>
|
|
|
|
setCollection({ ...collection, color })
|
|
|
|
}
|
|
|
|
weight={(collection.iconWeight || "regular") as IconWeight}
|
|
|
|
setWeight={(iconWeight: string) =>
|
|
|
|
setCollection({ ...collection, iconWeight })
|
|
|
|
}
|
|
|
|
iconName={collection.icon as string}
|
|
|
|
setIconName={(icon: string) =>
|
|
|
|
setCollection({ ...collection, icon })
|
|
|
|
}
|
|
|
|
reset={() =>
|
|
|
|
setCollection({
|
|
|
|
...collection,
|
|
|
|
color: "#0ea5e9",
|
|
|
|
icon: "",
|
|
|
|
iconWeight: "",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<div className="w-full">
|
|
|
|
<p className="mb-2">{t("name")}</p>
|
2023-12-01 16:42:45 -06:00
|
|
|
<TextInput
|
|
|
|
className="bg-base-200"
|
|
|
|
value={collection.name}
|
2024-06-09 08:27:16 -05:00
|
|
|
placeholder={t("collection_name_placeholder")}
|
2023-12-01 16:42:45 -06:00
|
|
|
onChange={(e) =>
|
|
|
|
setCollection({ ...collection, name: e.target.value })
|
|
|
|
}
|
|
|
|
/>
|
2023-12-01 11:01:56 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-12-01 16:42:45 -06:00
|
|
|
<div className="w-full">
|
2024-06-09 08:27:16 -05:00
|
|
|
<p className="mb-2">{t("description")}</p>
|
2023-12-01 16:42:45 -06:00
|
|
|
<textarea
|
|
|
|
className="w-full h-[13rem] resize-none border rounded-md duration-100 bg-base-200 p-2 outline-none border-neutral-content focus:border-primary"
|
2024-06-09 08:27:16 -05:00
|
|
|
placeholder={t("collection_description_placeholder")}
|
2023-12-01 16:42:45 -06:00
|
|
|
value={collection.description}
|
|
|
|
onChange={(e) =>
|
2024-06-09 08:27:16 -05:00
|
|
|
setCollection({ ...collection, description: e.target.value })
|
2023-12-01 16:42:45 -06:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-12-01 11:01:56 -06:00
|
|
|
</div>
|
2023-12-01 16:42:45 -06:00
|
|
|
|
2023-12-04 09:24:45 -06:00
|
|
|
<button
|
2023-12-07 11:29:45 -06:00
|
|
|
className="btn btn-accent dark:border-violet-400 text-white w-fit ml-auto"
|
2023-12-04 09:24:45 -06:00
|
|
|
onClick={submit}
|
|
|
|
>
|
2024-06-09 08:27:16 -05:00
|
|
|
{t("save_changes")}
|
2023-12-01 16:42:45 -06:00
|
|
|
</button>
|
2023-12-01 11:01:56 -06:00
|
|
|
</div>
|
2023-12-01 16:42:45 -06:00
|
|
|
</Modal>
|
2023-12-01 11:01:56 -06:00
|
|
|
);
|
|
|
|
}
|