-
-
Notifications
You must be signed in to change notification settings - Fork 468
/
AddOnRegister.tsx
159 lines (148 loc) · 4.62 KB
/
AddOnRegister.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import styles from './AddOnRegister.module.css';
import { Button, Form, Modal } from 'react-bootstrap';
import { useMutation } from '@apollo/client';
import { ADD_PLUGIN_MUTATION } from 'GraphQl/Mutations/mutations';
import { useTranslation } from 'react-i18next';
import { toast } from 'react-toastify';
interface InterfaceAddOnRegisterProps {
id?: string; // OrgId
createdBy?: string; // User
}
interface InterfaceFormStateTypes {
pluginName: string;
pluginCreatedBy: string;
pluginDesc: string;
pluginInstallStatus: boolean;
installedOrgs: [string] | [];
}
const currentUrl = window.location.href.split('=')[1];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function addOnRegister({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
createdBy,
}: InterfaceAddOnRegisterProps): JSX.Element {
const { t } = useTranslation('translation', { keyPrefix: 'addOnRegister' });
const [show, setShow] = useState(false);
const handleClose = (): void => setShow(false);
const handleShow = (): void => setShow(true);
const [create] = useMutation(ADD_PLUGIN_MUTATION);
const [formState, setFormState] = useState<InterfaceFormStateTypes>({
pluginName: '',
pluginCreatedBy: '',
pluginDesc: '',
pluginInstallStatus: false,
installedOrgs: [currentUrl],
});
const handleRegister = async (): Promise<void> => {
const { data } = await create({
variables: {
$pluginName: formState.pluginName,
$pluginCreatedBy: formState.pluginCreatedBy,
$pluginDesc: formState.pluginDesc,
$pluginInstallStatus: formState.pluginInstallStatus,
$installedOrgs: formState.installedOrgs,
},
});
if (data) {
toast.success('Plugin Added Successfully');
setTimeout(() => {
window.location.reload();
}, 2000);
}
};
return (
<>
<Button
className={styles.modalbtn}
variant="primary"
onClick={handleShow}
>
<i className="fa fa-plus"></i>
{t('addNew')}
</Button>
<Modal show={show} onHide={handleClose}>
<Modal.Header closeButton>
<Modal.Title> {t('addPlugin')}</Modal.Title>
</Modal.Header>
<Modal.Body>
<Form>
<Form.Group className="mb-3" controlId="registerForm.PluginName">
<Form.Label>{t('pluginName')}</Form.Label>
<Form.Control
type="text"
placeholder={t('pName')}
autoComplete="off"
required
value={formState.pluginName}
onChange={(e): void => {
setFormState({
...formState,
pluginName: e.target.value,
});
}}
/>
</Form.Group>
<Form.Group className="mb-3" controlId="registerForm.PluginName">
<Form.Label>{t('creatorName')}</Form.Label>
<Form.Control
type="text"
placeholder={t('cName')}
autoComplete="off"
required
value={formState.pluginCreatedBy}
onChange={(e): void => {
setFormState({
...formState,
pluginCreatedBy: e.target.value,
});
}}
/>
</Form.Group>
<Form.Group className="mb-3" controlId="registerForm.PluginURL">
<Form.Label>{t('pluginDesc')}</Form.Label>
<Form.Control
// type="text"
rows={3}
as="textarea"
placeholder={t('pDesc')}
required
value={formState.pluginDesc}
onChange={(e): void => {
setFormState({
...formState,
pluginDesc: e.target.value,
});
}}
/>
</Form.Group>
</Form>
</Modal.Body>
<Modal.Footer>
<Button
variant="secondary"
onClick={handleClose}
data-testid="addonclose"
>
{t('close')}
</Button>
<Button
variant="primary"
onClick={handleRegister}
data-testid="addonregister"
>
{t('register')}
</Button>
</Modal.Footer>
</Modal>
</>
);
}
addOnRegister.defaultProps = {
createdBy: 'Admin',
};
addOnRegister.propTypes = {
createdBy: PropTypes.string,
};
export default addOnRegister;