@@ -18,6 +18,10 @@ interface PlexImportProps {
1818const messages = defineMessages ( 'components.UserList' , {
1919 importfromplex : 'Import Plex Users' ,
2020 importfromplexerror : 'Something went wrong while importing Plex users.' ,
21+ importfromplexsynced :
22+ 'Plex users synced successfully. Existing users were refreshed.' ,
23+ syncnotice :
24+ 'You can still click Sync to refresh existing Plex users, such as updated email or username details.' ,
2125 importedfromplex :
2226 '<strong>{userCount}</strong> Plex {userCount, plural, one {user} other {users}} imported successfully!' ,
2327 importedPlexUsersNoPassword :
@@ -55,30 +59,37 @@ const PlexImportModal = ({ onCancel, onComplete }: PlexImportProps) => {
5559 { plexIds : selectedUsers }
5660 ) ;
5761
58- if ( ! Array . isArray ( createdUsers ) || createdUsers . length === 0 ) {
59- throw new Error ( 'No users were imported from Plex.' ) ;
62+ if ( ! Array . isArray ( createdUsers ) ) {
63+ throw new Error ( 'Invalid import response from Plex import endpoint .' ) ;
6064 }
6165
62- addToast (
63- intl . formatMessage ( messages . importedfromplex , {
64- userCount : createdUsers . length ,
65- strong : ( msg : React . ReactNode ) => < strong > { msg } </ strong > ,
66- } ) ,
67- {
66+ if ( createdUsers . length > 0 ) {
67+ addToast (
68+ intl . formatMessage ( messages . importedfromplex , {
69+ userCount : createdUsers . length ,
70+ strong : ( msg : React . ReactNode ) => < strong > { msg } </ strong > ,
71+ } ) ,
72+ {
73+ autoDismiss : true ,
74+ appearance : 'success' ,
75+ }
76+ ) ;
77+
78+ addToast (
79+ intl . formatMessage ( messages . importedPlexUsersNoPassword , {
80+ applicationTitle : settings . currentSettings . applicationTitle ,
81+ } ) ,
82+ {
83+ autoDismiss : false ,
84+ appearance : 'warning' ,
85+ }
86+ ) ;
87+ } else {
88+ addToast ( intl . formatMessage ( messages . importfromplexsynced ) , {
6889 autoDismiss : true ,
6990 appearance : 'success' ,
70- }
71- ) ;
72-
73- addToast (
74- intl . formatMessage ( messages . importedPlexUsersNoPassword , {
75- applicationTitle : settings . currentSettings . applicationTitle ,
76- } ) ,
77- {
78- autoDismiss : false ,
79- appearance : 'warning' ,
80- }
81- ) ;
91+ } ) ;
92+ }
8293
8394 if ( onComplete ) {
8495 onComplete ( ) ;
@@ -114,16 +125,26 @@ const PlexImportModal = ({ onCancel, onComplete }: PlexImportProps) => {
114125 }
115126 } ;
116127
128+ const isSyncOnly = ! ! data && data . length === 0 ;
129+
117130 return (
118131 < Modal
119132 loading = { ! data && ! error }
120133 title = { intl . formatMessage ( messages . importfromplex ) }
121134 onOk = { ( ) => {
122135 importUsers ( ) ;
123136 } }
124- okDisabled = { isImporting || ! selectedUsers . length }
137+ okDisabled = {
138+ isImporting || ! data || ( data . length > 0 && ! selectedUsers . length )
139+ }
125140 okText = { intl . formatMessage (
126- isImporting ? globalMessages . importing : globalMessages . import
141+ isImporting
142+ ? isSyncOnly
143+ ? globalMessages . syncing
144+ : globalMessages . importing
145+ : isSyncOnly
146+ ? globalMessages . sync
147+ : globalMessages . import
127148 ) }
128149 onCancel = { onCancel }
129150 >
@@ -245,10 +266,9 @@ const PlexImportModal = ({ onCancel, onComplete }: PlexImportProps) => {
245266 </ div >
246267 </ >
247268 ) : (
248- < Alert
249- title = { intl . formatMessage ( messages . nouserstoimport ) }
250- type = "info"
251- />
269+ < Alert title = { intl . formatMessage ( messages . nouserstoimport ) } type = "info" >
270+ { intl . formatMessage ( messages . syncnotice ) }
271+ </ Alert >
252272 ) }
253273 </ Modal >
254274 ) ;
0 commit comments