-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pci.private-network): implementing editable allocation pool
ref: TAPC-1860 Signed-off-by: tsiorifamonjena <[email protected]>
- Loading branch information
1 parent
30bb81e
commit c581689
Showing
7 changed files
with
137 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
58 changes: 58 additions & 0 deletions
58
...etwork/src/pages/new/subnet/advanced/allocationPool/AllocationPoolInputEdit.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { FC, PropsWithChildren } from 'react'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import IpRange from '@/components/ip-range/IpRange.component'; | ||
import { NewPrivateNetworkForm } from '@/types/private-network-form.type'; | ||
|
||
const AllocationPoolInputEdit: FC<PropsWithChildren<{ position: number }>> = ({ | ||
children, | ||
position, | ||
}) => { | ||
const { | ||
setValue, | ||
watch, | ||
formState: { touchedFields, errors }, | ||
} = useFormContext<NewPrivateNetworkForm>(); | ||
const allocationPools = watch('subnet.allocationPools'); | ||
const startIp = allocationPools[position]?.start; | ||
const endIp = allocationPools[position]?.end; | ||
|
||
const isTouched = touchedFields.subnet?.allocationPools; | ||
const isErrors = errors.subnet?.allocationPools?.[position]; | ||
const isStartIpHasError = isTouched && !!isErrors?.start; | ||
const isEndIpHasError = isTouched && !!isErrors?.end; | ||
|
||
const onIpChange = (key: string, value: string) => { | ||
if (value) { | ||
const updatedPools = [...allocationPools]; | ||
|
||
updatedPools[position] = { ...updatedPools[position], [key]: value }; | ||
|
||
setValue('subnet.allocationPools', updatedPools, { | ||
shouldTouch: true, | ||
shouldValidate: true, | ||
}); | ||
} | ||
}; | ||
|
||
const onStartIpChange = ({ target }) => | ||
onIpChange('start', target.value as string); | ||
|
||
const onEndIpChange = ({ target }) => { | ||
onIpChange('end', target.value as string); | ||
}; | ||
|
||
return ( | ||
<IpRange | ||
start={startIp} | ||
end={endIp} | ||
isStartIpHasError={isStartIpHasError} | ||
isEndIpHasError={isEndIpHasError} | ||
onStartIpChange={onStartIpChange} | ||
onEndIpChange={onEndIpChange} | ||
> | ||
{children} | ||
</IpRange> | ||
); | ||
}; | ||
|
||
export default AllocationPoolInputEdit; |
79 changes: 0 additions & 79 deletions
79
...e-network/src/pages/new/subnet/advanced/allocationPool/list/AllocationPools.component.tsx
This file was deleted.
Oops, something went wrong.
86 changes: 0 additions & 86 deletions
86
...-network/src/pages/new/subnet/advanced/allocationPool/new/NewAllocationPool.component.tsx
This file was deleted.
Oops, something went wrong.