You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
memos/web/src/components/ArchivedMemo.tsx

76 lines
2.2 KiB
TypeScript

import { toast } from "react-hot-toast";
import { useTranslation } from "react-i18next";
import { useMemoStore } from "@/store/module";
import * as utils from "@/helpers/utils";
import useToggle from "@/hooks/useToggle";
import MemoContent from "./MemoContent";
import MemoResources from "./MemoResources";
import "@/less/memo.less";
4 years ago
interface Props {
memo: Memo;
4 years ago
}
const ArchivedMemo: React.FC<Props> = (props: Props) => {
const { memo } = props;
const { t } = useTranslation();
const memoStore = useMemoStore();
4 years ago
const [showConfirmDeleteBtn, toggleConfirmDeleteBtn] = useToggle(false);
const handleDeleteMemoClick = async () => {
if (showConfirmDeleteBtn) {
try {
await memoStore.deleteMemoById(memo.id);
4 years ago
} catch (error: any) {
console.error(error);
toast.error(error.response.data.message);
4 years ago
}
} else {
toggleConfirmDeleteBtn();
}
};
const handleRestoreMemoClick = async () => {
try {
await memoStore.patchMemo({
id: memo.id,
rowStatus: "NORMAL",
});
await memoStore.fetchMemos();
toast(t("message.restored-successfully"));
4 years ago
} catch (error: any) {
console.error(error);
toast.error(error.response.data.message);
4 years ago
}
};
const handleMouseLeaveMemoWrapper = () => {
if (showConfirmDeleteBtn) {
toggleConfirmDeleteBtn(false);
}
};
return (
<div className={`memo-wrapper archived ${"memos-" + memo.id}`} onMouseLeave={handleMouseLeaveMemoWrapper}>
4 years ago
<div className="memo-top-wrapper">
<span className="time-text">
{t("memo.archived-at")} {utils.getDateTimeString(memo.updatedTs)}
</span>
4 years ago
<div className="btns-container">
<span className="btn-text" onClick={handleRestoreMemoClick}>
{t("common.restore")}
</span>
<span className={`btn-text ${showConfirmDeleteBtn ? "final-confirm" : ""}`} onClick={handleDeleteMemoClick}>
{t("common.delete")}
{showConfirmDeleteBtn ? "!" : ""}
4 years ago
</span>
</div>
</div>
<MemoContent content={memo.content} />
<MemoResources resourceList={memo.resourceList} />
4 years ago
</div>
);
};
export default ArchivedMemo;