Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 1a5048c

Browse files
committed
feat: remove window.alert
1 parent 6b7ab27 commit 1a5048c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/pages/Options/Options.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import React, {
77
import tw, { css, styled } from 'twin.macro'
88
import { Global } from '@emotion/react'
99
import cc from 'chrome-call'
10+
import { useSnackbar } from 'notistack'
1011

1112
import Client from '../../common/api'
1213
import { supportedLanguages } from '../../common/constant'
@@ -24,6 +25,7 @@ const Options: React.FC = () => {
2425
const [ocrSecretId, setOCRSecretId] = useState('')
2526
const [ocrSecretKey, setOCRSecretKey] = useState('')
2627
const [hoverButton, setHoverButton] = useState(true)
28+
const { enqueueSnackbar } = useSnackbar()
2729

2830
const onSubmit: FormEventHandler = (e) => {
2931
e.preventDefault()
@@ -37,15 +39,15 @@ const Options: React.FC = () => {
3739
hoverButton,
3840
})
3941

40-
window.alert('保存成功')
42+
enqueueSnackbar('保存成功', { variant: 'success' })
4143
})()
4244
}
4345

4446
const onTestToken: MouseEventHandler = (e) => {
4547
e.preventDefault()
4648

4749
if (!token) {
48-
window.alert('请填入 API Token')
50+
enqueueSnackbar('请填入 API Token', { variant: 'warning' })
4951
return
5052
}
5153

@@ -54,10 +56,10 @@ const Options: React.FC = () => {
5456
client
5557
.translate('This is a test message.', 'ZH')
5658
.then(() => {
57-
window.alert('测试成功')
59+
enqueueSnackbar('测试成功', { variant: 'success' })
5860
})
5961
.catch((err) => {
60-
window.alert('测试失败:' + err.message)
62+
enqueueSnackbar('测试失败:' + err.message, { variant: 'error' })
6163
})
6264
}
6365

src/pages/Options/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import { SnackbarProvider } from 'notistack'
12
import React from 'react'
23
import { render } from 'react-dom'
34
import { GlobalStyles } from 'twin.macro'
45

56
import Options from './Options'
67

78
render(
8-
<div>
9+
<SnackbarProvider>
910
<GlobalStyles />
1011
<Options />
11-
</div>,
12+
</SnackbarProvider>,
1213
window.document.querySelector('#app'),
1314
)

0 commit comments

Comments
 (0)