Skip to content

Commit cb4a91d

Browse files
author
achraf hafedh
committed
fix(account-creation): add siren field in account creation
ref: #MANAGER-20005 Signed-off-by: achraf hafedh <[email protected]>
1 parent 8b7b483 commit cb4a91d

File tree

11 files changed

+114
-42
lines changed

11 files changed

+114
-42
lines changed

packages/manager/apps/account-creation/public/translations/account-details/Messages_de_DE.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"account_details_field_name": "Name",
1313
"account_details_field_corporation_name": "Firmenname",
1414
"account_details_field_siret": "SIRET",
15+
"account_details_field_siren": "SIREN",
1516
"account_details_field_vat": "USt - IdNr.",
1617
"account_details_field_country": "Land des Wohnsitzes",
1718
"account_details_field_address": "Adresse",

packages/manager/apps/account-creation/public/translations/account-details/Messages_en_GB.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"account_details_field_name": "Name",
1313
"account_details_field_corporation_name": "Name of company",
1414
"account_details_field_siret": "SIRET",
15+
"account_details_field_siren": "SIREN",
1516
"account_details_field_vat": "VAT number",
1617
"account_details_field_country": "Country of residence",
1718
"account_details_field_address": "Address ",

packages/manager/apps/account-creation/public/translations/account-details/Messages_es_ES.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"account_details_field_name": "Nombre",
1313
"account_details_field_corporation_name": "Razón social",
1414
"account_details_field_siret": "SIRET",
15+
"account_details_field_siren": "SIREN",
1516
"account_details_field_vat": "Número de IVA",
1617
"account_details_field_country": "País de residencia",
1718
"account_details_field_address": "Dirección",

packages/manager/apps/account-creation/public/translations/account-details/Messages_fr_CA.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"account_details_field_name": "Nom",
1313
"account_details_field_corporation_name": "Raison sociale",
1414
"account_details_field_siret": "SIRET",
15+
"account_details_field_siren": "SIREN",
1516
"account_details_field_vat": "Numéro de TVA",
1617
"account_details_field_country": "Pays de résidence",
1718
"account_details_field_address": "Adresse",

packages/manager/apps/account-creation/public/translations/account-details/Messages_fr_FR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"account_details_field_name": "Nom",
2020
"account_details_field_corporation_name": "Raison sociale",
2121
"account_details_field_siret": "SIRET",
22+
"account_details_field_siren": "SIREN",
2223
"account_details_field_vat": "Numéro de TVA",
2324
"account_details_field_country": "Pays de résidence",
2425
"account_details_field_address": "Adresse",

packages/manager/apps/account-creation/public/translations/account-details/Messages_it_IT.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"account_details_field_name": "Nome",
1313
"account_details_field_corporation_name": "Ragione sociale",
1414
"account_details_field_siret": "SIRET",
15+
"account_details_field_siren": "SIREN",
1516
"account_details_field_vat": "Numero di P. IVA",
1617
"account_details_field_country": "Paese di residenza",
1718
"account_details_field_address": "Indirizzo",

packages/manager/apps/account-creation/public/translations/account-details/Messages_pl_PL.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"account_details_field_name": "Nazwa",
1313
"account_details_field_corporation_name": "Nazwa firmy",
1414
"account_details_field_siret": "SIRET",
15+
"account_details_field_siren": "SIREN",
1516
"account_details_field_vat": "Numer NIP",
1617
"account_details_field_country": "Kraj",
1718
"account_details_field_address": "Adres siedziby/zamieszkania i pobytu",

packages/manager/apps/account-creation/public/translations/account-details/Messages_pt_PT.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"account_details_field_name": "Nome",
1313
"account_details_field_corporation_name": "Razão social",
1414
"account_details_field_siret": "SIRET",
15+
"account_details_field_siren": "SIREN",
1516
"account_details_field_vat": "Número de IVA",
1617
"account_details_field_country": "País de residência",
1718
"account_details_field_address": "Morada",
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import { Country, LegalForm } from '@ovh-ux/manager-config';
22

3-
export const shouldAccessCompanySearch = (
3+
export const shouldAccessOrganizationSearch = (
44
country?: Country,
55
legalForm?: LegalForm,
66
) => country === 'FR' && legalForm && legalForm !== 'individual';
7+
8+
export const shouldEnableSIRENDisplay = (
9+
country?: Country,
10+
legalForm?: LegalForm,
11+
) => country === 'FR' && legalForm === 'corporation';
12+
13+
export const getSirenFromSiret = (
14+
siret?: string,
15+
pattern?: string | null,
16+
): string | null => {
17+
if (!siret || !pattern) return null;
18+
19+
return new RegExp(pattern).test(siret) ? siret.substring(0, 9) : null;
20+
};

packages/manager/apps/account-creation/src/pages/accountDetails/accountDetails.page.tsx

Lines changed: 89 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useEffect, useMemo, useState } from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { Controller, SubmitHandler, useForm } from 'react-hook-form';
3+
import { Controller, SubmitHandler, useForm, useWatch } from 'react-hook-form';
44
import { useMutation } from '@tanstack/react-query';
55
import { z } from 'zod';
66
import { zodResolver } from '@hookform/resolvers/zod';
@@ -44,7 +44,11 @@ import {
4444
} from '@/hooks/zod/useZod';
4545
import { putMe } from '@/data/api/me';
4646
import { urls } from '@/routes/routes.constant';
47-
import { shouldAccessCompanySearch } from '@/helpers/flowHelper';
47+
import {
48+
getSirenFromSiret,
49+
shouldAccessOrganizationSearch,
50+
shouldEnableSIRENDisplay,
51+
} from '@/helpers/flowHelper';
4852

