|
1 | 1 | import React, { Component } from 'react'; |
2 | 2 | import { CopyToClipboard } from 'react-copy-to-clipboard'; |
3 | | -import { Modal, Form, Input, message } from 'antd'; |
4 | | -import { ToolbarItem, Button } from '@patternfly/react-core'; |
| 3 | +import { |
| 4 | + Alert, |
| 5 | + AlertGroup, |
| 6 | + Modal, |
| 7 | + ModalVariant, |
| 8 | + Form, |
| 9 | + FormGroup, |
| 10 | + TextArea, |
| 11 | + TextInput, |
| 12 | + ToolbarItem, |
| 13 | + Button, |
| 14 | +} from '@patternfly/react-core'; |
5 | 15 | import { ShareAltIcon } from '@patternfly/react-icons'; |
6 | 16 |
|
7 | | -const { TextArea } = Input; |
8 | | - |
9 | 17 | class SessionModal extends Component { |
10 | 18 | constructor(props) { |
11 | 19 | super(props); |
12 | 20 |
|
13 | 21 | this.state = { |
14 | 22 | description: '', |
15 | | - visible: false, |
| 23 | + shareModalVisible: false, |
| 24 | + successModalVisible: false, |
| 25 | + copyLinkAlertVisible: false, |
16 | 26 | sessionUrl: '', |
17 | 27 | }; |
18 | 28 | } |
19 | 29 |
|
20 | | - showSuccess = () => { |
21 | | - const { sessionUrl } = this.state; |
22 | | - |
23 | | - Modal.success({ |
24 | | - title: 'Generated session link', |
25 | | - content: ( |
26 | | - <div style={{ display: 'flex', flex: 1, flexDirection: 'row' }}> |
27 | | - <Input value={sessionUrl} /> |
28 | | - <CopyToClipboard text={sessionUrl}> |
29 | | - <Button style={{ marginLeft: 8 }} onClick={this.copyLink}> |
30 | | - Copy Link |
31 | | - </Button> |
32 | | - </CopyToClipboard> |
33 | | - </div> |
34 | | - ), |
35 | | - }); |
36 | | - }; |
| 30 | + toggleShareModal = () => { |
| 31 | + const { shareModalVisible } = this.state; |
37 | 32 |
|
38 | | - handleCancel = () => { |
39 | 33 | this.setState({ |
40 | | - visible: false, |
| 34 | + shareModalVisible: !shareModalVisible, |
41 | 35 | }); |
42 | 36 | }; |
43 | 37 |
|
44 | | - showModal = () => { |
| 38 | + toggleSuccessModal = () => { |
| 39 | + const { successModalVisible } = this.state; |
| 40 | + |
45 | 41 | this.setState({ |
46 | | - visible: true, |
| 42 | + successModalVisible: !successModalVisible, |
47 | 43 | }); |
48 | 44 | }; |
49 | 45 |
|
50 | | - onGenerate = () => { |
| 46 | + onGenerateUrl = () => { |
51 | 47 | const { dispatch } = this.props; |
52 | | - let { sessionConfig } = this.props; |
53 | 48 | const { description } = this.state; |
54 | | - sessionConfig = JSON.stringify(sessionConfig); |
| 49 | + |
| 50 | + // eslint-disable-next-line no-underscore-dangle |
| 51 | + const { routing, global, dashboard, search } = window.g_app._store.getState(); |
| 52 | + const sessionConfig = JSON.stringify({ routing, global, dashboard, search }); |
55 | 53 |
|
56 | 54 | dispatch({ |
57 | | - type: 'global/saveUserSession', |
| 55 | + type: 'sessions/saveSession', |
58 | 56 | payload: { |
59 | 57 | sessionConfig, |
60 | 58 | description, |
61 | 59 | }, |
62 | 60 | }).then(result => { |
63 | 61 | this.setState({ |
64 | | - visible: false, |
65 | | - sessionUrl: `${window.location.origin}/#/dashboard/share/${result.data.createUrl.id}`, |
| 62 | + shareModalVisible: false, |
| 63 | + sessionUrl: `${window.location.origin}/dashboard/share/${result.data.createSession.id}`, |
66 | 64 | }); |
67 | | - this.showSuccess(); |
| 65 | + this.toggleSuccessModal(); |
68 | 66 | }); |
69 | 67 | }; |
70 | 68 |
|
71 | 69 | copyLink = () => { |
72 | | - const { sessionUrl } = this.state; |
73 | | - message.success(`Copied the link: ${sessionUrl}`); |
| 70 | + this.setState({ copyLinkAlertVisible: true }); |
74 | 71 | }; |
75 | 72 |
|
76 | | - changeDescription = e => { |
| 73 | + updateDescription = value => { |
77 | 74 | this.setState({ |
78 | | - description: e.target.value, |
| 75 | + description: value, |
79 | 76 | }); |
80 | 77 | }; |
81 | 78 |
|
82 | 79 | render() { |
83 | | - const { visible, description } = this.state; |
| 80 | + const { |
| 81 | + shareModalVisible, |
| 82 | + successModalVisible, |
| 83 | + copyLinkAlertVisible, |
| 84 | + description, |
| 85 | + sessionUrl, |
| 86 | + } = this.state; |
84 | 87 | const { savingSession } = this.props; |
85 | 88 |
|
86 | 89 | return ( |
87 | 90 | <span> |
88 | 91 | <ToolbarItem> |
89 | | - <Button onClick={this.showModal} variant="plain"> |
| 92 | + <Button onClick={this.toggleShareModal} variant="plain"> |
90 | 93 | <ShareAltIcon /> |
91 | 94 | </Button> |
92 | 95 | </ToolbarItem> |
93 | 96 | <Modal |
| 97 | + variant={ModalVariant.small} |
94 | 98 | title="Share Session Link" |
95 | | - visible={visible} |
96 | | - onOk={this.onGenerate} |
97 | | - onCancel={this.handleCancel} |
98 | | - footer={[ |
99 | | - <Button key="back" onClick={this.handleCancel}> |
100 | | - Cancel |
101 | | - </Button>, |
102 | | - <Button key="submit" type="primary" onClick={this.onGenerate} loading={savingSession}> |
| 99 | + isOpen={shareModalVisible} |
| 100 | + onClose={this.toggleShareModal} |
| 101 | + actions={[ |
| 102 | + <Button |
| 103 | + key="submit" |
| 104 | + type="primary" |
| 105 | + onClick={this.onGenerateUrl} |
| 106 | + loading={savingSession} |
| 107 | + > |
103 | 108 | Save |
104 | 109 | </Button>, |
| 110 | + <Button key="back" variant="link" onClick={this.toggleShareModal}> |
| 111 | + Cancel |
| 112 | + </Button>, |
105 | 113 | ]} |
106 | 114 | > |
107 | | - <Form layout="vertical"> |
108 | | - <Form.Item label="Description"> |
| 115 | + <Form> |
| 116 | + <FormGroup label="Description"> |
109 | 117 | <TextArea |
110 | | - rows={2} |
111 | 118 | id="description" |
112 | | - placeholder={description} |
113 | | - onChange={this.changeDescription} |
| 119 | + name="description" |
| 120 | + value={description} |
| 121 | + onChange={this.updateDescription} |
114 | 122 | /> |
115 | | - </Form.Item> |
| 123 | + </FormGroup> |
116 | 124 | </Form> |
117 | 125 | </Modal> |
| 126 | + <Modal |
| 127 | + variant={ModalVariant.small} |
| 128 | + title="Generated session link" |
| 129 | + isOpen={successModalVisible} |
| 130 | + onClose={this.toggleSuccessModal} |
| 131 | + > |
| 132 | + {copyLinkAlertVisible && ( |
| 133 | + <AlertGroup isToast> |
| 134 | + <Alert title={`Copied the link: ${sessionUrl}`} /> |
| 135 | + </AlertGroup> |
| 136 | + )} |
| 137 | + <div style={{ display: 'flex', flexDirection: 'row' }}> |
| 138 | + <TextInput value={sessionUrl} /> |
| 139 | + <CopyToClipboard text={sessionUrl}> |
| 140 | + <Button style={{ marginLeft: 8 }} onClick={this.copyLink}> |
| 141 | + Copy Link |
| 142 | + </Button> |
| 143 | + </CopyToClipboard> |
| 144 | + </div> |
| 145 | + </Modal> |
118 | 146 | </span> |
119 | 147 | ); |
120 | 148 | } |
|
0 commit comments