authscape 1.0.466 → 1.0.469

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,521 @@
1
+ import React, {useEffect, useState, useRef} from 'react';
2
+ // import {apiService, authService, StripeConnect, ReactDraft, EditableDatagrid, FileUploader} from 'authscape';
3
+ import Button from '@mui/material/Button';
4
+ import { Box } from '@mui/system';
5
+ import Dialog from '@mui/material/Dialog';
6
+ import DialogActions from '@mui/material/DialogActions';
7
+ import DialogContent from '@mui/material/DialogContent';
8
+ import DialogContentText from '@mui/material/DialogContentText';
9
+ import DialogTitle from '@mui/material/DialogTitle';
10
+ import TextField from '@mui/material/TextField';
11
+ import InputLabel from '@mui/material/InputLabel';
12
+ import MenuItem from '@mui/material/MenuItem';
13
+ import FormControl from '@mui/material/FormControl';
14
+ import Select from '@mui/material/Select';
15
+ import {GridActionsCellItem} from "@mui/x-data-grid";
16
+ import DeleteRoundedIcon from "@mui/icons-material/DeleteRounded";
17
+ import ListRoundedIcon from '@mui/icons-material/ListRounded';
18
+ import PublishRoundedIcon from '@mui/icons-material/PublishRounded';
19
+ import Grid from '@mui/material/Grid';
20
+ import DownloadRoundedIcon from '@mui/icons-material/DownloadRounded';
21
+
22
+ export default function ManageMappingDocuments({hideDocumentManager = false, companyId = null, locationId = null, userId = null, onManageField = null, onArchive = null}) {
23
+
24
+ const [document, setDocument] = useState(null);
25
+ const [addColumnDialog, setAddColumnDialog] = useState(false);
26
+
27
+ const [showAddNewDocument, setShowAddNewDocument] = useState(false);
28
+ const [showTrainingDocument, setShowTrainingDocument] = useState(false);
29
+
30
+ const [columnName, setColumnName] = useState('');
31
+ const [selectedAddedColumn, setSelectedAddedColumn] = useState(null);
32
+
33
+ const [documentMappingColumns, setDocumentMappingColumns] = useState(null);
34
+ const [toColumnOptions, setToColumnOptions] = useState(null);
35
+
36
+ const [removeDocument, setRemoveDocument] = useState(null);
37
+
38
+ const [selectedDocumentComponentId, setSelectedDocumentComponentId] = useState(null);
39
+
40
+ const [dataGridRefreshKey, setDataGridRefreshKey] = useState(0);
41
+ const [dataGridMappingRefreshKey, setDataGridMappingRefreshKey] = useState(0);
42
+
43
+ const [selectedDocument, setSelectedDocument] = useState(null);
44
+
45
+ const [status, setStatus] = useState(0);
46
+
47
+ const [componentTypes, setComponentTypes] = useState([]);
48
+
49
+ const refHeaderRowInput = useRef(null);
50
+ const fileUploaderRef = useRef(null);
51
+ const refNewDocumentName = useRef(null);
52
+ const refSelectDocumentType = useRef(null);
53
+ const refNewColumnFileColumn = useRef(null);
54
+
55
+ const documentColumns = [
56
+ { field: 'name', flex:1, headerName: 'Document Name', width: 150, editable: false },
57
+ { field: 'documentTypeName', flex:1, headerName: 'Document Type', width: 150, editable: false },
58
+ {
59
+ field: "actions",
60
+ type: "actions",
61
+ width: 200,
62
+ flex:1,
63
+ headerName: "",
64
+ cellClassName: "actions",
65
+ getActions: ({ id, row }) => {
66
+ return [
67
+ <Button variant="text" startIcon={<ListRoundedIcon/>} onClick={() => {
68
+
69
+ if (onManageField != null)
70
+ {
71
+ onManageField(row.id);
72
+ }
73
+
74
+ }}>
75
+ Manage Fields
76
+ </Button>,
77
+ <Button variant="text" startIcon={<DownloadRoundedIcon/>} onClick={() => {
78
+
79
+ window.open("https://view.officeapps.live.com/op/view.aspx?src=" + row.fileUri + "&wdOrigin=BROWSELINK");
80
+
81
+ }}>
82
+ Download File
83
+ </Button>,
84
+ <Button variant="text" startIcon={<DeleteRoundedIcon/>} onClick={async () => {
85
+
86
+ let documentMappingId = row.id;
87
+ setRemoveDocument({
88
+ companyId: companyId,
89
+ documentMappingId: documentMappingId
90
+ });
91
+
92
+ }}>
93
+ Remove
94
+ </Button>
95
+ ];
96
+ },
97
+ }
98
+
99
+ ];
100
+
101
+ useEffect(() => {
102
+
103
+ if (document != null)
104
+ {
105
+ const fetchData = async () => {
106
+
107
+ let response = await apiService().get("/DocumentMapping/GetMappingFieldsForDocument?documentId=" + document.id);
108
+ if (response != null)
109
+ {
110
+ setToColumnOptions(response.data);
111
+ setDocumentMappingColumns(
112
+ [
113
+ { field: 'name', flex:1, headerName: 'File Column', width: 150, editable: true },
114
+ {
115
+ field: 'toName',
116
+ headerName: 'Upload To',
117
+ flex:1,
118
+ width: 150,
119
+ editable: true,
120
+ type: 'singleSelect',
121
+ valueOptions: response.data,
122
+ },
123
+ {
124
+ field: "actions",
125
+ type: "actions",
126
+ width: 200,
127
+ headerName: "Archive Fields",
128
+ cellClassName: "actions",
129
+ getActions: ({ id, row }) => {
130
+ return [
131
+ <GridActionsCellItem key={id}
132
+ icon={<DeleteRoundedIcon />}
133
+ label="Archive"
134
+ className="textPrimary"
135
+ onClick={async () => {
136
+
137
+ let documentMappingId = row.id;
138
+ let documentComponentId = row.documentComponentId;
139
+
140
+ // archive the column
141
+ let response = await apiService()
142
+ .delete("/DocumentMapping/RemoveColumnFromDocumentComponent?documentMappingId=" +
143
+ documentMappingId + "&documentComponentId=" + documentComponentId);
144
+
145
+ if (response != null && response.status == 200)
146
+ {
147
+ setDataGridMappingRefreshKey(dataGridMappingRefreshKey + 1);
148
+ }
149
+
150
+ }}
151
+ />,
152
+ ];
153
+ },
154
+ }
155
+ ]
156
+ );
157
+ }
158
+
159
+ }
160
+ fetchData();
161
+ }
162
+
163
+ }, [document])
164
+
165
+ useEffect(() => {
166
+
167
+ if (showAddNewDocument)
168
+ {
169
+ // get all document types
170
+ const fetchData = async () => {
171
+ let response = await apiService().post("/DocumentMapping/GetDocumentTypes");
172
+ if (response != null && response.status == 200)
173
+ {
174
+ setComponentTypes(response.data.data);
175
+ }
176
+ };
177
+ fetchData();
178
+ }
179
+
180
+ }, [showAddNewDocument])
181
+
182
+ const GetHeaderRowData = async (documentComponentId) => {
183
+
184
+ let response = await apiService().get("/DocumentMapping/GetHeaderRow?documentComponentId=" + documentComponentId);
185
+ if (response != null && response.status == 200)
186
+ {
187
+ refHeaderRowInput.current.value = response.data;
188
+ }
189
+ }
190
+
191
+ useEffect(() => {
192
+
193
+ if (status != null)
194
+ {
195
+ setDataGridRefreshKey(dataGridRefreshKey + 1);
196
+ }
197
+
198
+ }, [status])
199
+
200
+ return (
201
+ <Box>
202
+ {!hideDocumentManager &&
203
+ <Box>
204
+
205
+ <Grid container spacing={2} sx={{paddingBottom:2}}>
206
+ <Grid item xs={3}>
207
+ <Box sx={{ minWidth: 120 }}>
208
+ <FormControl fullWidth>
209
+ <InputLabel id="demo-simple-select-label">Status</InputLabel>
210
+ <Select
211
+ labelId="demo-simple-select-label"
212
+ id="demo-simple-select"
213
+ value={status}
214
+ label="Status"
215
+ onChange={(event) => {
216
+ setStatus(event.target.value);
217
+ }}
218
+ >
219
+ <MenuItem value={0}>Open</MenuItem>
220
+ <MenuItem value={2}>Published</MenuItem>
221
+ <MenuItem value={1}>Archived</MenuItem>
222
+ </Select>
223
+ </FormControl>
224
+ </Box>
225
+ </Grid>
226
+ <Grid item xs={9}>
227
+
228
+
229
+ <Box sx={{textAlign:"right", marginBottom:2}}>
230
+ <Button variant="contained" onClick={() => {
231
+ setShowAddNewDocument(true);
232
+ }}>Upload Document</Button>
233
+ </Box>
234
+ </Grid>
235
+ </Grid>
236
+
237
+
238
+ <EditableDatagrid key={dataGridRefreshKey} loadedUser={true} params={{
239
+ companyId: companyId,
240
+ userId: userId,
241
+ locationId: locationId,
242
+ status: status
243
+ }} url={"/DocumentMapping/GetDocumentComponents"} columns={documentColumns}/>
244
+
245
+ </Box>
246
+ }
247
+
248
+ {hideDocumentManager &&
249
+ <Button variant="contained" onClick={() => {
250
+ setShowAddNewDocument(true);
251
+ }}>Upload Document</Button>
252
+ }
253
+
254
+ {/* <Box sx={{textAlign:"right"}}>
255
+ <Button variant='contained' onClick={async () => {
256
+
257
+ let response = await apiService().post("/DocumentMapping/SubmitMappedDocument", {
258
+ companyId: companyId,
259
+ documentComponentId: selectedDocumentComponentId
260
+ });
261
+
262
+ if (response != null && (response.status == 200 || response.status == 201))
263
+ {
264
+ alert("Worked!");
265
+ }
266
+
267
+ }}>Submit</Button>
268
+ </Box> */}
269
+
270
+ <Dialog
271
+ open={showAddNewDocument}
272
+ onClose={() => {
273
+ setShowAddNewDocument(false);
274
+ }}
275
+ fullWidth={true}
276
+ aria-labelledby="alert-dialog-title"
277
+ aria-describedby="alert-dialog-description">
278
+ <DialogTitle id="alert-dialog-title">Upload Document</DialogTitle>
279
+ <DialogContent>
280
+
281
+ <DialogContentText id="alert-dialog-description" sx={{paddingBottom:2}}>
282
+ Please select the type of document, then click "Choose a file"
283
+ </DialogContentText>
284
+
285
+ <Box sx={{marginTop:2}}>
286
+ <Box sx={{ minWidth: 120 }}>
287
+ <FormControl fullWidth>
288
+ <InputLabel id="demo-simple-select-label">Document Type</InputLabel>
289
+ <Select
290
+ labelId="demo-simple-select-label"
291
+ id="demo-simple-select"
292
+ inputRef={refSelectDocumentType}
293
+ onChange={(val) => {
294
+
295
+ var _selectedDocument = componentTypes.find(s => s.id == val.target.value);
296
+ setSelectedDocument(_selectedDocument);
297
+
298
+ }}
299
+ label="DocumentType">
300
+
301
+ {componentTypes != null && componentTypes.map((componentType) => {
302
+ return (<MenuItem value={componentType.id}>{componentType.name}</MenuItem>)
303
+ })}
304
+
305
+ </Select>
306
+ </FormControl>
307
+ </Box>
308
+ </Box>
309
+
310
+ {(selectedDocument != null) &&
311
+
312
+ <Box sx={{textAlign:"center", width:"100%", display:"flex", alignItems:"center", paddingTop:2}}>
313
+ <FileUploader refOveride={fileUploaderRef} params={{
314
+
315
+ documentTypeId: selectedDocument.id,
316
+ companyId: companyId
317
+
318
+ }} url={"/DocumentMapping/SyncDocument"} multiple={true} variant='custom' onUploadCompleted={(responses) => {
319
+
320
+ if (responses.length > 0)
321
+ {
322
+ let row = responses[0].data;
323
+
324
+ if (onManageField != null)
325
+ {
326
+ onManageField(row.id);
327
+ }
328
+ }
329
+
330
+ setShowAddNewDocument(false);
331
+
332
+ }}>
333
+
334
+ <Box sx={{display:"flex", alignItems:"center"}}>
335
+ <Box htmlFor="file-upload" sx={{border:"2px dashed #aaa", padding: 20, textAlign:"center", cursor:"pointer"}}>
336
+ {'Choose a file'}
337
+ </Box>
338
+ </Box>
339
+ </FileUploader>
340
+ </Box>
341
+ }
342
+
343
+ </DialogContent>
344
+ <DialogActions>
345
+ <Button onClick={() => {
346
+ setShowAddNewDocument(false);
347
+ }}>Cancel</Button>
348
+ </DialogActions>
349
+ </Dialog>
350
+
351
+ <Dialog
352
+ open={showTrainingDocument}
353
+ onClose={() => {
354
+ setShowTrainingDocument(false);
355
+ }}
356
+ fullWidth={true}
357
+ aria-labelledby="alert-dialog-title"
358
+ aria-describedby="alert-dialog-description">
359
+ <DialogTitle id="alert-dialog-title">Setup Mapping</DialogTitle>
360
+ <DialogContent>
361
+
362
+ <DialogContentText id="alert-dialog-description">
363
+ If you'd like to submit a file, we can assist in configuring the fields to match the formatting of your document.
364
+ </DialogContentText>
365
+
366
+ {document != null &&
367
+ <>
368
+ <FileUploader refOveride={fileUploaderRef} url={"/DocumentMapping/TrainDocument"} params={{
369
+ documentComponentId: document.id,
370
+ companyId: companyId,
371
+ locationId: locationId,
372
+ userId: userId
373
+ }} multiple={false} variant='custom' onUploadCompleted={() => {
374
+
375
+ setDataGridMappingRefreshKey(dataGridMappingRefreshKey + 1);
376
+
377
+ // setUpdate(!update);
378
+ // handleClose();
379
+ }}>
380
+ <Box sx={{marginTop:2, borderRadius: 2, backgroundColor: "#f5f5f5", border:"1px solid lightgray", cursor:"pointer", padding:2}}>
381
+ <Button
382
+ id="FileUploader"
383
+ aria-controls={open ? 'demo-customized-menu' : undefined}
384
+ aria-haspopup="true"
385
+ aria-expanded={open ? 'true' : undefined}
386
+ variant="text"
387
+ disableElevation
388
+ startIcon={<PublishRoundedIcon />}
389
+ sx={{marginLeft:1}}>
390
+ Upload Sample File
391
+ </Button>
392
+ </Box>
393
+ </FileUploader>
394
+ </>
395
+ }
396
+
397
+ </DialogContent>
398
+ <DialogActions>
399
+ <Button onClick={() => {
400
+ setShowTrainingDocument(false);
401
+ }}>No, thank you</Button>
402
+ </DialogActions>
403
+ </Dialog>
404
+
405
+ <Dialog
406
+ open={addColumnDialog}
407
+ onClose={() => {
408
+ setAddColumnDialog(false);
409
+ }}
410
+ fullWidth={true}
411
+ aria-labelledby="alert-dialog-title"
412
+ aria-describedby="alert-dialog-description">
413
+ <DialogTitle id="alert-dialog-title">Add Column</DialogTitle>
414
+ <DialogContent>
415
+ <DialogContentText id="alert-dialog-description">
416
+ Include a column for document mapping
417
+ </DialogContentText>
418
+
419
+ <Box sx={{marginTop:2}}>
420
+ <TextField inputRef={refNewColumnFileColumn} id="outlined-basic" label="File Column" fullWidth={true} variant="outlined" />
421
+ </Box>
422
+
423
+ <Box sx={{marginTop:4}}>
424
+ <FormControl fullWidth>
425
+ <InputLabel id="demo-simple-select-label">Column Name</InputLabel>
426
+ <Select
427
+ labelId="demo-simple-select-label"
428
+ id="demo-simple-select"
429
+ value={selectedAddedColumn}
430
+ label="Column Name"
431
+ onChange={(data) => {
432
+ setSelectedAddedColumn(data.target.value);
433
+ }}>
434
+ {/* {toColumnOptions != null && toColumnOptions.map((column) => {
435
+ return (
436
+ <MenuItem value={column}>{column}</MenuItem>
437
+ )
438
+ })} */}
439
+
440
+ </Select>
441
+ </FormControl>
442
+ </Box>
443
+
444
+ </DialogContent>
445
+ <DialogActions>
446
+ <Button onClick={() => {
447
+ setAddColumnDialog(false);
448
+ }}>Cancel</Button>
449
+ <Button onClick={async () => {
450
+
451
+ let response = await apiService().post("/DocumentMapping/AddNewField", {
452
+ tableName: document.name,
453
+ fieldName: refNewColumnFileColumn.current.value,
454
+ fileColumn: selectedAddedColumn,
455
+ companyId: companyId,
456
+ locationId: locationId,
457
+ userId: userId
458
+ });
459
+
460
+ if (response != null && response.status == 200)
461
+ {
462
+ setDataGridMappingRefreshKey(dataGridMappingRefreshKey + 1);
463
+ setAddColumnDialog(false);
464
+ }
465
+
466
+ }} autoFocus>
467
+ Add Column
468
+ </Button>
469
+ </DialogActions>
470
+ </Dialog>
471
+
472
+ <Dialog
473
+ open={removeDocument != null ? true : false}
474
+ onClose={() => {
475
+ setRemoveDocument(null);
476
+ }}
477
+ fullWidth={true}
478
+ aria-labelledby="alert-dialog-title"
479
+ aria-describedby="alert-dialog-description">
480
+ <DialogTitle id="alert-dialog-title">Remove the document</DialogTitle>
481
+ <DialogContent>
482
+ <DialogContentText id="alert-dialog-description">
483
+ Are you sure you want to remove this document?
484
+ </DialogContentText>
485
+ </DialogContent>
486
+ <DialogActions>
487
+ <Button onClick={() => {
488
+ setRemoveDocument(null);
489
+ }}>Cancel</Button>
490
+ <Button onClick={async () => {
491
+
492
+ let response = null;
493
+ if (companyId != null)
494
+ {
495
+ response = await apiService().delete("/DocumentMapping/RemoveDocument?companyId=" + removeDocument.companyId + "&documentId=" + removeDocument.documentMappingId)
496
+ }
497
+ else
498
+ {
499
+ response = await apiService().delete("/DocumentMapping/RemoveDocument?documentId=" + removeDocument.documentMappingId)
500
+ }
501
+
502
+ if (response != null && response.status == 200)
503
+ {
504
+ setDataGridRefreshKey(dataGridRefreshKey + 1);
505
+ setRemoveDocument(null);
506
+
507
+ if (onArchive != null)
508
+ {
509
+ onArchive(removeDocument.documentMappingId);
510
+ }
511
+ }
512
+
513
+ }}>
514
+ Remove Document
515
+ </Button>
516
+ </DialogActions>
517
+ </Dialog>
518
+
519
+ </Box>
520
+ )
521
+ }
@@ -0,0 +1,70 @@
1
+ import React, {useEffect, useState, useRef} from 'react';
2
+ import Card from '@mui/material/Card';
3
+ import CardActions from '@mui/material/CardActions';
4
+ import CardContent from '@mui/material/CardContent';
5
+ import { Box } from '@mui/system';
6
+ import Button from '@mui/material/Button';
7
+ import Typography from '@mui/material/Typography';
8
+ // import NewMappingColumn from './newMappingColumn';
9
+ import LinkIcon from '@mui/icons-material/Link';
10
+ import LinkOffIcon from '@mui/icons-material/LinkOff';
11
+ import Stack from '@mui/material/Stack';
12
+ // import MatchExistingMappedColumn from './matchExisting';
13
+ // import { apiService } from 'authscape';
14
+
15
+ export default function MappedColumn({companyId, documentId, documentType, documentMappingId, name, toName, isMapped, toOptions, onResponse}) {
16
+
17
+ const notMatchedColor = "#ffe5e5";
18
+ const matchedColor = "#fff";
19
+
20
+ return (
21
+ <Card sx={{marginTop:1}}>
22
+ <CardContent sx={{position:"relative", backgroundColor: isMapped ? notMatchedColor : matchedColor}}>
23
+ <Typography gutterBottom variant="h5" component="div">
24
+ {name}
25
+ </Typography>
26
+ <Box sx={{position:"absolute", top:"10px", right:"10px"}}>
27
+ {isMapped ?
28
+ <Stack direction="row" spacing={1}>
29
+ <LinkOffIcon />
30
+ <Typography variant="body2" sx={{paddingTop:0.5}}>Not Matched</Typography>
31
+ </Stack> :
32
+ <Stack direction="row" spacing={1}>
33
+ <LinkIcon />
34
+ <Typography variant="body2" sx={{paddingTop:0.5}}>Matched</Typography>
35
+ </Stack>
36
+ }
37
+ </Box>
38
+ <Typography variant="body2" color="text.secondary">
39
+ {!isMapped && <>This column is matched</>}
40
+ {isMapped && <>This column is not matched. If not matched it will not import</>}
41
+
42
+ </Typography>
43
+ </CardContent>
44
+ <CardActions sx={{backgroundColor: isMapped ? notMatchedColor : matchedColor}}>
45
+ {!isMapped ?
46
+ <>
47
+ <Button startIcon={<LinkOffIcon />} size="small" sx={{paddingLeft:3}} onClick={async () => {
48
+
49
+ let response = await apiService().delete(
50
+ "/DocumentMapping/RemoveMatch?companyId=" + companyId +
51
+ "&documentId=" + documentId +
52
+ "&documentMappingId=" + documentMappingId);
53
+
54
+ if (response != null && response.status == 200)
55
+ {
56
+ onResponse();
57
+ }
58
+
59
+ }}>Remove Match</Button>
60
+ </>
61
+ :
62
+ <>
63
+ <MatchExistingMappedColumn companyId={companyId} documentId={documentId} documentMappingId={documentMappingId} fromName={name} toOptions={toOptions} onResponse={onResponse} />
64
+ <NewMappingColumn name={name} companyId={companyId} documentType={documentType} documentId={documentId} documentMappingId={documentMappingId} onResponse={onResponse} />
65
+ </>
66
+ }
67
+ </CardActions>
68
+ </Card>
69
+ );
70
+ }