-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move notification form to debug
- Loading branch information
Showing
2 changed files
with
103 additions
and
13 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,88 @@ | ||
import { useState } from 'react' | ||
|
||
import { Button } from 'decentraland-ui/dist/components/Button/Button' | ||
import { Field } from 'decentraland-ui/dist/components/Field/Field' | ||
import { SelectField } from 'decentraland-ui/dist/components/SelectField/SelectField' | ||
|
||
import { Governance } from '../../clients/Governance' | ||
import { NotificationType } from '../../utils/notifications' | ||
import Heading from '../Common/Typography/Heading' | ||
import { ContentSection } from '../Layout/ContentLayout' | ||
|
||
interface Props { | ||
className?: string | ||
} | ||
|
||
export default function Notifications({ className }: Props) { | ||
const [notificationType, setNotificationType] = useState(NotificationType.TARGET) | ||
const [notificationAddress, setNotificationAddress] = useState('') | ||
const [notificationTitle, setNotificationTitle] = useState('') | ||
const [notificationBody, setNotificationBody] = useState('') | ||
const [notificationURL, setNotificationURL] = useState('') | ||
const [isSendingNotification, setIsSendingNotification] = useState(false) | ||
|
||
const handleSendNotification = async (e: any) => { | ||
e.preventDefault() | ||
setIsSendingNotification(true) | ||
|
||
try { | ||
await Governance.get().sendNotification( | ||
notificationAddress, | ||
notificationTitle, | ||
notificationBody, | ||
notificationType, | ||
notificationURL | ||
) | ||
setNotificationAddress('') | ||
setNotificationTitle('') | ||
setNotificationBody('') | ||
setNotificationURL('') | ||
} catch (error) { | ||
console.log('Error sending notification', error) | ||
} | ||
|
||
setIsSendingNotification(false) | ||
} | ||
|
||
return ( | ||
<div className={className}> | ||
<ContentSection> | ||
<form onSubmit={handleSendNotification}> | ||
<Heading size="sm">Send announcement notification</Heading> | ||
<SelectField | ||
value={notificationType} | ||
onChange={(_, { value }) => setNotificationType(Number(value))} | ||
options={[ | ||
{ text: 'Target', value: NotificationType.TARGET }, | ||
{ text: 'Broadcast', value: NotificationType.BROADCAST }, | ||
]} | ||
/> | ||
{notificationType === NotificationType.TARGET && ( | ||
<Field | ||
value={notificationAddress} | ||
required | ||
placeholder="Address (0x...)" | ||
onChange={(e) => setNotificationAddress(e.target.value)} | ||
/> | ||
)} | ||
<Field | ||
value={notificationTitle} | ||
required | ||
placeholder="Title" | ||
onChange={(e) => setNotificationTitle(e.target.value)} | ||
/> | ||
<Field | ||
value={notificationBody} | ||
required | ||
placeholder="Body" | ||
onChange={(e) => setNotificationBody(e.target.value)} | ||
/> | ||
<Field value={notificationURL} placeholder="URL" onChange={(e) => setNotificationURL(e.target.value)} /> | ||
<Button primary loading={isSendingNotification}> | ||
Send | ||
</Button> | ||
</form> | ||
</ContentSection> | ||
</div> | ||
) | ||
} |
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