Skip to content

Commit

Permalink
chore: update confirm dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Jul 1, 2024
1 parent 4a3afff commit 1ad5d9b
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 213 deletions.
91 changes: 0 additions & 91 deletions web/src/components/Dialog/CommonDialog.tsx

This file was deleted.

24 changes: 9 additions & 15 deletions web/src/components/HomeSidebar/TagsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import useCurrentUser from "@/hooks/useCurrentUser";
import { useFilterStore } from "@/store/module";
import { useMemoList, useTagStore } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import { showCommonDialog } from "../Dialog/CommonDialog";
import Icon from "../Icon";
import showRenameTagDialog from "../RenameTagDialog";

Expand Down Expand Up @@ -42,20 +41,15 @@ const TagsSection = (props: Props) => {
};

const handleDeleteTag = async (tag: string) => {
showCommonDialog({
title: t("tag.delete-tag"),
content: t("tag.delete-confirm"),
style: "danger",
dialogName: "delete-tag-dialog",
onConfirm: async () => {
await memoServiceClient.deleteMemoTag({
parent: "memos/-",
tag: tag,
});
await tagStore.fetchTags({ location, user }, { skipCache: true });
toast.success(t("message.deleted-successfully"));
},
});
const confirmed = window.confirm(t("tag.delete-confirm"));
if (confirmed) {
await memoServiceClient.deleteMemoTag({
parent: "memos/-",
tag: tag,
});
await tagStore.fetchTags({ location, user }, { skipCache: true });
toast.success(t("message.deleted-successfully"));
}
};

return (
Expand Down
22 changes: 8 additions & 14 deletions web/src/components/MemoActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useMemoStore } from "@/store/v1";
import { RowStatus } from "@/types/proto/api/v1/common";
import { Memo } from "@/types/proto/api/v1/memo_service";
import { useTranslate } from "@/utils/i18n";
import { showCommonDialog } from "./Dialog/CommonDialog";
import showMemoEditorDialog from "./MemoEditor/MemoEditorDialog";

