@@ -2,7 +2,12 @@ import React, { FC, useState } from 'react'
22import { useNavigate } from 'react-router-dom'
33
44import { useClient } from 'cozy-client'
5- import { copy } from 'cozy-client/dist/models/file'
5+ import {
6+ copy ,
7+ isDirectory ,
8+ moveRelateToSharedDrive
9+ } from 'cozy-client/dist/models/file'
10+ import { IOCozyFile } from 'cozy-client/types/types'
611import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
712import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
813
@@ -18,13 +23,17 @@ interface DuplicateModalProps {
1823 currentFolder : File
1924 onClose : ( ) => void | Promise < void >
2025 showNextcloudFolder ?: boolean
26+ showSharedDriveFolder ?: boolean
27+ driveId ?: string
2128}
2229
2330const DuplicateModal : FC < DuplicateModalProps > = ( {
2431 entries,
2532 currentFolder,
2633 onClose,
27- showNextcloudFolder
34+ showNextcloudFolder,
35+ showSharedDriveFolder,
36+ driveId
2837} ) => {
2938 const { t } = useI18n ( )
3039 const { showAlert } = useAlert ( )
@@ -39,7 +48,7 @@ const DuplicateModal: FC<DuplicateModalProps> = ({
3948 setBusy ( true )
4049 await Promise . all (
4150 entries . map ( async entry => {
42- await registerCancelable ( copy ( client , entry as Partial < File > , folder ) )
51+ await registerCancelable ( handleCopyApi ( client , entry , folder ) )
4352 } )
4453 )
4554
@@ -73,6 +82,35 @@ const DuplicateModal: FC<DuplicateModalProps> = ({
7382 }
7483 }
7584
85+ const handleCopyApi = async (
86+ client : unknown ,
87+ entry : FolderPickerEntry ,
88+ folder : File
89+ ) : Promise < void > => {
90+ if ( driveId || entry . driveId || ( folder as IOCozyFile ) . driveId ) {
91+ return await moveRelateToSharedDrive (
92+ client ,
93+ {
94+ instance : entry . driveId
95+ ? currentFolder . attributes ?. cozyMetadata ?. createdOn
96+ : '' ,
97+ file_id : ! isDirectory ( entry ) ? entry . _id : '' ,
98+ dir_id : isDirectory ( entry ) ? entry . _id : '' ,
99+ sharing_id : entry . driveId
100+ } ,
101+ {
102+ instance : ( folder as IOCozyFile ) . driveId
103+ ? folder . cozyMetadata ?. createdOn
104+ : '' ,
105+ sharing_id : ( folder as IOCozyFile ) . driveId ,
106+ dir_id : folder . _id
107+ } ,
108+ true
109+ )
110+ }
111+ return await copy ( client , entry , folder )
112+ }
113+
76114 /**
77115 * The content from nextcloud queries must be refreshed when coping files
78116 * This is only a proxy to Nextcloud queries so we don't have real-time or mutations updates
@@ -88,6 +126,7 @@ const DuplicateModal: FC<DuplicateModalProps> = ({
88126 return (
89127 < FolderPicker
90128 showNextcloudFolder = { showNextcloudFolder }
129+ showSharedDriveFolder = { showSharedDriveFolder }
91130 currentFolder = { currentFolder }
92131 entries = { entries }
93132 // eslint-disable-next-line @typescript-eslint/no-misused-promises
0 commit comments