import Link from "next/link"; import { useRouter } from "next/router"; import { useForm } from "react-hook-form"; import { IoChevronForwardSharp } from "react-icons/io5"; import Avatar from "~/components/Avatar"; import { LabelForm } from "~/components/LabelForm"; import LabelIcon from "~/components/LabelIcon"; import Modal from "~/components/modal"; import { NewWorkspaceForm } from "~/components/NewWorkspaceForm"; import { PageHead } from "~/components/PageHead"; import { useModal } from "~/providers/modal"; import { usePopup } from "~/providers/popup"; import { useWorkspace } from "~/providers/workspace"; import { api } from "~/utils/api"; import { formatMemberDisplayName, getAvatarUrl } from "~/utils/helpers"; import { DeleteLabelConfirmation } from "../../components/DeleteLabelConfirmation"; import ActivityList from "./components/ActivityList"; import { DeleteCardConfirmation } from "./components/DeleteCardConfirmation"; import { DeleteCommentConfirmation } from "./components/DeleteCommentConfirmation"; import Dropdown from "./components/Dropdown"; import LabelSelector from "./components/LabelSelector"; import ListSelector from "./components/ListSelector"; import MemberSelector from "./components/MemberSelector"; import NewCommentForm from "./components/NewCommentForm"; import Editor from "~/components/Editor"; interface FormValues { cardId: string; title: string; description: string; } export default function CardPage() { const router = useRouter(); const utils = api.useUtils(); const { modalContentType, entityId } = useModal(); const { showPopup } = usePopup(); const { workspace } = useWorkspace(); const cardId = Array.isArray(router.query.cardId) ? router.query.cardId[0] : router.query.cardId; const { data: card, isLoading } = api.card.byId.useQuery({ cardPublicId: cardId ?? "", }); const refetchCard = async () => { if (cardId) await utils.card.byId.refetch({ cardPublicId: cardId }); }; const board = card?.list.board; const boardId = board?.publicId; const labels = board?.labels; const activities = card?.activities; const workspaceMembers = board?.workspace.members; const selectedLabels = card?.labels; const selectedMembers = card?.members; const formattedLabels = labels?.map((label) => { const isSelected = selectedLabels?.some( (selectedLabel) => selectedLabel.publicId === label.publicId, ); return { key: label.publicId, value: label.name, selected: isSelected ?? false, leftIcon: , }; }) ?? []; const formattedLists = board?.lists.map((list) => ({ key: list.publicId, value: list.name, selected: list.publicId === card?.list.publicId, })) ?? []; const formattedMembers = workspaceMembers?.map((member) => { const isSelected = selectedMembers?.some( (assignedMember) => assignedMember.publicId === member.publicId, ); return { key: member.publicId, value: formatMemberDisplayName( member.user?.name ?? null, member.user?.email ?? member.email, ), imageUrl: member.user?.image ? getAvatarUrl(member.user.image) : undefined, selected: isSelected ?? false, leftIcon: ( ), }; }) ?? []; const updateCard = api.card.update.useMutation({ onError: () => { showPopup({ header: "Unable to update card", message: "Please try again later, or contact customer support.", icon: "error", }); }, onSettled: async () => { await utils.card.byId.invalidate({ cardPublicId: cardId }); }, }); const { register, handleSubmit, setValue, watch } = useForm({ values: { cardId: cardId ?? "", title: card?.title ?? "", description: card?.description ?? "", }, }); const onSubmit = (values: FormValues) => { updateCard.mutate({ cardPublicId: values.cardId, title: values.title, description: values.description, }); }; const description = watch("description"); if (!cardId) return <>>; return ( <> {!card && isLoading && ( )} {card && ( <> {board?.name} > )} {!card && !isLoading && ( Card not found )} {card && ( <> setValue("description", e)} onBlur={() => handleSubmit(onSubmit)()} /> Activity > )} List Labels Members {modalContentType === "NEW_LABEL" && ( )} {modalContentType === "EDIT_LABEL" && ( )} {modalContentType === "DELETE_LABEL" && ( )} {modalContentType === "DELETE_CARD" && ( )} {modalContentType === "DELETE_COMMENT" && ( )} {modalContentType === "NEW_WORKSPACE" && } > ); }
Card not found
List
Labels
Members