2022-11-16 04:15:53 +00:00
|
|
|
import { REP_DOMAIN } from '../consts/REG_EXP_PATTERNS';
|
|
|
|
|
2023-04-04 03:25:23 +00:00
|
|
|
import testNotBlank from './testNotBlank';
|
2022-11-16 04:15:53 +00:00
|
|
|
import { InlineMonoText } from '../../components/Text';
|
|
|
|
|
|
|
|
const buildDomainTestBatch: BuildInputTestBatchFunction = (
|
|
|
|
inputName,
|
|
|
|
onSuccess,
|
2023-03-04 00:28:48 +00:00
|
|
|
{ isRequired, onFinishBatch, ...defaults } = {},
|
2022-11-16 04:15:53 +00:00
|
|
|
onDomainTestFailure,
|
|
|
|
) => ({
|
2022-11-25 04:56:46 +00:00
|
|
|
defaults: { ...defaults, onSuccess },
|
2023-03-04 00:28:48 +00:00
|
|
|
isRequired,
|
2022-11-25 04:56:46 +00:00
|
|
|
onFinishBatch,
|
2022-11-16 04:15:53 +00:00
|
|
|
tests: [
|
2023-04-04 03:25:23 +00:00
|
|
|
{
|
|
|
|
test: testNotBlank,
|
|
|
|
},
|
2022-11-16 04:15:53 +00:00
|
|
|
{
|
|
|
|
onFailure: (...args) => {
|
|
|
|
onDomainTestFailure(
|
|
|
|
<>
|
|
|
|
{inputName} can only contain lowercase alphanumeric, hyphen (
|
2023-04-05 21:18:51 +00:00
|
|
|
<InlineMonoText inheritColour text="-" />
|
|
|
|
), and dot (<InlineMonoText inheritColour text="." />) characters.
|
2022-11-16 04:15:53 +00:00
|
|
|
</>,
|
|
|
|
...args,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
test: ({ compare, value }) =>
|
|
|
|
(compare[0] as boolean) || REP_DOMAIN.test(value as string),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
export default buildDomainTestBatch;
|