diff --git a/src/App.tsx b/src/App.tsx index e48c453..fd3a55c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,12 +13,12 @@ import FileUpload from './components/FileUpload'; import Profil from './components/Profil'; import useSWR from 'swr'; import {getUser} from './services/PhpApi' -import toast, { Toaster } from 'react-hot-toast'; import { TUser } from './context/UserContext'; import PasswordReset from './components/PasswordReset'; import WantNewPw from './components/WantNewPw'; import { MantineProvider } from '@mantine/core'; import { NotificationsProvider } from '@mantine/notifications'; +import { notificationError } from './services/Notifications'; const App: React.FC = () => { @@ -29,10 +29,9 @@ const App: React.FC = () => if (error) { - toast.error(error.message); + notificationError(error.message); return ( <> -
failed to load
); } diff --git a/src/components/DogContactForm.tsx b/src/components/DogContactForm.tsx index a8fe33c..1b1e825 100644 --- a/src/components/DogContactForm.tsx +++ b/src/components/DogContactForm.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import toast, { Toaster } from "react-hot-toast"; +import { notificationError, notificationSuccess } from "../services/Notifications"; import { foundMsg, logFormData } from "../services/PhpApi"; import './ContactForm.css'; @@ -38,7 +38,7 @@ export default function DogContactForm( if(!Object.values(formData).every(val => val.trim() !== '')) { - toast.error('Bitte alle Felder ausfüllen!'); + notificationError('Bitte alle Felder ausfüllen!'); return; } @@ -67,12 +67,12 @@ export default function DogContactForm( if(data.success) { - toast.success('Eine Kopie wurde auch an ' + toEmail + ' geschickt!'); - toast.success('Nachricht gesendet!'); + notificationSuccess('Eine Kopie wurde auch an ' + toEmail + ' geschickt!'); + notificationSuccess('Nachricht gesendet!'); } else if(!data.success && data.message) { - toast.error(data.message); + notificationError(data.message); } } @@ -80,7 +80,6 @@ export default function DogContactForm( <>
-
Bitte schreib eine Email:
diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 8646626..1dc01bb 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -2,7 +2,7 @@ import './Header.css'; import '../App.css'; import './InputForm.css'; import {logOut} from '../services/PhpApi' -import { toast, Toaster } from 'react-hot-toast'; +import { notificationSuccess } from '../services/Notifications'; function Header() @@ -10,14 +10,13 @@ function Header() const logOutForm = () => { logOut(); - toast.success("logged out!"); + notificationSuccess("logged out!"); window.location.href = '/dog/'; } return (
-
Header
diff --git a/src/components/PasswordReset.tsx b/src/components/PasswordReset.tsx index 301a7e5..4408910 100644 --- a/src/components/PasswordReset.tsx +++ b/src/components/PasswordReset.tsx @@ -1,9 +1,9 @@ import React, { useState } from 'react'; -import toast, { Toaster } from 'react-hot-toast'; import { Link, useParams } from 'react-router-dom'; import { passwordReset, getPwToken } from '../services/PhpApi'; import useSWR from 'swr'; import './InputForm.css'; +import { notificationError, notificationSuccess } from '../services/Notifications'; export default function PasswordReset() { @@ -31,7 +31,6 @@ export default function PasswordReset() { return(
-

Email nicht mehr gültig!

) @@ -43,13 +42,13 @@ export default function PasswordReset() if(!Object.values(formData).every(val => val.trim() !== '')) { - toast.error('Bitte alle Felder ausfüllen!'); + notificationError('Bitte alle Felder ausfüllen!'); return; } if(formData.password1 !== formData.password2) { - toast.error('Bitte 2mal das gleiche Passwort eingeben!'); + notificationError('Bitte 2mal das gleiche Passwort eingeben!'); return; } @@ -68,18 +67,17 @@ export default function PasswordReset() const dataRes = await passwordReset(sendData); if(dataRes.success) { - toast.success('Erfolgreich Passwort geändert!'); + notificationSuccess('Erfolgreich Passwort geändert!'); e.currentTarget?.reset(); } else if(!dataRes.success && dataRes.message) { - toast.error(dataRes.message); + notificationError(dataRes.message); } } return (
-

Passwort zurücksetzten!

diff --git a/src/components/Profil.tsx b/src/components/Profil.tsx index 48fef22..289a277 100644 --- a/src/components/Profil.tsx +++ b/src/components/Profil.tsx @@ -1,7 +1,6 @@ import React, { useRef, useState } from 'react'; import useSWR from 'swr'; import { Link } from 'react-router-dom'; -import toast, { Toaster } from 'react-hot-toast'; import {TUser} from '../context/UserContext'; import {getProfilData, updateDog} from '../services/PhpApi'; import CreateQr from '../services/CreateQr'; @@ -9,6 +8,7 @@ import Img from './Img'; import './InputForm.css'; import './Profil.css'; import { TextInput } from '@mantine/core'; +import { notificationError, notificationSuccess } from '../services/Notifications'; function Profil() { @@ -74,13 +74,14 @@ function Profil() }; } - const onChangeInput = (e: React.FormEvent ) => + const onChangeInput = (e: React.FormEvent) => { formData_loc = { ...formData_loc, - [e.currentTarget.name]:e.currentTarget.value + [e!.currentTarget.name]:e!.currentTarget.value }; + setFormData(formData_loc); edit.current = true; formDataSave.current = {...formData_loc}; @@ -90,21 +91,25 @@ function Profil() { if(data.success) { - toast.success('Daten geändert!'); + notificationSuccess('Daten geändert!'); } else if(!data.success && data.message) { - toast.error(data.message); + notificationError(data.message); } } const submitForm = async (e: React.FormEvent) => { e.preventDefault(); + console.log(formData); + console.log(formData_loc); + console.log(formDataSave.current); + if(!Object.values(formData).every(val => val?.trim() !== '')) { - toast.error('Bitte alle Felder ausfüllen!'); + notificationError('Bitte alle Felder ausfüllen!'); return; } setFormData(formData); @@ -143,7 +148,6 @@ function Profil() return (
-

Profil

diff --git a/src/components/WantNewPw.tsx b/src/components/WantNewPw.tsx index 96ec406..abee320 100644 --- a/src/components/WantNewPw.tsx +++ b/src/components/WantNewPw.tsx @@ -1,6 +1,6 @@ import { TextInput } from '@mantine/core'; import React, { useState } from 'react' -import toast, { Toaster } from 'react-hot-toast'; +import { notificationError, notificationSuccess } from '../services/Notifications'; import {wantNewPw} from '../services/PhpApi' import './InputForm.css'; @@ -28,18 +28,17 @@ function WantNewPw() const data = await wantNewPw({email: email}); if(data.success) { - toast.success('Passwort angefordert! Bitte Postfach ' + email + ' checken!'); + notificationSuccess('Passwort angefordert! Bitte Postfach ' + email + ' checken!'); //e.currentTarget.reset(); } else if(!data.success && data.message) { - toast.error(data.message); + notificationError(data.message); } } return (
-

Neues Passwort setzen!