Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add signalement client authentification #919

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ NEXT_PUBLIC_MATOMO_SITE_ID=
NEXT_PUBLIC_MATOMO_TRACKER_URL=https://stats.beta.gouv.fr/
NEXT_PUBLIC_BAL_ADMIN_URL=
NEXT_PUBLIC_API_SIGNALEMENT=
PORT=3000
PORT=3000
SIGNALEMENT_CLIENT_TOKEN=
29 changes: 6 additions & 23 deletions components/bal/address-preview.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
import { Pane, Text } from "evergreen-ui";

import { computeCompletNumero } from "@/lib/utils/numero";
import { CommuneType } from "@/types/commune";

const getAddressPreview = (numero, suffixe, toponyme, voie, commune) => {
const completNumero = computeCompletNumero(numero, suffixe) || "";
if (toponyme) {
return `${completNumero} ${voie}, ${toponyme} - ${commune.nom} (${commune.code})`;
}

if (voie) {
return `${completNumero} ${voie} - ${commune.nom} (${commune.code})`;
}

if (!voie && !toponyme) {
return `${completNumero} - ${commune.nom} (${commune.code})`;
}

return `${completNumero} ${voie} - ${commune.nom} (${commune.code})`;
};
import { getAddressPreview } from "@/lib/utils/address";

interface AddressPreviewProps {
numero: string | number;
suffixe?: string;
selectedNomToponyme: string;
voie: string;
commune: CommuneType;
selectedNomToponyme?: string;
voie?: string;
commune?: CommuneType;
}

function AddressPreview({
Expand All @@ -38,9 +21,9 @@ function AddressPreview({
const address = getAddressPreview(
numero,
suffixe,
commune,
selectedNomToponyme,
voie,
commune
voie
);

return (
Expand Down
5 changes: 2 additions & 3 deletions components/bal/habilitation-infos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ function HabilitationInfos({ commune }: HabilitationInfosProps) {
}
>
<Text marginTop={5} is="p">
Cette Base Adresse Locale détient une habilitation permettant
d&apos;alimenter la Base Adresse Nationale pour la commune de{" "}
{commune.nom}. Cette habilitation est valide jusqu&apos;au{" "}
Toutes les modifications remonteront automatiquement dans la Base
Adresse Nationale jusqu&apos;au{" "}
<b>{format(new Date(habilitation.expiresAt), "dd/MM/yyyy")}</b>.
</Text>
</Alert>
Expand Down
6 changes: 3 additions & 3 deletions components/bal/numero-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
refreshBALSync,
reloadVoies,
} = useContext(BalDataContext);
const { selectedParcelles } = useContext(ParcellesContext);
const { highlightedParcelles } = useContext(ParcellesContext);
const { markers, suggestedNumero, setCompleteNumero } =
useContext(MarkersContext);
const { reloadTiles } = useContext(MapContext);
Expand Down Expand Up @@ -116,7 +116,7 @@
numero: Number(numero),
suffixe: suffixe?.length > 0 ? suffixe.toLowerCase().trim() : null,
comment: comment.length > 0 ? comment : null,
parcelles: selectedParcelles,
parcelles: highlightedParcelles,
certifie: certifie ?? (initialValue?.certifie || false),
};

Expand All @@ -143,7 +143,7 @@
certifie,
toponymeId,
comment,
selectedParcelles,
highlightedParcelles,
]);

const onFormSubmit = useCallback(
Expand Down Expand Up @@ -262,14 +262,14 @@
if (onVoieChanged) {
onVoieChanged();
}
}, []);

Check warning on line 265 in components/bal/numero-editor.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

React Hook useCallback has a missing dependency: 'onVoieChanged'. Either include it or remove the dependency array. If 'onVoieChanged' changes too often, find the parent component that defines it and wrap that definition in useCallback

const handleNomVoieChange = useCallback((nomVoie) => {
onNomVoieChange(nomVoie);
if (onVoieChanged) {
onVoieChanged();
}
}, []);

Check warning on line 272 in components/bal/numero-editor.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

React Hook useCallback has a missing dependency: 'onVoieChanged'. Either include it or remove the dependency array. If 'onVoieChanged' changes too often, find the parent component that defines it and wrap that definition in useCallback

