Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 25 additions & 14 deletions web/src/components/MemoActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const MemoActionMenu = (props: Props) => {
const location = useLocation();
const navigateTo = useNavigateTo();
const memoStore = useMemoStore();
const isInMemoDetailPage = location.pathname.startsWith(`/m/${memo.name}`);
const isInMemoDetailPage = location.pathname.startsWith(`/m/${memo.uid}`);

const handleTogglePinMemoBtnClick = async () => {
try {
Expand Down Expand Up @@ -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");
}
};

Expand Down Expand Up @@ -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" />
Expand Down
1 change: 1 addition & 0 deletions web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions web/src/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down