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

Update route bal api with refacto nestjs mes-adresses-api #852

Merged
merged 20 commits into from
Dec 12, 2023
Merged
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
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
NEXT_PUBLIC_EDITEUR_URL=https://mes-adresses.data.gouv.fr
NEXT_PUBLIC_BAL_API_URL=https://api-bal.adresse.data.gouv.fr/v1
NEXT_PUBLIC_MES_ADRESSES_API_URL=https://api-bal.adresse.data.gouv.fr/
NEXT_PUBLIC_GEO_API_URL=https://geo.api.gouv.fr
NEXT_PUBLIC_ADRESSE_URL=https://adresse.data.gouv.fr
NEXT_PUBLIC_API_BAN_URL=https://plateforme.adresse.data.gouv.fr
Expand Down
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["next", "prettier"]
}
30 changes: 19 additions & 11 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@ name: Node.js CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

env:
NEXT_PUBLIC_EDITEUR_URL: https://mes-adresses.data.gouv.fr
NEXT_PUBLIC_BAL_API_URL: https://api-bal.adresse.data.gouv.fr/v1
NEXT_PUBLIC_MES_ADRESSES_API_URL: https://api-bal.adresse.data.gouv.fr/
NEXT_PUBLIC_GEO_API_URL: https://geo.api.gouv.fr
NEXT_PUBLIC_ADRESSE_URL: https://adresse.data.gouv.fr
NEXT_PUBLIC_API_BAN_URL: https://plateforme.adresse.data.gouv.fr
NEXT_PUBLIC_BAN_API_DEPOT: https://plateforme-bal.adresse.data.gouv.fr/api-depot

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- run: yarn xo
- run: yarn build
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- run: yarn lint
- run: yarn build
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

Il est disponible en ligne à l'adresse [mes-adresses.data.gouv.fr](https://mes-adresses.data.gouv.fr).

