Skip to content

Commit

Permalink
fix(pci-object-storage): containerNameStep
Browse files Browse the repository at this point in the history
ref: DTCORE-2996, DTCORE-2997
Signed-off-by: Florian Renaut <[email protected]>
  • Loading branch information
frenautvh committed Jan 22, 2025
1 parent 372ca9e commit e9c8f6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
STORAGE_ASYNC_REPLICATION_LINK,
} from '@/constants';

const validNameRegex = '^[a-z0-9]([a-z0-9.-]{1,61})[a-z0-9]$';
const validNameRegex = /^[a-z0-9]([a-z0-9.\\-]{1,61})[a-z0-9]$/;

interface ContainerNameStepProps {
isCreationPending: boolean;
Expand All @@ -42,8 +42,14 @@ export function ContainerNameStep({
const navigate = useNavigate();
const { ovhSubsidiary } = context.environment.getUser();
const { form, stepper, setContainerName } = useContainerCreationStore();
const [isTouched, setIsTouched] = useState(false);

const [nameError, setNameError] = useState(undefined);
let nameError: string | undefined;
if (isTouched && !form.containerName) {
nameError = t('pci-common:common_field_error_required');
} else if (isTouched && !validNameRegex.test(form.containerName)) {
nameError = t('pci-common:common_field_error_pattern');
}

const asyncReplicationLink =
STORAGE_ASYNC_REPLICATION_LINK[ovhSubsidiary] ||
Expand All @@ -67,7 +73,7 @@ export function ContainerNameStep({
onSubmit(form);
},
label: t('pci_projects_project_storages_containers_add_submit_label'),
isDisabled: nameError,
isDisabled: !!nameError,
}}
skip={{
action: () => {
Expand All @@ -86,18 +92,11 @@ export function ContainerNameStep({
name="containerName"
color="primary"
isRequired
pattern={`${validNameRegex}`}
onOdsChange={(event) => {
if (event.detail.validity?.valueMissing) {
setNameError(t('pci-common:common_field_error_required'));
} else if (event.detail.validity?.patternMismatch) {
setNameError(t('pci-common:common_field_error_pattern'));
} else {
setNameError(undefined);
}

if (event.detail.value)
setContainerName(event.detail.value.toString());
setContainerName(`${event.detail.value}`);
}}
onOdsBlur={() => {
setIsTouched(true);
}}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ exports[`ContainerNameStep > renders the component 1`] = `
color="primary"
is-required="true"
name="containerName"
pattern="^[a-z0-9]([a-z0-9.-]{1,61})[a-z0-9]$"
value=""
/>
<ods-text
Expand Down

0 comments on commit e9c8f6b

Please sign in to comment.