Skip to content

Commit

Permalink
feat: update public view
Browse files Browse the repository at this point in the history
  • Loading branch information
MaGOs92 committed Oct 19, 2023
1 parent 875f84a commit 74c8ce7
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 239 deletions.
28 changes: 0 additions & 28 deletions components/bal/commune-tab.js

This file was deleted.

31 changes: 31 additions & 0 deletions components/bal/commune-tab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, {useContext} from 'react'
import {Pane} from 'evergreen-ui'

import BalDataContext from '@/contexts/bal-data'
import TokenContext from '@/contexts/token'

import CertificationInfos from './certification-infos'
import HabilitationInfos from './habilitation-infos'
import ReadOnlyInfos from './read-only-infos'
import {CommmuneType} from '@/types/commune'

interface CommuneTabProps {
commune: CommmuneType;
openRecoveryDialog: () => void;
}

function CommuneTab({commune, openRecoveryDialog}: CommuneTabProps) {
const {baseLocale} = useContext(BalDataContext)
const {token} = useContext(TokenContext)

return (
<Pane overflowY='auto'>
{!token && <ReadOnlyInfos openRecoveryDialog={openRecoveryDialog} />}
{token && baseLocale.status !== 'demo' && <HabilitationInfos commune={commune} />}
<CertificationInfos />
</Pane>
)
}

export default CommuneTab

35 changes: 35 additions & 0 deletions components/bal/read-only-infos.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react'
import {Pane, Alert, Text, Button} from 'evergreen-ui'

interface BALReadOnlyProps {
openRecoveryDialog: () => void;
}

function BALReadOnly({openRecoveryDialog}: BALReadOnlyProps) {
return (
<Pane
backgroundColor='white'
padding={8}
borderRadius={10}
margin={8}
>
<Alert
intent='warning'
title='Vous êtes en mode consultation'
marginBottom={15}
>
<Text is='p'>
Vous ne pouvez pas modifier cette Base Adresse Locale car vous n’êtes pas authentifié comme administrateur.
</Text>
<Text is='p'>
Si vous êtes administrateur de cette Base Adresse Locale, vous pouvez récupérer vos accès en cliquant sur le bouton ci-dessous.
</Text>
<Button appearance='primary' onClick={openRecoveryDialog}>
Récupérer mes accès
</Button>
</Alert>
</Pane>
)
}

export default BALReadOnly
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {useContext, useMemo, useState} from 'react'
import PropTypes from 'prop-types'
import {sortBy} from 'lodash'
import {Table, Paragraph, Pane} from 'evergreen-ui'
import {useRouter} from 'next/router'
Expand All @@ -16,8 +15,18 @@ import TableRow from '@/components/table-row'
import DeleteWarning from '@/components/delete-warning'
import InfiniteScrollList from '@/components/infinite-scroll-list'
import CommentsContent from '@/components/comments-content'
import {ToponymeType} from '@/types/toponyme'

function ToponymesList({toponymes, onEnableEditing, onRemove, balId, addButton}) {
interface ToponymesListProps {
toponymes: ToponymeType[];
onRemove: () => Promise<void>;
onEnableEditing: (id: string) => void;
balId: string;
addButton: React.ReactNode;
openRecoveryDialog: () => void;
}

function ToponymesList({toponymes, onEnableEditing, onRemove, balId, addButton, openRecoveryDialog}: ToponymesListProps) {
const {token} = useContext(TokenContext)
const [toRemove, setToRemove] = useState(null)
const [isDisabled, setIsDisabled] = useState(false)
Expand All @@ -33,8 +42,8 @@ function ToponymesList({toponymes, onEnableEditing, onRemove, balId, addButton})
setIsDisabled(false)
}

const onSelect = id => {
router.push(`/bal/${balId}/toponymes/${id}`)
const onSelect = (id: string) => {
void router.push(`/bal/${balId}/toponymes/${id}`)
}

const [filtered, setFilter] = useFuse(toponymes, 200, {
Expand All @@ -57,7 +66,9 @@ function ToponymesList({toponymes, onEnableEditing, onRemove, balId, addButton})
</Paragraph>
)}
isDisabled={isDisabled}
onCancel={() => setToRemove(null)}
onCancel={() => {
setToRemove(null)
}}
onConfirm={handleRemove}
/>
<Pane
Expand Down Expand Up @@ -88,22 +99,30 @@ function ToponymesList({toponymes, onEnableEditing, onRemove, balId, addButton})
)}

