-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mespapiers): Add CategoryItemByKonnector
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
packages/cozy-mespapiers-lib/src/components/Papers/CategoryItemByKonnector.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import { useQuery, isQueryLoading } from 'cozy-client' | ||
import ListItem from 'cozy-ui/transpiled/react/MuiCozyTheme/ListItem' | ||
import ListItemIcon from 'cozy-ui/transpiled/react/MuiCozyTheme/ListItemIcon' | ||
import ListItemText from 'cozy-ui/transpiled/react/ListItemText' | ||
import Divider from 'cozy-ui/transpiled/react/MuiCozyTheme/Divider' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
|
||
import { buildAccountsQueryBySlug } from '../../helpers/queries' | ||
import { useScannerI18n } from '../Hooks/useScannerI18n' | ||
import { addAccountsToKonnectors, makeIsLast } from './helpers' | ||
import styles from './styles.styl' | ||
|
||
const CategoryItemByKonnector = ({ | ||
konnectorsWithAccounts, | ||
konnector, | ||
onClick | ||
}) => { | ||
const scannerT = useScannerI18n() | ||
|
||
const queryAccounts = buildAccountsQueryBySlug(konnector.slug) | ||
const { data: accounts, ...accountsQueryLeft } = useQuery( | ||
queryAccounts.definition, | ||
queryAccounts.options | ||
) | ||
const isLoading = isQueryLoading(accountsQueryLeft) | ||
|
||
if (isLoading) return null | ||
|
||
addAccountsToKonnectors({ | ||
konnectorsWithAccounts, | ||
konnector, | ||
accounts | ||
}) | ||
|
||
if (accounts?.length === 0) { | ||
return null | ||
} | ||
|
||
const isLast = makeIsLast(konnectorsWithAccounts, konnector) | ||
|
||
return ( | ||
<> | ||
<ListItem | ||
button | ||
onClick={() => onClick(konnector.qualification_labels[0])} | ||
> | ||
<ListItemIcon> | ||
<div className={styles['emptyKonnectorIcon']} /> | ||
</ListItemIcon> | ||
<ListItemText | ||
primary={scannerT(`items.${konnector.qualification_labels[0]}`)} | ||
/> | ||
<Icon icon="right" /> | ||
</ListItem> | ||
{!isLast && <Divider variant="inset" component="li" />} | ||
</> | ||
) | ||
} | ||
|
||
CategoryItemByKonnector.propTypes = { | ||
konnectorsWithAccounts: PropTypes.array, | ||
konnector: PropTypes.object, | ||
onClick: PropTypes.func | ||
} | ||
|
||
export default CategoryItemByKonnector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/cozy-mespapiers-lib/src/components/Papers/styles.styl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.emptyKonnectorIcon | ||
border 1px dashed var(--borderMainColor) | ||
border-radius 8px | ||
width 2rem | ||
height 2rem |