useEffect(() => {
let nom = null;
Expand Down
16 changes: 10 additions & 6 deletions components/bal/numero-editor/select-parcelles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function SelectParcelles({
const { isCadastreDisplayed, setIsCadastreDisplayed } =
useContext(MapContext);
const {
selectedParcelles,
setSelectedParcelles,
highlightedParcelles,
setHighlightedParcelles,
setIsParcelleSelectionEnabled,
hoveredParcelle,
handleHoveredParcelle,
Expand All @@ -36,23 +36,27 @@ function SelectParcelles({
const addressType = isToponyme ? "toponyme" : "numéro";

useEffect(() => {
setSelectedParcelles(initialParcelles);
setHighlightedParcelles(initialParcelles);
setIsParcelleSelectionEnabled(true);

return () => {
setIsParcelleSelectionEnabled(false);
};
}, []);
}, [
setHighlightedParcelles,
setIsParcelleSelectionEnabled,
initialParcelles,
]);

return (
<Pane display="flex" flexDirection="column">
<InputLabel
title="Parcelles cadastre"
help={`Depuis la carte, cliquez sur les parcelles que vous souhaitez ajouter au ${addressType}. En précisant les parcelles associées à cette adresse, vous accélérez sa réutilisation par de nombreux services, DDFiP, opérateurs de courrier, de fibre et de GPS.`}
/>
{selectedParcelles.length > 0 ? (
{highlightedParcelles.length > 0 ? (
<Pane display="grid" gridTemplateColumns="1fr 1fr 1fr">
{selectedParcelles.map((parcelle) => {
{highlightedParcelles.map((parcelle) => {
const isHovered = parcelle === hoveredParcelle?.id;

return (
Expand Down
46 changes: 35 additions & 11 deletions components/bal/signalement-infos.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
import React from "react";
import NextLink from "next/link";
import { Pane, Text, Heading, Link } from "evergreen-ui";
import { Pane, Heading, Button, Alert } from "evergreen-ui";
import { Signalement } from "@/lib/openapi-signalement";
import { useRouter } from "next/navigation";

interface SignalementInfosProps {
balId: string;
signalements: Signalement[];
}

function SignalementInfos({ balId, signalements }: SignalementInfosProps) {
const router = useRouter();
const onClick = () => {
router.push(`/bal/${balId}/signalements`);
};

return (
<Pane backgroundColor="white" padding={8} borderRadius={10} margin={8}>
<Pane
display="flex"
flexDirection="column"
backgroundColor="white"
padding={8}
borderRadius={10}
margin={8}
>
<Heading marginBottom={15}>Signalements</Heading>
<Text marginTop={5} is="p">
Vous avez <b>{signalements.length}</b>{" "}
{signalements.length > 1 ? "signalements" : "signalement"} en attente de
traitement.
</Text>
<Link is={NextLink} href={`/bal/${balId}/signalements`}>
Consulter les signalements
</Link>
<Alert
intent="info"
title={
<Pane fontWeight="normal">
Vous avez reçu <b>{signalements.length}</b>{" "}
{signalements.length > 1 ? "propositions" : "proposition"}.
</Pane>
}
>
<Button
marginTop="1rem"
type="button"
onClick={onClick}
width="fit-content"
alignSelf="center"
appearance="primary"
>
Consulter les signalements
</Button>
</Alert>
</Pane>
);
}
Expand Down
6 changes: 3 additions & 3 deletions components/bal/toponyme-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function ToponymeEditor({
reloadParcelles,
} = useContext(BalDataContext);
const { markers } = useContext(MarkersContext);
const { selectedParcelles } = useContext(ParcellesContext);
const { highlightedParcelles } = useContext(ParcellesContext);
const [ref, setIsFocus] = useFocus(true);

const onFormSubmit = useCallback(
Expand All @@ -66,7 +66,7 @@ function ToponymeEditor({
nom,
nomAlt: Object.keys(nomAlt).length > 0 ? nomAlt : null,
positions: [],
parcelles: selectedParcelles,
parcelles: highlightedParcelles,
};

if (markers) {
Expand Down Expand Up @@ -133,7 +133,7 @@ function ToponymeEditor({
nom,
nomAlt,
markers,
selectedParcelles,
highlightedParcelles,
setToponyme,
closeForm,
refreshBALSync,
Expand Down
16 changes: 16 additions & 0 deletions components/base-locale-card/base-locale-card-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface BaseLocaleCardContentProps {
onRemove?: (e: any) => void;
onHide?: (e: any) => void;
isShownHabilitationStatus?: boolean;
pendingSignalementsCount?: number;
}

function BaseLocaleCardContent({
Expand All @@ -50,6 +51,7 @@ function BaseLocaleCardContent({
onSelect,
onRemove,
onHide,
pendingSignalementsCount,
}: BaseLocaleCardContentProps) {
const { status, createdAt, emails } = baseLocale;
const { isMobile } = useContext(LayoutContext);
Expand Down Expand Up @@ -120,6 +122,20 @@ function BaseLocaleCardContent({
</Pane>
)}

{pendingSignalementsCount && (
<Pane
flex={1}
textAlign="center"
margin="auto"
{...(isMobile && { marginBottom: 10 })}
>
<Text display="block">Signalements</Text>
<Text fontWeight="bold" whiteSpace="nowrap">
{pendingSignalementsCount}
</Text>
</Pane>
)}

{commune && (
<Pane
flex={1}
Expand Down
21 changes: 21 additions & 0 deletions components/base-locale-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import { ApiGeoService } from "@/lib/geo-api";
import StatusBadge from "@/components/status-badge";
import BaseLocaleCardContent from "@/components/base-locale-card/base-locale-card-content";
import {
BaseLocale,
ExtendedBaseLocaleDTO,
HabilitationDTO,
HabilitationService,
OpenAPI,
} from "@/lib/openapi";
import { CommuneApiGeoType } from "@/lib/geo-api/type";
import { Signalement, SignalementsService } from "@/lib/openapi-signalement";

const ADRESSE_URL =
process.env.NEXT_PUBLIC_ADRESSE_URL || "https://adresse.data.gouv.fr";
Expand Down Expand Up @@ -52,6 +54,8 @@ function BaseLocaleCard({
const [habilitation, setHabilitation] = useState<HabilitationDTO | null>(
null
);
const [pendingSignalementsCount, setPendingSignalementsCount] =
useState<number>();
const [isHabilitationValid, setIsHabilitationValid] =
useState<boolean>(false);
const [isOpen, setIsOpen] = useState(isAdmin ? isDefaultOpen : false);
Expand Down Expand Up @@ -100,11 +104,27 @@ function BaseLocaleCard({
Object.assign(OpenAPI, { TOKEN: null });
};

const fetchPendingSignalementsCount = async () => {
const paginatedSignalements = await SignalementsService.getSignalements(
[baseLocale.commune],
undefined,
undefined,
[Signalement.status.PENDING]
);
setPendingSignalementsCount(paginatedSignalements.total);
};

void fetchCommune();

if (!baseLocale.token) {
void fetchHabilitationIsValid();
} else {
if (
baseLocale.status === BaseLocale.status.PUBLISHED &&
process.env.NEXT_PUBLIC_API_SIGNALEMENT
) {
void fetchPendingSignalementsCount();
}
void fetchHabilitation();
}
}, [baseLocale]);
Expand Down Expand Up @@ -181,6 +201,7 @@ function BaseLocaleCard({
onSelect={onSelect}
onRemove={onRemove}
onHide={onHide}
pendingSignalementsCount={pendingSignalementsCount}
/>
)}
</Card>
Expand Down
2 changes: 1 addition & 1 deletion components/breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function Breadcrumbs({
if (innerPath === "signalements" && router.query.idSignalement) {
const signalementId = router.query.idSignalement;
const signalement = signalements.find(
(signalement) => signalement._id === signalementId
(signalement) => signalement.id === signalementId
);
signalementLabel = signalement && getSignalementLabel(signalement);
}
Expand Down
6 changes: 0 additions & 6 deletions components/certification-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,12 @@ function CertificationButton({
position: sticky;
width: 100%;
bottom: -12px;
// bottom: 0;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
padding: 10px 0;

background-color: #e6e8f0;

// background-color: white;
// border-radius: 8px;
// border: 1px solid #c1c4d6;
}

.certification-button-wrapper > div {
Expand Down
Loading
Loading