11import { React , useEffect , useState } from "react" ;
2- import { Button , Form , Spinner , Alert } from "react-bootstrap" ;
2+ import { Button , Form , Spinner } from "react-bootstrap" ;
33import { useTranslation } from "react-i18next" ;
44import { useNavigate } from "react-router-dom" ;
55import PropTypes from "prop-types" ;
6- import { useDispatch } from "react-redux" ;
76import ContentBody from "../util/content-body/content-body" ;
87import ContentFooter from "../util/content-footer/content-footer" ;
98import FormInput from "../util/forms/form-input" ;
@@ -13,13 +12,13 @@ import GridGenerationAndSelect from "./util/grid-generation-and-select";
1312import MultiSelectComponent from "../util/forms/multiselect-dropdown/multi-dropdown" ;
1413import idFromUrl from "../util/helpers/id-from-url" ;
1514import {
16- api ,
1715 useGetV2LayoutsQuery ,
1816 useGetV2ScreensByIdScreenGroupsQuery ,
1917} from "../../redux/api/api.generated.ts" ;
20- import { displayError } from "../util/list/toast-component/display-toast" ;
2118import FormCheckbox from "../util/forms/form-checkbox" ;
2219import "./screen-form.scss" ;
20+ import ScreenStatus from "./screen-status" ;
21+ import { displayError } from "../util/list/toast-component/display-toast" ;
2322
2423/**
2524 * The screen form component.
@@ -49,11 +48,10 @@ function ScreenForm({
4948} ) {
5049 const { t } = useTranslation ( "common" , { keyPrefix : "screen-form" } ) ;
5150 const navigate = useNavigate ( ) ;
52- const dispatch = useDispatch ( ) ;
51+
5352 const [ layoutError , setLayoutError ] = useState ( false ) ;
5453 const [ selectedLayout , setSelectedLayout ] = useState ( ) ;
5554 const [ layoutOptions , setLayoutOptions ] = useState ( ) ;
56- const [ bindKey , setBindKey ] = useState ( "" ) ;
5755 const { data : layouts } = useGetV2LayoutsQuery ( {
5856 page : 1 ,
5957 itemsPerPage : 20 ,
@@ -112,57 +110,6 @@ function ScreenForm({
112110 } ) ;
113111 } ;
114112
115- const handleBindScreen = ( ) => {
116- if ( bindKey ) {
117- dispatch (
118- api . endpoints . postScreenBindKey . initiate ( {
119- id : idFromUrl ( screen [ "@id" ] ) ,
120- screenBindObject : JSON . stringify ( {
121- bindKey,
122- } ) ,
123- } )
124- ) . then ( ( response ) => {
125- if ( response . error ) {
126- const err = response . error ;
127- displayError (
128- t ( "error-messages.error-binding" , {
129- status : err . status ,
130- } ) ,
131- err
132- ) ;
133- } else {
134- // Set screenUser to true, to indicate it has been set.
135- handleInput ( { target : { id : "screenUser" , value : true } } ) ;
136- }
137- } ) ;
138- }
139- } ;
140-
141- const handleUnbindScreen = ( ) => {
142- if ( screen ?. screenUser ) {
143- setBindKey ( "" ) ;
144-
145- dispatch (
146- api . endpoints . postScreenUnbind . initiate ( {
147- id : idFromUrl ( screen [ "@id" ] ) ,
148- } )
149- ) . then ( ( response ) => {
150- if ( response . error ) {
151- const err = response . error ;
152- displayError (
153- t ( "error-messages.error-unbinding" , {
154- status : err . status ,
155- } ) ,
156- err
157- ) ;
158- } else {
159- // Set screenUser to null, to indicate it has been removed.
160- handleInput ( { target : { id : "screenUser" , value : null } } ) ;
161- }
162- } ) ;
163- }
164- } ;
165-
166113 const isVertical = ( ) => {
167114 if ( screen ?. orientation ?. length > 0 ) {
168115 return screen . orientation [ 0 ] . id === "vertical" ;
@@ -203,35 +150,7 @@ function ScreenForm({
203150 { Object . prototype . hasOwnProperty . call ( screen , "@id" ) && (
204151 < ContentBody >
205152 < h2 className = "h4 mb-3" > { t ( "bind-header" ) } </ h2 >
206- { screen ?. screenUser && (
207- < >
208- < div className = "mb-3" >
209- < Alert key = "screen-bound" variant = "success" >
210- { t ( "already-bound" ) }
211- </ Alert >
212- </ div >
213- < Button onClick = { handleUnbindScreen } > { t ( "unbind" ) } </ Button >
214- </ >
215- ) }
216- { ! screen ?. screenUser && (
217- < >
218- < div className = "mb-3" >
219- < Alert key = "screen-not-bound" variant = "danger" >
220- { t ( "not-bound" ) }
221- </ Alert >
222- </ div >
223- < FormInput
224- onChange = { ( { target } ) => {
225- setBindKey ( target ?. value ) ;
226- } }
227- name = "bindKey"
228- value = { bindKey }
229- label = { t ( "bindkey-label" ) }
230- className = "mb-3"
231- />
232- < Button onClick = { handleBindScreen } > { t ( "bind" ) } </ Button >
233- </ >
234- ) }
153+ < ScreenStatus screen = { screen } handleInput = { handleInput } />
235154 </ ContentBody >
236155 ) }
237156 < ContentBody >
@@ -371,6 +290,7 @@ ScreenForm.propTypes = {
371290 screenUser : PropTypes . string ,
372291 size : PropTypes . string ,
373292 title : PropTypes . string ,
293+ status : PropTypes . shape ( { } ) ,
374294 playlists : PropTypes . arrayOf (
375295 PropTypes . shape ( { name : PropTypes . string , id : PropTypes . number } )
376296 ) ,
0 commit comments