@@ -2,46 +2,47 @@ import {
2
2
formatDate ,
3
3
DATE_FORMAT_MEDIUM_WITH_TIME ,
4
4
} from '../../../utils/date-utils'
5
+ import { DOCUMENT_TYPES } from './constants'
5
6
6
- export const transformArchivedToApi = ( archived ) =>
7
- archived ?. length === 1 ? archived [ 0 ] === 'true' : undefined
8
-
9
- export const transformContactToListItem = ( ) => ( file ) => {
7
+ export const transformFileToListItem = ( ) => ( file ) => {
10
8
let title = ''
11
9
const links = [ ]
12
10
let summaryRows = [ ]
13
11
14
12
// Check if document type is SharePoint-related
15
- if ( file . document_type === 'documents.sharepointdocument' ) {
16
- title = 'SharePoint link'
17
- if ( file . document . title ) {
18
- title += ` - ${ file . document . title } `
19
- }
13
+ switch ( file . document_type ) {
14
+ case DOCUMENT_TYPES . SHAREPOINT :
15
+ title = 'SharePoint link'
16
+ if ( file . document . title ) {
17
+ title += ` - ${ file . document . title } `
18
+ }
20
19
21
- // Add links
22
- links . push (
23
- {
24
- text : 'View file (opens in new tab)' ,
25
- url : file . document . url ,
26
- attrs : { target : '_blank' , rel : 'noopener noreferrer' } ,
27
- } ,
28
- { text : 'Delete' , url : '#' }
29
- )
20
+ // Add links
21
+ links . push (
22
+ {
23
+ text : 'View file (opens in new tab)' ,
24
+ url : file . document . url ,
25
+ attrs : { target : '_blank' , rel : 'noopener noreferrer' } ,
26
+ } ,
27
+ { text : 'Delete' , url : '#' }
28
+ // TODO: Handle that when delete is clicked you go to the delete flow.
29
+ )
30
30
31
- // Add summary rows
32
- summaryRows = [
33
- {
34
- label : 'Date added' ,
35
- value : formatDate (
36
- file . document . created_on ,
37
- DATE_FORMAT_MEDIUM_WITH_TIME
38
- ) ,
39
- } ,
40
- { label : 'Added by' , value : file . created_by . name } ,
41
- { label : 'SharePoint url' , value : file . document . url } ,
42
- ]
43
- } else {
31
+ // Add summary rows
32
+ summaryRows = [
33
+ {
34
+ label : 'Date added' ,
35
+ value : formatDate (
36
+ file . document . created_on ,
37
+ DATE_FORMAT_MEDIUM_WITH_TIME
38
+ ) ,
39
+ } ,
40
+ { label : 'Added by' , value : file . created_by . name } ,
41
+ { label : 'SharePoint url' , value : file . document . url } ,
42
+ ]
43
+ case DOCUMENT_TYPES . FILE_UPLOAD :
44
44
// TODO: Handle flow for uploaded files.
45
+ default :
45
46
}
46
47
47
48
return {
@@ -53,9 +54,9 @@ export const transformContactToListItem = () => (file) => {
53
54
}
54
55
55
56
export const transformResponseToCollection = (
56
- companyId ,
57
+ file ,
57
58
{ count, results = [ ] }
58
59
) => ( {
59
60
count,
60
- results : results . map ( transformContactToListItem ( companyId ) ) ,
61
+ results : results . map ( transformFileToListItem ( file ) ) ,
61
62
} )
0 commit comments