Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/pages/PasswordReset.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState } from 'react';
import {useNavigate, useSearchParams} from 'react-router';
import { apiRoutes } from '@/apiRoutes';
import {
Box, Button,
Center,
Expand All @@ -10,12 +9,13 @@ import {
Stack,
Title, useComputedColorScheme,
} from '@mantine/core';
import axios from 'axios';
import { notifications } from '@mantine/notifications';
import { IconCheck, IconX } from '@tabler/icons-react';
import Logo from '../images/ots-logo.png';
import axios from 'axios';
import { useState } from 'react';
import { useNavigate, useSearchParams } from 'react-router';
import { Header } from '../components/Header';
import { apiRoutes } from '@/apiRoutes';
import Logo from '../images/ots-logo.png';

export default function PasswordReset() {
const [searchParams, setSearchParams] = useSearchParams();
Expand All @@ -34,11 +34,15 @@ export default function PasswordReset() {
).then(r => {
if (r.status === 200) {
notifications.show({
message: 'Your password has been changed',
message: 'Your password has been changed. You will be logged out.',
color: 'green',
icon: <IconCheck />,
});
navigate('/login');
axios.post(apiRoutes.logout).finally(() => {
localStorage.clear();
navigate('/login');
});
}
}).catch(err => {
notifications.show({
Expand Down
17 changes: 13 additions & 4 deletions src/pages/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
TableData,
TextInput, useComputedColorScheme,
} from '@mantine/core';
import React, { useEffect, useState } from 'react';
import { IconCheck, IconUserPlus, IconX } from '@tabler/icons-react';
import { notifications } from '@mantine/notifications';
import axios from '../axios_config';
import { IconCheck, IconUserPlus, IconX } from '@tabler/icons-react';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router';
import { apiRoutes } from '../apiRoutes';
import axios from '../axios_config';

export default function Users() {
const [users, setUsers] = useState<TableData>({
Expand All @@ -32,6 +33,7 @@ export default function Users() {
const [confirm_password, setConfirmPassword] = useState('');
const [role, setRole] = useState('');
const computedColorScheme = useComputedColorScheme('light', { getInitialValueInEffect: true });
const navigate = useNavigate();

function getUsers() {
axios.get(
Expand Down Expand Up @@ -215,10 +217,17 @@ export default function Users() {
getUsers();
setShowResetPassword(false);
setPassword('');
const isSelf = username === localStorage.getItem('username');
notifications.show({
message: `${username}'s password has been changed`,
message: isSelf ? 'Your password has been changed. You will be logged out.' : `${username}'s password has been changed`,
color: 'green',
});
if (isSelf) {
axios.post(apiRoutes.logout).finally(() => {
localStorage.clear();
navigate('/login');
});
}
}
}).catch(err => {
notifications.show({
Expand Down