@@ -26,11 +26,13 @@ import {
2626 ActionGroup ,
2727 Alert ,
2828 Content ,
29+ EmptyState ,
2930 Form ,
3031 FormGroup ,
3132 FormSelect ,
3233 FormSelectOption ,
3334} from "@patternfly/react-core" ;
35+ import Icon from "~/components/layout/Icon" ;
3436import { Page , PasswordInput } from "~/components/core" ;
3537import { Connection , WifiNetwork , Wireless } from "~/types/network" ;
3638import { useWifiNetworks } from "~/hooks/model/system/network" ;
@@ -98,7 +100,7 @@ const formReducer = (state: FormState, action: FormAction): FormState => {
98100 }
99101} ;
100102
101- export default function WifiConnectionForm ( ) {
103+ function WifiConnectionFormContent ( ) {
102104 const navigate = useNavigate ( ) ;
103105 const networks = useWifiNetworks ( ) ;
104106 const [ form , dispatch ] = useReducer ( formReducer , { ssid : "" , security : "" , password : "" } ) ;
@@ -127,6 +129,69 @@ export default function WifiConnectionForm() {
127129 navigate ( PATHS . root ) ;
128130 } ;
129131
132+ if ( networks . length === 0 )
133+ return (
134+ < EmptyState
135+ titleText = { _ ( "No Wi-Fi networks were found" ) }
136+ icon = { ( ) => < Icon name = "error" /> }
137+ />
138+ ) ;
139+
140+ return (
141+ < Form id = "wifiConnectionForm" onSubmit = { accept } aria-label = { _ ( "Wi-Fi connection form" ) } >
142+ < FormGroup fieldId = "ssid" label = { _ ( "Network" ) } >
143+ < WifiNetworksSelector
144+ id = "ssid"
145+ value = { form . ssid }
146+ onChange = { ( _ , v ) => dispatch ( { type : "SET_SSID" , ssid : v , networks } ) }
147+ />
148+ </ FormGroup >
149+
150+ { isPublicNetwork && < PublicNetworkAlert /> }
151+ { /* TRANSLATORS: Wifi security configuration (password protected or not) */ }
152+ { ! isEmpty ( network ?. security ) && (
153+ < FormGroup fieldId = "security" label = { _ ( "Security" ) } >
154+ < FormSelect
155+ id = "security"
156+ aria-label = { _ ( "Security" ) }
157+ value = { form . security }
158+ onChange = { ( _ , v ) => dispatch ( { type : "SET_SECURITY" , security : v } ) }
159+ >
160+ { securityOptions . map ( ( security ) => (
161+ < FormSelectOption
162+ key = { security . value }
163+ value = { security . value }
164+ /* eslint-disable agama-i18n/string-literals */
165+ label = { _ ( security . label ) }
166+ />
167+ ) ) }
168+ </ FormSelect >
169+ </ FormGroup >
170+ ) }
171+ { form . security === "wpa-psk" && (
172+ // TRANSLATORS: WiFi password
173+ < FormGroup fieldId = "password" label = { _ ( "WPA Password" ) } >
174+ < PasswordInput
175+ id = "password"
176+ name = "password"
177+ aria-label = { _ ( "Password" ) }
178+ value = { form . password }
179+ onChange = { ( _ , v ) => dispatch ( { type : "SET_PASSWORD" , password : v } ) }
180+ />
181+ </ FormGroup >
182+ ) }
183+ < ActionGroup >
184+ < Page . Submit form = "wifiConnectionForm" >
185+ { /* TRANSLATORS: button label, connect to a Wi-Fi network */ }
186+ { _ ( "Connect" ) }
187+ </ Page . Submit >
188+ < Page . Back > { _ ( "Cancel" ) } </ Page . Back >
189+ </ ActionGroup >
190+ </ Form >
191+ ) ;
192+ }
193+
194+ export default function wifiConnectionForm ( ) {
130195 return (
131196 < Page
132197 breadcrumbs = { [
@@ -136,57 +201,7 @@ export default function WifiConnectionForm() {
136201 progress = { { scope : "network" , ensureRefetched : "system" } }
137202 >
138203 < Page . Content >
139- { /** TRANSLATORS: accessible name for the WiFi connection form */ }
140- < Form id = "wifiConnectionForm" onSubmit = { accept } aria-label = { _ ( "Wi-Fi connection form" ) } >
141- < FormGroup fieldId = "ssid" label = { _ ( "Network" ) } >
142- < WifiNetworksSelector
143- id = "ssid"
144- value = { form . ssid }
145- onChange = { ( _ , v ) => dispatch ( { type : "SET_SSID" , ssid : v , networks } ) }
146- />
147- </ FormGroup >
148-
149- { isPublicNetwork && < PublicNetworkAlert /> }
150- { /* TRANSLATORS: Wifi security configuration (password protected or not) */ }
151- { ! isEmpty ( network ?. security ) && (
152- < FormGroup fieldId = "security" label = { _ ( "Security" ) } >
153- < FormSelect
154- id = "security"
155- aria-label = { _ ( "Security" ) }
156- value = { form . security }
157- onChange = { ( _ , v ) => dispatch ( { type : "SET_SECURITY" , security : v } ) }
158- >
159- { securityOptions . map ( ( security ) => (
160- < FormSelectOption
161- key = { security . value }
162- value = { security . value }
163- /* eslint-disable agama-i18n/string-literals */
164- label = { _ ( security . label ) }
165- />
166- ) ) }
167- </ FormSelect >
168- </ FormGroup >
169- ) }
170- { form . security === "wpa-psk" && (
171- // TRANSLATORS: WiFi password
172- < FormGroup fieldId = "password" label = { _ ( "WPA Password" ) } >
173- < PasswordInput
174- id = "password"
175- name = "password"
176- aria-label = { _ ( "Password" ) }
177- value = { form . password }
178- onChange = { ( _ , v ) => dispatch ( { type : "SET_PASSWORD" , password : v } ) }
179- />
180- </ FormGroup >
181- ) }
182- < ActionGroup >
183- < Page . Submit form = "wifiConnectionForm" >
184- { /* TRANSLATORS: button label, connect to a Wi-Fi network */ }
185- { _ ( "Connect" ) }
186- </ Page . Submit >
187- < Page . Back > { _ ( "Cancel" ) } </ Page . Back >
188- </ ActionGroup >
189- </ Form >
204+ < WifiConnectionFormContent />
190205 </ Page . Content >
191206 </ Page >
192207 ) ;
0 commit comments