mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
refactor(ui): update the check username api (#2294)
This commit is contained in:
parent
69f7534b32
commit
de870d6def
3 changed files with 12 additions and 13 deletions
|
@ -73,10 +73,9 @@ export const verifyRegisterEmailPasscode = async (email: string, code: string) =
|
|||
})
|
||||
.json<Response>();
|
||||
|
||||
// TODO: @simeng LOG-4503
|
||||
export const verifyUsernameExistence = async (username: string) => {
|
||||
export const checkUsername = async (username: string) => {
|
||||
await api
|
||||
.post(`${apiPrefix}/check/username`, {
|
||||
.post(`${apiPrefix}/register/password/check-username`, {
|
||||
json: {
|
||||
username,
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@ import { fireEvent, act, waitFor } from '@testing-library/react';
|
|||
|
||||
import renderWithPageContext from '@/__mocks__/RenderWithPageContext';
|
||||
import SettingsProvider from '@/__mocks__/RenderWithPageContext/SettingsProvider';
|
||||
import { verifyUsernameExistence } from '@/apis/register';
|
||||
import { checkUsername } from '@/apis/register';
|
||||
|
||||
import UsernameRegister from '.';
|
||||
|
||||
|
@ -14,7 +14,7 @@ jest.mock('react-router-dom', () => ({
|
|||
}));
|
||||
|
||||
jest.mock('@/apis/register', () => ({
|
||||
verifyUsernameExistence: jest.fn(async () => ({})),
|
||||
checkUsername: jest.fn(async () => ({})),
|
||||
}));
|
||||
|
||||
describe('<UsernameRegister />', () => {
|
||||
|
@ -40,7 +40,7 @@ describe('<UsernameRegister />', () => {
|
|||
|
||||
expect(queryByText('username_required')).not.toBeNull();
|
||||
|
||||
expect(verifyUsernameExistence).not.toBeCalled();
|
||||
expect(checkUsername).not.toBeCalled();
|
||||
});
|
||||
|
||||
test('username with initial numeric char should throw', () => {
|
||||
|
@ -57,7 +57,7 @@ describe('<UsernameRegister />', () => {
|
|||
|
||||
expect(queryByText('username_should_not_start_with_number')).not.toBeNull();
|
||||
|
||||
expect(verifyUsernameExistence).not.toBeCalled();
|
||||
expect(checkUsername).not.toBeCalled();
|
||||
|
||||
// Clear error
|
||||
if (usernameInput) {
|
||||
|
@ -80,7 +80,7 @@ describe('<UsernameRegister />', () => {
|
|||
|
||||
expect(queryByText('username_valid_charset')).not.toBeNull();
|
||||
|
||||
expect(verifyUsernameExistence).not.toBeCalled();
|
||||
expect(checkUsername).not.toBeCalled();
|
||||
|
||||
// Clear error
|
||||
if (usernameInput) {
|
||||
|
@ -111,7 +111,7 @@ describe('<UsernameRegister />', () => {
|
|||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(verifyUsernameExistence).toBeCalledWith('username');
|
||||
expect(checkUsername).toBeCalledWith('username');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ import { useCallback, useMemo } from 'react';
|
|||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { verifyUsernameExistence } from '@/apis/register';
|
||||
import { checkUsername } from '@/apis/register';
|
||||
import Button from '@/components/Button';
|
||||
import Input from '@/components/Input';
|
||||
import TermsOfUse from '@/containers/TermsOfUse';
|
||||
|
@ -54,7 +54,7 @@ const UsernameRegister = ({ className }: Props) => {
|
|||
[setFieldErrors]
|
||||
);
|
||||
|
||||
const { run: asyncVerifyUsername } = useApi(verifyUsernameExistence, errorHandlers);
|
||||
const { run: asyncCheckUsername } = useApi(checkUsername, errorHandlers);
|
||||
|
||||
const onSubmitHandler = useCallback(
|
||||
async (event?: React.FormEvent<HTMLFormElement>) => {
|
||||
|
@ -71,7 +71,7 @@ const UsernameRegister = ({ className }: Props) => {
|
|||
const { username } = fieldValue;
|
||||
|
||||
// Use sync call for this api to make sure the username value being passed to the password set page stays the same
|
||||
const result = await asyncVerifyUsername(username);
|
||||
const result = await asyncCheckUsername(username);
|
||||
|
||||
if (result) {
|
||||
navigate(`/${UserFlow.register}/${SignInIdentifier.Username}/password`, {
|
||||
|
@ -79,7 +79,7 @@ const UsernameRegister = ({ className }: Props) => {
|
|||
});
|
||||
}
|
||||
},
|
||||
[validateForm, termsValidation, fieldValue, asyncVerifyUsername, navigate]
|
||||
[validateForm, termsValidation, fieldValue, asyncCheckUsername, navigate]
|
||||
);
|
||||
|
||||
return (
|
||||
|
|
Loading…
Add table
Reference in a new issue