Skip to content

Commit

Permalink
feat: lbac 1738 exposition pass (#828)
Browse files Browse the repository at this point in the history
* feat: mix job description according to avail. data

* fix: employerDescription is only matcha

* fix: yarnlock & prettier

* fix: open api schema

* feat: extract constant
  • Loading branch information
kevbarns authored Nov 20, 2023
1 parent 526f220 commit 82d7105
Show file tree
Hide file tree
Showing 11 changed files with 2,309 additions and 1,866 deletions.
4 changes: 2 additions & 2 deletions server/src/http/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function siretSchema() {
error.code === "string.base"
? `Error: schema not valid : ValidationError: ${error.key} must be a string`
: error.value
? `Error: schema not valid : ValidationError: ${error.key} must follow Luhn algorithm`
: `Error: schema not valid : ValidationError: empty ${error.key}`
? `Error: schema not valid : ValidationError: ${error.key} must follow Luhn algorithm`
: `Error: schema not valid : ValidationError: empty ${error.key}`
)
})
}
Expand Down
24 changes: 12 additions & 12 deletions server/src/jobs/seed/referentielRome/referentielRome.seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ const formatRawData = ({ appellations, competences, contextes_travail, mobilites
savoir_faire: isNull(competences.savoir_faire.enjeux)
? null
: isArray(competences.savoir_faire.enjeux.enjeu)
? competences.savoir_faire.enjeux.enjeu.map((x) => x)
: competences.savoir_faire.enjeux.enjeu,
? competences.savoir_faire.enjeux.enjeu.map((x) => x)
: competences.savoir_faire.enjeux.enjeu,
savoir_etre_professionnel: isNull(competences.savoir_etre_professionnel.enjeux)
? null
: isObject(competences.savoir_etre_professionnel.enjeux.enjeu)
? isArray(competences.savoir_etre_professionnel.enjeux.enjeu.items.item)
? competences.savoir_etre_professionnel?.enjeux?.enjeu?.items?.item?.map((x) => x)
: competences.savoir_etre_professionnel.enjeux.enjeu
: null,
? isArray(competences.savoir_etre_professionnel.enjeux.enjeu.items.item)
? competences.savoir_etre_professionnel?.enjeux?.enjeu?.items?.item?.map((x) => x)
: competences.savoir_etre_professionnel.enjeux.enjeu
: null,
savoirs: isNull(competences.savoirs.categories)
? null
: isArray(competences.savoirs.categories.categorie)
? competences.savoirs.categories && competences.savoirs.categories.categorie.map((x) => x)
: competences.savoirs.categories.categorie,
? competences.savoirs.categories && competences.savoirs.categories.categorie.map((x) => x)
: competences.savoirs.categories.categorie,
},
contextes_travail: isNull(contextes_travail)
? null
: isArray(contextes_travail.type_contexte)
? contextes_travail.type_contexte.map((x) => x)
: contextes_travail.type_contexte,
? contextes_travail.type_contexte.map((x) => x)
: contextes_travail.type_contexte,
mobilites: {
proche: mobilites.proche && mobilites.proche.mobilite,
si_evolution: isNull(mobilites.si_evolution)
? null
: isArray(mobilites.si_evolution?.mobilite)
? mobilites.si_evolution.mobilite.map((x) => x)
: mobilites.si_evolution.mobilite,
? mobilites.si_evolution.mobilite.map((x) => x)
: mobilites.si_evolution.mobilite,
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions server/src/security/authenticationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ declare module "fastify" {
type AuthenticatedUser<AuthScheme extends WithSecurityScheme["securityScheme"]["auth"]> = AuthScheme extends "cookie-session"
? UserWithType<"IUserRecruteur", IUserRecruteur>
: AuthScheme extends "api-key"
? UserWithType<"ICredential", ICredential>
: AuthScheme extends "access-token"
? UserWithType<"IAccessToken", IAccessToken>
: never
? UserWithType<"ICredential", ICredential>
: AuthScheme extends "access-token"
? UserWithType<"IAccessToken", IAccessToken>
: never

export const getUserFromRequest = <S extends WithSecurityScheme>(req: Pick<FastifyRequest, "user">, _schema: S): AuthenticatedUser<S["securityScheme"]["auth"]> => {
if (!req.user) {
Expand Down
3 changes: 2 additions & 1 deletion server/src/services/lbajob.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ function transformLbaJob({
diplomaLevel: offre.job_level_label || null,
job: {
id: offre._id.toString(),
description: offre.job_description || "",
description: offre.job_description || null,
employeurDescription: offre.job_employer_description || null,
creationDate: offre.job_creation_date ? new Date(offre.job_creation_date) : null,
contractType: offre.job_type ? offre.job_type.join(", ") : null,
jobStartDate: offre.job_start_date ? new Date(offre.job_start_date) : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,12 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"null",
],
},
"employeurDescription": {
"type": [
"string",
"null",
],
},
"id": {
"type": [
"string",
Expand Down
1 change: 1 addition & 0 deletions shared/models/lbaItem.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export type ILbaItemCompany = z.output<typeof ZLbaItemCompany>
const ZLbaItemJob = z
.object({
description: z.string().nullable(), // pe -> description | matcha -> description
employeurDescription: z.string().nullable().optional(), // matcha -> job.job_employer_description
creationDate: z.date().nullable(), // pe -> dateCreation | matcha -> createdAt
id: z.string().nullable(), // pe -> id | matcha -> id mongo offre
contractType: z.string().nullable(), // pe -> typeContrat | matcha -> offres.type
Expand Down
4 changes: 2 additions & 2 deletions shared/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export const zRoutes: IRoutes = {
export type IResponse<S extends IRouteSchema> = S["response"][`200`] extends ZodType
? Jsonify<z.output<S["response"][`200`]>>
: S["response"][`2${string}`] extends ZodType
? Jsonify<z.output<S["response"][`2${string}`]>>
: never
? Jsonify<z.output<S["response"][`2${string}`]>>
: never

export type IBody<S extends IRouteSchemaWrite> = S["body"] extends ZodType ? z.input<S["body"]> : never

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AddIcon, MinusIcon } from "@chakra-ui/icons"
import { Accordion, AccordionButton, AccordionItem, AccordionPanel, Box } from "@chakra-ui/react"
import DOMPurify from "isomorphic-dompurify"

const MatchaCustomDescription = ({ data, title }: { data: string; title: string }) => {
const sanitizedData = () => ({
__html: DOMPurify.sanitize(data),
})
return (
<Accordion allowToggle>
<AccordionItem>
{({ isExpanded }) => (
<>
<AccordionButton fontSize="1rem" fontWeight={700} color="#161616">
<Box as="span" flex="1" textAlign="left">
{title}
</Box>
{isExpanded ? <MinusIcon fontSize="10px" /> : <AddIcon fontSize="10px" />}
</AccordionButton>

<AccordionPanel pb={4}>
<Box pl="12px" mt={4}>
<div dangerouslySetInnerHTML={sanitizedData()} />
</Box>
</AccordionPanel>
</>
)}
</AccordionItem>
</Accordion>
)
}

export default MatchaCustomDescription
48 changes: 43 additions & 5 deletions ui/components/ItemDetail/MatchaDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ExternalLinkIcon } from "@chakra-ui/icons"
import { Box, Flex, Image, Link, Text } from "@chakra-ui/react"
import React, { useEffect } from "react"
import { ILbaItemLbaJob } from "shared"

import { DisplayContext } from "../../context/DisplayContextProvider"
import { notifyLbaJobDetailView } from "../../services/notifyLbaJobDetailView"
Expand All @@ -9,12 +10,53 @@ import { formatDate } from "../../utils/strutils"

import MatchaAcces from "./MatchaComponents/MatchaAcces"
import MatchaCompetences from "./MatchaComponents/MatchaCompetences"
import MatchaCustomDescription from "./MatchaComponents/MatchaCustomDescription"
import MatchaDescription from "./MatchaComponents/MatchaDescription"

const BADDESCRIPTION = 30

const getContractTypes = (contractTypes) => {
return contractTypes instanceof Array ? contractTypes.join(", ") : contractTypes
}

const RomeDescriptions = (job) => (
<>
<MatchaDescription job={job} />
<MatchaCompetences job={job} />
<MatchaAcces job={job} />
</>
)

const getDescriptionContext = (job: ILbaItemLbaJob) => {
const { description, employeurDescription } = job.job

if ((!description && !employeurDescription) || description.length < BADDESCRIPTION) {
return RomeDescriptions(job)
}

if (description && employeurDescription) {
return (
<>
<MatchaCustomDescription data={description} title="Description du Métier" />
<MatchaCustomDescription data={employeurDescription} title="Description de l'employeur" />
</>
)
}

if (description && !employeurDescription) {
return <MatchaCustomDescription data={description} title="Description du Métier" />
}

if (!description && employeurDescription) {
return (
<>
{RomeDescriptions(job)}
<MatchaCustomDescription data={employeurDescription} title="Description de l'employeur" />
</>
)
}
}

const MatchaDetail = ({ job }) => {
useEffect(() => {
// S'assurer que l'utilisateur voit bien le haut de la fiche au départ
Expand Down Expand Up @@ -113,11 +155,7 @@ const MatchaDetail = ({ job }) => {
<Box pb="0px" mt={6} position="relative" background="white" padding="16px 24px" mx={["0", "30px"]}>
<Text as="h2" variant="itemDetailH2" mt={2}>{`En savoir plus sur ${job.title}`}</Text>
<Box data-testid="lbb-component">
<Box mb={4}>
<MatchaDescription job={job} />
<MatchaCompetences job={job} />
<MatchaAcces job={job} />
</Box>
<Box mb={4}>{getDescriptionContext(job)}</Box>
</Box>
</Box>
)}
Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"email-validator": "^2.0.4",
"formik": "^2.4.5",
"framer-motion": "^6.5.1",
"isomorphic-dompurify": "^1.9.0",
"jose": "^4.14.6",
"lodash": "^4.17.21",
"mapbox-gl": "^2.15.0",
Expand Down
Loading

0 comments on commit 82d7105

Please sign in to comment.