From fc5a385d08a4fa9076d89a35e5e9996d68f5b1ab Mon Sep 17 00:00:00 2001 From: grafixeyehero <32230989+grafixeyehero@users.noreply.github.com> Date: Wed, 9 Mar 2022 19:52:47 +0300 Subject: [PATCH] use UserDto type from API --- src/components/dashboard/users/UserPasswordForm.tsx | 7 ++++--- src/components/pages/UserProfilePage.tsx | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/dashboard/users/UserPasswordForm.tsx b/src/components/dashboard/users/UserPasswordForm.tsx index 6b64953569..6f14142207 100644 --- a/src/components/dashboard/users/UserPasswordForm.tsx +++ b/src/components/dashboard/users/UserPasswordForm.tsx @@ -1,3 +1,4 @@ +import { UserDto } from '@thornbill/jellyfin-sdk/dist/generated-client'; import React, { FunctionComponent, useCallback, useEffect, useRef } from 'react'; import Dashboard from '../../../scripts/clientUtils'; import globalize from '../../../scripts/globalize'; @@ -25,7 +26,7 @@ const UserPasswordForm: FunctionComponent = ({userId}: IProps) => { } window.ApiClient.getUser(userId).then(function (user) { - Dashboard.getCurrentUser().then(function (loggedInUser: { Policy: { IsAdministrator: boolean; }; }) { + Dashboard.getCurrentUser().then(function (loggedInUser: UserDto) { if (!user.Policy) { throw new Error('Unexpected null user.Policy'); } @@ -47,13 +48,13 @@ const UserPasswordForm: FunctionComponent = ({userId}: IProps) => { (page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.add('hide'); } - if (loggedInUser.Policy.IsAdministrator || user.Policy.EnableUserPreferenceAccess) { + if (loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess) { (page.querySelector('.passwordSection') as HTMLDivElement).classList.remove('hide'); } else { (page.querySelector('.passwordSection') as HTMLDivElement).classList.add('hide'); } - if (showLocalAccessSection && (loggedInUser.Policy.IsAdministrator || user.Policy.EnableUserPreferenceAccess)) { + if (showLocalAccessSection && (loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess)) { (page.querySelector('.localAccessSection') as HTMLDivElement).classList.remove('hide'); } else { (page.querySelector('.localAccessSection') as HTMLDivElement).classList.add('hide'); diff --git a/src/components/pages/UserProfilePage.tsx b/src/components/pages/UserProfilePage.tsx index dd39f523cc..b2f365e7c6 100644 --- a/src/components/pages/UserProfilePage.tsx +++ b/src/components/pages/UserProfilePage.tsx @@ -1,4 +1,4 @@ -import { ImageType } from '@thornbill/jellyfin-sdk/dist/generated-client'; +import { ImageType, UserDto } from '@thornbill/jellyfin-sdk/dist/generated-client'; import React, { FunctionComponent, useEffect, useState, useRef, useCallback } from 'react'; import Dashboard from '../../scripts/clientUtils'; @@ -51,7 +51,7 @@ const UserProfilePage: FunctionComponent = ({userId}: IProps) => { const userImage = (page.querySelector('#image') as HTMLDivElement); userImage.style.backgroundImage = 'url(' + imageUrl + ')'; - Dashboard.getCurrentUser().then(function (loggedInUser: { Policy: { IsAdministrator: boolean; }; }) { + Dashboard.getCurrentUser().then(function (loggedInUser: UserDto) { if (!user.Policy) { throw new Error('Unexpected null user.Policy'); } @@ -59,7 +59,7 @@ const UserProfilePage: FunctionComponent = ({userId}: IProps) => { if (user.PrimaryImageTag) { (page.querySelector('.btnAddImage') as HTMLButtonElement).classList.add('hide'); (page.querySelector('.btnDeleteImage') as HTMLButtonElement).classList.remove('hide'); - } else if (appHost.supports('fileinput') && (loggedInUser.Policy.IsAdministrator || user.Policy.EnableUserPreferenceAccess)) { + } else if (appHost.supports('fileinput') && (loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess)) { (page.querySelector('.btnDeleteImage') as HTMLButtonElement).classList.add('hide'); (page.querySelector('.btnAddImage') as HTMLButtonElement).classList.remove('hide'); }