@@ -3,7 +3,6 @@ import { Button, Form, Spinner, Alert, Col, Row } 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 { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
87import { faExpand } from "@fortawesome/free-solid-svg-icons" ;
98import ContentBody from "../util/content-body/content-body" ;
@@ -14,17 +13,17 @@ import GridGenerationAndSelect from "./util/grid-generation-and-select";
1413import MultiSelectComponent from "../util/forms/multiselect-dropdown/multi-dropdown" ;
1514import idFromUrl from "../util/helpers/id-from-url" ;
1615import {
17- api ,
1816 useGetV2LayoutsQuery ,
1917 useGetV2ScreensByIdScreenGroupsQuery ,
2018} from "../../redux/api/api.generated.ts" ;
21- import { displayError } from "../util/list/toast-component/display-toast" ;
2219import FormCheckbox from "../util/forms/form-checkbox" ;
2320import "./screen-form.scss" ;
2421import Preview from "../preview/preview" ;
2522import StickyFooter from "../util/sticky-footer" ;
2623import Select from "../util/forms/select" ;
2724import userContext from "../../context/user-context" ;
25+ import ScreenStatus from "./screen-status" ;
26+ import { displayError } from "../util/list/toast-component/display-toast" ;
2827
2928/**
3029 * The screen form component.
@@ -55,11 +54,10 @@ function ScreenForm({
5554 const { t } = useTranslation ( "common" , { keyPrefix : "screen-form" } ) ;
5655 const { config } = useContext ( userContext ) ;
5756 const navigate = useNavigate ( ) ;
58- const dispatch = useDispatch ( ) ;
57+
5958 const [ layoutError , setLayoutError ] = useState ( false ) ;
6059 const [ selectedLayout , setSelectedLayout ] = useState ( ) ;
6160 const [ layoutOptions , setLayoutOptions ] = useState ( ) ;
62- const [ bindKey , setBindKey ] = useState ( "" ) ;
6361 const { data : layouts } = useGetV2LayoutsQuery ( {
6462 page : 1 ,
6563 itemsPerPage : 20 ,
@@ -136,57 +134,6 @@ function ScreenForm({
136134 } ) ;
137135 } ;
138136
139- const handleBindScreen = ( ) => {
140- if ( bindKey ) {
141- dispatch (
142- api . endpoints . postScreenBindKey . initiate ( {
143- id : idFromUrl ( screen [ "@id" ] ) ,
144- screenBindObject : JSON . stringify ( {
145- bindKey,
146- } ) ,
147- } )
148- ) . then ( ( response ) => {
149- if ( response . error ) {
150- const err = response . error ;
151- displayError (
152- t ( "error-messages.error-binding" , {
153- status : err . status ,
154- } ) ,
155- err
156- ) ;
157- } else {
158- // Set screenUser to true, to indicate it has been set.
159- handleInput ( { target : { id : "screenUser" , value : true } } ) ;
160- }
161- } ) ;
162- }
163- } ;
164-
165- const handleUnbindScreen = ( ) => {
166- if ( screen ?. screenUser ) {
167- setBindKey ( "" ) ;
168-
169- dispatch (
170- api . endpoints . postScreenUnbind . initiate ( {
171- id : idFromUrl ( screen [ "@id" ] ) ,
172- } )
173- ) . then ( ( response ) => {
174- if ( response . error ) {
175- const err = response . error ;
176- displayError (
177- t ( "error-messages.error-unbinding" , {
178- status : err . status ,
179- } ) ,
180- err
181- ) ;
182- } else {
183- // Set screenUser to null, to indicate it has been removed.
184- handleInput ( { target : { id : "screenUser" , value : null } } ) ;
185- }
186- } ) ;
187- }
188- } ;
189-
190137 const isVertical = ( ) => {
191138 if ( screen ?. orientation ?. length > 0 ) {
192139 return screen . orientation [ 0 ] . id === "vertical" ;
@@ -230,35 +177,7 @@ function ScreenForm({
230177 { Object . prototype . hasOwnProperty . call ( screen , "@id" ) && (
231178 < ContentBody >
232179 < h2 className = "h4 mb-3" > { t ( "bind-header" ) } </ h2 >
233- { screen ?. screenUser && (
234- < >
235- < div className = "mb-3" >
236- < Alert key = "screen-bound" variant = "success" >
237- { t ( "already-bound" ) }
238- </ Alert >
239- </ div >
240- < Button onClick = { handleUnbindScreen } > { t ( "unbind" ) } </ Button >
241- </ >
242- ) }
243- { ! screen ?. screenUser && (
244- < >
245- < div className = "mb-3" >
246- < Alert key = "screen-not-bound" variant = "danger" >
247- { t ( "not-bound" ) }
248- </ Alert >
249- </ div >
250- < FormInput
251- onChange = { ( { target } ) => {
252- setBindKey ( target ?. value ) ;
253- } }
254- name = "bindKey"
255- value = { bindKey }
256- label = { t ( "bindkey-label" ) }
257- className = "mb-3"
258- />
259- < Button onClick = { handleBindScreen } > { t ( "bind" ) } </ Button >
260- </ >
261- ) }
180+ < ScreenStatus screen = { screen } handleInput = { handleInput } />
262181 </ ContentBody >
263182 ) }
264183 < ContentBody >
@@ -494,6 +413,7 @@ ScreenForm.propTypes = {
494413 screenUser : PropTypes . string ,
495414 size : PropTypes . string ,
496415 title : PropTypes . string ,
416+ status : PropTypes . shape ( { } ) ,
497417 playlists : PropTypes . arrayOf (
498418 PropTypes . shape ( { name : PropTypes . string , id : PropTypes . number } )
499419 ) ,
0 commit comments