Skip to content

Commit

Permalink
fix: lbac 1893: petit refactoring des candidatures (#971)
Browse files Browse the repository at this point in the history
* fix: lbac 1893: fix iv use

* fix: amélioration du typage et simplification du code
  • Loading branch information
remy-auricoste authored Jan 8, 2024
1 parent 86ff87c commit 3e51edc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
4 changes: 1 addition & 3 deletions server/src/services/lbacompany.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ const transformCompany = ({
email?: string
iv?: string
phone?: string | null
} = {
...encryptMailWithIV({ value: company.email !== "null" ? company.email : "" }),
}
} = encryptMailWithIV({ value: company.email !== "null" ? company.email : "" })

if (contactAllowedOrigin) {
contact.phone = company.phone
Expand Down
15 changes: 5 additions & 10 deletions ui/components/ItemDetail/CandidatureLba/services/getSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@ export function getInitialSchemaValues() {
fileName: "",
fileContent: null,
message: "",
//interetOffresMandataire: false,
}
}

const commonControls = {
fileName: Yup.string().nullable().required("⚠ La pièce jointe est obligatoire"),
firstName: Yup.string().max(50, "⚠ Doit avoir 50 caractères ou moins").required("⚠ Le prénom est obligatoire"),
lastName: Yup.string().max(50, "⚠ Doit avoir 50 caractères ou moins").required("⚠ Le nom est obligatoire"),
email: Yup.string().email("⚠ Adresse e-mail invalide").required("⚠ L'adresse e-mail est obligatoire"),
phone: phoneValidation().required("⚠ Le téléphone est obligatoire"),
}

export function getValidationSchema() {
return Yup.object({
...commonControls,
fileName: Yup.string().nullable().required("⚠ La pièce jointe est obligatoire"),
firstName: Yup.string().max(50, "⚠ Doit avoir 50 caractères ou moins").required("⚠ Le prénom est obligatoire"),
lastName: Yup.string().max(50, "⚠ Doit avoir 50 caractères ou moins").required("⚠ Le nom est obligatoire"),
email: Yup.string().email("⚠ Adresse e-mail invalide").required("⚠ L'adresse e-mail est obligatoire"),
phone: phoneValidation().required("⚠ Le téléphone est obligatoire"),
})
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import extractCompanyValues from "../../../../services/extractCompanyValues"
import postCandidature from "../../../../services/postCandidature"

export default async function submitCandidature(
{
applicantValues,
setSendingState = (m: string) => {
console.log(m)
},
item = {},
caller = null,
jobLabel = null,
},
_postCandidature = postCandidature,
_extractCompanyValues = extractCompanyValues
) {
export default async function submitCandidature({
applicantValues,
setSendingState,
item = {},
caller = null,
jobLabel = null,
}: {
applicantValues: any // TODO
setSendingState: (state: string) => void
item?: any // TODO
caller?: string | null
jobLabel?: string | null
}) {
setSendingState("currently_sending")
let success = true
let result = null
try {
result = await _postCandidature(applicantValues, _extractCompanyValues(item), jobLabel, caller)
result = await postCandidature({ applicantValues, company_h: extractCompanyValues(item), jobLabel, caller })
if (result !== "ok") {
success = false
}
Expand Down
10 changes: 5 additions & 5 deletions ui/services/postCandidature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { logError } from "../utils/tools"

import extractCandidatureParams from "./extractCandidatureParams"

export default async function postCandidature(applicant_h, company_h, jobLabel = null, caller, _apiEndpoint = apiEndpoint, _axios = axios, _window = window, _logError = logError) {
export default async function postCandidature({ applicantValues, company_h, jobLabel, caller }) {
let res = ""

const candidatureApi = _apiEndpoint + "/v1/application"
const candidatureApi = apiEndpoint + "/v1/application"

let response = null
let isAxiosError = false

try {
response = await _axios.post(candidatureApi, extractCandidatureParams(applicant_h, company_h, jobLabel, caller))
response = await axios.post(candidatureApi, extractCandidatureParams(applicantValues, company_h, jobLabel, caller))
} catch (error) {
response = error.response

Expand All @@ -33,10 +33,10 @@ export default async function postCandidature(applicant_h, company_h, jobLabel =

if (isError) {
if (isAxiosError) {
_logError("Candidature API error", `Candidature API error ${response.data.error}`)
logError("Candidature API error", `Candidature API error ${response.data.error}`)
res = response.statusText
} else if (isSimulatedError) {
_logError("Candidature API error simulated")
logError("Candidature API error simulated")
res = "simulated_error"
} else {
res = "unexpected_error"
Expand Down

0 comments on commit 3e51edc

Please sign in to comment.