diff --git a/src/apps/dashboard/routes/users/parentalcontrol.tsx b/src/apps/dashboard/routes/users/parentalcontrol.tsx index 20e338b6034..73abd265c0c 100644 --- a/src/apps/dashboard/routes/users/parentalcontrol.tsx +++ b/src/apps/dashboard/routes/users/parentalcontrol.tsx @@ -65,6 +65,7 @@ const UserParentalControl = () => { const [ userName, setUserName ] = useState(''); const [ parentalRatings, setParentalRatings ] = useState([]); const [ unratedItems, setUnratedItems ] = useState([]); + const [ maxParentalRating, setMaxParentalRating ] = useState(); const [ accessSchedules, setAccessSchedules ] = useState([]); const [ allowedTags, setAllowedTags ] = useState([]); const [ blockedTags, setBlockedTags ] = useState([]); @@ -163,15 +164,13 @@ const UserParentalControl = () => { populateRatings(allParentalRatings); let ratingValue = ''; - if (user.Policy?.MaxParentalRating) { - allParentalRatings.forEach(rating => { - if (rating.Value && user.Policy?.MaxParentalRating && user.Policy.MaxParentalRating >= rating.Value) { - ratingValue = `${rating.Value}`; - } - }); - } + allParentalRatings.forEach(rating => { + if (rating.Value != null && user.Policy?.MaxParentalRating != null && user.Policy.MaxParentalRating >= rating.Value) { + ratingValue = `${rating.Value}`; + } + }); - (page.querySelector('#selectMaxParentalRating') as HTMLSelectElement).value = String(ratingValue); + setMaxParentalRating(ratingValue); if (user.Policy?.IsAdministrator) { (page.querySelector('.accessScheduleSection') as HTMLDivElement).classList.add('hide'); @@ -329,11 +328,24 @@ const UserParentalControl = () => { }; }, [setAllowedTags, setBlockedTags, loadData, userId]); + useEffect(() => { + const page = element.current; + + if (!page) { + console.error('[userparentalcontrol] Unexpected null page reference'); + return; + } + + (page.querySelector('#selectMaxParentalRating') as HTMLSelectElement).value = String(maxParentalRating); + }, [maxParentalRating, parentalRatings]); + const optionMaxParentalRating = () => { let content = ''; content += ''; for (const rating of parentalRatings) { - content += ``; + if (rating.Value != null) { + content += ``; + } } return content; };