4953
type AccountDetailsFormProps = {
5054
rules: Record<RuleField, Rule>;
@@ -113,6 +117,28 @@ function AccountDetailsForm({
113117
resolver: zodResolver(zodSchema),
114118
});
115119

120+
const shouldDisplaySIREN = useMemo(
121+
() => shouldEnableSIRENDisplay(currentUser.country, legalForm),
122+
[currentUser.country, legalForm],
123+
);
124+
125+
const corporationIdValue = useWatch({
126+
control,
127+
name: 'companyNationalIdentificationNumber',
128+
});
129+
130+
const sirenValue = useMemo(
131+
() =>
132+
getSirenFromSiret(
133+
corporationIdValue,
134+
rules?.companyNationalIdentificationNumber?.regularExpression,
135+
),
136+
[
137+
corporationIdValue,
138+
rules?.companyNationalIdentificationNumber?.regularExpression,
139+
],
140+
);
141+
116142
const phoneCountry = watch('phoneCountry');
117143

118144
useEffect(() => {
@@ -291,41 +317,63 @@ function AccountDetailsForm({
291317
control={control}
292318
name="companyNationalIdentificationNumber"
293319
render={({ field: { name, value, onChange, onBlur } }) => (
294-
<OdsFormField>
295-
<label
296-
htmlFor={name}
297-
slot="label"
298-
aria-label={t('account_details_field_siret')}
299-
>
300-
<OdsText preset="caption">
301-
{t('account_details_field_siret')}
302-
</OdsText>
303-
</label>
304-
<OdsInput
305-
isReadonly={Boolean(companyNationalIdentificationNumber)}
306-
name="companyNationalIdentificationNumber"
307-
value={value}
308-
maxlength={
309-
rules?.companyNationalIdentificationNumber.maxLength ||
310-
undefined
311-
}
312-
hasError={!!errors[name]}
313-
onOdsChange={onChange}
314-
onOdsBlur={onBlur}
315-
/>
316-
{errors[name] &&
317-
rules?.companyNationalIdentificationNumber && (
318-
<OdsText
319-
className="text-critical leading-[0.8]"
320-
preset="caption"
321-
>
322-
{renderTranslatedZodError(
323-
errors[name].message,
324-
rules?.companyNationalIdentificationNumber,
325-
)}
320+
<>
321+
<OdsFormField>
322+
<label
323+
htmlFor={name}
324+
slot="label"
325+
aria-label={t('account_details_field_siret')}
326+
>
327+
<OdsText preset="caption">
328+
{t('account_details_field_siret')}
326329
</OdsText>
327-
)}
328-
</OdsFormField>
330+
</label>
331+
<OdsInput
332+
isReadonly={Boolean(
333+
companyNationalIdentificationNumber,
334+
)}
335+
name="companyNationalIdentificationNumber"
336+
value={value}
337+
maxlength={
338+
rules?.companyNationalIdentificationNumber
339+
.maxLength || undefined
340+
}
341+
hasError={!!errors[name]}
342+
onOdsChange={onChange}
343+
onOdsBlur={onBlur}
344+
/>
345+
{errors[name] &&
346+
rules?.companyNationalIdentificationNumber && (
347+
<OdsText
348+
className="text-critical leading-[0.8]"
349+
preset="caption"
350+
>
351+
{renderTranslatedZodError(
352+
errors[name].message,
353+
rules?.companyNationalIdentificationNumber,
354+
)}
355+
</OdsText>
356+
)}
357+
</OdsFormField>
358+
{shouldDisplaySIREN && (
359+
<OdsFormField>
360+
<label
361+
htmlFor="companyNationalRegistrationNumber"
362+
slot="label"
363+
aria-label={t('account_details_field_siren')}
364+
>
365+
<OdsText preset="caption">
366+
{t('account_details_field_siren')}
367+
</OdsText>
368+
</label>
369+
<OdsInput
370+
isReadonly
371+
name="companyNationalRegistrationNumber"
372+
value={sirenValue}
373+
/>
374+
</OdsFormField>
375+
)}
376+
</>
329377
)}
330378
/>
331379
)}
@@ -695,7 +743,7 @@ export default function AccountDetailsPage() {
695743
const { t: tAction } = useTranslation(NAMESPACES.ACTIONS);
696744
const { legalForm, organisation } = useUserContext();
697745
const { data: currentUser } = useMe();
698-
const wentThroughCompanySearch = shouldAccessCompanySearch(
746+
const wentThroughOrganizationSearch = shouldAccessOrganizationSearch(
699747
currentUser?.country,
700748
legalForm,
701749
);
@@ -740,11 +788,13 @@ export default function AccountDetailsPage() {
740788
<OdsLink
741789
icon={ODS_ICON_NAME.arrowLeft}
742790
iconAlignment={ODS_LINK_ICON_ALIGNMENT.left}
743-
href={`#${wentThroughCompanySearch ? urls.company : urls.accountType}`}
791+
href={`#${
792+
wentThroughOrganizationSearch ? urls.company : urls.accountType
793+
}`}
744794
label={tAction('back')}
745795
className="flex mb-6"
746796
/>
747-
{wentThroughCompanySearch && (
797+
{wentThroughOrganizationSearch && (
748798
<OdsText preset={ODS_TEXT_PRESET.caption}>
749799
{tCommon('step', { current: 2, total: 2 })}
750800
</OdsText>

0 commit comments

Comments
 (0)