From 2fe6d606ecf74b6bc9985ff463abe9eca8c9b770 Mon Sep 17 00:00:00 2001 From: The Anh Nguyen Date: Sat, 30 Mar 2024 12:06:08 +0700 Subject: [PATCH] feat: handle restore memo when is in archived memo detail page (#3165) --- web/src/components/MemoActionMenu.tsx | 37 +++++++++++++++++---------- web/src/locales/en.json | 1 + web/src/locales/vi.json | 1 + 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/web/src/components/MemoActionMenu.tsx b/web/src/components/MemoActionMenu.tsx index bf414960..b728d376 100644 --- a/web/src/components/MemoActionMenu.tsx +++ b/web/src/components/MemoActionMenu.tsx @@ -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")} )} - - - {t("common.archive")} + + {memo.rowStatus === RowStatus.ARCHIVED ? : } + {memo.rowStatus === RowStatus.ARCHIVED ? t("common.restore") : t("common.archive")} diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 4967dfa2..6d58c8ef 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -312,6 +312,7 @@ "no-data": "No data found.", "memos-ready": "all memos are ready", "resource-ready": "all resource are ready", + "archived-successfully": "Archived successfully", "restored-successfully": "Restored successfully", "memo-updated-datetime": "Memo created datetime changed.", "invalid-created-datetime": "Invalid created datetime.", diff --git a/web/src/locales/vi.json b/web/src/locales/vi.json index e0f5c011..23da84fd 100644 --- a/web/src/locales/vi.json +++ b/web/src/locales/vi.json @@ -126,6 +126,7 @@ "private-only": "Bản ghi chú này là riêng tư", "resource-filename-updated": "Tên tệp tài nguyên đã được cập nhật.", "resource-ready": "tất cả tài nguyên đã sẵn sàng", + "archived-successfully": "Lưu trữ thành công", "restored-successfully": "Khôi phục thành công", "signup-failed": "Đăng ký thất bại", "succeed-copy-code": "Mã đã được sao chép thành công.",