11import { useAllVPCsQuery , useRegionQuery } from '@linode/queries' ;
2- import {
3- Autocomplete ,
4- Box ,
5- Checkbox ,
6- Divider ,
7- FormControlLabel ,
8- Notice ,
9- Stack ,
10- TextField ,
11- TooltipIcon ,
12- Typography ,
13- } from '@linode/ui' ;
2+ import { Autocomplete , Box , Divider , Stack , Typography } from '@linode/ui' ;
143import { LinkButton } from '@linode/ui' ;
154import React , { useState } from 'react' ;
165import { Controller , useFormContext , useWatch } from 'react-hook-form' ;
176
18- import {
19- VPCIPv6PublicIPLabel ,
20- VPCPublicIPLabel ,
21- } from 'src/features/VPCs/components/VPCPublicIPLabel' ;
22- import {
23- REGION_CAVEAT_HELPER_TEXT ,
24- VPC_AUTO_ASSIGN_IPV4_TOOLTIP ,
25- VPC_AUTO_ASSIGN_IPV6_TOOLTIP ,
26- VPC_IPV4_INPUT_HELPER_TEXT ,
27- VPC_IPV6_INPUT_HELPER_TEXT ,
28- } from 'src/features/VPCs/constants' ;
7+ import { PublicIPv4Access } from 'src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeInterfaces/PublicIPv4Access' ;
8+ import { PublicIPv6Access } from 'src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeInterfaces/PublicIPv6Access' ;
9+ import { VPCIPv4Address } from 'src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeInterfaces/VPCIPv4Address' ;
10+ import { VPCIPv6Address } from 'src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeInterfaces/VPCIPv6Address' ;
11+ import { REGION_CAVEAT_HELPER_TEXT } from 'src/features/VPCs/constants' ;
2912import { VPCCreateDrawer } from 'src/features/VPCs/VPCCreateDrawer/VPCCreateDrawer' ;
3013import { useVPCDualStack } from 'src/hooks/useVPCDualStack' ;
3114
@@ -161,85 +144,35 @@ export const VPC = ({ index }: Props) => {
161144 control = { control }
162145 name = { `linodeInterfaces.${ index } .vpc.ipv4.addresses.0.address` }
163146 render = { ( { field, fieldState } ) => (
164- < Box >
165- < FormControlLabel
166- checked = { field . value === 'auto' }
167- control = { < Checkbox sx = { { ml : 0.4 } } /> }
168- disabled = { ! regionSupportsVPCs }
169- label = {
170- < Stack alignItems = "center" direction = "row" >
171- < Typography > Auto-assign VPC IPv4</ Typography >
172- < TooltipIcon
173- status = "info"
174- text = { VPC_AUTO_ASSIGN_IPV4_TOOLTIP }
175- />
176- </ Stack >
177- }
178- onChange = { ( e , checked ) =>
179- field . onChange ( checked ? 'auto' : '' )
180- }
181- />
182- { field . value !== 'auto' && (
183- < TextField
184- containerProps = { { sx : { mb : 1.5 , mt : 1 } } }
185- errorText = {
186- fieldState . error ?. message ??
187- errors . linodeInterfaces ?. [ index ] ?. vpc ?. ipv4
188- ?. addresses ?. [ 0 ] ?. message
189- }
190- helperText = { VPC_IPV4_INPUT_HELPER_TEXT }
191- label = "VPC IPv4"
192- noMarginTop
193- onBlur = { field . onBlur }
194- onChange = { field . onChange }
195- required
196- value = { field . value }
197- />
198- ) }
199- </ Box >
147+ < VPCIPv4Address
148+ disabled = { ! regionSupportsVPCs }
149+ errorMessage = {
150+ fieldState . error ?. message ??
151+ errors . linodeInterfaces ?. [ index ] ?. vpc ?. ipv4 ?. addresses ?. [ 0 ]
152+ ?. message
153+ }
154+ fieldValue = { field . value }
155+ onBlur = { field . onBlur }
156+ onChange = { field . onChange }
157+ />
200158 ) }
201159 />
202160 { showIPv6Fields && (
203161 < Controller
204162 control = { control }
205163 name = { `linodeInterfaces.${ index } .vpc.ipv6.slaac.0.range` }
206164 render = { ( { field, fieldState } ) => (
207- < Box >
208- < FormControlLabel
209- checked = { field . value === 'auto' }
210- control = { < Checkbox sx = { { ml : 0.4 } } /> }
211- disabled = { ! regionSupportsVPCs }
212- label = {
213- < Stack alignItems = "center" direction = "row" >
214- < Typography > Auto-assign VPC IPv6</ Typography >
215- < TooltipIcon
216- status = "info"
217- text = { VPC_AUTO_ASSIGN_IPV6_TOOLTIP }
218- />
219- </ Stack >
220- }
221- onChange = { ( e , checked ) =>
222- field . onChange ( checked ? 'auto' : '' )
223- }
224- />
225- { field . value !== 'auto' && (
226- < TextField
227- containerProps = { { sx : { mb : 1.5 , mt : 1 } } }
228- errorText = {
229- fieldState . error ?. message ??
230- errors . linodeInterfaces ?. [ index ] ?. vpc ?. ipv6 ?. slaac ?. [ 0 ]
231- ?. range ?. message
232- }
233- helperText = { VPC_IPV6_INPUT_HELPER_TEXT }
234- label = "VPC IPv6"
235- noMarginTop
236- onBlur = { field . onBlur }
237- onChange = { field . onChange }
238- required
239- value = { field . value }
240- />
241- ) }
242- </ Box >
165+ < VPCIPv6Address
166+ disabled = { ! regionSupportsVPCs }
167+ errorMessage = {
168+ fieldState . error ?. message ??
169+ errors . linodeInterfaces ?. [ index ] ?. vpc ?. ipv6 ?. slaac ?. [ 0 ]
170+ ?. range ?. message
171+ }
172+ fieldValue = { field . value }
173+ onBlur = { field . onBlur }
174+ onChange = { field . onChange }
175+ />
243176 ) }
244177 />
245178 ) }
@@ -254,39 +187,25 @@ export const VPC = ({ index }: Props) => {
254187 control = { control }
255188 name = { `linodeInterfaces.${ index } .vpc.ipv4.addresses.0.nat_1_1_address` }
256189 render = { ( { field, fieldState } ) => (
257- < Box >
258- { fieldState . error ?. message && (
259- < Notice text = { fieldState . error . message } variant = "error" />
260- ) }
261- < FormControlLabel
262- checked = { field . value === 'auto' }
263- control = { < Checkbox sx = { { ml : 0.4 } } /> }
264- disabled = { ! regionSupportsVPCs }
265- label = { < VPCPublicIPLabel /> }
266- onChange = { ( e , checked ) =>
267- field . onChange ( checked ? 'auto' : null )
268- }
269- />
270- </ Box >
190+ < PublicIPv4Access
191+ checked = { Boolean ( field . value ) }
192+ disabled = { ! regionSupportsVPCs }
193+ errorMessage = { fieldState . error ?. message }
194+ onChange = { field . onChange }
195+ />
271196 ) }
272197 />
273198 { showIPv6Fields && (
274199 < Controller
275200 control = { control }
276201 name = { `linodeInterfaces.${ index } .vpc.ipv6.is_public` }
277202 render = { ( { field, fieldState } ) => (
278- < Box >
279- { fieldState . error ?. message && (
280- < Notice text = { fieldState . error . message } variant = "error" />
281- ) }
282- < FormControlLabel
283- checked = { field . value === true }
284- control = { < Checkbox sx = { { ml : 0.4 } } /> }
285- disabled = { ! regionSupportsVPCs }
286- label = { < VPCIPv6PublicIPLabel /> }
287- onChange = { ( ) => field . onChange ( ! field . value ) }
288- />
289- </ Box >
203+ < PublicIPv6Access
204+ checked = { field . value === true }
205+ disabled = { ! regionSupportsVPCs }
206+ errorMessage = { fieldState . error ?. message }
207+ onChange = { field . onChange }
208+ />
290209 ) }
291210 />
292211 ) }
0 commit comments