Files
MyClub/frontend/src/pages/admin/AdminResetPasswordPage.tsx
T
Tomáš Dvořák 12cba639b9 upload
2025-10-16 13:32:05 +02:00

49 lines
1.9 KiB
TypeScript

import React, { useState } from 'react';
import AdminLayout from '../../layouts/AdminLayout';
import { Box, Heading, FormControl, FormLabel, Input, Button, VStack, useToast, Text } from '@chakra-ui/react';
import api from '../../services/api';
const AdminResetPasswordPage: React.FC = () => {
const [email, setEmail] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [sent, setSent] = useState(false);
const toast = useToast();
const sendReset = async (e: React.FormEvent) => {
e.preventDefault();
setIsLoading(true);
try {
await api.post('/admin/users/send-reset', { email });
setSent(true);
toast({ status: 'success', title: 'Odesláno', description: 'Pokud účet existuje, byl odeslán e-mail pro reset hesla.' });
} catch (err: any) {
toast({ status: 'error', title: 'Chyba', description: err.response?.data?.error || 'Nepodařilo se odeslat e-mail.' });
} finally {
setIsLoading(false);
}
};
return (
<AdminLayout>
<Box maxW="lg">
<Heading size="md" mb={4}>Odeslat reset hesla</Heading>
<Text fontSize="sm" color="gray.600" mb={3}>
Tato akce odešle uživateli e-mail s odkazem pro nastavení nového hesla. Použije se speciální SMTP konfigurace určená pouze pro reset.
</Text>
<VStack as="form" onSubmit={sendReset} spacing={4} align="stretch">
<FormControl isRequired>
<FormLabel>Email uživatele</FormLabel>
<Input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="uzivatel@example.com" />
</FormControl>
<Button colorScheme="blue" type="submit" isLoading={isLoading}>Odeslat e-mail</Button>
{sent && (
<Text color="green.600">Pokud adresa existuje, e-mail s odkazem byl odeslán.</Text>
)}
</VStack>
</Box>
</AdminLayout>
);
};
export default AdminResetPasswordPage;