Skip to content

Commit

Permalink
feat: Add onClose props on Contact and Information Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Dec 18, 2024
1 parent f353159 commit db5078c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
20 changes: 14 additions & 6 deletions src/components/Views/ContactEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const useStyles = makeStyles({
}
})

const ContactEdit = () => {
const ContactEdit = ({ onClose }) => {
const { fileId } = useParams()
const navigate = useNavigate()
const client = useClient()
Expand All @@ -32,8 +32,12 @@ const ContactEdit = () => {
])
const [isBusy, setIsBusy] = useState(false)

const onClose = () => {
navigate('..')
const _onClose = () => {
if (onClose) {
onClose()
} else {
navigate('..')
}
}

const onConfirm = async contactSelected => {
Expand Down Expand Up @@ -71,12 +75,16 @@ const ContactEdit = () => {
severity: 'success',
variant: 'filled'
})
onClose()
_onClose()
}
const isLoading = currentEditInformation.isLoading || isLoadingContacts

if (!isLoading && !currentEditInformation.file) {
return <Navigate to=".." />
if (onClose) {
onClose()
} else {
return <Navigate to=".." />
}
}

return isLoading ? (
Expand All @@ -88,7 +96,7 @@ const ContactEdit = () => {
contacts={contacts}
currentEditInformation={currentEditInformation}
onConfirm={onConfirm}
onClose={onClose}
onClose={_onClose}
isBusy={isBusy}
/>
)
Expand Down
20 changes: 14 additions & 6 deletions src/components/Views/InformationEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

const InformationEdit = () => {
const InformationEdit = ({ onClose }) => {
const { fileId } = useParams()
const client = useClient()
const { t } = useI18n()
Expand Down Expand Up @@ -59,8 +59,12 @@ const InformationEdit = () => {
? scannerT(`items.${currentEditInformations.paperDef.label}`)
: ''

const onClose = () => {
navigate('..')
const _onClose = () => {
if (onClose) {
onClose()
} else {
navigate('..')
}
}

const onConfirm = async () => {
Expand Down Expand Up @@ -93,14 +97,18 @@ const InformationEdit = () => {
variant: 'filled'
})

navigate('..')
_onClose()
}

if (
!currentEditInformations.isLoading &&
!isInformationEditPermitted(currentEditInformations)
) {
return <Navigate to=".." />
if (onClose) {
onClose()
} else {
return <Navigate to=".." />
}
}

const fallbackIcon =
Expand All @@ -115,7 +123,7 @@ const InformationEdit = () => {
return (
<FixedDialog
open
onClose={onClose}
onClose={_onClose}
title={dialogTitle}
content={
<div
Expand Down

0 comments on commit db5078c

Please sign in to comment.