Skip to content

Commit c61a304

Browse files
committed
refactor: replace App.useApp message with custom message component
Replace antd App.useApp message with custom message component from '@/components/EscapeAntd' across multiple pages and components. Also simplify clipboard handling in CreateApiKeyModal by removing try-catch block since the custom message component handles errors.
1 parent 837b253 commit c61a304

File tree

8 files changed

+20
-22
lines changed

8 files changed

+20
-22
lines changed

src/pages/ApiKey/components/CreateApiKeyModal.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,10 @@ const CreateApiKeyModal: React.FC<Props> = (props) => {
7575
const [createModalVisible, setCreateModalVisible] = useState(false);
7676

7777
const handleCopy = async (text: string, setCopied: (value: boolean) => void) => {
78-
try {
79-
await navigator.clipboard.writeText(text);
80-
setCopied(true);
81-
message.success(intl.formatMessage(INTL.COPY_SUCCESS));
82-
setTimeout(() => setCopied(false), 2000);
83-
} catch (err) {
84-
message.error(intl.formatMessage(INTL.COPY_FAILED));
85-
}
78+
await navigator.clipboard.writeText(text);
79+
setCopied(true);
80+
message.success(intl.formatMessage(INTL.COPY_SUCCESS));
81+
setTimeout(() => setCopied(false), 2000);
8682
};
8783

8884
const SuccessContent = ({ result }: { result: API.ApiKey }) => (

src/pages/Application/Edit/_hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { App, Form } from 'antd';
1+
import { Form } from 'antd';
2+
import { message } from '@/components/EscapeAntd';
23
import { BASIC_INTL } from '@/constant';
34
import { useEffect, useRef } from 'react';
45
import { ProFormInstance } from '@ant-design/pro-components';
@@ -12,7 +13,6 @@ import {
1213

1314
export default function useAppHook() {
1415
const intl = useIntl();
15-
const { message } = App.useApp();
1616
const { instanceId } = useParams();
1717
const formRef = useRef<ProFormInstance<UpdateApplicationRequest>>();
1818
const name = Form.useWatch('name', formRef.current);

src/pages/IdentityProvider/Create/_hooks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { App, Form } from 'antd';
1+
import { Form } from 'antd';
2+
import { message } from '@/components/EscapeAntd';
23
import { BASIC_INTL } from '@/constant';
34
import { useEffect, useRef } from 'react';
45
import { ProFormInstance } from '@ant-design/pro-components';
@@ -21,7 +22,7 @@ export type FormProps = {
2122

2223
export default function useIdentityProviderHook() {
2324
const intl = useIntl();
24-
const { message } = App.useApp();
25+
2526
const { instanceId } = useParams();
2627
const formRef = useRef<ProFormInstance<FormType>>();
2728
const name = Form.useWatch('name', formRef.current);

src/pages/Login/_hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App } from 'antd';
1+
import { message } from '@/components/EscapeAntd';
22
import { flushSync } from 'react-dom';
33
import { history, useIntl, useModel, useRequest } from '@umijs/max';
44
import { login } from '@/services/system/login';
@@ -20,7 +20,7 @@ const INTL = {
2020

2121
export default function useLoginHook() {
2222
const intl = useIntl();
23-
const { message } = App.useApp();
23+
2424
const [appConfLoadCompleted, setAppConfLoadCompleted] = useState(false);
2525
const [loginType, setLoginType] = useState<string>('account');
2626
const { initialState, setInitialState } = useModel('@@initialState');

src/pages/Organization/Edit/_hooks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { history, useIntl, useParams, useRequest } from '@@/exports';
22
import { useEffect, useState } from 'react';
3-
import { App, Form } from 'antd';
3+
import { Form } from 'antd';
4+
import { message } from '@/components/EscapeAntd';
45
import { BASIC_INTL } from '@/constant';
56
import {
67
getOrganization,
@@ -12,7 +13,7 @@ import {
1213

1314
export default function useOrganizationHook() {
1415
const intl = useIntl();
15-
const { message } = App.useApp();
16+
1617
const { instanceId } = useParams();
1718
const [orgInfoForm] = Form.useForm();
1819
const [currentTab, setCurrentTab] = useState('info');

src/pages/Organization/Tree/_hooks.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DependencyList, Key, useEffect, useState } from 'react';
2-
import { App } from 'antd';
2+
import { message } from '@/components/EscapeAntd';
33
import { useActive } from '@/hooks';
44
import { BASIC_INTL } from '@/constant';
55
import { useIntl, useRequest } from '@@/exports';
@@ -21,7 +21,6 @@ export type Props = {
2121
export default function useOrgTreeHook(props: Props) {
2222
const { initDeps = [], onSelect, currentKey } = props;
2323
const intl = useIntl();
24-
const { message } = App.useApp();
2524

2625
const [initLoading, { active: showInitLoading, deactive: hideInitLoading }] = useActive(false);
2726
const [searching, { active: beginSearching, deactive: endSearching }] = useActive(false);

src/pages/Policy/Create/_hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createPolicy, CreatePolicyRequest } from '@/services/policy/createPolic
55
import { updatePolicy, UpdatePolicyRequest } from '@/services/policy/updatePolicy';
66
import { getPolicyInfo } from '@/services/policy/getPolicyInfo';
77
import { listResources } from '@/services/resource/listResources';
8-
import { App } from 'antd';
8+
import { message } from '@/components/EscapeAntd';
99
import { PolicyType } from '@/enums';
1010

1111
const INTL = {
@@ -42,7 +42,7 @@ type FormType = UpdatePolicyRequest &
4242

4343
export default function usePolicyHook() {
4444
const intl = useIntl();
45-
const { message } = App.useApp();
45+
4646
const { instanceId } = useParams();
4747
const formRef = useRef<ProFormInstance<FormType>>();
4848

src/pages/User/Edit/_hooks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { history, useIntl, useParams, useRequest } from '@@/exports';
33
import { getUserInfo } from '@/services/user/getUserInfo';
44
import { useEffect, useRef, useState } from 'react';
55
import { updateUser } from '@/services/user/updateUser';
6-
import { App, Form } from 'antd';
6+
import { Form } from 'antd';
7+
import { message } from '@/components/EscapeAntd';
78
import { revokeRole } from '@/services/role/revokeRole';
89
import { ActionType } from '@ant-design/pro-components';
910
import { batchAssignRole } from '@/services/role/assignRole';
@@ -42,7 +43,7 @@ const USER_TABS = {
4243

4344
export default function useUserHook() {
4445
const intl = useIntl();
45-
const { message } = App.useApp();
46+
4647
const { instanceId } = useParams();
4748
const [userInfoForm] = Form.useForm();
4849
const [accountInfoForm] = Form.useForm();

0 commit comments

Comments
 (0)