diff --git a/ui2/src/components/tags/EditButton.tsx b/ui2/src/components/tags/EditButton.tsx index 7ec46f905..befae7e2a 100644 --- a/ui2/src/components/tags/EditButton.tsx +++ b/ui2/src/components/tags/EditButton.tsx @@ -1,55 +1,50 @@ -//import {useDispatch, useSelector} from "react-redux" +import {useDispatch, useSelector} from "react-redux" import {Button} from "@mantine/core" import {IconEdit} from "@tabler/icons-react" -/* + import {openModal} from "@/components/modals/Generic" import { - fetchGroupDetails, - selectGroupDetails, - updateGroupDetails -} from "@/slices/groupDetails" + fetchTagDetails, + selectTagDetails, + updateTagDetails +} from "@/slices/tagDetails" -//import EditGroupModal from "./EditGroupModal" -import type {GroupDetails, SliceState} from "@/types" -*/ +import EditTagModal from "./EditTagModal" +import type {ColoredTagType, SliceState} from "@/types" export default function EditButton({tagId}: {tagId?: string}) { - /* const dispatch = useDispatch() - const group = useSelector(selectGroupDetails) as SliceState + const tag = useSelector(selectTagDetails) as SliceState - const missingGroupDetails = (groupId: number) => { - if (!group) { + const missingTagDetails = (tagId: string) => { + if (!tag) { return true } - if (!group.data) { + if (!tag.data) { return true } - if (group.data.id != groupId) { + if (tag.data.id != tagId) { return true } return false } - */ const onClick = () => { - /* - if (groupId && missingGroupDetails(groupId)) { - dispatch(fetchGroupDetails(groupId!)) + if (tagId && missingTagDetails(tagId)) { + dispatch(fetchTagDetails(tagId!)) } - openModal(EditGroupModal, { - groupId: groupId! + openModal(EditTagModal, { + tagId: tagId! }) - .then((group: GroupDetails) => { - dispatch(updateGroupDetails(group)) + .then((tag: ColoredTagType) => { + dispatch(updateTagDetails(tag)) }) .catch(() => {}) - */ } if (!tagId) { diff --git a/ui2/src/components/tags/EditTagModal.tsx b/ui2/src/components/tags/EditTagModal.tsx new file mode 100644 index 000000000..8c3ef2666 --- /dev/null +++ b/ui2/src/components/tags/EditTagModal.tsx @@ -0,0 +1,135 @@ +import {useState, useEffect} from "react" +import {useDispatch, useSelector} from "react-redux" + +import { + Checkbox, + Group, + Button, + Modal, + TextInput, + ColorInput, + Pill, + Box, + LoadingOverlay +} from "@mantine/core" + +import {selectTagDetails} from "@/slices/tagDetails" +import {updateTag} from "@/slices/tags" +import {RootState} from "@/app/types" +import type {ColoredTagType, SliceState} from "@/types" + +type Args = { + onOK: (value: ColoredTagType) => void + onCancel: (reason?: any) => void +} + +export default function EditTagModal({onOK, onCancel}: Args) { + const [name, setName] = useState("") + const {status, data} = useSelector( + selectTagDetails + ) as SliceState + const [description, setDescription] = useState("") + const [pinned, setPinned] = useState(false) + const [bgColor, setBgColor] = useState("") + const [fgColor, setFgColor] = useState("") + const dispatch = useDispatch() + const [show, setShow] = useState(true) + + useEffect(() => { + if (data) { + setName(data.name) + setBgColor(data.bg_color) + setFgColor(data.fg_color) + setDescription(data.description) + setPinned(data.pinned) + } + }, [status]) + + const onNameChange = (value: string) => { + setName(value) + } + + const onBgColorChange = (value: string) => { + setBgColor(value) + } + + const onFgColorChange = (value: string) => { + setFgColor(value) + } + + const onSubmit = async () => { + const updatedTagData = { + name, + pinned, + description, + id: data!.id!, + bg_color: bgColor, + fg_color: fgColor + } + + const response = await dispatch(updateTag(updatedTagData)) + const tagDetailsData = response.payload as ColoredTagType + + onOK(tagDetailsData) + setShow(false) + } + const onClose = () => { + onCancel() + setShow(false) + } + + return ( + + + + onNameChange(e.currentTarget.value)} + placeholder="Name" + /> + + + setPinned(e.currentTarget.checked)} + mt="sm" + label="Pinned" + checked={pinned} + /> + setDescription(e.currentTarget.value)} + /> + + + {name || "preview"} + + + + + + + + + ) +} diff --git a/ui2/src/slices/tags.ts b/ui2/src/slices/tags.ts index faf71a9d4..a131c45b6 100644 --- a/ui2/src/slices/tags.ts +++ b/ui2/src/slices/tags.ts @@ -8,6 +8,7 @@ import axios from "@/httpClient" import {RootState} from "@/app/types" import type { + ColoredTagType, NewColoredTag, ColoredTag, Paginated, @@ -123,7 +124,7 @@ export const addTag = createAsyncThunk( export const updateTag = createAsyncThunk( "tags/updateTag", - async (tag: ColoredTag) => { + async (tag: ColoredTagType) => { const response = await axios.patch(`/api/tags/${tag.id}`, tag) const data = response.data as ColoredTag return data