[![XO code style](https://badgen.net/badge/code%20style/XO/cyan)](https://github.com/xojs/xo)

## Guide

https://adresse.data.gouv.fr/data/docs/guide-mes-adresses-v4.0.pdf
Expand Down
48 changes: 26 additions & 22 deletions components/demo-warning.js → components/demo-warning.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
import {useState, useCallback, useContext} from 'react'
import PropTypes from 'prop-types'
import {Pane, Text, Button, Dialog, TextInputField, WarningSignIcon, toaster} from 'evergreen-ui'

import {transformToDraft} from '@/lib/bal-api'
import {BasesLocalesService} from '@/lib/openapi/services/BasesLocalesService'

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

import {useInput} from '@/hooks/input'
import useFocus from '@/hooks/focus'
import {BaseLocaleType} from '@/types/base-locale'

function DemoWarning({baseLocale, communeName}) {
interface DemoWarningProps {
baseLocale: BaseLocaleType;
communeName: string;
}

function DemoWarning({baseLocale, communeName}: DemoWarningProps) {
const [isShown, setIsShown] = useState(false)
const [isLoading, setIsLoading] = useState(false)
const [nom, setNom] = useState(`Adresses de ${communeName}`)
const [email, onEmailChange] = useInput()
const [ref, setIsFocus] = useFocus()

const {reloadBaseLocale} = useContext(BalDataContext)
const {token} = useContext(TokenContext)

const onSubmit = useCallback(async e => {
e.preventDefault()
setIsLoading(true)

try {
await transformToDraft(
await BasesLocalesService.updateBaseLocaleDemoToDraft(
baseLocale._id, {
nom: nom ? nom.trim() : null,
email
},
token
}
)

await reloadBaseLocale()
} catch (error) {
} catch (error: unknown) {
toaster.danger('Impossible de conserver cette Base Adresse Locale', {
description: error.message
description: (error as any).message
})
}

setIsShown(false)
setIsLoading(false)
}, [baseLocale._id, token, email, nom, reloadBaseLocale])
}, [baseLocale._id, email, nom, reloadBaseLocale])

return (
<Pane
Expand All @@ -69,8 +71,12 @@ function DemoWarning({baseLocale, communeName}) {
isConfirmLoading={isLoading}
confirmLabel='Conserver'
hasFooter={false}
onCloseComplete={() => setIsShown(false)}
onOpenComplete={() => setIsFocus(true)}
onCloseComplete={() => {
setIsShown(false)
}}
onOpenComplete={() => {
setIsFocus(true)
}}
>
<form onSubmit={onSubmit}>

Expand All @@ -84,7 +90,9 @@ function DemoWarning({baseLocale, communeName}) {
value={nom}
label='Nom de la Base Adresse Locale'
placeholder={communeName}
onChange={e => setNom(e.target.value)}
onChange={e => {
setNom(e.target.value as string)
}}
/>

<TextInputField
Expand All @@ -102,16 +110,12 @@ function DemoWarning({baseLocale, communeName}) {
</form>
</Dialog>

<Button height={24} marginX='.5em' width='fit-content' onClick={() => setIsShown(true)}>Je souhaite la conserver</Button>
<Button height={24} marginX='.5em' width='fit-content' onClick={() => {
setIsShown(true)
}}
>Je souhaite la conserver</Button>
</Pane>
)
}

DemoWarning.propTypes = {
baseLocale: PropTypes.shape({
_id: PropTypes.string.isRequired,
}).isRequired,
communeName: PropTypes.string.isRequired
}

export default DemoWarning
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ function isEmail(email) {
return regexp.test(String(email).toLowerCase())
}

const AnnuaireServicePublic = React.memo(() => (
const AnnuaireServicePublic = React.memo(function AnnuaireServicePublic () {
<OrderedList>
<ListItem>Rendez vous sur <Link href='https://lannuaire.service-public.fr/'>lannuaire.service-public.fr</Link></ListItem>
<ListItem>Consultez la fiche annuaire de votre commune</ListItem>
<ListItem>Cliquer sur le lien «Demander une mise à jour de cette page», visible en bas de page</ListItem>
</OrderedList>
))
})

function CodeEmail({emailCommune, handleStrategy}) {
const isValidEmail = isEmail(emailCommune)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Pane, Strong, Alert, Text, Heading, PeopleIcon, TimeIcon, LogInIcon, Uno
import FranceConnect from '@/components/habilitation-process/strategy-selection/france-connect'
import CodeEmail from '@/components/habilitation-process/strategy-selection/code-email'

const StrategySelection = React.memo(({franceconnectAuthenticationUrl, emailCommune, handleStrategy}) => {
const StrategySelection = React.memo(function StrategySelection({franceconnectAuthenticationUrl, emailCommune, handleStrategy}) {
const [hovered, setHovered] = useState()

return (
Expand Down
2 changes: 1 addition & 1 deletion components/settings/bal-settings-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const mailHasChanged = (listA, listB) => {
return !isEqual([...listA].sort(), [...listB].sort())
}

const BALSettingsForm = React.memo(({baseLocale}) => {
const BALSettingsForm = React.memo(function BALSettingsForm({baseLocale}) {
const {token, emails, reloadEmails} = useContext(TokenContext)
const {reloadBaseLocale} = useContext(BalDataContext)

Expand Down
2 changes: 1 addition & 1 deletion components/table-row/table-row-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import {Table, Popover, Menu, Position, IconButton, EditIcon, MoreIcon, SendToMapIcon, TrashIcon} from 'evergreen-ui'

const TableRowActions = React.memo(({onSelect, onEdit, onRemove, extra}) => {
const TableRowActions = React.memo(function TableRowActions({onSelect, onEdit, onRemove, extra}) {
return (
<Table.TextCell flex='0 1 1'>
<Popover
Expand Down
8 changes: 3 additions & 5 deletions components/trash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ function Trash() {
onRemoveToponyme,
onRestoreToponyme,
onRestoreVoie,
reloadVoiesDeleted,
reloadToponymesDelete
reloadAllDeleted,
} = useTrash()
const [selectedTabIndex, setSelectedTabIndex] = useState(0)
const [restoreVoie, setRestoreVoie] = useState(null)

useEffect(() => {
reloadVoiesDeleted()
reloadToponymesDelete()
}, [reloadVoiesDeleted, reloadToponymesDelete])
reloadAllDeleted()
}, [reloadAllDeleted])

const propsDeletedList = useMemo(() => {
if (selectedTabIndex === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import {Table, Popover, Menu, Position, IconButton, MoreIcon} from 'evergreen-ui'

const TableRowActions = React.memo(({actions}) => {
const TableRowActions = React.memo(function TableRowActions({actions}) {
return (
<Table.TextCell flex='0 1 1'>
<Popover
Expand Down
2 changes: 1 addition & 1 deletion components/user-bases-locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function UserBasesLocales() {
}

return (
<Pane display='flex' flexDirection='column' flex={1} justifyContent='center'>
<Pane display='flex' flexDirection='column' flex={1} justifyContent='flex-start'>
{basesLocales.length > 0 ? (
<BasesLocalesList basesLocales={basesLocales} />
) : (
Expand Down
1 change: 0 additions & 1 deletion contexts/bal-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function BalDataContextProvider({

const reloadBaseLocale = useCallback(async () => {
const bal = await getBaseLocale(baseLocale._id)

setBaseLocale(bal)
}, [baseLocale._id])

Expand Down
42 changes: 27 additions & 15 deletions contexts/bal-recovery.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
import RecoverBALAlert from '@/components/bal-recovery/recover-bal-alert'
import React, {useState, useMemo} from 'react'
import RecoverBALAlert from "@/components/bal-recovery/recover-bal-alert";
import React, { useState, useMemo } from "react";

interface BALRecoveryContextType {
isRecoveryDisplayed: boolean;
setIsRecoveryDisplayed: (value: boolean) => void;
}

const BALRecoveryContext = React.createContext<BALRecoveryContextType | null>(null)
const BALRecoveryContext = React.createContext<BALRecoveryContextType | null>(
null
);

interface BALRecoveryProviderProps {
balId: string;
children: React.ReactNode;
}

export function BALRecoveryProvider({balId, ...props}: BALRecoveryProviderProps) {
const [isRecoveryDisplayed, setIsRecoveryDisplayed] = useState(false)
export function BALRecoveryProvider({
balId,
...props
}: BALRecoveryProviderProps) {
const [isRecoveryDisplayed, setIsRecoveryDisplayed] = useState(false);

const value = useMemo(() => ({
isRecoveryDisplayed,
setIsRecoveryDisplayed
}), [isRecoveryDisplayed])
const value = useMemo(
() => ({
isRecoveryDisplayed,
setIsRecoveryDisplayed,
}),
[isRecoveryDisplayed]
);

return (
<>
<RecoverBALAlert isShown={isRecoveryDisplayed} onClose={() => {
setIsRecoveryDisplayed(false)
}} baseLocaleId={balId} />
<RecoverBALAlert
isShown={isRecoveryDisplayed}
onClose={() => {
setIsRecoveryDisplayed(false);
}}
baseLocaleId={balId}
/>
<BALRecoveryContext.Provider value={value} {...props} />
</>
)
);
}

export const BALRecoveryConsumer = BALRecoveryContext.Consumer
export const BALRecoveryConsumer = BALRecoveryContext.Consumer;

export default BALRecoveryContext
export default BALRecoveryContext;
25 changes: 25 additions & 0 deletions contexts/open-api-config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {OpenAPI, OpenAPIConfig} from '@/lib/openapi'
import React, {useCallback} from 'react'

const OpenAPIConfigContext = React.createContext<(config: Partial<OpenAPIConfig>) => void | null>(null)

interface OpenAPIConfigProviderProps {
baseConfig?: Partial<OpenAPIConfig>;
children: React.ReactNode;
}

export function OpenAPIConfigProvider({baseConfig, ...props}: OpenAPIConfigProviderProps) {
if (baseConfig) {
Object.assign(OpenAPI, baseConfig)
}

const setOpenAPIConfig = useCallback((config: Partial<OpenAPIConfig>) => {
Object.assign(OpenAPI, config)
}, [])

return <OpenAPIConfigContext.Provider value={setOpenAPIConfig} {...props} />
}

export const OpenAPIConfigConsumer = OpenAPIConfigContext.Consumer

export default OpenAPIConfigContext
5 changes: 4 additions & 1 deletion contexts/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import Router from 'next/router'
import {getBaseLocale} from '@/lib/bal-api'

import LocalStorageContext from '@/contexts/local-storage'
import OpenAPIConfigContext from '@/contexts/open-api-config'

const TokenContext = React.createContext()

export function TokenContextProvider({balId, _token, ...props}) {
const {getBalToken, addBalAccess} = useContext(LocalStorageContext)
const setOpenAPIConfig = useContext(OpenAPIConfigContext)

const [tokenIsChecking, setTokenIsChecking] = useState(false)
const [token, setToken] = useState(null)
Expand All @@ -21,12 +23,13 @@ export function TokenContextProvider({balId, _token, ...props}) {
if (baseLocale.token) {
setToken(baseLocale.token)
setEmails(baseLocale.emails)
setOpenAPIConfig({TOKEN: baseLocale.token})
} else {
setToken(null)
}

setTokenIsChecking(false)
}, [balId])
}, [balId, setOpenAPIConfig])

useEffect(() => {
if (balId) {
Expand Down
16 changes: 0 additions & 16 deletions hooks/focus.js

This file was deleted.

Loading
Loading