interface Props {
Expand Down Expand Up @@ -95,19 +94,14 @@ const MemoActionMenu = (props: Props) => {
};

const handleDeleteMemoClick = async () => {
showCommonDialog({
title: t("memo.delete-memo"),
content: t("memo.delete-confirm"),
style: "danger",
dialogName: "delete-memo-dialog",
onConfirm: async () => {
await memoStore.deleteMemo(memo.name);
toast.success(t("message.deleted-successfully"));
if (isInMemoDetailPage) {
navigateTo("/");
}
},
});
const confirmed = window.confirm(t("memo.delete-confirm"));
if (confirmed) {
await memoStore.deleteMemo(memo.name);
toast.success(t("message.deleted-successfully"));
if (isInMemoDetailPage) {
navigateTo("/");
}
}
};

return (
Expand Down
18 changes: 7 additions & 11 deletions web/src/components/Settings/AccessTokenSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import useCurrentUser from "@/hooks/useCurrentUser";
import { UserAccessToken } from "@/types/proto/api/v1/user_service";
import { useTranslate } from "@/utils/i18n";
import showCreateAccessTokenDialog from "../CreateAccessTokenDialog";
import { showCommonDialog } from "../Dialog/CommonDialog";
import Icon from "../Icon";
import LearnMore from "../LearnMore";

Expand Down Expand Up @@ -38,16 +37,13 @@ const AccessTokenSection = () => {
};

const handleDeleteAccessToken = async (accessToken: string) => {
showCommonDialog({
title: "Delete Access Token",
content: `Are you sure to delete access token \`${getFormatedAccessToken(accessToken)}\`? You cannot undo this action.`,
style: "danger",
dialogName: "delete-access-token-dialog",
onConfirm: async () => {
await userServiceClient.deleteUserAccessToken({ name: currentUser.name, accessToken: accessToken });
setUserAccessTokens(userAccessTokens.filter((token) => token.accessToken !== accessToken));
},
});
const confirmed = window.confirm(
`Are you sure to delete access token \`${getFormatedAccessToken(accessToken)}\`? You cannot undo this action.`,
);
if (confirmed) {
await userServiceClient.deleteUserAccessToken({ name: currentUser.name, accessToken: accessToken });
setUserAccessTokens(userAccessTokens.filter((token) => token.accessToken !== accessToken));
}
};

const getFormatedAccessToken = (accessToken: string) => {
Expand Down
47 changes: 18 additions & 29 deletions web/src/components/Settings/MemberSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { RowStatus } from "@/types/proto/api/v1/common";
import { User, User_Role } from "@/types/proto/api/v1/user_service";
import { useTranslate } from "@/utils/i18n";
import showChangeMemberPasswordDialog from "../ChangeMemberPasswordDialog";
import { showCommonDialog } from "../Dialog/CommonDialog";
import Icon from "../Icon";

interface State {
Expand Down Expand Up @@ -101,23 +100,18 @@ const MemberSection = () => {
showChangeMemberPasswordDialog(user);
};

const handleArchiveUserClick = (user: User) => {
showCommonDialog({
title: t("setting.member-section.archive-member"),
content: t("setting.member-section.archive-warning", { username: user.nickname }),
style: "danger",
dialogName: "archive-user-dialog",
onConfirm: async () => {
await userServiceClient.updateUser({
user: {
name: user.name,
rowStatus: RowStatus.ARCHIVED,
},
updateMask: ["row_status"],
});
fetchUsers();
},
});
const handleArchiveUserClick = async (user: User) => {
const confirmed = window.confirm(t("setting.member-section.archive-warning", { username: user.nickname }));
if (confirmed) {
await userServiceClient.updateUser({
user: {
name: user.name,
rowStatus: RowStatus.ARCHIVED,
},
updateMask: ["row_status"],
});
fetchUsers();
}
};

const handleRestoreUserClick = async (user: User) => {
Expand All @@ -131,17 +125,12 @@ const MemberSection = () => {
fetchUsers();
};

const handleDeleteUserClick = (user: User) => {
showCommonDialog({
title: t("setting.member-section.delete-member"),
content: t("setting.member-section.delete-warning", { username: user.nickname }),
style: "danger",
dialogName: "delete-user-dialog",
onConfirm: async () => {
await userStore.deleteUser(user.name);
fetchUsers();
},
});
const handleDeleteUserClick = async (user: User) => {
const confirmed = window.confirm(t("setting.member-section.delete-warning", { username: user.nickname }));
if (confirmed) {
await userStore.deleteUser(user.name);
fetchUsers();
}
};

return (
Expand Down
28 changes: 10 additions & 18 deletions web/src/components/Settings/SSOSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { identityProviderServiceClient } from "@/grpcweb";
import { IdentityProvider } from "@/types/proto/api/v1/idp_service";
import { useTranslate } from "@/utils/i18n";
import showCreateIdentityProviderDialog from "../CreateIdentityProviderDialog";
import { showCommonDialog } from "../Dialog/CommonDialog";
import Icon from "../Icon";
import LearnMore from "../LearnMore";

Expand All @@ -24,23 +23,16 @@ const SSOSection = () => {
};

const handleDeleteIdentityProvider = async (identityProvider: IdentityProvider) => {
const content = t("setting.sso-section.confirm-delete", { name: identityProvider.title });

showCommonDialog({
title: t("setting.sso-section.delete-sso"),
content: content,
style: "danger",
dialogName: "delete-identity-provider-dialog",
onConfirm: async () => {
try {
await identityProviderServiceClient.deleteIdentityProvider({ name: identityProvider.name });
} catch (error: any) {
console.error(error);
toast.error(error.details);
}
await fetchIdentityProviderList();
},
});
const confirmed = window.confirm(t("setting.sso-section.confirm-delete", { name: identityProvider.title }));
if (confirmed) {
try {
await identityProviderServiceClient.deleteIdentityProvider({ name: identityProvider.name });
} catch (error: any) {
console.error(error);
toast.error(error.details);
}
await fetchIdentityProviderList();
}
};

return (
Expand Down
16 changes: 5 additions & 11 deletions web/src/components/Settings/WebhookSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import useCurrentUser from "@/hooks/useCurrentUser";
import { Webhook } from "@/types/proto/api/v1/webhook_service";
import { useTranslate } from "@/utils/i18n";
import showCreateWebhookDialog from "../CreateWebhookDialog";
import { showCommonDialog } from "../Dialog/CommonDialog";
import Icon from "../Icon";

const listWebhooks = async (userId: number) => {
Expand All @@ -33,16 +32,11 @@ const WebhookSection = () => {
};

const handleDeleteWebhook = async (webhook: Webhook) => {
showCommonDialog({
title: "Delete Webhook",
content: `Are you sure to delete webhook \`${webhook.name}\`? You cannot undo this action.`,
style: "danger",
dialogName: "delete-webhook-dialog",
onConfirm: async () => {
await webhookServiceClient.deleteWebhook({ id: webhook.id });
setWebhooks(webhooks.filter((item) => item.id !== webhook.id));
},
});
const confirmed = window.confirm(`Are you sure to delete webhook \`${webhook.name}\`? You cannot undo this action.`);
if (confirmed) {
await webhookServiceClient.deleteWebhook({ id: webhook.id });
setWebhooks(webhooks.filter((item) => item.id !== webhook.id));
}
};

return (
Expand Down
14 changes: 4 additions & 10 deletions web/src/pages/Archived.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Button, Tooltip } from "@mui/joy";
import { ClientError } from "nice-grpc-web";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";
import { showCommonDialog } from "@/components/Dialog/CommonDialog";
import Empty from "@/components/Empty";
import Icon from "@/components/Icon";
import MemoContent from "@/components/MemoContent";
Expand Down Expand Up @@ -57,15 +56,10 @@ const Archived = () => {
};

const handleDeleteMemoClick = async (memo: Memo) => {
showCommonDialog({
title: t("memo.delete-memo"),
content: t("memo.delete-confirm"),
style: "danger",
dialogName: "delete-memo-dialog",
onConfirm: async () => {
await memoStore.deleteMemo(memo.name);
},
});
const confirmed = window.confirm(t("memo.delete-confirm"));
if (confirmed) {
await memoStore.deleteMemo(memo.name);
}
};

const handleRestoreMemoClick = async (memo: Memo) => {
Expand Down
Loading

0 comments on commit 1ad5d9b

Please sign in to comment.