feat: handle restore memo when is in archived memo detail page (#3165)

This commit is contained in:
The Anh Nguyen
2024-03-30 12:06:08 +07:00
committed by GitHub
parent c8baeb86ec
commit 2fe6d606ec
3 changed files with 26 additions and 13 deletions

View File

@ -57,24 +57,35 @@ const MemoActionMenu = (props: Props) => {
});
};
const handleArchiveMemoClick = async () => {
const handleToggleMemoStatusClick = async () => {
try {
await memoStore.updateMemo(
{
name: memo.name,
rowStatus: RowStatus.ARCHIVED,
},
["row_status"],
);
if (memo.rowStatus === RowStatus.ARCHIVED) {
await memoStore.updateMemo(
{
name: memo.name,
rowStatus: RowStatus.ACTIVE,
},
["row_status"],
);
toast(t("message.restored-successfully"));
} else {
await memoStore.updateMemo(
{
name: memo.name,
rowStatus: RowStatus.ARCHIVED,
},
["row_status"],
);
toast.success(t("message.archived-successfully"));
}
} catch (error: any) {
console.error(error);
toast.error(error.response.data.message);
return;
}
toast.success("Archived successfully");
if (isInMemoDetailPage) {
navigateTo("/archived");
memo.rowStatus === RowStatus.ARCHIVED ? navigateTo("/") : navigateTo("/archived");
}
};
@ -120,9 +131,9 @@ const MemoActionMenu = (props: Props) => {
{t("common.share")}
</MenuItem>
)}
<MenuItem color="warning" onClick={handleArchiveMemoClick}>
<Icon.Archive className="w-4 h-auto" />
{t("common.archive")}
<MenuItem color="warning" onClick={handleToggleMemoStatusClick}>
{memo.rowStatus === RowStatus.ARCHIVED ? <Icon.ArchiveRestore className="w-4 h-auto" /> : <Icon.Archive className="w-4 h-auto" />}
{memo.rowStatus === RowStatus.ARCHIVED ? t("common.restore") : t("common.archive")}
</MenuItem>
<MenuItem color="danger" onClick={handleDeleteMemoClick}>
<Icon.Trash className="w-4 h-auto" />