From 3eb26fb41687ab30fff55093fac9ed87b49d62c7 Mon Sep 17 00:00:00 2001 From: MontejoJorge Date: Mon, 21 Apr 2025 23:34:18 +0200 Subject: [PATCH 01/11] refactor: forgotPassword page to react component --- src/apps/stable/routes/asyncRoutes/index.ts | 1 + src/apps/stable/routes/asyncRoutes/public.ts | 5 + src/apps/stable/routes/legacyRoutes/public.ts | 7 -- src/apps/stable/routes/routes.tsx | 3 +- .../routes/session/forgotPassword/index.tsx | 117 ++++++++++++++++++ .../session/forgotPassword/index.html | 24 ---- .../session/forgotPassword/index.js | 56 --------- 7 files changed, 125 insertions(+), 88 deletions(-) create mode 100644 src/apps/stable/routes/asyncRoutes/public.ts create mode 100644 src/apps/stable/routes/session/forgotPassword/index.tsx delete mode 100644 src/controllers/session/forgotPassword/index.html delete mode 100644 src/controllers/session/forgotPassword/index.js diff --git a/src/apps/stable/routes/asyncRoutes/index.ts b/src/apps/stable/routes/asyncRoutes/index.ts index e5abc8565..3e37e3b9d 100644 --- a/src/apps/stable/routes/asyncRoutes/index.ts +++ b/src/apps/stable/routes/asyncRoutes/index.ts @@ -1 +1,2 @@ export * from './user'; +export * from './public'; diff --git a/src/apps/stable/routes/asyncRoutes/public.ts b/src/apps/stable/routes/asyncRoutes/public.ts new file mode 100644 index 000000000..9c8b28e31 --- /dev/null +++ b/src/apps/stable/routes/asyncRoutes/public.ts @@ -0,0 +1,5 @@ +import { AsyncRoute } from '../../../../components/router/AsyncRoute'; + +export const ASYNC_PUBLIC_ROUTES: AsyncRoute[] = [ + { path: 'forgotpassword', page: 'session/forgotPassword' } +]; diff --git a/src/apps/stable/routes/legacyRoutes/public.ts b/src/apps/stable/routes/legacyRoutes/public.ts index abf6439bc..7b491625c 100644 --- a/src/apps/stable/routes/legacyRoutes/public.ts +++ b/src/apps/stable/routes/legacyRoutes/public.ts @@ -22,13 +22,6 @@ export const LEGACY_PUBLIC_ROUTES: LegacyRoute[] = [ view: 'session/login/index.html' } }, - { - path: 'forgotpassword', - pageProps: { - controller: 'session/forgotPassword/index', - view: 'session/forgotPassword/index.html' - } - }, { path: 'forgotpasswordpin', pageProps: { diff --git a/src/apps/stable/routes/routes.tsx b/src/apps/stable/routes/routes.tsx index bcd328ace..317479829 100644 --- a/src/apps/stable/routes/routes.tsx +++ b/src/apps/stable/routes/routes.tsx @@ -9,7 +9,7 @@ import FallbackRoute from 'components/router/FallbackRoute'; import AppLayout from '../AppLayout'; -import { ASYNC_USER_ROUTES } from './asyncRoutes'; +import { ASYNC_PUBLIC_ROUTES, ASYNC_USER_ROUTES } from './asyncRoutes'; import { LEGACY_PUBLIC_ROUTES, LEGACY_USER_ROUTES } from './legacyRoutes'; export const STABLE_APP_ROUTES: RouteObject[] = [ @@ -33,6 +33,7 @@ export const STABLE_APP_ROUTES: RouteObject[] = [ /* Public routes */ element: , children: [ + ...ASYNC_PUBLIC_ROUTES.map(toAsyncPageRoute), ...LEGACY_PUBLIC_ROUTES.map(toViewManagerPageRoute), /* Fallback route for invalid paths */ { diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx new file mode 100644 index 000000000..eff26d340 --- /dev/null +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -0,0 +1,117 @@ +import React, { useCallback, useState } from 'react'; +import Page from 'components/Page'; +import { useNavigate } from 'react-router-dom'; +import globalize from 'lib/globalize'; +import Button from 'elements/emby-button/Button'; +import Input from 'elements/emby-input/Input'; +import ServerConnections from 'components/ServerConnections'; +import { useMutation } from '@tanstack/react-query'; +import Dashboard from 'utils/dashboard'; + +export const ForgotPasswordPage = () => { + const navigate = useNavigate(); + const [username, setUsername] = useState(''); + + const apiClient = ServerConnections.currentApiClient(); + + const forgotPasswordMutation = useMutation({ + mutationFn: (enteredUsername: string) => { + if (!apiClient) { + throw new Error('API client is not available'); + } + return apiClient.ajax({ + type: 'POST', + url: apiClient.getUrl('Users/ForgotPassword'), + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify({ + EnteredUsername: enteredUsername + }) + }); + }, + onSuccess: (result) => { + if (result.Action == 'ContactAdmin') { + Dashboard.alert({ + message: globalize.translate('MessageContactAdminToResetPassword'), + title: globalize.translate('ButtonForgotPassword') + }); + } + + if (result.Action == 'InNetworkRequired') { + Dashboard.alert({ + message: globalize.translate('MessageForgotPasswordInNetworkRequired'), + title: globalize.translate('ButtonForgotPassword') + }); + } + + if (result.Action == 'PinCode') { + navigate('/forgotpasswordpin'); + } + } + }); + + const handleCancel = useCallback(() => { + navigate(-1); + }, [navigate]); + + const handleSubmit = useCallback(async (e: React.FormEvent) => { + e.preventDefault(); + forgotPasswordMutation.mutate(username); + }, [username, forgotPasswordMutation]); + + const handleUsernameChange = useCallback((e: React.ChangeEvent) => { + setUsername(e.target.value); + }, []); + + return ( + +
+
+
+

{globalize.translate('ButtonForgotPassword')}

+ +
+ +
+ {globalize.translate('LabelForgotPasswordUsernameHelp')} +
+
+ +
+
+
+
+
+
+ ); +}; + +export default ForgotPasswordPage; diff --git a/src/controllers/session/forgotPassword/index.html b/src/controllers/session/forgotPassword/index.html deleted file mode 100644 index 31e92c2c5..000000000 --- a/src/controllers/session/forgotPassword/index.html +++ /dev/null @@ -1,24 +0,0 @@ -
-
-
-
-

${ButtonForgotPassword}

- -
- -
${LabelForgotPasswordUsernameHelp}
-
- -
- - - -
-
-
-
-
diff --git a/src/controllers/session/forgotPassword/index.js b/src/controllers/session/forgotPassword/index.js deleted file mode 100644 index d94dac455..000000000 --- a/src/controllers/session/forgotPassword/index.js +++ /dev/null @@ -1,56 +0,0 @@ -import globalize from 'lib/globalize'; -import Dashboard from 'utils/dashboard'; - -function processForgotPasswordResult(result) { - if (result.Action == 'ContactAdmin') { - Dashboard.alert({ - message: globalize.translate('MessageContactAdminToResetPassword'), - title: globalize.translate('ButtonForgotPassword') - }); - return; - } - - if (result.Action == 'InNetworkRequired') { - Dashboard.alert({ - message: globalize.translate('MessageForgotPasswordInNetworkRequired'), - title: globalize.translate('ButtonForgotPassword') - }); - return; - } - - if (result.Action == 'PinCode') { - let msg = globalize.translate('MessageForgotPasswordFileCreated'); - msg += '
'; - msg += '
'; - msg += 'Enter PIN here to finish Password Reset
'; - msg += '
'; - msg += result.PinFile; - msg += '
'; - Dashboard.alert({ - message: msg, - title: globalize.translate('ButtonForgotPassword'), - callback: function () { - Dashboard.navigate('forgotpasswordpin'); - } - }); - } -} - -export default function (view) { - function onSubmit(e) { - ApiClient.ajax({ - type: 'POST', - url: ApiClient.getUrl('Users/ForgotPassword'), - dataType: 'json', - contentType: 'application/json', - data: JSON.stringify({ - EnteredUsername: view.querySelector('#txtName').value - }) - }).then(processForgotPasswordResult); - e.preventDefault(); - return false; - } - - view.querySelector('form').addEventListener('submit', onSubmit); -} - From a505fb4d30d877ed422e3f8dfb22f6af7ad9b5bb Mon Sep 17 00:00:00 2001 From: MontejoJorge Date: Tue, 22 Apr 2025 10:47:46 +0200 Subject: [PATCH 02/11] show alert and globalize message --- .../stable/routes/session/forgotPassword/index.tsx | 14 +++++++++++++- src/strings/en-us.json | 1 + src/strings/es.json | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx index eff26d340..55a0c3ff6 100644 --- a/src/apps/stable/routes/session/forgotPassword/index.tsx +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -45,7 +45,19 @@ export const ForgotPasswordPage = () => { } if (result.Action == 'PinCode') { - navigate('/forgotpasswordpin'); + let msg = globalize.translate('MessageForgotPasswordFileCreated'); + msg += '

'; + msg += globalize.translate('MessageForgotPasswordPinReset'); + msg += '

'; + msg += result.PinFile; + msg += '
'; + Dashboard.alert({ + message: msg, + title: globalize.translate('ButtonForgotPassword'), + callback: function () { + navigate('forgotpasswordpin'); + } + }); } } }); diff --git a/src/strings/en-us.json b/src/strings/en-us.json index 9f6e69f1c..62d49a750 100644 --- a/src/strings/en-us.json +++ b/src/strings/en-us.json @@ -1127,6 +1127,7 @@ "MessageEnablingOptionLongerScans": "Enabling this option may result in significantly longer library scans.", "MessageFileReadError": "There was an error reading the file. Please try again.", "MessageForgotPasswordFileCreated": "The following file has been created on your server and contains instructions on how to proceed", + "MessageForgotPasswordPinReset": "Enter PIN here to finish Password reset", "MessageForgotPasswordInNetworkRequired": "Please try again within your home network to initiate the password reset process.", "MessageGetInstalledPluginsError": "An error occurred while getting the list of currently installed plugins.", "MessageImageFileTypeAllowed": "Only JPEG and PNG files are supported.", diff --git a/src/strings/es.json b/src/strings/es.json index 5870de605..803721341 100644 --- a/src/strings/es.json +++ b/src/strings/es.json @@ -714,6 +714,7 @@ "MessageEnablingOptionLongerScans": "Activar esta opción implicará escaneos de la biblioteca más largos.", "MessageFileReadError": "Ha habido un error leyendo el fichero. Por favor, inténtalo más tarde.", "MessageForgotPasswordFileCreated": "Se ha creado el siguiente archivo en tu servidor y contiene instrucciones de cómo proceder", + "MessageForgotPasswordPinReset": "Introdice el PIN aqui para finalizar el reseteo de contraseña", "MessageForgotPasswordInNetworkRequired": "Por favor, inténtalo de nuevo desde tu red de casa para iniciar el proceso de restablecimiento de la contraseña.", "MessageInvalidForgotPasswordPin": "Has introducido un código PIN inválido o expirado. Por favor, inténtalo de nuevo.", "MessageInvalidUser": "Usuario o contraseña inválidos. Por favor, inténtalo otra vez.", From 8047483a7cd2d41558bcfce79b85d239f74e1317 Mon Sep 17 00:00:00 2001 From: MontejoJorge Date: Tue, 29 Apr 2025 22:43:37 +0200 Subject: [PATCH 03/11] use the TS SDK as @viown suggested --- .../routes/session/forgotPassword/index.tsx | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx index 55a0c3ff6..6a5a1094b 100644 --- a/src/apps/stable/routes/session/forgotPassword/index.tsx +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -4,30 +4,28 @@ import { useNavigate } from 'react-router-dom'; import globalize from 'lib/globalize'; import Button from 'elements/emby-button/Button'; import Input from 'elements/emby-input/Input'; -import ServerConnections from 'components/ServerConnections'; import { useMutation } from '@tanstack/react-query'; import Dashboard from 'utils/dashboard'; +import { getUserApi } from '@jellyfin/sdk/lib/utils/api/user-api'; +import ServerConnections from 'components/ServerConnections'; export const ForgotPasswordPage = () => { const navigate = useNavigate(); const [username, setUsername] = useState(''); - const apiClient = ServerConnections.currentApiClient(); - const forgotPasswordMutation = useMutation({ - mutationFn: (enteredUsername: string) => { - if (!apiClient) { - throw new Error('API client is not available'); + mutationFn: async (enteredUsername: string) => { + const currentApi = ServerConnections.getCurrentApi(); + if (!currentApi) { + throw new Error('API not available'); } - return apiClient.ajax({ - type: 'POST', - url: apiClient.getUrl('Users/ForgotPassword'), - dataType: 'json', - contentType: 'application/json', - data: JSON.stringify({ + const response = await getUserApi(currentApi).forgotPassword({ + forgotPasswordDto: { EnteredUsername: enteredUsername - }) + } }); + + return response.data; }, onSuccess: (result) => { if (result.Action == 'ContactAdmin') { From 99a6c653ff0754434e595486846df0e263c9cc0e Mon Sep 17 00:00:00 2001 From: MontejoJorge Date: Tue, 29 Apr 2025 22:56:58 +0200 Subject: [PATCH 04/11] use ForgotPasswordAction enum --- src/apps/stable/routes/session/forgotPassword/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx index 6a5a1094b..c75ac9d53 100644 --- a/src/apps/stable/routes/session/forgotPassword/index.tsx +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -7,6 +7,7 @@ import Input from 'elements/emby-input/Input'; import { useMutation } from '@tanstack/react-query'; import Dashboard from 'utils/dashboard'; import { getUserApi } from '@jellyfin/sdk/lib/utils/api/user-api'; +import { ForgotPasswordAction } from '@jellyfin/sdk/lib/generated-client/models/forgot-password-action'; import ServerConnections from 'components/ServerConnections'; export const ForgotPasswordPage = () => { @@ -28,21 +29,21 @@ export const ForgotPasswordPage = () => { return response.data; }, onSuccess: (result) => { - if (result.Action == 'ContactAdmin') { + if (result.Action == ForgotPasswordAction.ContactAdmin) { Dashboard.alert({ message: globalize.translate('MessageContactAdminToResetPassword'), title: globalize.translate('ButtonForgotPassword') }); } - if (result.Action == 'InNetworkRequired') { + if (result.Action == ForgotPasswordAction.InNetworkRequired) { Dashboard.alert({ message: globalize.translate('MessageForgotPasswordInNetworkRequired'), title: globalize.translate('ButtonForgotPassword') }); } - if (result.Action == 'PinCode') { + if (result.Action == ForgotPasswordAction.PinCode) { let msg = globalize.translate('MessageForgotPasswordFileCreated'); msg += '

'; msg += globalize.translate('MessageForgotPasswordPinReset'); From 9d05c9e65d827006653a6b90e179b8f24be05e67 Mon Sep 17 00:00:00 2001 From: MontejoJorge Date: Tue, 29 Apr 2025 22:58:28 +0200 Subject: [PATCH 05/11] remove es translation (weblate handle this) --- src/strings/es.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/strings/es.json b/src/strings/es.json index 803721341..5870de605 100644 --- a/src/strings/es.json +++ b/src/strings/es.json @@ -714,7 +714,6 @@ "MessageEnablingOptionLongerScans": "Activar esta opción implicará escaneos de la biblioteca más largos.", "MessageFileReadError": "Ha habido un error leyendo el fichero. Por favor, inténtalo más tarde.", "MessageForgotPasswordFileCreated": "Se ha creado el siguiente archivo en tu servidor y contiene instrucciones de cómo proceder", - "MessageForgotPasswordPinReset": "Introdice el PIN aqui para finalizar el reseteo de contraseña", "MessageForgotPasswordInNetworkRequired": "Por favor, inténtalo de nuevo desde tu red de casa para iniciar el proceso de restablecimiento de la contraseña.", "MessageInvalidForgotPasswordPin": "Has introducido un código PIN inválido o expirado. Por favor, inténtalo de nuevo.", "MessageInvalidUser": "Usuario o contraseña inválidos. Por favor, inténtalo otra vez.", From b86e463174efeaeabc361e8617cc9bd979073f16 Mon Sep 17 00:00:00 2001 From: MontejoJorge Date: Wed, 30 Apr 2025 08:21:24 +0200 Subject: [PATCH 06/11] fix navigate path --- src/apps/stable/routes/session/forgotPassword/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx index c75ac9d53..9b6485022 100644 --- a/src/apps/stable/routes/session/forgotPassword/index.tsx +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -54,7 +54,7 @@ export const ForgotPasswordPage = () => { message: msg, title: globalize.translate('ButtonForgotPassword'), callback: function () { - navigate('forgotpasswordpin'); + navigate('/forgotpasswordpin'); } }); } From 3968f1ba3148798e6a92bdddcd12b52d5de45f06 Mon Sep 17 00:00:00 2001 From: Jorge Montejo Date: Wed, 30 Apr 2025 19:48:22 +0200 Subject: [PATCH 07/11] Update src/apps/stable/routes/session/forgotPassword/index.tsx Co-authored-by: Bill Thornton --- src/apps/stable/routes/session/forgotPassword/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx index 9b6485022..8458977f5 100644 --- a/src/apps/stable/routes/session/forgotPassword/index.tsx +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -77,7 +77,7 @@ export const ForgotPasswordPage = () => { return (
Date: Wed, 30 Apr 2025 19:58:38 +0200 Subject: [PATCH 08/11] use switch --- .../routes/session/forgotPassword/index.tsx | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx index 9b6485022..0fe81e7c0 100644 --- a/src/apps/stable/routes/session/forgotPassword/index.tsx +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -29,35 +29,34 @@ export const ForgotPasswordPage = () => { return response.data; }, onSuccess: (result) => { - if (result.Action == ForgotPasswordAction.ContactAdmin) { - Dashboard.alert({ - message: globalize.translate('MessageContactAdminToResetPassword'), - title: globalize.translate('ButtonForgotPassword') - }); + let msg = ''; + let callback: () => void | undefined = () => undefined; + + switch (result.Action) { + case ForgotPasswordAction.ContactAdmin: + msg = globalize.translate('MessageContactAdminToResetPassword'); + break; + case ForgotPasswordAction.InNetworkRequired: + msg = globalize.translate('MessageForgotPasswordInNetworkRequired'); + break; + case ForgotPasswordAction.PinCode: + msg = globalize.translate('MessageForgotPasswordFileCreated'); + msg += '

'; + msg += globalize.translate('MessageForgotPasswordPinReset'); + msg += '

'; + msg += result.PinFile; + msg += '
'; + callback = () => navigate('/forgotpasswordpin'); + break; + default: + return; } - if (result.Action == ForgotPasswordAction.InNetworkRequired) { - Dashboard.alert({ - message: globalize.translate('MessageForgotPasswordInNetworkRequired'), - title: globalize.translate('ButtonForgotPassword') - }); - } - - if (result.Action == ForgotPasswordAction.PinCode) { - let msg = globalize.translate('MessageForgotPasswordFileCreated'); - msg += '

'; - msg += globalize.translate('MessageForgotPasswordPinReset'); - msg += '

'; - msg += result.PinFile; - msg += '
'; - Dashboard.alert({ - message: msg, - title: globalize.translate('ButtonForgotPassword'), - callback: function () { - navigate('/forgotpasswordpin'); - } - }); - } + Dashboard.alert({ + message: msg, + title: globalize.translate('ButtonForgotPassword'), + callback: callback + }); } }); From ac28346aceb3797570e036d03e6b21739073e763 Mon Sep 17 00:00:00 2001 From: MontejoJorge Date: Wed, 30 Apr 2025 20:06:12 +0200 Subject: [PATCH 09/11] use SimpleAlert component --- .../routes/session/forgotPassword/index.tsx | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx index 0fe81e7c0..2e3045e24 100644 --- a/src/apps/stable/routes/session/forgotPassword/index.tsx +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -5,14 +5,17 @@ import globalize from 'lib/globalize'; import Button from 'elements/emby-button/Button'; import Input from 'elements/emby-input/Input'; import { useMutation } from '@tanstack/react-query'; -import Dashboard from 'utils/dashboard'; import { getUserApi } from '@jellyfin/sdk/lib/utils/api/user-api'; import { ForgotPasswordAction } from '@jellyfin/sdk/lib/generated-client/models/forgot-password-action'; import ServerConnections from 'components/ServerConnections'; +import SimpleAlert from 'components/SimpleAlert'; export const ForgotPasswordPage = () => { const navigate = useNavigate(); const [username, setUsername] = useState(''); + const [isAlertOpen, setIsAlertOpen] = useState(false); + const [alertMessage, setAlertMessage] = useState(''); + const [alertCallback, setAlertCallback] = useState<(() => void) | undefined>(undefined); const forgotPasswordMutation = useMutation({ mutationFn: async (enteredUsername: string) => { @@ -41,22 +44,17 @@ export const ForgotPasswordPage = () => { break; case ForgotPasswordAction.PinCode: msg = globalize.translate('MessageForgotPasswordFileCreated'); - msg += '

'; - msg += globalize.translate('MessageForgotPasswordPinReset'); - msg += '

'; + msg += ': '; msg += result.PinFile; - msg += '
'; callback = () => navigate('/forgotpasswordpin'); break; default: return; } - Dashboard.alert({ - message: msg, - title: globalize.translate('ButtonForgotPassword'), - callback: callback - }); + setAlertMessage(msg); + setAlertCallback(() => callback); + setIsAlertOpen(true); } }); @@ -73,11 +71,23 @@ export const ForgotPasswordPage = () => { setUsername(e.target.value); }, []); + const handleAlertClose = useCallback(() => { + setIsAlertOpen(false); + if (alertCallback) { + alertCallback(); + } + }, [alertCallback]); + return ( +
Date: Thu, 1 May 2025 12:03:00 +0200 Subject: [PATCH 10/11] Revert "use SimpleAlert component" This reverts commit ac28346aceb3797570e036d03e6b21739073e763. --- .../routes/session/forgotPassword/index.tsx | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx index 832c388a8..d0da1defc 100644 --- a/src/apps/stable/routes/session/forgotPassword/index.tsx +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -5,17 +5,14 @@ import globalize from 'lib/globalize'; import Button from 'elements/emby-button/Button'; import Input from 'elements/emby-input/Input'; import { useMutation } from '@tanstack/react-query'; +import Dashboard from 'utils/dashboard'; import { getUserApi } from '@jellyfin/sdk/lib/utils/api/user-api'; import { ForgotPasswordAction } from '@jellyfin/sdk/lib/generated-client/models/forgot-password-action'; import ServerConnections from 'components/ServerConnections'; -import SimpleAlert from 'components/SimpleAlert'; export const ForgotPasswordPage = () => { const navigate = useNavigate(); const [username, setUsername] = useState(''); - const [isAlertOpen, setIsAlertOpen] = useState(false); - const [alertMessage, setAlertMessage] = useState(''); - const [alertCallback, setAlertCallback] = useState<(() => void) | undefined>(undefined); const forgotPasswordMutation = useMutation({ mutationFn: async (enteredUsername: string) => { @@ -44,17 +41,22 @@ export const ForgotPasswordPage = () => { break; case ForgotPasswordAction.PinCode: msg = globalize.translate('MessageForgotPasswordFileCreated'); - msg += ': '; + msg += '

'; + msg += globalize.translate('MessageForgotPasswordPinReset'); + msg += '

'; msg += result.PinFile; + msg += '
'; callback = () => navigate('/forgotpasswordpin'); break; default: return; } - setAlertMessage(msg); - setAlertCallback(() => callback); - setIsAlertOpen(true); + Dashboard.alert({ + message: msg, + title: globalize.translate('ButtonForgotPassword'), + callback: callback + }); } }); @@ -71,23 +73,11 @@ export const ForgotPasswordPage = () => { setUsername(e.target.value); }, []); - const handleAlertClose = useCallback(() => { - setIsAlertOpen(false); - if (alertCallback) { - alertCallback(); - } - }, [alertCallback]); - return ( -
Date: Thu, 1 May 2025 12:10:25 +0200 Subject: [PATCH 11/11] use alert component --- .../stable/routes/session/forgotPassword/index.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/apps/stable/routes/session/forgotPassword/index.tsx b/src/apps/stable/routes/session/forgotPassword/index.tsx index d0da1defc..5d6e0ebb6 100644 --- a/src/apps/stable/routes/session/forgotPassword/index.tsx +++ b/src/apps/stable/routes/session/forgotPassword/index.tsx @@ -5,7 +5,7 @@ import globalize from 'lib/globalize'; import Button from 'elements/emby-button/Button'; import Input from 'elements/emby-input/Input'; import { useMutation } from '@tanstack/react-query'; -import Dashboard from 'utils/dashboard'; +import alert from 'components/alert'; import { getUserApi } from '@jellyfin/sdk/lib/utils/api/user-api'; import { ForgotPasswordAction } from '@jellyfin/sdk/lib/generated-client/models/forgot-password-action'; import ServerConnections from 'components/ServerConnections'; @@ -52,10 +52,11 @@ export const ForgotPasswordPage = () => { return; } - Dashboard.alert({ - message: msg, - title: globalize.translate('ButtonForgotPassword'), - callback: callback + return alert({ + text: msg, + title: globalize.translate('ButtonForgotPassword') + }).then(() => { + if (callback) callback(); }); } });