Skip to content

Commit

Permalink
feat(procu): error, eject, info round (#3024)
Browse files Browse the repository at this point in the history
  • Loading branch information
OverGlass committed Jun 18, 2024
1 parent b095dc3 commit f462896
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ describe('Mandate person card', () => {
}

it('Should expand card', async () => {
const tree = render(<MandatePersonCard {...payload} expended={false} />)
const queryClient = new QueryClient()
const tree = render(
<QueryClientProvider client={queryClient}>
<MandatePersonCard {...payload} expended={false} />
</QueryClientProvider>
)

const moreButton = await tree.findByTestId('moreButton')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from '@emotion/styled'
import { Button, Grid, Paper, Typography } from '@mui/material'
import Divider from '@mui/material/Divider'
import { ReactNode } from 'react'
import { Fragment, ReactNode } from 'react'
import MandateCardEntry from '~/components/Procurations/Components/MandantTab/Components/MandateCardEntry'
import PersonWithAvatar from '~/components/Procurations/Components/PersonWithAvatar/PersonWithAvatar'
import pluralize from '~/components/shared/pluralize/pluralize'
Expand Down Expand Up @@ -96,8 +96,8 @@ export default function MandatePersonCard(props: MandatePersonCardProps) {
</Grid>

{linkedPeople?.map(x => (
<>
<Grid key={x.uuid} item xs={12}>
<Fragment key={x.uuid + props.id}>
<Grid item xs={12}>
<Typography variant="h6" sx={{ mt: MuiSpacing.normal }}>
{x.round.name}
</Typography>
Expand Down Expand Up @@ -139,7 +139,7 @@ export default function MandatePersonCard(props: MandatePersonCardProps) {

{x.proxy.map(el =>
el ? (
<Grid sx={{ mb: MuiSpacing.small }} key={el.uuid}>
<Grid sx={{ mb: MuiSpacing.small }} key={el.uuid + 'proxy'}>
<PersonWithAvatar
firstName={el.first_names}
lastName={el.last_name}
Expand Down Expand Up @@ -172,7 +172,7 @@ export default function MandatePersonCard(props: MandatePersonCardProps) {
<Grid item xs={12}>
<Divider sx={{ mt: MuiSpacing.normal }} />
</Grid>
</>
</Fragment>
))}
</Grid>

Expand All @@ -191,6 +191,7 @@ export default function MandatePersonCard(props: MandatePersonCardProps) {

{props.extraInfos && <Divider sx={withBottomSpacing} />}

{!props.hideStateActions && <MandatePersonCardStateActions {...props} />}
{!props.expended && props.onExpend && <ExpandButton onExpand={() => props.onExpend?.(props.id)} />}

{props.expended && (
Expand All @@ -199,8 +200,6 @@ export default function MandatePersonCard(props: MandatePersonCardProps) {

{props.onNarrow && <Divider sx={withBottomSpacing} />}

{!props.hideStateActions && <MandatePersonCardStateActions {...props} />}

{props.onNarrow && <NarrowButton onNarrow={() => props.onNarrow?.(props.id)} />}
</>
)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Procurations/Pages/MandateEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default function MandateEditPage() {
<Paper sx={{ p: MuiSpacing.normal }}>
<Grid container>
<Grid container sx={{ mb: MuiSpacing.small }} spacing={MuiSpacing.normal}>
<InfoLine label={'Tour'} value={slot?.round.name}></InfoLine>
<InfoLine label={'Bureau de vote'} value={data?.vote_place_name}></InfoLine>
<InfoLine
label={'Date de l’association'}
Expand Down
9 changes: 6 additions & 3 deletions src/components/shared/error/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useCustomSnackbar } from '../notification/hooks'
import { getFormattedErrorMessages, handleGenericHttpErrors } from './helpers'
import * as Sentry from '@sentry/react'

const hasErrorDetail = x => typeof x === 'object' && x !== null && 'detail' in x

export const useErrorHandler = () => {
const [errorMessages, setErrorMessages] = useState([])
const [errorRawMessage, setErrorRawMessage] = useState(null)
Expand All @@ -20,12 +22,13 @@ export const useErrorHandler = () => {

const handleError = useCallback(
error => {
const { response = { data: {} }, stack, message } = error
const { response = { data }, stack, message } = error
const { status, data } = response
handleGenericHttpErrors(snackBarWithOptions, status, stack, message)
const errorMessage = hasErrorDetail(data) ? data.detail : message
handleGenericHttpErrors(snackBarWithOptions, status, stack, errorMessage)
const formattedErrorMessages = getFormattedErrorMessages(data)
setErrorMessages(formattedErrorMessages)
setErrorRawMessage(message)
setErrorRawMessage(errorMessage)
Sentry.addBreadcrumb({
category: 'request',
message: Object.keys(data).length ? JSON.stringify(data) : message,
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/notification/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useCustomSnackbar = () => {
(message, variant = notifyVariants.success, detail = null, options = {}) => {
const key = uuid()
const content = (key, message) => (
<UISnackBar id={key} message={message} variant={variant}>
<UISnackBar id={key} message={message} variant={variant} expend>
{detail}
</UISnackBar>
)
Expand Down
6 changes: 4 additions & 2 deletions src/ui/SnackBar/SnackBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const Content = styled(
`
)

const UISnackBar = forwardRef(({ id, message, variant, dismissResolve, children }, ref) => {
const [expanded, setExpanded] = useState(false)
const UISnackBar = forwardRef(({ id, message, variant, dismissResolve, expend = false, children }, ref) => {
const [expanded, setExpanded] = useState(expend)
const { closeSnackbar } = useCustomSnackbar()

const handleExpandToggle = useCallback(() => {
Expand Down Expand Up @@ -100,13 +100,15 @@ UISnackBar.defaultProps = {
content: null,
dismissResolve: null,
children: null,
expend: false,
}
UISnackBar.propTypes = {
id: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
variant: PropTypes.string.isRequired,
children: PropTypes.node,
dismissResolve: PropTypes.func,
expend: PropTypes.bool,
}

export default UISnackBar

0 comments on commit f462896

Please sign in to comment.