Skip to content

Commit

Permalink
fix: use commune flag proxy for formulaire de publication
Browse files Browse the repository at this point in the history
  • Loading branch information
MaGOs92 committed Nov 29, 2024
1 parent 65c0298 commit 6c94f7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/FormulaireDePublication/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Commune } from '@/types/api-geo.types'
import { validateHabilitationPinCode, createHabilitation, createRevision, getHabilitation, sendHabilitationPinCode, getCurrentRevision, publishRevision } from '@/lib/api-depot'
import Alert from '@codegouvfr/react-dsfr/Alert'
import Image from 'next/image'
import { getCommuneFlag } from '@/lib/api-blasons-communes'
import { getCommuneFlagProxy } from '@/lib/api-blasons-communes'
import { HabilitationMethod } from './steps/HablitationMethod'
import { Habilitation, HabilitationStatus, Revision } from '@/types/api-depot.types'
import { PinCodeValidation } from './steps/PinCodeValidation'
Expand Down Expand Up @@ -81,6 +81,9 @@ export default function FormulaireDePublication({ initialHabilitation, initialRe
if (!report.parseOk) {
throw new Error(`Impossible d’analyser le fichier… [${report.parseErrors[0].message}]`)
}
else if (!report.profilesValidation['1.3'].isValid) {
throw new Error('Le fichier n\'est pas valide en version 1.3, veuillez corriger les erreurs en utilsant le Validateur BAL (Les Outils -> Validateur BAL) puis essayez à nouveau.')
}
const communes = new Set<string>(Array.from(report.rows.map((r: any) => r.parsedValues.commune_insee || r.additionalValues.cle_interop.codeCommune)))

if (communes.size !== 1) {
Expand All @@ -89,7 +92,7 @@ export default function FormulaireDePublication({ initialHabilitation, initialRe

const [codeCommune] = communes
const commune = await getCommune(codeCommune)
const communeFlagUrl = await getCommuneFlag(codeCommune) || '/commune/default-logo.svg'
const communeFlagUrl = await getCommuneFlagProxy(codeCommune)

const habilitation = await createHabilitation(codeCommune)
setHabilitation(habilitation)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api-blasons-communes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const BASE_URL = 'https://base-adresse-locale-prod-blasons-communes.s3.fr-par.sc
const DEFAULT_URL_DISTRICT_FLAG = '/commune/default-logo.svg'

// Fetch the commune flag from a proxy for front-end to avoid CORS issues
export const getCommuneFlagProxy = async (codeCommune: string): Promise<string | undefined> => {
export const getCommuneFlagProxy = async (codeCommune: string): Promise<string> => {
const response = await fetch(`/api/proxy-flag-commune/${codeCommune}`)

return response.json()
Expand Down

0 comments on commit 6c94f7f

Please sign in to comment.