<InfiniteScrollList items={scrollableItems}>
{toponyme => (
{(toponyme: ToponymeType) => (
<TableRow
key={toponyme._id}
label={toponyme.nom}
nomAlt={toponyme.nomAlt}
isEditingEnabled={Boolean(!isEditing && token)}
isAdmin={Boolean(token)}
isEditing={Boolean(isEditing)}
notifications={{
warning: toponyme.positions.length === 0 ? 'Ce toponyme n’a pas de position' : null,
comment: toponyme.commentedNumeros.length > 0 ? <CommentsContent comments={toponyme.commentedNumeros} /> : null,
certification: toponyme.isAllCertified ? 'Toutes les adresses de ce toponyme sont certifiées par la commune' : null
}}
actions={{
onSelect: () => onSelect(toponyme._id),
onEdit: () => onEnableEditing(toponyme._id),
onRemove: () => setToRemove(toponyme._id)
onSelect: () => {
onSelect(toponyme._id)
},
onEdit: () => {
onEnableEditing(toponyme._id)
},
onRemove: () => {
setToRemove(toponyme._id)
}
}}
openRecoveryDialog={openRecoveryDialog}
/>
)}
</InfiniteScrollList>
Expand All @@ -112,12 +131,4 @@ function ToponymesList({toponymes, onEnableEditing, onRemove, balId, addButton})
)
}

ToponymesList.propTypes = {
toponymes: PropTypes.array.isRequired,
onRemove: PropTypes.func,
onEnableEditing: PropTypes.func.isRequired,
balId: PropTypes.string.isRequired,
addButton: PropTypes.object
}

export default ToponymesList
45 changes: 34 additions & 11 deletions components/bal/voies-list.js → components/bal/voies-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ import CommentsContent from '@/components/comments-content'
import DeleteWarning from '@/components/delete-warning'

import InfiniteScrollList from '../infinite-scroll-list'
import {VoieType} from '@/types/voie'

