Uniformize success/error alerts across forms
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { get, post } from '../api';
|
||||
import PageLayout from '../components/PageLayout';
|
||||
import Alert from '../components/Alert';
|
||||
|
||||
export default function Wifi() {
|
||||
const [config, setConfig] = useState({ ssid: '', password: '' });
|
||||
@@ -36,15 +37,15 @@ export default function Wifi() {
|
||||
const save = async () => {
|
||||
try {
|
||||
await post('/api/v1/config/wifi', config);
|
||||
setMsg('Configuração gravada com sucesso!');
|
||||
setMsg('Alterações guardadas com sucesso!');
|
||||
} catch {
|
||||
setMsg('Erro ao gravar.');
|
||||
setMsg('Erro ao guardar alterações.');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<PageLayout title="Configuração Wi-Fi">
|
||||
{msg && <div className="p-2 mb-2 bg-gray-200 rounded">{msg}</div>}
|
||||
{msg && <Alert type={msg.startsWith('Erro') ? 'error' : 'success'}>{msg}</Alert>}
|
||||
|
||||
{loading ? (
|
||||
<p>A carregar...</p>
|
||||
|
||||
Reference in New Issue
Block a user