Skip to content

Commit 4a0e197

Browse files
committed
feat(PlexImportModal): add user details sync functionality
1 parent b32ab02 commit 4a0e197

3 files changed

Lines changed: 52 additions & 26 deletions

File tree

src/components/UserList/PlexImportModal.tsx

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ interface PlexImportProps {
1818
const 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
);

src/i18n/globalMessages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const globalMessages = defineMessages('i18n', {
3636
saving: 'Saving…',
3737
import: 'Import',
3838
importing: 'Importing…',
39+
sync: 'Sync',
40+
syncing: 'Syncing…',
3941
close: 'Close',
4042
edit: 'Edit',
4143
areyousure: 'Are you sure?',

src/i18n/locale/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,7 @@
13971397
"components.UserList.importfrommediaserver": "Import {mediaServerName} Users",
13981398
"components.UserList.importfromplex": "Import Plex Users",
13991399
"components.UserList.importfromplexerror": "Something went wrong while importing Plex users.",
1400+
"components.UserList.importfromplexsynced": "Plex users synced successfully. Existing users were refreshed.",
14001401
"components.UserList.localLoginDisabled": "The <strong>Enable Local Sign-In</strong> setting is currently disabled.",
14011402
"components.UserList.localuser": "Local User",
14021403
"components.UserList.mediaServerUser": "{mediaServerName} User",
@@ -1415,6 +1416,7 @@
14151416
"components.UserList.sortByRole": "Sort by user role",
14161417
"components.UserList.sortByType": "Sort by account type",
14171418
"components.UserList.sortByUser": "Sort by username",
1419+
"components.UserList.syncnotice": "You can still click Sync to refresh existing Plex users, such as updated email or username details.",
14181420
"components.UserList.toggleSortDirection": "Click again to sort {direction}",
14191421
"components.UserList.toggleSortDirectionAria": "Toggle sort direction",
14201422
"components.UserList.totalrequests": "Requests",
@@ -1653,6 +1655,8 @@
16531655
"i18n.showingresults": "Showing <strong>{from}</strong> to <strong>{to}</strong> of <strong>{total}</strong> results",
16541656
"i18n.specials": "Specials",
16551657
"i18n.status": "Status",
1658+
"i18n.sync": "Sync",
1659+
"i18n.syncing": "Syncing…",
16561660
"i18n.test": "Test",
16571661
"i18n.testing": "Testing…",
16581662
"i18n.tvshow": "Series",

0 commit comments

Comments
 (0)