|
1 | 1 | import React, {useState} from 'react';
|
2 |
| -import Button from '@mui/material/Button'; |
3 |
| -import DialogActions from '@mui/material/DialogActions'; |
4 |
| -import DialogContent from '@mui/material/DialogContent'; |
5 |
| -import DialogTitle from '@mui/material/DialogTitle'; |
6 |
| -import MythicTextField from '../../MythicComponents/MythicTextField'; |
7 | 2 | import {useQuery, gql, useMutation} from '@apollo/client';
|
8 | 3 | import { snackActions } from '../../utilities/Snackbar';
|
9 | 4 | import {MythicConfirmDialog} from "../../MythicComponents/MythicConfirmDialog";
|
10 | 5 | import Typography from '@mui/material/Typography';
|
| 6 | +import {MythicModifyStringDialog} from "../../MythicComponents/MythicDialog"; |
11 | 7 |
|
12 | 8 | const updateDescriptionMutation = gql`
|
13 | 9 | mutation updateDescription ($payload_id: Int!, $description: String) {
|
@@ -37,14 +33,14 @@ query getDescriptionQuery ($payload_id: Int!) {
|
37 | 33 | `;
|
38 | 34 |
|
39 | 35 | export function PayloadDescriptionDialog(props) {
|
40 |
| - const [description, setDescription] = useState(""); |
41 |
| - const oldDescription = React.useRef(); |
| 36 | + const description = React.useRef(""); |
| 37 | + const [oldDescription, setOldDescription] = useState(""); |
42 | 38 | const hasCallbacks = React.useRef(false);
|
43 | 39 | useQuery(getDescriptionQuery, {
|
44 | 40 | variables: {payload_id: props.payload_id},
|
45 | 41 | onCompleted: data => {
|
46 |
| - setDescription(data.payload_by_pk.description) |
47 |
| - oldDescription.current = data.payload_by_pk.description; |
| 42 | + description.current = data.payload_by_pk.description; |
| 43 | + setOldDescription(data.payload_by_pk.description); |
48 | 44 | hasCallbacks.current = data.payload_by_pk.callbacks.length > 0;
|
49 | 45 | },
|
50 | 46 | fetchPolicy: "network-only"
|
@@ -81,43 +77,34 @@ export function PayloadDescriptionDialog(props) {
|
81 | 77 | setOpenUpdateAll(false);
|
82 | 78 | updateCallbackDescriptions({variables: {
|
83 | 79 | payloadID: props.payload_id,
|
84 |
| - oldDescription: oldDescription.current, |
85 |
| - newDescription: description, |
| 80 | + oldDescription: oldDescription, |
| 81 | + newDescription: description.current, |
86 | 82 | }});
|
87 | 83 | updatePayloadDescription();
|
88 | 84 | // now update all
|
89 | 85 | }
|
90 | 86 | const updatePayloadDescription = () => {
|
91 | 87 | setOpenUpdateAll(false);
|
92 |
| - updateDescription({variables: {payload_id: props.payload_id, description: description}}); |
| 88 | + updateDescription({variables: {payload_id: props.payload_id, description: description.current}}); |
93 | 89 | props.onClose();
|
94 | 90 | }
|
95 |
| - const onCommitSubmit = () => { |
| 91 | + const onCommitSubmit = (updatedMessage) => { |
| 92 | + description.current = updatedMessage; |
96 | 93 | if(hasCallbacks.current){
|
97 | 94 | setOpenUpdateAll(true);
|
98 | 95 | } else {
|
99 | 96 | updatePayloadDescription();
|
100 | 97 | }
|
101 | 98 |
|
102 | 99 | }
|
103 |
| - const onChange = (name, value, error) => { |
104 |
| - setDescription(value); |
105 |
| - } |
106 |
| - |
| 100 | + |
107 | 101 | return (
|
108 | 102 | <React.Fragment>
|
109 |
| - <DialogTitle id="form-dialog-title">Edit Payload Description</DialogTitle> |
110 |
| - <DialogContent dividers={true}> |
111 |
| - <MythicTextField autoFocus onChange={onChange} value={description} onEnter={onCommitSubmit}/> |
112 |
| - </DialogContent> |
113 |
| - <DialogActions> |
114 |
| - <Button variant="contained" onClick={props.onClose} color="primary"> |
115 |
| - Close |
116 |
| - </Button> |
117 |
| - <Button variant="contained" onClick={onCommitSubmit} color="success"> |
118 |
| - Submit |
119 |
| - </Button> |
120 |
| - </DialogActions> |
| 103 | + <MythicModifyStringDialog title={"Edit Payload Description"} |
| 104 | + maxRows={5} |
| 105 | + onClose={props.onClose} |
| 106 | + value={description.current} |
| 107 | + onSubmit={onCommitSubmit} /> |
121 | 108 | {openUpdateAll &&
|
122 | 109 | <MythicConfirmDialog title={"Update Associated Callback's Descriptions?"}
|
123 | 110 | dontCloseOnSubmit={true}
|
|
0 commit comments