-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ServerNoticeButton to UserEditToolbar
For this, the feature "Server Notices" must be activated on the server. Change-Id: If3873dc5548822a06a7be0c55e48835c9fb8f78f
- Loading branch information
1 parent
7f16f78
commit c41b8ab
Showing
6 changed files
with
149 additions
and
0 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
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,100 @@ | ||
import React, { Fragment, useState } from "react"; | ||
import { | ||
Button, | ||
SaveButton, | ||
SimpleForm, | ||
TextInput, | ||
Toolbar, | ||
required, | ||
useCreate, | ||
useNotify, | ||
useTranslate, | ||
} from "react-admin"; | ||
import MessageIcon from "@material-ui/icons/Message"; | ||
import IconCancel from "@material-ui/icons/Cancel"; | ||
import Dialog from "@material-ui/core/Dialog"; | ||
import DialogContent from "@material-ui/core/DialogContent"; | ||
import DialogContentText from "@material-ui/core/DialogContentText"; | ||
import DialogTitle from "@material-ui/core/DialogTitle"; | ||
|
||
const ServerNoticeDialog = ({ open, loading, onClose, onSend }) => { | ||
const translate = useTranslate(); | ||
|
||
const ServerNoticeToolbar = props => ( | ||
<Toolbar {...props}> | ||
<SaveButton label="resources.servernotices.action.send" /> | ||
<Button label="ra.action.cancel" onClick={onClose}> | ||
<IconCancel /> | ||
</Button> | ||
</Toolbar> | ||
); | ||
|
||
return ( | ||
<Dialog open={open} onClose={onClose} loading={loading}> | ||
<DialogTitle> | ||
{translate("resources.servernotices.action.send")} | ||
</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText> | ||
{translate("resources.servernotices.helper.send")} | ||
</DialogContentText> | ||
<SimpleForm | ||
toolbar={<ServerNoticeToolbar />} | ||
submitOnEnter={false} | ||
redirect={false} | ||
save={onSend} | ||
> | ||
<TextInput | ||
source="body" | ||
label="resources.servernotices.fields.body" | ||
fullWidth | ||
multiline | ||
rows="4" | ||
resettable | ||
validate={required()} | ||
/> | ||
</SimpleForm> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export const ServerNoticeButton = ({ record }) => { | ||
const [open, setOpen] = useState(false); | ||
const notify = useNotify(); | ||
const [create, { loading }] = useCreate("servernotices"); | ||
|
||
const handleDialogOpen = () => setOpen(true); | ||
const handleDialogClose = () => setOpen(false); | ||
|
||
const handleSend = values => { | ||
create( | ||
{ payload: { data: { id: record.id, ...values } } }, | ||
{ | ||
onSuccess: () => { | ||
notify("resources.servernotices.action.send_success"); | ||
handleDialogClose(); | ||
}, | ||
onFailure: () => | ||
notify("resources.servernotices.action.send_failure", "error"), | ||
} | ||
); | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
<Button | ||
label="resources.servernotices.send" | ||
onClick={handleDialogOpen} | ||
disabled={loading} | ||
> | ||
<MessageIcon /> | ||
</Button> | ||
<ServerNoticeDialog | ||
open={open} | ||
onClose={handleDialogClose} | ||
onSend={handleSend} | ||
/> | ||
</Fragment> | ||
); | ||
}; |
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
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