Skip to content

Commit

Permalink
feat: Implement new alert
Browse files Browse the repository at this point in the history
remove old api use new api
add new button to go to folder
  • Loading branch information
acezard committed Apr 24, 2024
1 parent b90d6a4 commit 72c797c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@
},
"Move": {
"to": "Move to:",
"go_to_dir": "Open directory",
"action": "Move",
"cancel": "Cancel",
"modalTitle": "Move",
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@
},
"Move": {
"to": "Déplacer vers:",
"go_to_dir": "Ouvrir le dossier",
"action": "Déplacer",
"cancel": "Annuler",
"modalTitle": "Déplacer",
Expand Down
54 changes: 41 additions & 13 deletions src/modules/move/MoveModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { useDisplayedFolder } from 'hooks'
import { CozyFile } from 'models'
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'

import { cancelable, Q, useClient } from 'cozy-client'
import { useSharingContext } from 'cozy-sharing'
import { useBreakpoints } from 'cozy-ui/transpiled/react'
import Button from 'cozy-ui/transpiled/react/Buttons'
import { FixedDialog } from 'cozy-ui/transpiled/react/CozyDialogs'
import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter'
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
import { withStyles } from 'cozy-ui/transpiled/react/styles'

Expand Down Expand Up @@ -53,6 +56,8 @@ const MoveModal = ({ onClose, entries, classes }) => {
byDocId,
allLoaded
} = useSharingContext()
const navigate = useNavigate()
const { showAlert } = useAlert()

const [folderId, setFolderId] = useState(
displayedFolder ? displayedFolder._id : ROOT_DIR_ID
Expand Down Expand Up @@ -146,19 +151,42 @@ const MoveModal = ({ onClose, entries, classes }) => {
client.query(Q('io.cozy.files').getById(folderId))
)
const targetName = response.data?.name || t('breadcrumb.title_drive')
Alerter.info('Move.success', {
subject: entries.length === 1 ? entries[0].name : '',
target: targetName,
smart_count: entries.length,
buttonText: t('Move.cancel'),
buttonAction: () =>
cancelMove({
entries,
trashedFiles,
client,
registerCancelable,
refreshSharing
})
const targetDir = response.data?.id

showAlert({
action: (
<>
<Button
color="success"
label={t('Move.cancel')}
onClick={() =>
cancelMove({
entries,
trashedFiles,
client,
registerCancelable,
refreshSharing
})
}
size="small"
variant="text"
/>

<Button
color="success"
label={t('Move.go_to_dir')}
onClick={() => navigate(`/folder/${targetDir}`)}
size="small"
variant="text"
/>
</>
),
message: t('Move.success', {
smart_count: entries.length,
subject: entries.length === 1 ? entries[0].name : '',
target: targetName
}),
severity: 'success'
})
if (refreshSharing) refreshSharing()
} catch (e) {
Expand Down

0 comments on commit 72c797c

Please sign in to comment.