-
Notifications
You must be signed in to change notification settings - Fork 14
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: POC RNF #751
Draft
XavierJp
wants to merge
2
commits into
main
Choose a base branch
from
731-RNF
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: POC RNF #751
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import routes from '#clients/routes'; | ||
import { IETATADMINSTRATIF } from '#models/etat-administratif'; | ||
import { IFondation } from '#models/fondations'; | ||
import { IdRnf } from '#utils/helpers/id-rnf'; | ||
import { httpGet } from '#utils/network'; | ||
|
||
type IRNFResponse = { | ||
createdAt: string; | ||
updatedAt: string; | ||
rnfId: string; //"075-FDD-00003-01" | ||
type: string; | ||
department: string; | ||
title: string; | ||
dissolvedAt: string | null; | ||
phone: string; | ||
email: string; | ||
address: { | ||
createdAt: string; | ||
updatedAt: string; | ||
label: string; | ||
type: string; | ||
streetAddress: string; | ||
streetNumber: string; | ||
streetName: string; | ||
postalCode: string; | ||
cityName: string; | ||
cityCode: string; | ||
departmentName: string; | ||
departmentCode: string; | ||
regionName: string; | ||
regionCode: string; | ||
}; | ||
status: unknown; | ||
persons: unknown[]; | ||
}; | ||
|
||
/** | ||
* Call RNF API using an Id RNF | ||
* @param idRnf | ||
*/ | ||
const clientRNF = async (idRnf: IdRnf, useCache = true) => { | ||
const url = `${routes.rnf}${idRnf}`; | ||
const response = await httpGet<IRNFResponse>(url, { useCache }); | ||
|
||
return mapToDomainObject(idRnf, response); | ||
}; | ||
|
||
const mapToDomainObject = ( | ||
idRnf: IdRnf, | ||
response: IRNFResponse | ||
): IFondation => { | ||
const { | ||
title, | ||
dissolvedAt, | ||
address, | ||
department, | ||
type, | ||
createdAt, | ||
phone, | ||
email, | ||
} = response; | ||
|
||
return { | ||
idRnf, | ||
nomComplet: title, | ||
etatAdministratif: !dissolvedAt | ||
? IETATADMINSTRATIF.ACTIF | ||
: IETATADMINSTRATIF.CESSEE, | ||
adresse: address.label, | ||
departement: department, | ||
type, | ||
dateCreation: createdAt.split('T')[0], | ||
dateFermeture: (dissolvedAt || '').split('T')[0], | ||
telephone: phone, | ||
email, | ||
}; | ||
}; | ||
|
||
export { clientRNF }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { clientRNF } from '#clients/api-rnf'; | ||
import { HttpNotFound } from '#clients/exceptions'; | ||
import { IETATADMINSTRATIF } from '#models/etat-administratif'; | ||
import { IdRnf, verifyIdRnf } from '#utils/helpers/id-rnf'; | ||
import logErrorInSentry from '#utils/sentry'; | ||
import { NotAnIdRnfError, RnfNotFoundError } from '..'; | ||
|
||
export type IFondation = { | ||
idRnf: IdRnf; | ||
etatAdministratif: IETATADMINSTRATIF; | ||
nomComplet: string; | ||
adresse: string; | ||
departement: string; | ||
type: string; | ||
dateCreation: string; | ||
dateFermeture: string; | ||
telephone: string; | ||
email: string; | ||
}; | ||
|
||
/** | ||
* Get a fondation if it exists | ||
* @param slug | ||
* @returns | ||
*/ | ||
export const getFondationFromSlug = async (slug: string) => { | ||
try { | ||
const idRnf = verifyIdRnf(slug); | ||
return await clientRNF(idRnf); | ||
} catch (e: any) { | ||
if (e instanceof HttpNotFound) { | ||
throw new RnfNotFoundError(slug); | ||
} else if (e instanceof NotAnIdRnfError) { | ||
throw e; | ||
} | ||
|
||
logErrorInSentry(e, { | ||
details: slug, | ||
errorName: 'Error in API RNF', | ||
}); | ||
throw e; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { GetServerSideProps } from 'next'; | ||
import { FondationBadge } from '#components-ui/badge/frequent'; | ||
import { HorizontalSeparator } from '#components-ui/horizontal-separator'; | ||
import IsActiveTag from '#components-ui/is-active-tag'; | ||
import Meta from '#components/meta'; | ||
import { DataSection } from '#components/section/data-section'; | ||
import { TwoColumnTable } from '#components/table/simple'; | ||
import { EAdministration } from '#models/administrations'; | ||
import { IFondation, getFondationFromSlug } from '#models/fondations'; | ||
import { ISTATUTDIFFUSION } from '#models/statut-diffusion'; | ||
import { formatDate, formatIntFr } from '#utils/helpers'; | ||
import { libelleFromDepartement } from '#utils/helpers/formatting/labels'; | ||
import extractParamsFromContext from '#utils/server-side-props-helper/extract-params-from-context'; | ||
import { | ||
IPropsWithMetadata, | ||
postServerSideProps, | ||
} from '#utils/server-side-props-helper/post-server-side-props'; | ||
import { NextPageWithLayout } from 'pages/_app'; | ||
|
||
interface IProps extends IPropsWithMetadata { | ||
fondation: IFondation; | ||
} | ||
|
||
const FondationPage: NextPageWithLayout<IProps> = ({ fondation }) => ( | ||
<> | ||
<Meta | ||
title={fondation.nomComplet} | ||
noIndex={true} | ||
canonical={`https://annuaire-entreprises.data.gouv.fr/fondation/${fondation.idRnf}`} | ||
/> | ||
|
||
<h1>{fondation.nomComplet}</h1> | ||
<div className="fondation-sub-title"> | ||
<FondationBadge /> | ||
<span className="siren"> ‣ {formatIntFr(fondation.idRnf)}</span> | ||
<span> | ||
<IsActiveTag | ||
etatAdministratif={fondation.etatAdministratif} | ||
statutDiffusion={ISTATUTDIFFUSION.DIFFUSIBLE} | ||
/> | ||
</span> | ||
</div> | ||
|
||
<div className="content-container"> | ||
<DataSection | ||
title="Répertoire National des fondations" | ||
sources={[EAdministration.MI]} | ||
data={fondation} | ||
> | ||
{(fondation) => ( | ||
<> | ||
<TwoColumnTable | ||
body={[ | ||
['N°RNF', fondation.idRnf], | ||
['Nom', fondation.nomComplet], | ||
[ | ||
'Département', | ||
`${libelleFromDepartement(fondation.departement)} (${ | ||
fondation.departement | ||
})`, | ||
], | ||
['Adresse', fondation.adresse], | ||
['Date de création', formatDate(fondation.dateCreation)], | ||
...(fondation.dateFermeture | ||
? [['Date de fermeture', formatDate(fondation.dateCreation)]] | ||
: []), | ||
[ | ||
'Téléphone', | ||
fondation.telephone ? ( | ||
<a href={`tel:${fondation.telephone}`}> | ||
{fondation.telephone} | ||
</a> | ||
) : ( | ||
'' | ||
), | ||
], | ||
[ | ||
'Email', | ||
fondation.email ? ( | ||
<a href={`mailto:${fondation.email}`}>{fondation.email}</a> | ||
) : ( | ||
'' | ||
), | ||
], | ||
]} | ||
/> | ||
</> | ||
)} | ||
</DataSection> | ||
</div> | ||
<HorizontalSeparator /> | ||
<style jsx>{` | ||
.fondation-sub-title { | ||
display: flex; | ||
align-items: center; | ||
} | ||
`}</style> | ||
</> | ||
); | ||
|
||
export const getServerSideProps: GetServerSideProps = postServerSideProps( | ||
async (context) => { | ||
const { slug } = extractParamsFromContext(context, true); | ||
|
||
const fondation = await getFondationFromSlug(slug); | ||
|
||
return { | ||
props: { | ||
fondation, | ||
}, | ||
}; | ||
} | ||
); | ||
|
||
export default FondationPage; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can omit the constructor...