Skip to content

Commit 3b0b83d

Browse files
committed
fix(pci-instances): update naming instance
ref: #TAPC-6793 Signed-off-by: Yann Allançon <yann.allancon.ext@corp.ovh.com>
1 parent 2479fed commit 3b0b83d

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

  • packages/manager/apps/pci-instances/src/pages/instances/create/components

packages/manager/apps/pci-instances/src/pages/instances/create/components/Name.component.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const Name = () => {
1414
register,
1515
control,
1616
setValue,
17+
getValues,
1718
formState: {
1819
errors: { name: error },
1920
},
@@ -25,14 +26,16 @@ export const Name = () => {
2526
select: selectOvhInstanceName(flavorId),
2627
});
2728

28-
const hasInitializedName = useRef(false);
29+
const lastAutoGeneratedName = useRef<string | null>(null);
2930

3031
useEffect(() => {
31-
if (ovhInstanceName && !hasInitializedName.current) {
32+
if (!ovhInstanceName) return;
33+
const currentName = getValues('name');
34+
if (!currentName || currentName === lastAutoGeneratedName.current) {
3235
setValue('name', ovhInstanceName);
33-
hasInitializedName.current = true;
36+
lastAutoGeneratedName.current = ovhInstanceName;
3437
}
35-
}, [ovhInstanceName, setValue]);
38+
}, [ovhInstanceName, getValues, setValue]);
3639

3740
return (
3841
<article className="flex w-full flex-col">

0 commit comments

Comments
 (0)