function VoiesList({voies, onEnableEditing, setToConvert, balId, onRemove, addButton}) {
interface VoiesListProps {
voies: VoieType[];
onRemove: () => Promise<void>;
onEnableEditing: (id: string) => void;
balId: string;
setToConvert: (id: string) => void;
addButton: React.ReactNode;
openRecoveryDialog: () => void;
}

function VoiesList({voies, onEnableEditing, setToConvert, balId, onRemove, addButton, openRecoveryDialog}: VoiesListProps) {
const {token} = useContext(TokenContext)
const [toRemove, setToRemove] = useState(null)
const {isEditing, reloadVoies} = useContext(BalDataContext)
Expand All @@ -34,8 +45,8 @@ function VoiesList({voies, onEnableEditing, setToConvert, balId, onRemove, addBu
setIsDisabled(false)
}

const onSelect = id => {
router.push(`/bal/${balId}/voies/${id}`)
const onSelect = (id: string) => {
void router.push(`/bal/${balId}/voies/${id}`)
}

const [filtered, setFilter] = useFuse(voies, 200, {
Expand All @@ -57,7 +68,9 @@ function VoiesList({voies, onEnableEditing, setToConvert, balId, onRemove, addBu
Êtes vous bien sûr de vouloir supprimer cette voie ainsi que tous ses numéros ?
</Paragraph>
)}
onCancel={() => setToRemove(null)}
onCancel={() => {
setToRemove(null)
}}
onConfirm={handleRemove}
isDisabled={isDisabled}
/>
Expand Down Expand Up @@ -89,27 +102,37 @@ function VoiesList({voies, onEnableEditing, setToConvert, balId, onRemove, addBu
)}

<InfiniteScrollList items={scrollableItems}>
{voie => (
{(voie: VoieType) => (
<TableRow
key={voie._id}
label={voie.nom}
nomAlt={voie.nomAlt}
isEditingEnabled={Boolean(!isEditing && token)}
isAdmin={Boolean(token)}
isEditing={Boolean(isEditing)}
actions={{
onSelect: () => onSelect(voie._id),
onEdit: () => onEnableEditing(voie._id),
onRemove: () => setToRemove(voie._id),
onSelect: () => {
onSelect(voie._id)
},
onEdit: () => {
onEnableEditing(voie._id)
},
onRemove: () => {
setToRemove(voie._id)
},
extra: voie.nbNumeros === 0 ? {
callback: () => setToConvert(voie._id),
callback: () => {
setToConvert(voie._id)
},
icon: KeyTabIcon,
text: 'Convertir en toponyme',
text: 'Convertir en toponyme'
} : null
}}
notifications={{
certification: voie.isAllCertified ? 'Toutes les adresses de cette voie sont certifiées par la commune' : null,
comment: voie.commentedNumeros.length > 0 ? <CommentsContent comments={voie.commentedNumeros} /> : null,
warning: voie.nbNumeros === 0 ? 'Cette voie ne contient aucun numéro' : null
}}
openRecoveryDialog={openRecoveryDialog}
/>
)}
</InfiniteScrollList>
Expand Down
24 changes: 9 additions & 15 deletions components/delete-warning.js → components/delete-warning.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import PropTypes from 'prop-types'
import {Pane, Dialog} from 'evergreen-ui'

function DeleteWarning({isShown, content, onCancel, onConfirm, isDisabled}) {
interface DeleteWarningProps {
isShown: boolean;
content: React.ReactNode;
onCancel: () => void;
onConfirm: () => void;
isDisabled?: boolean;
}

function DeleteWarning({isShown, content, onCancel, onConfirm, isDisabled}: DeleteWarningProps) {
return (
<Pane>
<Dialog
Expand All @@ -22,17 +29,4 @@ function DeleteWarning({isShown, content, onCancel, onConfirm, isDisabled}) {
)
}

DeleteWarning.propTypes = {
isShown: PropTypes.bool,
content: PropTypes.node.isRequired,
onCancel: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
isDisabled: PropTypes.bool
}

DeleteWarning.defaultProps = {
isShown: false,
isDisabled: false
}

export default DeleteWarning
19 changes: 2 additions & 17 deletions components/sub-header/bal-status/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types'
import {Pane, Tooltip, Button, Position, EditIcon} from 'evergreen-ui'
import {Pane} from 'evergreen-ui'

import {pauseSync, resumeSync} from '@/lib/bal-api'

Expand Down Expand Up @@ -29,7 +29,7 @@ function BALStatus({baseLocale, commune, token, isHabilitationValid, isRefrehSyn
)}
</Pane>

{token ? (
{token && (
baseLocale.sync && isHabilitationValid ? (
<BANSync
baseLocale={baseLocale}
Expand All @@ -47,21 +47,6 @@ function BALStatus({baseLocale, commune, token, isHabilitationValid, isRefrehSyn
/>
)
)
) : (
<Tooltip
content='Vous n’êtes pas identifié comme administrateur de cette base adresse locale, vous ne pouvez donc pas l’éditer.'
position={Position.BOTTOM_RIGHT}
>
<Button
height={24}
marginRight={8}
appearance='primary'
intent='danger'
iconBefore={EditIcon}
>
Édition impossible
</Button>
</Tooltip>
)}
</>
)
Expand Down
Loading

0 comments on commit 74c8ce7

Please sign in to comment.