Skip to content

Commit 7954f77

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 7954f77

File tree

11 files changed

+97
-40
lines changed

11 files changed

+97
-40
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 shouldEnableForFrenchCorporation = (
9+
country?: Country,
10+
legalForm?: LegalForm,
11+
) => country === 'FR' && legalForm && 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: 72 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
shouldEnableForFrenchCorporation,
51+
} from '@/helpers/flowHelper';
4852

4953
type AccountDetailsFormProps = {
5054
rules: Record<RuleField, Rule>;
@@ -291,41 +295,70 @@ function AccountDetailsForm({
291295
control={control}
292296
name="companyNationalIdentificationNumber"
293297
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"
298+
<>
299+
<OdsFormField>
300+
<label
301+
htmlFor={name}
302+
slot="label"
303+
aria-label={t('account_details_field_siret')}
304+
>
305+
<OdsText preset="caption">
306+
{t('account_details_field_siret')}
307+
</OdsText>
308+
</label>
309+
<OdsInput
310+
isReadonly={Boolean(
311+
companyNationalIdentificationNumber,
312+
)}
313+
name="companyNationalIdentificationNumber"
314+
value={value}
315+
maxlength={
316+
rules?.companyNationalIdentificationNumber
317+
.maxLength || undefined
318+
}
319+
hasError={!!errors[name]}
320+
onOdsChange={onChange}
321+
onOdsBlur={onBlur}
322+
/>
323+
{errors[name] &&
324+
rules?.companyNationalIdentificationNumber && (
325+
<OdsText
326+
className="text-critical leading-[0.8]"
327+
preset="caption"
328+
>
329+
{renderTranslatedZodError(
330+
errors[name].message,
331+
rules?.companyNationalIdentificationNumber,
332+
)}
333+
</OdsText>
334+
)}
335+
</OdsFormField>
336+
{shouldEnableForFrenchCorporation(
337+
currentUser.country,
338+
legalForm,
339+
) && (
340+
<OdsFormField>
341+
<label
342+
htmlFor="companyNationalRegistrationNumber"
343+
slot="label"
344+
aria-label={t('account_details_field_siren')}
321345
>
322-
{renderTranslatedZodError(
323-
errors[name].message,
324-
rules?.companyNationalIdentificationNumber,
346+
<OdsText preset="caption">
347+
{t('account_details_field_siren')}
348+
</OdsText>
349+
</label>
350+
<OdsInput
351+
isReadonly
352+
name="companyNationalRegistrationNumber"
353+
value={getSirenFromSiret(
354+
value,
355+
rules.companyNationalIdentificationNumber
356+
.regularExpression,
325357
)}
326-
</OdsText>
327-
)}
328-
</OdsFormField>
358+
/>
359+
</OdsFormField>
360+
)}
361+
</>
329362
)}
330363
/>
331364
)}
@@ -695,7 +728,7 @@ export default function AccountDetailsPage() {
695728
const { t: tAction } = useTranslation(NAMESPACES.ACTIONS);
696729
const { legalForm, organisation } = useUserContext();
697730
const { data: currentUser } = useMe();
698-
const wentThroughCompanySearch = shouldAccessCompanySearch(
731+
const wentThroughOrganizationSearch = shouldAccessOrganizationSearch(
699732
currentUser?.country,
700733
legalForm,
701734
);
@@ -740,11 +773,13 @@ export default function AccountDetailsPage() {
740773
<OdsLink
741774
icon={ODS_ICON_NAME.arrowLeft}
742775
iconAlignment={ODS_LINK_ICON_ALIGNMENT.left}
743-
href={`#${wentThroughCompanySearch ? urls.company : urls.accountType}`}
776+
href={`#${
777+
wentThroughOrganizationSearch ? urls.company : urls.accountType
778+
}`}
744779
label={tAction('back')}
745780
className="flex mb-6"
746781
/>
747-
{wentThroughCompanySearch && (
782+
{wentThroughOrganizationSearch && (
748783
<OdsText preset={ODS_TEXT_PRESET.caption}>
749784
{tCommon('step', { current: 2, total: 2 })}
750785
</OdsText>

0 commit comments

Comments
 (0)