0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

refactor(console): add loading state to confirm reset password form (#2779)

This commit is contained in:
Xiao Yijun 2022-12-30 15:27:26 +08:00 committed by GitHub
parent c92120b1c1
commit 0e9a214140
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,6 @@
import type { User } from '@logto/schemas';
import { nanoid } from 'nanoid';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import ConfirmModal from '@/components/ConfirmModal';
@ -15,10 +16,13 @@ const ResetPasswordForm = ({ onClose, userId }: Props) => {
keyPrefix: 'admin_console',
});
const api = useApi();
const [isLoading, setIsLoading] = useState(false);
const onSubmit = async () => {
const password = nanoid(8);
setIsLoading(true);
await api.patch(`/api/users/${userId}/password`, { json: { password } }).json<User>();
setIsLoading(false);
onClose?.(password);
};
@ -26,6 +30,7 @@ const ResetPasswordForm = ({ onClose, userId }: Props) => {
<ConfirmModal
isOpen
title="user_details.reset_password.title"
isLoading={isLoading}
onCancel={() => {
onClose?.();
}}