forked from nervosnetwork/ckb-explorer-frontend
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
248 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
.container { | ||
font-size: 1rem; | ||
|
||
&::backdrop { | ||
background: rgb(0 0 0 / 40%); | ||
} | ||
|
||
form { | ||
background: #fff; | ||
position: fixed; | ||
transform: translateX(-50%) translateY(-50%); | ||
font-size: 0.875rem; | ||
width: min-content; | ||
margin: 16px auto; | ||
top: 50%; | ||
left: 50%; | ||
padding: 23px 40px; | ||
border-radius: 4px; | ||
} | ||
|
||
h3 { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding-bottom: 22px; | ||
border-bottom: 1px solid #e5e5e5; | ||
margin-bottom: 16px; | ||
|
||
button { | ||
svg { | ||
color: #000; | ||
} | ||
} | ||
} | ||
|
||
fieldset { | ||
display: flex; | ||
flex-direction: column; | ||
margin-bottom: 16px; | ||
} | ||
|
||
label { | ||
display: flex; | ||
align-items: center; | ||
gap: 4px; | ||
color: #666; | ||
margin-bottom: 12px; | ||
|
||
&[data-required]::after { | ||
content: '*'; | ||
color: var(--accent-color); | ||
} | ||
} | ||
|
||
input { | ||
width: 320px; | ||
padding: 9px 12px; | ||
border: 1px solid #e5e5e5; | ||
border-radius: 4px; | ||
font-size: inherit; | ||
} | ||
|
||
button[type='submit'] { | ||
padding: 14px 40px; | ||
color: #fff; | ||
background: var(--primary-color); | ||
border-radius: 4px; | ||
font-size: 1rem; | ||
} | ||
|
||
@media screen and (width < 1030px) { | ||
font-size: 14px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { Cross2Icon } from '@radix-ui/react-icons' | ||
import { type FC, useRef, useEffect } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useSetToast } from '../../../components/Toast' | ||
import { explorerService } from '../../../services/ExplorerService' | ||
import styles from './AddPeerForm.module.scss' | ||
|
||
interface AddPeerFormProps { | ||
onSuccess: () => void | ||
} | ||
const AddPeerForm: FC<AddPeerFormProps> = ({ onSuccess }) => { | ||
const dialogRef = useRef<HTMLDialogElement | null>(null) | ||
const [t] = useTranslation() | ||
const setToast = useSetToast() | ||
|
||
useEffect(() => { | ||
const handleKeyDown = (e: KeyboardEvent) => { | ||
if (e.key === 'Escape') { | ||
dialogRef.current?.close() | ||
} | ||
} | ||
|
||
window.addEventListener('keydown', handleKeyDown) | ||
|
||
return () => { | ||
window.removeEventListener('keydown', handleKeyDown) | ||
} | ||
}, []) | ||
|
||
const handleClose = () => { | ||
dialogRef.current?.close() | ||
} | ||
|
||
const handleSubmit = async (e: React.SyntheticEvent<HTMLFormElement>) => { | ||
e.preventDefault() | ||
e.stopPropagation() | ||
const form = e.currentTarget | ||
|
||
const { peer_id, peer_name, rpc } = form | ||
const params: Parameters<typeof explorerService.api.addFiberPeer>[0] = { | ||
rpc: rpc instanceof HTMLInputElement ? rpc.value : '', | ||
id: peer_id instanceof HTMLInputElement ? peer_id.value : '', | ||
name: peer_name instanceof HTMLInputElement ? peer_name.value : undefined, | ||
} | ||
|
||
if (params.rpc && params.id) { | ||
try { | ||
await explorerService.api.addFiberPeer(params) | ||
setToast({ message: 'submitted' }) | ||
onSuccess() | ||
} catch (e) { | ||
const message = e instanceof Error ? e.message : JSON.stringify(e) | ||
setToast({ message }) | ||
} | ||
} | ||
} | ||
|
||
const handleClickOutside = (e: React.MouseEvent) => { | ||
if (e.target === dialogRef.current) { | ||
dialogRef.current?.close() | ||
} | ||
} | ||
|
||
const handleOpen = () => { | ||
dialogRef.current?.showModal() | ||
} | ||
|
||
return ( | ||
<> | ||
<button type="button" onClick={handleOpen}> | ||
Add Peer | ||
</button> | ||
|
||
<dialog ref={dialogRef} onClick={handleClickOutside} className={styles.container}> | ||
<form onSubmit={handleSubmit}> | ||
<h3> | ||
<span>Add Fiber Peer</span> | ||
<button type="button" onClick={handleClose}> | ||
<Cross2Icon /> | ||
</button> | ||
</h3> | ||
<fieldset> | ||
<label htmlFor="rpc" data-required> | ||
{t('fiber.peer.rpc_addr')} | ||
</label> | ||
<input required id="rpc" placeholder="Peer RPC Address" /> | ||
</fieldset> | ||
<fieldset> | ||
<label htmlFor="peer_id" data-required> | ||
Peer ID | ||
</label> | ||
<input required id="peer_id" placeholder="Peer ID" /> | ||
</fieldset> | ||
<fieldset> | ||
<label htmlFor="peer_name">{t('fiber.peer.name')}</label> | ||
<input id="peer_name" placeholder="Peer Alias" /> | ||
</fieldset> | ||
<button type="submit">Submit</button> | ||
</form> | ||
</dialog> | ||
</> | ||
) | ||
} | ||
|
||
export default AddPeerForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
%base-table { | ||
width: 100%; | ||
text-align: left; | ||
cursor: default; | ||
overflow: hidden; | ||
border-radius: 6px; | ||
box-shadow: rgb(0 0 0 / 12%) 0 2px 6px 0; | ||
font-size: 0.875rem; | ||
|
||
tr { | ||
background: #fff; | ||
} | ||
|
||
td, | ||
th { | ||
padding: 8px; | ||
padding-right: 1rem; | ||
|
||
&:first-child { | ||
padding-left: 40px; | ||
} | ||
|
||
&:last-child { | ||
text-align: right; | ||
} | ||
} | ||
|
||
thead { | ||
th { | ||
height: 3.5rem; | ||
} | ||
} | ||
|
||
tbody { | ||
tr:hover { | ||
background: #ccc; | ||
} | ||
} | ||
|
||
.tableSeparator { | ||
height: 4px; | ||
} | ||
} |