@swan-io/shared-business 18.5.0 → 18.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/components/BirthdatePicker.d.ts +3 -1
- package/src/components/BirthdatePicker.js +2 -2
- package/src/components/FileInput.js +25 -10
- package/src/components/FileTile.d.ts +4 -3
- package/src/components/FileTile.js +14 -7
- package/src/components/FilesUploader.js +12 -4
- package/src/components/FraudReport/CardDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/CardDetailsStep.js +46 -0
- package/src/components/FraudReport/DocumentsStep.d.ts +13 -0
- package/src/components/FraudReport/DocumentsStep.js +49 -0
- package/src/components/FraudReport/FraudReportLayout.d.ts +2 -1
- package/src/components/FraudReport/FraudReportLayout.js +2 -2
- package/src/components/FraudReport/FraudsterDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/FraudsterDetailsStep.js +56 -0
- package/src/components/FraudReport/IntroStep.js +5 -1
- package/src/components/FraudReport/TransactionPicker.d.ts +13 -0
- package/src/components/FraudReport/TransactionPicker.js +213 -0
- package/src/components/FraudReport/TransactionPickerFilters.d.ts +8 -0
- package/src/components/FraudReport/TransactionPickerFilters.js +213 -0
- package/src/components/FraudReport/TransactionRows.d.ts +8 -0
- package/src/components/FraudReport/TransactionRows.js +32 -0
- package/src/components/FraudReport/TransactionsStep.js +9 -27
- package/src/components/FraudReport/TransferDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/TransferDetailsStep.js +25 -0
- package/src/components/FraudReport/VictimStep.d.ts +3 -1
- package/src/components/FraudReport/VictimStep.js +38 -5
- package/src/components/LakeModal.js +1 -1
- package/src/components/SupportingDocumentCollection.d.ts +1 -0
- package/src/components/SupportingDocumentCollection.js +13 -14
- package/src/hooks/__tests__/useFilesUploader.test.d.ts +1 -0
- package/src/hooks/__tests__/useFilesUploader.test.js +101 -0
- package/src/hooks/__tests__/useFraudReportFlow.test.js +108 -20
- package/src/hooks/useFilesUploader.d.ts +2 -1
- package/src/hooks/useFilesUploader.js +28 -9
- package/src/hooks/useFraudReportFlow.js +12 -7
- package/src/locales/de.json +84 -8
- package/src/locales/en.json +77 -1
- package/src/locales/es.json +77 -1
- package/src/locales/fi.json +77 -1
- package/src/locales/fr.json +77 -1
- package/src/locales/it.json +77 -1
- package/src/locales/nl.json +77 -1
- package/src/locales/pt.json +77 -1
- package/src/utils/SwanFile.d.ts +2 -0
- package/src/utils/__tests__/fraudReport.card.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.card.test.js +39 -0
- package/src/utils/__tests__/fraudReport.documents.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.documents.test.js +61 -0
- package/src/utils/__tests__/fraudReport.fraudster.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.fraudster.test.js +35 -0
- package/src/utils/__tests__/fraudReport.messages.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.messages.test.js +28 -0
- package/src/utils/__tests__/fraudReport.picker.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.picker.test.js +186 -0
- package/src/utils/__tests__/fraudReport.pickerFilters.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.pickerFilters.test.js +144 -0
- package/src/utils/__tests__/fraudReport.prefill.test.js +7 -1
- package/src/utils/__tests__/fraudReport.rejections.test.js +11 -19
- package/src/utils/__tests__/fraudReport.resume.test.js +19 -4
- package/src/utils/__tests__/fraudReport.toInput.test.js +160 -40
- package/src/utils/__tests__/fraudReport.transactions.test.js +11 -1
- package/src/utils/__tests__/fraudReport.transfer.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.transfer.test.js +31 -0
- package/src/utils/__tests__/fraudReport.victim.test.js +27 -1
- package/src/utils/__tests__/validation.test.js +81 -7
- package/src/utils/fraudReport/card.d.ts +11 -0
- package/src/utils/fraudReport/card.js +15 -0
- package/src/utils/fraudReport/documents.d.ts +9 -0
- package/src/utils/fraudReport/documents.js +18 -0
- package/src/utils/fraudReport/fakeApi.js +1 -1
- package/src/utils/fraudReport/fraudster.d.ts +10 -0
- package/src/utils/fraudReport/fraudster.js +11 -0
- package/src/utils/fraudReport/messages.d.ts +4 -0
- package/src/utils/fraudReport/messages.js +7 -0
- package/src/utils/fraudReport/picker.d.ts +19 -0
- package/src/utils/fraudReport/picker.js +50 -0
- package/src/utils/fraudReport/pickerFilters.d.ts +26 -0
- package/src/utils/fraudReport/pickerFilters.js +62 -0
- package/src/utils/fraudReport/prefill.d.ts +1 -1
- package/src/utils/fraudReport/prefill.js +6 -3
- package/src/utils/fraudReport/rejections.d.ts +0 -1
- package/src/utils/fraudReport/rejections.js +2 -6
- package/src/utils/fraudReport/resume.js +4 -4
- package/src/utils/fraudReport/toInput.d.ts +6 -3
- package/src/utils/fraudReport/toInput.js +41 -24
- package/src/utils/fraudReport/transactions.d.ts +2 -0
- package/src/utils/fraudReport/transactions.js +4 -0
- package/src/utils/fraudReport/transfer.d.ts +6 -0
- package/src/utils/fraudReport/transfer.js +8 -0
- package/src/utils/fraudReport/types.d.ts +1 -1
- package/src/utils/fraudReport/validation.d.ts +1 -1
- package/src/utils/fraudReport/validation.js +4 -0
- package/src/utils/fraudReport/victim.d.ts +11 -0
- package/src/utils/fraudReport/victim.js +9 -0
- package/src/utils/validation.d.ts +2 -0
- package/src/utils/validation.js +15 -8
|
@@ -10,9 +10,9 @@ export const toRequiredFraudDetails = (values) => Option.allFromDict({
|
|
|
10
10
|
reportedTypology: Option.fromNullable(values.reportedTypology),
|
|
11
11
|
description: toFilled(values.description),
|
|
12
12
|
});
|
|
13
|
-
const toFraudDetails = (values
|
|
13
|
+
const toFraudDetails = (values) => {
|
|
14
14
|
const hasFraudster = getDetailsSteps(values).includes("Fraudster");
|
|
15
|
-
return toRequiredFraudDetails(values).map(required => { var _a;
|
|
15
|
+
return toRequiredFraudDetails(values).map(required => { var _a; return ({
|
|
16
16
|
...required,
|
|
17
17
|
discoveredAt: toFilled(values.discoveredAt).toNull(),
|
|
18
18
|
discoveryDetails: toFilled(values.discoveryDetails).toNull(),
|
|
@@ -20,35 +20,52 @@ const toFraudDetails = (values, savedDetails) => {
|
|
|
20
20
|
sharedInformationWithFraudster: hasFraudster
|
|
21
21
|
? toFilledList(values.sharedInformationWithFraudster).toNull()
|
|
22
22
|
: null,
|
|
23
|
-
hasFiledPoliceComplaint: (
|
|
23
|
+
hasFiledPoliceComplaint: (_a = values.hasFiledPoliceComplaint) !== null && _a !== void 0 ? _a : null,
|
|
24
24
|
}); });
|
|
25
25
|
};
|
|
26
|
-
const toFraudCardDetails = (values,
|
|
26
|
+
const toFraudCardDetails = (values, { sendEmpty }) => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const details = {
|
|
29
|
+
isLostOrStolen: (_a = values.isLostOrStolen) !== null && _a !== void 0 ? _a : null,
|
|
30
|
+
lostOrStolenNoticedAt: toFilled(values.lostOrStolenNoticedAt).toNull(),
|
|
31
|
+
hasContactedMerchant: (_b = values.hasContactedMerchant) !== null && _b !== void 0 ? _b : null,
|
|
32
|
+
};
|
|
33
|
+
return sendEmpty || Object.values(details).some(value => value !== null)
|
|
34
|
+
? Option.Some(details)
|
|
35
|
+
: Option.None();
|
|
36
|
+
};
|
|
37
|
+
const toFraudTransferDetails = (values, { sendEmpty }) => {
|
|
27
38
|
var _a;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
? Option.
|
|
33
|
-
: Option.
|
|
34
|
-
isLostOrStolen: isLostOrStolen.toNull(),
|
|
35
|
-
lostOrStolenNoticedAt: lostOrStolenNoticedAt.toNull(),
|
|
36
|
-
hasContactedMerchant: (_b = (_a = savedDetails === null || savedDetails === void 0 ? void 0 : savedDetails.fraudCardDetails) === null || _a === void 0 ? void 0 : _a.hasContactedMerchant) !== null && _b !== void 0 ? _b : null,
|
|
37
|
-
});
|
|
39
|
+
const details = {
|
|
40
|
+
hasContactedBankOrBeneficiary: (_a = values.hasContactedBankOrBeneficiary) !== null && _a !== void 0 ? _a : null,
|
|
41
|
+
};
|
|
42
|
+
return sendEmpty || Object.values(details).some(value => value !== null)
|
|
43
|
+
? Option.Some(details)
|
|
44
|
+
: Option.None();
|
|
38
45
|
};
|
|
39
|
-
const toDetails = (values,
|
|
40
|
-
const fraudDetails = toFraudDetails(values
|
|
46
|
+
const toDetails = (values, { isUpdate }) => {
|
|
47
|
+
const fraudDetails = toFraudDetails(values)
|
|
41
48
|
.map(value => ({ fraudDetails: value }))
|
|
42
49
|
.toUndefined();
|
|
50
|
+
const fraudCardDetails = toFraudCardDetails(values, { sendEmpty: isUpdate })
|
|
51
|
+
.map(value => ({ fraudCardDetails: value }))
|
|
52
|
+
.toUndefined();
|
|
53
|
+
const fraudTransferDetails = toFraudTransferDetails(values, { sendEmpty: isUpdate })
|
|
54
|
+
.map(value => ({ fraudTransferDetails: value }))
|
|
55
|
+
.toUndefined();
|
|
43
56
|
return match(getCaseRail(values.transactions))
|
|
44
|
-
.with(Option.P.Some(
|
|
57
|
+
.with(Option.P.Some("CardOnly"), () => ({
|
|
45
58
|
...fraudDetails,
|
|
46
|
-
...
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
...fraudCardDetails,
|
|
60
|
+
}))
|
|
61
|
+
.with(Option.P.Some("Mixed"), () => ({
|
|
62
|
+
...fraudDetails,
|
|
63
|
+
...fraudCardDetails,
|
|
64
|
+
...fraudTransferDetails,
|
|
49
65
|
}))
|
|
50
66
|
.with(Option.P.Some("TransferOnly"), () => ({
|
|
51
67
|
...fraudDetails,
|
|
68
|
+
...fraudTransferDetails,
|
|
52
69
|
...toFilled(values.victimAccountMembershipId)
|
|
53
70
|
.map(value => ({ victimAccountMembershipId: value }))
|
|
54
71
|
.toUndefined(),
|
|
@@ -63,17 +80,17 @@ const isSameSelection = (transactionIds, savedTransactionIds) => {
|
|
|
63
80
|
};
|
|
64
81
|
export const toDraftInput = (values) => ({
|
|
65
82
|
transactionIds: toTransactionIds(values),
|
|
66
|
-
...toDetails(values),
|
|
83
|
+
...toDetails(values, { isUpdate: false }),
|
|
67
84
|
...match(values.externalReference)
|
|
68
85
|
.with(P.union(undefined, ""), () => undefined)
|
|
69
86
|
.otherwise(externalReference => ({ externalReference })),
|
|
70
87
|
});
|
|
71
|
-
export const toUpdateInput = ({
|
|
88
|
+
export const toUpdateInput = ({ disputeCaseId, values, savedTransactionIds, }) => {
|
|
72
89
|
const transactionIds = toTransactionIds(values);
|
|
73
90
|
return {
|
|
74
|
-
disputeCaseId
|
|
91
|
+
disputeCaseId,
|
|
75
92
|
...(isSameSelection(transactionIds, savedTransactionIds) ? undefined : { transactionIds }),
|
|
76
|
-
...toDetails(values,
|
|
93
|
+
...toDetails(values, { isUpdate: true }),
|
|
77
94
|
...match(values.externalReference)
|
|
78
95
|
.with(undefined, () => undefined)
|
|
79
96
|
.with("", () => ({ externalReference: null }))
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { FraudReportTransaction } from "./types";
|
|
2
|
+
export declare const MAX_TRANSACTIONS = 100;
|
|
3
|
+
export declare const getTransactionsOverLimit: (count: number) => number;
|
|
2
4
|
export declare const removeDuplicateTransactions: (transactions: FraudReportTransaction[]) => FraudReportTransaction[];
|
|
3
5
|
export declare const getTransactionsTotal: (transactions: Pick<FraudReportTransaction, "amount">[]) => {
|
|
4
6
|
value: number;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// The most transactions a dispute case takes (`DisputeCaseTransactionsLimitExceededRejection`).
|
|
2
|
+
export const MAX_TRANSACTIONS = 100;
|
|
3
|
+
// How many transactions a selection has to lose to fit in one report.
|
|
4
|
+
export const getTransactionsOverLimit = (count) => Math.max(0, count - MAX_TRANSACTIONS);
|
|
1
5
|
export const removeDuplicateTransactions = (transactions) => transactions.filter((transaction, index) => transactions.findIndex(({ id }) => id === transaction.id) === index);
|
|
2
6
|
export const getTransactionsTotal = (transactions) => {
|
|
3
7
|
var _a;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FraudReportFormValues } from "./toInput";
|
|
2
|
+
export type TransferAction = "BankOrBeneficiary" | "Police";
|
|
3
|
+
type TransferValues = Pick<FraudReportFormValues, "hasContactedBankOrBeneficiary" | "hasFiledPoliceComplaint">;
|
|
4
|
+
export declare const getTransferActions: ({ hasContactedBankOrBeneficiary, hasFiledPoliceComplaint, }: TransferValues) => TransferAction[];
|
|
5
|
+
export declare const toTransferValues: (actions: TransferAction[]) => TransferValues;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const getTransferActions = ({ hasContactedBankOrBeneficiary, hasFiledPoliceComplaint, }) => [
|
|
2
|
+
...(hasContactedBankOrBeneficiary === true ? ["BankOrBeneficiary"] : []),
|
|
3
|
+
...(hasFiledPoliceComplaint === true ? ["Police"] : []),
|
|
4
|
+
];
|
|
5
|
+
export const toTransferValues = (actions) => ({
|
|
6
|
+
hasContactedBankOrBeneficiary: actions.includes("BankOrBeneficiary") ? true : undefined,
|
|
7
|
+
hasFiledPoliceComplaint: actions.includes("Police") ? true : undefined,
|
|
8
|
+
});
|
|
@@ -4,7 +4,7 @@ export type FraudsterChannel = "Email" | "Sms" | "Phone" | "Website" | "Applicat
|
|
|
4
4
|
export type SharedInformationWithFraudster = "SwanPasscode" | "PartnerPassword" | "VerificationCode" | "PersonalInformation" | "CardDetails" | "BankDetails" | "Other" | "None";
|
|
5
5
|
export type DisputeCaseStatus = "Draft" | "Expired" | "Canceled" | "Submitted";
|
|
6
6
|
export type DisputeCaseTransactionNotReportableReason = "TransactionTypeNotReportable" | "TransactionStatusNotReportable";
|
|
7
|
-
export type FraudReportDocumentPurpose = "PoliceReport" | "FraudEvidence" | "DisputeCorrespondence" | "
|
|
7
|
+
export type FraudReportDocumentPurpose = "PoliceReport" | "FraudEvidence" | "DisputeCorrespondence" | "Other";
|
|
8
8
|
export type SupportingDocumentCollectionStatus = "WaitingForDocument" | "PendingReview" | "Approved" | "Canceled" | "Rejected";
|
|
9
9
|
export type FraudDetailsInput = {
|
|
10
10
|
reportedReason: FraudReason;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Validator } from "@swan-io/use-form";
|
|
2
2
|
import type { SharedInformationWithFraudster } from "./types";
|
|
3
|
-
export type FraudReportValidationError = "Required" | "Duplicates" | "InvalidDate" | "DateInFuture" | "NoneWithOtherValues" | "TooLong" | "InvalidCharacters";
|
|
3
|
+
export type FraudReportValidationError = "Required" | "Duplicates" | "TooMany" | "InvalidDate" | "DateInFuture" | "NoneWithOtherValues" | "TooLong" | "InvalidCharacters";
|
|
4
4
|
type FraudReportValidator<Value> = Validator<Value, FraudReportValidationError>;
|
|
5
5
|
export declare const DESCRIPTION_MAX_LENGTH = 2000;
|
|
6
6
|
export declare const DISCOVERY_DETAILS_MAX_LENGTH = 1000;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
|
+
import { MAX_TRANSACTIONS } from "./transactions";
|
|
2
3
|
export const DESCRIPTION_MAX_LENGTH = 2000;
|
|
3
4
|
export const DISCOVERY_DETAILS_MAX_LENGTH = 1000;
|
|
4
5
|
export const EXTERNAL_REFERENCE_MAX_LENGTH = 255;
|
|
@@ -10,6 +11,9 @@ export const validateTransactionIds = transactionIds => {
|
|
|
10
11
|
if (new Set(transactionIds).size !== transactionIds.length) {
|
|
11
12
|
return "Duplicates";
|
|
12
13
|
}
|
|
14
|
+
if (transactionIds.length > MAX_TRANSACTIONS) {
|
|
15
|
+
return "TooMany";
|
|
16
|
+
}
|
|
13
17
|
};
|
|
14
18
|
export const validateSelected = (value) => (value == null ? "Required" : undefined);
|
|
15
19
|
export const validateNotInFuture = value => {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import type { FraudReportTransaction } from "./types";
|
|
2
3
|
export type FraudReportAccountMembership = {
|
|
3
4
|
id: string;
|
|
4
5
|
name: string;
|
|
6
|
+
phoneNumber?: string;
|
|
5
7
|
};
|
|
6
8
|
export type VictimAnswer = "Myself" | "SomeoneElse";
|
|
7
9
|
type VictimChoice = {
|
|
@@ -27,4 +29,13 @@ export declare const getVictimAccountMembershipId: ({ currentAccountMembership,
|
|
|
27
29
|
accountMemberships: FraudReportAccountMembership[];
|
|
28
30
|
choice: VictimChoice;
|
|
29
31
|
}) => Option<string>;
|
|
32
|
+
export declare const getVictimChange: ({ transactions, previousVictimAccountMembershipId, victimAccountMembershipId, }: {
|
|
33
|
+
transactions: FraudReportTransaction[];
|
|
34
|
+
previousVictimAccountMembershipId: string | undefined;
|
|
35
|
+
victimAccountMembershipId: string | undefined;
|
|
36
|
+
}) => {
|
|
37
|
+
changed: boolean;
|
|
38
|
+
removed: FraudReportTransaction[];
|
|
39
|
+
kept: FraudReportTransaction[];
|
|
40
|
+
};
|
|
30
41
|
export {};
|
|
@@ -26,3 +26,12 @@ export const getVictimAccountMembershipId = ({ currentAccountMembership, account
|
|
|
26
26
|
.exhaustive()),
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
+
export const getVictimChange = ({ transactions, previousVictimAccountMembershipId, victimAccountMembershipId, }) => {
|
|
30
|
+
const changed = victimAccountMembershipId != null &&
|
|
31
|
+
previousVictimAccountMembershipId !== victimAccountMembershipId;
|
|
32
|
+
return {
|
|
33
|
+
changed,
|
|
34
|
+
removed: changed ? transactions.filter(({ rail }) => rail === "Card") : [],
|
|
35
|
+
kept: changed ? transactions.filter(({ rail }) => rail !== "Card") : transactions,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -20,6 +20,8 @@ export { printFormat as printIbanFormat } from "iban";
|
|
|
20
20
|
export declare const validateIban: (iban: string) => string | undefined;
|
|
21
21
|
export declare const validateDate: (value: ExtractedDate | undefined) => string | undefined;
|
|
22
22
|
export declare const validateBirthdate: (value: ExtractedDate | undefined) => string | undefined;
|
|
23
|
+
export declare const validateAdultBirthdate: (value: ExtractedDate | undefined) => string | undefined;
|
|
24
|
+
export declare const validateAdultBirthdateString: (value: string | undefined) => string | undefined;
|
|
23
25
|
export declare const getTaxNumberLabel: (isCompany: boolean, country: CompanyCountryCCA3) => string;
|
|
24
26
|
export declare const getIndividualTaxNumberPlaceholder: (country: IndividualCountryCCA3 | CompanyCountryCCA3) => string | undefined;
|
|
25
27
|
export declare const getCompanyTaxNumberPlaceholder: (country: IndividualCountryCCA3 | CompanyCountryCCA3) => string | undefined;
|
package/src/utils/validation.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isNullish } from "@swan-io/lake/src/utils/nullish";
|
|
1
|
+
import { isNotNullishOrEmpty, isNullish } from "@swan-io/lake/src/utils/nullish";
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
3
|
import { isValid as isValidIban } from "iban";
|
|
4
4
|
import { match, P } from "ts-pattern";
|
|
5
|
-
import { formatExtractedDate } from "./date";
|
|
5
|
+
import { extractDate, formatExtractedDate } from "./date";
|
|
6
6
|
import { locale, t } from "./i18n";
|
|
7
7
|
const EMAIL_REGEX = /^[A-Z0-9_+.-]*[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i;
|
|
8
8
|
const VAT_NUMBER_REGEX = /^((AT)?U[0-9]{8}|(BE)?[01][0-9]{9}|(BG)?[0-9]{9,10}|(CY)?[0-9]{8}L|(CZ)?[0-9]{8,10}|(DE)?[0-9]{9}|(DK)?[0-9]{8}|(EE)?[0-9]{9}|(EL|GR)?[0-9]{9}|(ES)?[0-9A-Z][0-9]{7}[0-9A-Z]|(FI)?[0-9]{8}|(FR)?[0-9A-Z]{2}[0-9]{9}|(GB)?([0-9]{9}([0-9]{3})?|[A-Z]{2}[0-9]{3})|(HU)?[0-9]{8}|(IE)?[0-9]S[0-9]{5}L|(IT)?[0-9]{11}|(LT)?([0-9]{9}|[0-9]{12})|(LU)?[0-9]{8}|(LV)?[0-9]{11}|(MT)?[0-9]{8}|(NL)?[0-9]{9}B[0-9]{2}|(PL)?[0-9]{10}|(PT)?[0-9]{9}|(RO)?[0-9]{2,10}|(SE)?[0-9]{12}|(SI)?[0-9]{8}|(SK)?[0-9]{10})$/;
|
|
@@ -48,7 +48,7 @@ const TAX_NUMBER_REGEX = {
|
|
|
48
48
|
message: t("common.form.help.nbCharacters", { nbCharacters: "9" }),
|
|
49
49
|
},
|
|
50
50
|
FIN: {
|
|
51
|
-
pattern:
|
|
51
|
+
pattern: /^\d{6}[-+A-FU-Y]\d{3}[0-9A-FHJ-NPR-Y]$/i,
|
|
52
52
|
message: t("common.form.help.nbCharacters", { nbCharacters: "11" }),
|
|
53
53
|
},
|
|
54
54
|
FRA: {
|
|
@@ -221,20 +221,27 @@ export const validateDate = (value) => {
|
|
|
221
221
|
return t("validation.invalidDate");
|
|
222
222
|
}
|
|
223
223
|
};
|
|
224
|
-
|
|
224
|
+
const MAX_AGE = 150;
|
|
225
|
+
const ADULT_AGE = 18;
|
|
226
|
+
const getBirthdateError = (value, adultsOnly) => {
|
|
225
227
|
if (isNullish(value)) {
|
|
226
228
|
return t("validation.invalidBirthDate");
|
|
227
229
|
}
|
|
228
230
|
const date = dayjs.utc(formatExtractedDate(value), "YYYY-MM-DD", true);
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
if (!date.isValid() || isBirthdateOver150years || isBirthdateWithin4years) {
|
|
231
|
+
const today = dayjs.utc().startOf("day");
|
|
232
|
+
if (!date.isValid() || date.isBefore(today.subtract(MAX_AGE, "years"))) {
|
|
232
233
|
return t("validation.invalidBirthDate");
|
|
233
234
|
}
|
|
234
|
-
if (date.isAfter(
|
|
235
|
+
if (date.isAfter(today)) {
|
|
235
236
|
return t("validation.birthdateCannotBeFuture");
|
|
236
237
|
}
|
|
238
|
+
if (adultsOnly && today.diff(date, "years") < ADULT_AGE) {
|
|
239
|
+
return t("validation.birthdateMustBeAdult");
|
|
240
|
+
}
|
|
237
241
|
};
|
|
242
|
+
export const validateBirthdate = (value) => getBirthdateError(value, false);
|
|
243
|
+
export const validateAdultBirthdate = (value) => getBirthdateError(value, true);
|
|
244
|
+
export const validateAdultBirthdateString = (value) => isNotNullishOrEmpty(value) ? validateAdultBirthdate(extractDate(value)) : undefined;
|
|
238
245
|
/*
|
|
239
246
|
* Translation helpers for tax validation
|
|
240
247
|
*/
|