Skip to content

Commit

Permalink
redirect admin on username change
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Wójcik committed Jan 19, 2024
1 parent beb87ac commit 25b1719
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { pick } from 'lodash-es';
import { useEffect, useMemo, useRef, useState } from 'react';
import { Controller, SubmitErrorHandler, SubmitHandler, useForm } from 'react-hook-form';
import { useNavigate, useParams } from 'react-router';
import * as yup from 'yup';

import { useI18nContext } from '../../../../../i18n/i18n-react';
Expand Down Expand Up @@ -59,6 +60,8 @@ export const ProfileDetailsForm = () => {
user: { editUser },
groups: { getGroups },
} = useApi();
const { username: paramsUsername } = useParams();
const navigate = useNavigate();

const schema = useMemo(
() =>
Expand Down Expand Up @@ -123,11 +126,16 @@ export const ProfileDetailsForm = () => {
[MutationKeys.EDIT_USER],
editUser,
{
onSuccess: () => {
onSuccess: (_data, variables) => {
queryClient.invalidateQueries([QueryKeys.FETCH_USERS_LIST]);
queryClient.invalidateQueries([QueryKeys.FETCH_USER_PROFILE]);
toaster.success(LL.userPage.messages.editSuccess());
setUserProfile({ editMode: false, loading: false });
// if username was changed redirect to new profile page
const newUsername = variables.data.username;
if (paramsUsername !== newUsername) {
navigate(`/admin/users/${variables.data.username}`, { replace: true });
}
},
onError: (err) => {
toaster.error(LL.messages.error());
Expand Down

0 comments on commit 25b1719

Please sign in to comment.