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

73 lines
2.3 KiB
TypeScript

import { Tooltip } from "@mui/joy";
import { toast } from "react-hot-toast";
import { useTranslation } from "react-i18next";
import { useMemoStore } from "@/store/module";
feat: improve i18n support as a whole (#1526) * feat: improve i18n support as a whole - Remove dayjs in favor of /helpers/datetime.ts, which uses Intl.DateTimeFormat and Date. Dayjs is not exactly i18n friendly and has several locale related opened issues. - Move/refactor date/time code from /helpers/utils.ts to /helpers/datetime.ts. - Fix Daily Review weekday not changing according to selected date. - Localize Daily review weekday and month. - Load i18n listed strings from /locales/{locale}.json in a dynamic way. This makes much easier to add new locales, by just adding a properly named json file and listing it only in /web/src/i18n.ts and /api/user_setting.go. - Fallback languages are now set in /web/src/i18n.ts. - Full language codes are now preffered, but they fallback to 2-letter codes when not available. - The locale dropdown is now populated dynamically from the available locales. Locale names are populated by the browser via Intl.DisplayNames(locale). - /web/src/i18n.ts now exports a type TLocale from availableLocales array. This is used only by findNearestLanguageMatch(). As I was unable to use this type in ".d.ts" files, I switched the Locale type from /web/src/types/i18n.d.ts to string. - Move pretty much all hardcoded text strings to i18n strings. - Add pt-BR translation. - Remove site.ts and move its content to a i18n string. - Rename zh.json to zh-Hans.json to get the correct language name on selector dropdown. - Remove pt_BR.json and replace with pt-BR.json. - Some minor layout spacing fixes to accommodate larger texts. - Improve some error messages. * Delete .yarnrc.yml * Delete package-lock.json * fix: 158:28 error Insert `⏎` prettier/prettier
2 years ago
import { getDateTimeString } from "@/helpers/datetime";
import Icon from "./Icon";
import MemoContent from "./MemoContent";
import MemoResourceListView from "./MemoResourceListView";
import { showCommonDialog } from "./Dialog/CommonDialog";
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 handleDeleteMemoClick = async () => {
showCommonDialog({
title: t("memo.delete-memo"),
content: t("memo.delete-confirm"),
style: "warning",
dialogName: "delete-memo-dialog",
onConfirm: async () => {
await memoStore.deleteMemoById(memo.id);
},
});
4 years ago
};
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
}
};
return (
<div className={`memo-wrapper archived ${"memos-" + memo.id}`}>
4 years ago
<div className="memo-top-wrapper">
<div className="status-text-container">
<span className="time-text">{getDateTimeString(memo.updatedTs)}</span>
</div>
<div className="flex flex-row justify-end items-center gap-x-2">
<Tooltip title={t("common.restore")} placement="top">
<button onClick={handleRestoreMemoClick}>
<Icon.ArchiveRestore className="w-4 h-auto cursor-pointer text-gray-500 dark:text-gray-400" />
</button>
</Tooltip>
<Tooltip title={t("common.delete")} placement="top">
<button onClick={handleDeleteMemoClick} className="text-gray-500 dark:text-gray-400">
<Icon.Trash className="w-4 h-auto cursor-pointer" />
</button>
</Tooltip>
4 years ago
</div>
</div>
<MemoContent content={memo.content} />
<MemoResourceListView resourceList={memo.resourceList} />
4 years ago
</div>
);
};
export default ArchivedMemo;